/*
	Copyright 2010 Atanas Laskov
 */
function init_menu(first){
	//$('.menuitem_in').each(function(e){ this.src = this.src.replace("_a.gif", ".gif"); });
	$('.menuitem a').hover( 
		function(e){ itemOver($(this).parent().attr("id")); }, function(e){ itemOut($(this).parent().attr("id")); }
	);
	$('.menuitem a').click(function(e){ 
		itemClick($(this).parent().attr("id")); e.preventDefault(); 
	} );
	
	linkLinks();
	if(first){
		$(".display_title").html('<img id="stitle" name="stitle" src="no_title.gif" alt="" />');
		preload("sec_"+module+".gif"); getHome();
	}else itemOver(module);
}
function getHome(){
	//Note: without this home could be rendered on top the dark bg
	if(preloadIsReady()) itemClick(module); else setTimeout("getHome();", 10);
}

function linkLinks()
{
	// Show the email form in colorbox
	//
	$("a.contact_link").colorbox({iframe:true, opacity:0.7, width: 590, height: 485, scrolling: false, initialWidth:500, initialHeight: 100});

	$("a[rel=external]").attr('target', "_blank");
	$("a[rel=section]").click(function(e){
		var args = parseLink($(this).attr('href'));
		itemClick(args['module']); e.preventDefault();
	});
	
	
}

function itemOver(id) { itemOver(id, 0.02); }
function itemOver(id) { $("#"+id+"_txt").fadeIn('fast'); }
function itemOut(id) { if(module != id) $("#"+id+"_txt").fadeOut('fast'); }

function itemClick(id){
	var old_mod = module; module = id;
	setPageCookie(module); itemOut(old_mod); itemOver(module);	
	
	file = "m_en_"+id+".php";
	title_style ="position:absolute;"+_position_string("#stitle");
	title_style +="padding-bottom: 10px; padding-right: "+Math.max(0, 260-$('#stitle').width())+"px;"
	title_style +="background-color: #ffffff;";
	navigate({
		get_file:file, target_dom:"#module_container",
		trans_append:title_style, trans_img_t: 200, 
		ready_fn: function(){ 
			$("#stitle").attr("src", "sec_"+id+".gif"); linkLinks(); init_index(); 
			if(id=="index")  $(".paging span").show(); else $(".paging span").hide();
		}
	});
}