/* -- start ready ------------ */
$(document).ready(function(){

//inicializacao dos elementos
var animationEasing = "easeInOutQuad";




/* -------------------------------------------------------------------------------------- */
/* -- AJUSTA A ALTURA DOS CONTAINERS PARA O BACKGROUND IMAGE OU FLASH ------------------- */
/* -------------------------------------------------------------------------------------- */
	//alert (navigator.userAgent);
	//alert($.fn.jquery);
	
	// Retifica a falha do IE7 ser reconhecido pelo "navigator.userAgent"
	$.browser.version = $.browser.msie && /msie 7\.0/i.test(navigator.userAgent) ? "7.0" : $.browser.version;

	//Altera o height do background on scroll
	$(window).scroll(function() {
		if($.browser.msie && $.browser.version=="6.0"){
			$("#pageBackgroundImage").height($("#pageLayout").height());
		}
	});

	//Altera o height do background on resize
	$(window).resize(function(){
		if($.browser.msie && $.browser.version=="6.0"){
			$("#pageBackgroundImage").height($("#pageLayout").height());
		}
	});
/* -------------------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------------------- */





/* -------------------------------------------------------------------------------------- */
/* -- CONTROLA O OVER DOS HIGHLIGHTS ---------------------------------------------------- */
/* -------------------------------------------------------------------------------------- */
$(".globalHighlight a").hover(
	function(){
		$(this).next().next(".bgConfig").animate({width:"100%"}, {duration: 500, queue: false}, animationEasing);
	},
	function(){
		$(this).next().next(".bgConfig").animate({width:"0"}, {duration: 500, queue: false}, animationEasing);
	}
);
/* -------------------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------------------- */




/* -------------------------------------------------------------------------------------- */
/* -- CAROUSEL GANHA COM LIPTON --------------------------------------------------------- */

if($('.ganhaComLipton .highlightsCarousel').length>0){
	var carouselCount = $('.ganhaComLipton .highlightsCarousel li').length;
	var carouselPosition =1;
	if(carouselCount>3){
		$('.ganhaComLipton .highlightsCarousel').after('<div class="navigation"><a href="#" id="previous">anterior</a><a href="#" class="enabled" id="next">seguinte</a></div>');
		function positionCarousel(){
			$('.ganhaComLipton .highlightsCarousel ul').animate({left:(carouselPosition-1)*-210},750,animationEasing);
			if(carouselPosition>=carouselCount-2){
				$('#next').hide()
			} else if(carouselPosition<=1){
				$('#previous').hide()			
			}
		}
		$('#previous').click(function(event){
			event.preventDefault();
			$('#next').show();
			if(carouselPosition>1){
				carouselPosition--;
				positionCarousel()
				//alert(carouselCount);
			}
		});
		$('#next').click(function(event){
			event.preventDefault();
			$('#previous').show();
			if(carouselPosition<carouselCount-2){
				carouselPosition++;
				positionCarousel()
				//alert(carouselCount);
			}
		});
	}
};


/* -------------------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------------------- */


/* --  Adiciona Botão Share do Facebook  -- */
/* ----------------------------------------------------------------------------------------------------------------------------------------------- */
if ($('.productsContainer.shared').length>0){
	var pageDirectURL = encodeURI("http://www.lipton.pt/index.aspx?p="+(window.location.pathname.substr(1)));
	$('.productsContainer.shared').append('<a id="fb_share" name="fb_share" type="button" share_url="'+pageDirectURL+'" href="http://www.facebook.com/sharer.php">Partilhar no Facebook</a><script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script>');
}


/* ----------------------------------------------------------------------------------------------------------------------------------------------- */
/* ----------------------------------------------------------------------------------------------------------------------------------------------- */






});
/* -- end ready ------------ */
















/* -------------------------------------------------------------------------------------- */
/* -- CONTROLA O FADEIN E FADEOUT DO CONTEUDO COM O FLASH ------------------------------- */
/* -------------------------------------------------------------------------------------- */

var newIframeSrc = "";

//fadeIn
function contentFadeIn(){
	$(function(){
		$(".mainContentContainer").fadeIn("slow")
	});
}

//fadeOut
function contentFadeOut(){
	$(function(){
		$(".mainContentContainer").fadeOut("slow", function(){
			 document.getElementById("layoutBgImage").contentFadeOut();
		});
	});
}
function contentFadeOutFormParent(srcFromParent){
	newIframeSrc = srcFromParent;
	contentFadeOut();
}

//Change Iframe
function changeIframeSrc(){
	$(function(){
		$("#contentFRM", parent.document).attr("src", newIframeSrc);
	});
}


//click dos highlights
$(function(){
	$(".globalHighlight a:not(.externalLink)").click(function(event){
		event.preventDefault();
		newIframeSrc = $(this).attr("href");
		contentFadeOut();
	});
});

/* -------------------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------------------- */














/* ----------------------------------------------------------------------------------------------------------------------------------------------- */
/* --  Resolve o problema das imagens em background onOver - NO IE  -- */
/* ----------------------------------------------------------------------------------------------------------------------------------------------- */
try{document.execCommand("BackgroundImageCache", false, true);}
catch(err){}
/* ----------------------------------------------------------------------------------------------------------------------------------------------- */
/* ----------------------------------------------------------------------------------------------------------------------------------------------- */




/* ----------------------------------------------------------------------------------------------------------------------------------------------- */

