
$(function(){

	// UK navi current
	if(document.URL.match('/cl/es/about/')) {
		$('#global-nav ul li#about').addClass('cu');
	}else if(document.URL.match('/cl/es/bg/')) {
		$('#global-nav ul li#bg').addClass('cu');
	}else if(document.URL.match('/cl/es/contact/')) {
		$('#global-nav ul li#contact').addClass('cu');
	}else if(document.URL.match(new RegExp('(/cl/es/index.html|/cl/es/)$'))){
		$('#home').addClass('cu');
	}

});




/* -------------------------------------------
	Mega Drop Down - 2010/12/13
------------------------------------------- */
//Use Name
var status = "normal";
var showTimer;
var hideTimer;
var navi;

//function
$(function(){
	
	//Parts Create
	$("body").append("<div id='mdd'><div class='wrapper'><div class='inner'></div></div></div>");
	$("body").append("<div class='overlayA'></div>");
	$("body").append("<div class='overlayB'></div>");
	$("body").append("<div class='overlayC'></div>");
	
	//Parts Hide
	$("div.overlayA,div.overlayB,div.overlayC").css('opacity',0).fadeTo("0",0.4).hide();
	
	$("#global-nav ul:first li:not(#home,#sitemap,#contact) a").mouseover(function(){
		$("#mdd").width(234);
		var naviX = $(this).position().left;
		$("#mdd").css("marginLeft",(naviX-469)+"px");
	});
	
	//Global Navigation
	$("#global-nav ul:first li:not(#home,#sitemap,#contact) a").hover(function(){
		
		//Set Mdd Contents
		var h = Math.max.apply( null, [document.body.clientHeight , document.body.scrollHeight, document.documentElement.scrollHeight, document.documentElement.clientHeight] );  
		$("div.overlayC").height(h -120);
		var menu = $(this).nextAll("div.mdd").html();
		navi = $(this);
		$("div#mdd div.wrapper div.inner").html("");
		$("div#mdd div.wrapper div.inner").append(menu);
		$("div#mdd div.wrapper div.inner a").click(function() {
			var path = $(this).attr('href');
			GaMddCode('MDD Link','Click',path);
		});
		$("#global-nav ul:first li a").removeClass("hover click");
		$(navi).addClass("hover");
		
		//Mouse Over Action
		if(status == "normal"){
			showTimerSet();
		}else if(status == "showTimerSet"){
			clearTimeout(showTimer);
			showTimerSet();
		}else if(status == "active"){
			$("#global-nav ul:first li a").removeClass("hover click");
			$(navi).addClass("hover");
		}else if(status == "hideTimerSet"){
			clearTimeout(hideTimer);
			status == "active";
		}

	},function(){
		
		//Mouse Out Action
		if(status == "showTimerSet"){
			clearTimeout(showTimer);
			$("#global-nav ul:first li a").removeClass("hover click");
		}else if(status == "active"){
			hideTimerSet();
		}else if(status == "hideTimerSet"){
			clearTimeout(hideTimer);
			hideTimerSet();
		}
		
	});
	
	//Mega Drop Down
	$("#mdd").hover(function(){
		if(status == "hideTimerSet"){
			clearTimeout(hideTimer);
		}
	},function(){
		if(status == "active"){
			hideTimerSet();
		}else if(status == "hideTimerSet"){
			clearTimeout(hideTimer);
			hideTimerSet();
		}
	});
	$("div.overlayA, div.overlayC").click(function(){
		if(status == "active"){
			hideMdd();
		}
	});
});

//showTimerSet
function showTimerSet(){
	status = "showTimerSet";
	showTimer = setTimeout("showMdd()",100);
}

//hideTimerSet
function hideTimerSet(){
	status = "hideTimerSet";
	hideTimer = setTimeout("hideMdd()",250);
}

//showMdd
function showMdd(){
	status = "show";
	$("div.overlayA,div.overlayB,div.overlayC,div#mdd").fadeIn("fast",function(){
		status = "active";
		$(navi).addClass("hover");
	});
}

//hideMdd
function hideMdd(){
	status = "hide";
	$("div.overlayA,div.overlayB,div.overlayC,div#mdd").fadeOut("fast",function(){
		status = "normal";
		$("#global-nav ul:first li a").removeClass("hover click");
	});
}


/* -------------------------------------------
	Mega Drop Down (tracking code) - 2011/1/19
------------------------------------------- */
function GaMddCode(category,action,path) {
	_gaq.push(['_trackEvent', category, action, path]);
}

