/* <![CDATA[ */

//menu panes
var inter = "";var inter2 = "";var inter3 = "";var inter4 = "";

function clearTimer(){clearTimeout(inter);inter = "";}
function clearTimer2(){clearTimeout(inter2);inter2 = "";}
function clearTimer3(){clearTimeout(inter3);inter3 = "";}
function clearTimer4(){clearTimeout(inter4);inter4 = "";}
function initTimer(){inter = setTimeout("hidePane()", 600);}
function initTimer2(){inter2 = setTimeout("hidePane2()", 600);}
function initTimer3(){inter3 = setTimeout("hidePane3()", 600);}
function initTimer4(){inter4 = setTimeout("hidePane4()", 600);}
function hidePane(){$(".prods ul.group").animate({height:"hide"},"fast");$(".prods a.prodsLink").removeClass("selected");clearTimer();}
function hidePane2(){$(".sobre ul.group").animate({height:"hide"},"fast");$(".sobre a.sobreLink").removeClass("selected");clearTimer2();}
function hidePane3(){$(".locais ul.group").animate({height:"hide"},"fast");$(".locais a.locaisLink").removeClass("selected");clearTimer3();}
function hidePane4(){$(".takeAway ul.group").animate({height:"hide"},"fast");$(".takeAway a.takeAwayLink").removeClass("selected");clearTimer4();}

//map overlay
function shoot(){$('#kfcpop').jqmHide();return false;}

$(document).ready(
	function(){

		//menu prods
		$(".prods a.prodsLink").click(function(){return false});
		$(".prods a.prodsLink").mouseenter(function(){
			if(inter!="")clearTimer();
			hidePane2();//hide sobre
			hidePane4();//hide takeaway
			$(".prods ul.group").animate({height:"show"},{queue:false, duration:600, easing: "easeOutCubic"});
			$(this).addClass("selected");
		});
		$(".prods ul.group").mouseenter(function(){if(inter!="")clearTimer()});
		$(".prods a.prodsLink").mouseleave(function(){if(inter=="")initTimer()});
		$(".prods ul.group").mouseleave(function(){if(inter=="")initTimer()});
		
		
		//menu prods
		$(".takeAway a.takeAwayLink").click(function(){return false});
		$(".takeAway a.takeAwayLink").mouseenter(function(){
			if(inter4!="")clearTimer4();
			hidePane();//hide prods
			hidePane2();//hide sobre
			$(".takeAway ul.group").animate({height:"show"},{queue:false, duration:600, easing: "easeOutCubic"});
			$(this).addClass("selected");
		});
		$(".takeAway ul.group").mouseenter(function(){if(inter4!="")clearTimer4()});
		$(".takeAway a.takeAwayLink").mouseleave(function(){if(inter4=="")initTimer4()});
		$(".takeAway ul.group").mouseleave(function(){if(inter4=="")initTimer4()});
		
		
		//menu about
		$(".sobre a.sobreLink").click(function(){return false});
		$(".sobre a.sobreLink").mouseenter(function(){
			if(inter2!="")clearTimer2();
			hidePane();//hide prods
			hidePane4();//hide takeaway
			$(".sobre ul.group").animate({height:"show"},{queue:false, duration:600, easing: "easeOutCubic"});
			$(this).addClass("selected");
		});
		$(".sobre ul.group").mouseenter(function(){if(inter2!="")clearTimer2()});
		$(".sobre a.sobreLink").mouseleave(function(){if(inter2=="")initTimer2()});
		$(".sobre ul.group").mouseleave(function(){if(inter2=="")initTimer2()});
		
		
		//menu locator
		$(".locais a.locaisLink").click(function(){return false});
		$(".locais a.locaisLink").mouseenter(function(){
			if(inter3!="")clearTimer3();
			$(".locais ul.group").animate({height:"show"},{queue:false, duration:600, easing: "easeOutCubic"});
			$(this).addClass("selected");
		});
		$(".locais ul.group").mouseenter(function(){if(inter3!="")clearTimer3()});
		$(".locais a.locaisLink").mouseleave(function(){if(inter3=="")initTimer3()});
		$(".locais ul.group").mouseleave(function(){if(inter3=="")initTimer3()});
		
		
		/*
		//map overlay
		var myClose=function(hash) { hash.w.fadeOut('slow',function(){ hash.o.remove(); }); }; 
		//var myOpen=function(hash){ hash.w.css('opacity',0.88).show(); }; 
		var myOpen=function(hash){ hash.w.fadeIn('slow',function(){hash.o.show(); }); }; 
		*/
		//map overlay
		var myClose=function(hash) { $('.contentHolder').show(); hash.w.fadeOut('slow',function(){ hash.o.remove(); }); }; 
		//var myOpen=function(hash){ hash.w.css('opacity',0.88).show(); }; 
		var myOpen=function(hash){ $('.contentHolder').hide(); hash.w.fadeIn('slow',function(){hash.o.show(); }); }; 

		$('#kfcoverlay').jqm({
			iframe: 'map/overlay.php', 
			trigger: '#Overlaylink', 
			overlay: 80, 
			onHide: myClose, 
			onShow: myOpen, 
			modal:false
		});

		$('#kfcpop').jqm({
			iframe: 'map/map2.htm', 
			trigger: '#Maplink_,#Mapalink_', 
			overlay: 80, 
			onHide: myClose, 
			onShow: myOpen, 
			modal:false
		});

		$('.locais li').click(function(){
			$('#kfcpop').jqmShow();
			a=$(this).attr("value");
			b=$(this).attr("title");
			window.mapwindow.chall2(a,b);
			return false;
		});

		$('#Maplink').click(function(){
			//a=this.attr("href"); 
			$('#kfcpop').jqmShow();
			a="zero";
			b="Escolhe a tua Área...";
			window.mapwindow.chall2(a,b);
			return false;
		});

		$('#Mapalink').click(function(){
			//a=this.attr("href"); 
			$('#kfcpop').jqmShow();
			a="zero";
			b="Escolhe a tua Área...";
			window.mapwindow.chall2(a,b);
			return false;
		});

	}
);

