$(document).ready(function(){



/* -------------------------------------------------------------------------------------- */
/* -- CONTROLA NAVIGATION DO SITE ------------------------------------------------------- */
/* -------------------------------------------------------------------------------------- */

//esconde o background para o FF, IE7 e Safari
$(".mainPanelBgWrap").hide();
$(".registerPanelBgWrap").hide();

//inicializacao dos elementos
var animationEasing = "easeOutSine";
//var animationEasing = "easeOutSine";
//$('.subNavigation').hide();
//$('.subSubNavigation').hide();
//$('.itemsWrap img').hide();




// --------------------------------------------------------------- //
//atribui a nova source na iframe
// --------------------------------------------------------------- //
//var lastIframeSrc = "homepage/index.html";
var lastIframeSrc = $('#contentFRM').attr('src');
$.sendNewIframeSrc = function(newIframeSrc){
	if(newIframeSrc != lastIframeSrc){
		document.getElementById('contentFRM').contentWindow.contentFadeOutFormParent(newIframeSrc);
		lastIframeSrc = newIframeSrc;
	}
};

// --------------------------------------------------------------- //




// --------------------------------------------------------------- //
//control do link no logo lipton
// --------------------------------------------------------------- //
$(".mainPanelLogo a").click(function(event){
	event.preventDefault();
	$(".mainNavigation a").removeClass("active");
	newIframeSrc = $(this).attr("href");
	$.sendNewIframeSrc(newIframeSrc);
});
// --------------------------------------------------------------- //







// --------------------------------------------------------------- //
//control do carregamento do painel com os formularios
// --------------------------------------------------------------- //

$.closePainelForms = function(){
	$(".mainNavigation a").removeClass("active");
	$("#formsFRM").css("display", "none");
	$(".formsFRMContainer").animate({height: 1}, "slow", animationEasing);
};


$(".formsPanelAlign .close a").click(function(event){
	event.preventDefault();
	$.closePainelForms();
});


$(".panelLink").click(function(event){
	event.preventDefault();
	resetMainNavigation();
	$.updateHeightLoginStart();
		
	$(".mainNavigation a").removeClass("active");
	$(this).addClass("active");
	
	if($(this).attr("rel") == "contactos"){
		$("#formsFRM").attr("src", $(this).attr("href"));
		$(".formsFRMContainer").animate({height: 300}, "slow", animationEasing, function(){
			$("#formsFRM").fadeIn("slow");
			$.updateHeightLoginStop();
		});
	}
	
	if($(this).attr("rel") == "register"){
		$("#formsFRM").attr("src", $(this).attr("href"));
		$(".formsFRMContainer").animate({height: 320}, "slow", animationEasing, function(){
			$("#formsFRM").fadeIn("slow");
			$.updateHeightLoginStop();
		});
	}
	
	if($(this).attr("rel") == "change"){
		$("#formsFRM").attr("src", $(this).attr("href"));
		$(".formsFRMContainer").animate({height: 320}, "slow", animationEasing, function(){
			$("#formsFRM").fadeIn("slow");
			$.updateHeightLoginStop();
		});
	}
	
	if($(this).attr("rel") == "recoverPassword"){
		$.closePainelLogin();
		//$(".formsPanelAlign").css({width: 841});
		$("#formsFRM").attr("src", $(this).attr("href"));
		$(".formsFRMContainer").animate({height: 310}, "slow", animationEasing, function(){
			$("#formsFRM").fadeIn("slow");
			$.updateHeightLoginStop();
		});
	}

});

// --------------------------------------------------------------- //




// --------------------------------------------------------------- //
//reset das propriedades do sub e subSub
// --------------------------------------------------------------- //
function resetMainNavigation(){
	$(".mainNavigation a").removeClass("active");
	resetSubNavigation();
	resetSubSubNavigation();
};
function resetSubNavigation(){
	$(".subNavigation a").removeClass("active");
	$(".subNavigation").slideUp("slow", animationEasing);
};
function resetSubSubNavigation(){
	$(".subSubNavigation a").removeClass("active");
	$(".subSubNavigation").slideUp("slow", animationEasing);
	$(".itemsWrap").slideUp("slow", animationEasing);
};
// --------------------------------------------------------------- //




// --------------------------------------------------------------- //
//relaciona a altura no painel de login com o painel de navegacao
// --------------------------------------------------------------- //
var diffHeight = $(".userPanelAlign").height() - $(".mainPanelAlign").height();
$.updateHeightLoginStart = function(){
	//$(".developmentTrace").append('<p>start</p>');
	$.updateHeightInterval = setInterval(updateHeightLogin, 50);
	function updateHeightLogin(){
		heightToFollow = $(".mainPanelAlign").height();
		heightFinal = heightToFollow+diffHeight;
		$(".userPanelAlign").animate({height: heightFinal}, {duration: 90, queue: false});
	};
};
$.updateHeightLoginStop = function(){
	//$(".developmentTrace").append('<p>stop</p>');
	clearInterval($.updateHeightInterval);
};
// --------------------------------------------------------------- //




// --------------------------------------------------------------- //
//control das animacoes dos submenus
// --------------------------------------------------------------- //
$(".mainNavigation a:not(.externalLink, .panelLink)").click(function(event){
	event.preventDefault();
	$.updateHeightLoginStart();
	resetSubNavigation();
	resetSubSubNavigation();
	
	$(".mainNavigation a").removeClass("active");
	$(this).addClass("active");
	
	if($(this).attr("href") == ""){
		$("."+$(this).attr("rel")).slideDown("slow", function(){
			$.updateHeightLoginStop();		
		}, animationEasing);
	}else{
		newIframeSrc = $(this).attr("href");
		$.sendNewIframeSrc(newIframeSrc);
	}
});
// --------------------------------------------------------------- //

// --------------------------------------------------------------- //
//control das animacoes dos subsubmenus
// --------------------------------------------------------------- //
$(".subNavigation a").click(function(event){
	event.preventDefault();
	$.updateHeightLoginStart();
	resetSubSubNavigation();
	
	$(".subNavigation a").removeClass("active");
	$(this).addClass("active");
	
	if($(this).attr("href") == ""){
		$("."+$(this).attr("rel")).slideDown("slow", function(){
			$.updateHeightLoginStop();
		}, animationEasing);
	}else{
		newIframeSrc = $(this).attr("href");
		$.sendNewIframeSrc(newIframeSrc);
	}
});
// --------------------------------------------------------------- //

// --------------------------------------------------------------- //
//control do acordeon dos produtos
// --------------------------------------------------------------- //
$(".subSubNavigation li").find("a:first").click(function(event){
	//event.preventDefault();
	$.updateHeightLoginStart();

	if($(this).is(".active")){
		$(this).next(".itemsWrap").slideToggle(function(){
			$.updateHeightLoginStop();
		});
	} else {
		$(".subSubNavigation a").removeClass("active");
		$(".itemsWrap").slideUp(450, animationEasing);
		$(this).addClass("active").next(".itemsWrap").slideDown(400, function(){
			$.updateHeightLoginStop();
		}, animationEasing);
	}
});
// --------------------------------------------------------------- //

// --------------------------------------------------------------- //
//control dos produtos
// --------------------------------------------------------------- //
$(".subSubNavigation a:not(.externalLink)").click(function(event){
	event.preventDefault();
	if($(this).attr("href") != ""){
		resetMainNavigation();
		$.updateHeightLoginStart();
		newIframeSrc = $(this).attr("href");
		$.sendNewIframeSrc(newIframeSrc);
	}
});
$(".itemsWrap a").hover(
	function(){
		$(this).next("span").animate({opacity: 1}, {duration: 500, queue: false}, animationEasing);
	},
	function(){
		$(this).next("span").animate({opacity: 0}, {duration: 500, queue: false}, animationEasing);
	}
);
// --------------------------------------------------------------- //

//	var theURL = GET_HTTP_QueryString("theURL");
//	if (theURL.indexOf('http://')==-1 ) 
//	{
//		if (theURL =='/contactos/contacto_form.html')
//		{
//			$('#contactos_btn').click();
//		} 
//		else if (theURL =='lipton')
//		{
//			$("a[rel='lipton']").click();
//		}
//		else if (theURL =='ice_tea')
//		{
//			$("a[rel='lipton']").click();
//			$("a[rel='icetea']").click();
//			$('.subSubNavigation.icetea li.last a:first').click();
//		}
//		else if (theURL =='tea')
//		{
//			$("a[rel='lipton']").click();
//			$("a[rel='tea']").click();
//		} else {
//			document.getElementById("contentFRM").src = theURL;
//			lastIframeSrc = theURL;
//		}
//	} 





/* -------------------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------------------- */





});













/* ----------------------------------------------------------------------------------------------------------------------------------------------- */
/* --  Resolve o problema das imagens em background onOver - NO IE  -- */
/* ----------------------------------------------------------------------------------------------------------------------------------------------- */
try{document.execCommand("BackgroundImageCache", false, true);}
catch(err){}
/* ----------------------------------------------------------------------------------------------------------------------------------------------- */
/* ----------------------------------------------------------------------------------------------------------------------------------------------- */
