$(document).ready( function(){
	
	$("a#full").fancybox({
		'overlayShow'	: true,
		'transitionIn'	: 'elastic',
		'transitionOut': 'elastic'
	});


$(".thumbs ul").each( function(){
	var idPost = $(this).attr("id");
	
	sizeUL('go');
	
	function sizeUL(type){
		
		var w = 180; // Tamanho da Imagem (Width).
		var i = 0;
		
		$(".thumbs ul#"+idPost+" li").each( function(){ i++; });
		
		if(type == 'go'){
			$(".thumbs ul#"+idPost).css("width", (i*w)+"px");
		} else if(type == 'get'){
			return (i*w);
		}
	}
	
		
	var navRight = $(".nav-right-"+idPost);
	var navLeft = $(".nav-left-"+idPost);
	var play = true;
	var thumbs = 0; $(".thumbs ul#"+idPost+" li").each( function(){ return thumbs++; });
	var y = 0; if(thumbs == 6){ y = 180*thumbs; } else { y = 180*6; }

	
	if(thumbs<=5){
		navLeft.animate({ opacity: 0 }, 100, function(){ $(this).css("display", "none"); });
		navRight.animate({ opacity: 0 }, 100, function(){ $(this).css("display", "none"); });
	} else {
		navLeft.animate({ opacity: 0 }, 100, function(){ $(this).css("display", "none"); });
	}
		
	
	navRight.click( function(){
		var left = $(".thumbs ul#"+idPost).css("left");
		
		if(play){
			play = false;
			
			navLeft.animate({ opacity: 1 }, 300, function(){ $(this).css("display","block"); });
			
			//alert(left+' | -'+((sizeUL('get')-y)+'px'));
			
			if(left == '-'+((sizeUL('get')-y)+'px')){
				$(".thumbs ul#"+idPost).animate({ 
					left: '-='+200,
					opacity: 0.8
				}, 350, function(){ 
							$(this).animate({
								 left:'+='+20, 
								 opacity: 1
							}, 250, function(){
									play = true;
							});
				});
						
				navRight.animate({ opacity: 0 }, 300, function(){ $(this).css("display", "none"); });
			} else {
				$(".thumbs ul#"+idPost).animate({ 
					left: '-='+200,
					opacity: 0.8
				}, 350, function(){ 
							$(this).animate({
								 left:'+='+20, 
								 opacity: 1
							}, 250, function(){
									play = true;
							});
				});
			}
		}
		
	});
	
	navLeft.click( function(){
		var left = $(".thumbs ul#"+idPost).css("left");
		
		if(play){
			play = false;
			navRight.animate({ opacity: 1 }, 300, function(){ $(this).css("display", "block"); });
			if(left == "-180px") {
				$(".thumbs ul#"+idPost).animate({ 
					left: '+='+200,
					opacity: 0.8
				}, 350, function(){ 
							$(this).animate({
								 left:'-='+20, 
								 opacity: 1
							}, 250, function(){
									play = true;
							});
				});
				navLeft.animate({ opacity: 0 }, 300, function(){ $(this).css("display", "none") });
			} else {
				$(".thumbs ul#"+idPost).animate({ 
					left: '+='+200,
					opacity: 0.8
				}, 350, function(){ 
							$(this).animate({
								 left:'-='+20, 
								 opacity: 1
							}, 250, function(){
									play = true;
							});
				});
			}
		}
		
	});

}); // End Foreach id Post	



	// Slider Emergencias Index
	
	EmergenciaSizeUL('go');
	
	function EmergenciaSizeUL(type){
		
		var w = 438; // Tamanho da Imagem (Width).
		var i = 0;
		
		$(".content-primeiros-socorros ul li").each( function(){ i++; });
		
		if(type == 'go'){
			$(".content-primeiros-socorros ul").css("width", (i*w)+"px");
		} else if(type == 'get'){
			return (i*w);
		}
	}
	
		
	var navNext = $(".next"); // right
	var navPrevious = $(".previous");
	var play = true;
	var thumbs = 0; $(".content-primeiros-socorros ul li").each( function(){ return thumbs++; });
	var y = 0; if(thumbs == 2){ y = 438*thumbs; } else { y = 438*2; }

	
	if(thumbs<=1){
		navPrevious.animate({ opacity: 0 }, 100, function(){ $(this).css("display", "none"); });
		navNext.animate({ opacity: 0 }, 100, function(){ $(this).css("display", "none"); });
	} else {
		navPrevious.animate({ opacity: 0 }, 100, function(){ $(this).css("display", "none"); });
	}
		
	
	navNext.click( function(){
		var left = $(".content-primeiros-socorros ul").css("left");
		
		if(play){
			play = false;
			
			navPrevious.animate({ opacity: 1 }, 300, function(){ $(this).css("display","block"); });
			
			//alert(left+' | -'+((sizeUL('get')-y)+'px'));
			
			if(left == '-'+((EmergenciaSizeUL('get')-y)+'px')){
				$(".content-primeiros-socorros ul").animate({ 
					left: '-='+450,
					opacity: 0.8
				}, 350, function(){ 
							$(this).animate({
								 left:'+='+12, 
								 opacity: 1
							}, 250, function(){
									play = true;
							});
				});
						
				navNext.animate({ opacity: 0 }, 300, function(){ $(this).css("display", "none"); });
			} else {
				$(".content-primeiros-socorros ul").animate({ 
					left: '-='+450,
					opacity: 0.8
				}, 350, function(){ 
							$(this).animate({
								 left:'+='+12, 
								 opacity: 1
							}, 250, function(){
									play = true;
							});
				});
			}
		}
		
	});
	
	navPrevious.click( function(){
		var left = $(".content-primeiros-socorros ul").css("left");
		
		if(play){
			play = false;
			navNext.animate({ opacity: 1 }, 300, function(){ $(this).css("display", "block"); });
			if(left == "-438px") {
				$(".content-primeiros-socorros ul").animate({ 
					left: '+='+450,
					opacity: 0.8
				}, 350, function(){ 
							$(this).animate({
								 left:'-='+12, 
								 opacity: 1
							}, 250, function(){
									play = true;
							});
				});
				navPrevious.animate({ opacity: 0 }, 300, function(){ $(this).css("display", "none") });
			} else {
				$(".content-primeiros-socorros ul").animate({ 
					left: '+='+450,
					opacity: 0.8
				}, 350, function(){ 
							$(this).animate({
								 left:'-='+12, 
								 opacity: 1
							}, 250, function(){
									play = true;
							});
				});
			}
		}
		
	});



	

	$("#telefone").mask('(99) 9999-9999');



	
});

	