// NEWSLETTER

// pretty simple function, we pass an url, some data 
// and the target where we want the action to happen
$(document).ready(function() {
	var defautlTxt = "Email";
	$("input[name='email']").focus(function(){if($(this).val() == defautlTxt)$(this).val("");});//clean default text on focus
	$("input[name='email']").blur(function(){if($(this).val() == "")$(this).val(defautlTxt);});//write default text on blur
});

function request_action(jurl,jdata,jtarget)	
{
	if(jtarget == "#msgbox"){$("#msgbox").text("Processando pedido...");}
	//autclose
	closeMsg = function(){clearInterval(inter);$(".boxSubscribeInfo").fadeOut(function(){$(".boxSubscribeTxt").fadeIn()});}
	$.ajax({
		type: "GET",
		url: jurl,
		data: jdata,
		success: function(data){
			if(jtarget == "#msgbox"){
				//check msg type : error / success
				switch(data){
					case "Email invÃ¡lido!" :
					case "Email nÃ£o existe na base de dados!" : 
					case "Email jÃ¡ existe na base de dados!" : 
						if($("#msgbox").hasClass("infoMsg")){$("#msgbox").removeClass("infoMsg blue").addClass("errorMsg red").text(data);} 
						else if($("#msgbox").hasClass("successMsg")){$("#msgbox").removeClass("successMsg green").addClass("errorMsg red").text(data);}
						else {$("#msgbox").text(data);}
					break;
					default :
						if($("#msgbox").hasClass("infoMsg")){$("#msgbox").removeClass("infoMsg blue").addClass("successMsg green").text(data);}
						else if($("#msgbox").hasClass("errorMsg")){$("#msgbox").removeClass("errorMsg red").addClass("successMsg green").text(data);}
						else{$("#msgbox").text(data);}
					break;
				}
			} else {
				//check msg type : error / success
				switch(data){
					case "Email invÃ¡lido!" :
					case "Email nÃ£o existe na base de dados!" : 
					case "Email jÃ¡ existe na base de dados!" : 
						var msgCss = "error";
						var time = 8000;
						break;
					default :
						var msgCss = "success";
						var time = 3000;
						break;
				}
				var msg = "<span class=\"" + msgCss + "\">" + data + "</span>";
				//show msg
				$(".boxSubscribeTxt").fadeOut(function(){$(".boxSubscribeInfo").html(msg);$(".boxSubscribeInfo").fadeIn();});
				//hide msg
				$(".boxSubscribeInfo").click(function(event){closeMsg();});
				//auto hide message in 10 seconds
				inter = setInterval("closeMsg();", time);
			}
		}
	});
};


/* ]]> */

