$(document).ready(function() {

	$('.slideshow').cycle({
		fx: 'fade' 
	});
	
	$(window).resize(function(){ 
		positionFooter();
    }); 
	
	function positionFooter()
	{
		var mainH = $(window).height()-($("#footer").height()+50);	
		
		if($("#body").height()<= mainH)
		{
			$("#body").css({height:mainH});
		}
	}
	positionFooter();
	
	//Slide página inicial
	$('.slideShow')
		.after('<div id="nav">')
		.cycle({
			fx:     'scrollLeft',
			easing: 'easeOutExpo',
			pager:  '#nav',
			timeout: 3000
	});
	
	var tam=0;
	$('.destaques li').each(function(i){
		$(this).height($('.destaques').height());
	});
	
	
	
	// Efeito Input
	$('.inputText').focusin(
		function(){
			$(this).addClass('inputFocus');
		}
	);
	$('.inputText').focusout(
		function(){
			$(this).removeClass('inputFocus');
		}
	);
	// Promoções
	$('.btn-participar-promo').click(function(){
		var _this = $(this);
		var rotulo = $(this).text();
		var initRotulo = decodeURIComponent( escape("Clique aqui e participe dessa promoção"));
		//alert(unescape(encodeURIComponent(initRotulo)))
		//alert(decodeURIComponent( escape(initRotulo)))

		if(rotulo == initRotulo)
		{
			$(_this).text("Voltar");
			$(_this).parent().parent().find('.promoDesc').animate({
				opacity: 'toggle'
			}, 300, 'linear', function() {
				$(_this).parent().parent().find('.promoParticipe').animate({
					opacity: 'show'
				});
			});
		}
		else
		{
			$(_this).text(initRotulo);
			$(_this).parent().parent().find('.promoParticipe').animate({
				opacity: 'toggle'
			}, 300, 'linear', function() {
				$(_this).parent().parent().find('.promoDesc').animate({
					opacity: 'show'
				});
			});
		}
	});
	
	// Programação
	$("a.viewProgramacao").hover(
		function(e){
			var obj = $(this);
			var content = $(obj).parent().find("p").html()
			if(content){
				$("body").append(
					'<div id="programacao-preview" class="border-radius">'+ content +'</div>'
				);
				
				var posY = $(this).position().top- Math.round(($(this).height()/2));
				var posX = ($(this).position().left)+$(this).width();

				if($(this).position().left>600){
					posX = ($(this).position().left)-$(this).width()-20;
				}
				
				$("#programacao-preview")
					.css("top",posY + "px")
					.css("left",posX + "px")
					.fadeIn("slow");
			}
		},
		function(e){
			$("#programacao-preview").remove();
		}
	);	
	
	
	
});
function popUp(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=300');");
}
function openBlank(URL){
	window.open(URL,'_blank');
	return false;
}
