$(function(){
	mov.start();
	texto.init();
	flecha.init();
	
	$("#btn-big-disfraces, #btn-big-cotillon, #btn-big-eventos, #btn-big-espectaculos").bind({
								 mouseover:function(){
													   $(this).animate({
																	   opacity: 0.6
																	   },600);
													   },
								mouseout:function(){
										$(this).animate({
													   opacity: 1
													   },600);
									}
								});
	var bodyHeight = $("body").height();
	if(bodyHeight <= 665 ){
		$("#footer").css({position : 'relative'});
	}
	//alert(bodyHeight);
});

var mov={
	start:function(area){
		//$("#"+area).animate({marginTop: '-=10'},200,'easeOutQuad');
		$("#piccasa").bind({mouseover:function(){
										   $(this).animate({marginTop: '-=6'},800,'easeInOutBack');
										   $("#face_sombra").css({'opacity':0, 'display':'block'});
										  	$("#face_sombra").animate({opacity:0.8,width:'+=0'},800);
										   },
										   mouseout:function(){
											$(this).animate({marginTop: '+=6'},800,'easeInOutBack'); 
											$("#face_sombra").animate({width:'-=0',opacity:0},800,function(){$(this).css({'display':'none'})});
										   }});
		$("#facebook").bind({mouseover:function(){
										   $(this).animate({marginTop: '-=6'},800,'easeInOutBack');
										   $("#in_sombra").css({'opacity':0, 'display':'block'});
										  	$("#in_sombra").animate({opacity:0.8,width:'+=0'},800);
										   },
										   mouseout:function(){
											$(this).animate({marginTop: '+=6'},800,'easeInOutBack'); 
											$("#in_sombra").animate({width:'-=0',opacity:0},800,function(){$(this).css({'display':'none'})});
										   }});
		$("#youtube").bind({mouseover:function(){
										   $(this).animate({marginTop: '-=6'},800,'easeInOutBack');
										   $("#tw_sombra").css({'opacity':0, 'display':'block'});
										  	$("#tw_sombra").animate({opacity:0.8,width:'+=0'},800);
										   },
										   mouseout:function(){
											$(this).animate({marginTop: '+=6'},800,'easeInOutBack'); 
											$("#tw_sombra").animate({width:'-=0',opacity:0},800,function(){$(this).css({'display':'none'})});
										   }});
	}
};

var	texto={
	vars:{
		cant_p:'',
		pos_actual:1
	},
	init:function(){
			texto.vars.cant_p=$("#texto-content p");
			if(texto.vars.pos_actual==1){
				var flecha_right=$(".arrow_right");
				flecha_right.show().bind('click',function(){
														  	texto.vars.pos_actual++;
														  	$("#texto-content").animate({marginLeft: '-=400'},2000);	
															
															flecha_right.hide();
															flecha_right.unbind('click');
															texto.init();
															replaceImgAdult();
														  });
			}else if(texto.vars.cant_p.length==texto.vars.pos_actual){
				var flecha_left=$(".arrow_left a");
				flecha_left.show().bind('click',function(){
														 	texto.vars.pos_actual--;
														  	$("#texto-content").animate({marginLeft: '+=400'},2000);	
															
															flecha_left.hide();
															flecha_left.unbind('click');
															texto.init();
															replaceImgKid();
														  });	
			}else{
				var flecha_right=$(".arrow_right");
				flecha_right.show().bind('click',function(){
														  	texto.vars.pos_actual++;
														  	$("#texto-content").animate({marginLeft: '-=400'},2000);	
															
															flecha_right.hide();
															flecha_right.unbind('click');
															flecha_left.unbind('click');
															texto.init();
														  });
				var flecha_left=$(".arrow_left a");
				flecha_left.show().bind('click',function(){
														 	texto.vars.pos_actual--;
														  	$("#texto-content").animate({marginLeft: '+=400'},2000);	
															
															flecha_left.hide();
															flecha_left.unbind('click');
															flecha_right.unbind('click');
															texto.init();
														  });	
			}
	}
}

var flecha={
	init:function(){
		setInterval(flecha.animacion,3000);
	},
	animacion:function(){
		var flecha_right=$(".arrow_right");
		var flecha_left=$(".arrow_left");
		flecha_right.animate({opacity:'0.3'},1500,function(){
														   $(this).animate({opacity:'1'},1500)
														   });
		flecha_left.animate({opacity:'0.3'},1300,function(){
														   $(this).animate({opacity:'1'},1300)
														   });
	}
}

function replaceImgAdult(){
	clearTimeout(timeOut);
	$("#title").removeClass("ninos").addClass("adultos");
	$("#piccasa2").attr('href', "https://picasaweb.google.com/105446411050016527143/EspectaculosParaAdultos#");
	$("#pic").attr('href', "https://picasaweb.google.com/105446411050016527143/EspectaculosParaAdultos#");
	var images = $("#images");
	images.html("<img src='images/espectaculos/adultos/1.jpg' class='top-left over imgs2' /><img src='images/espectaculos/adultos/2.jpg' class='top-right over imgs2' /><img src='images/espectaculos/adultos/3.jpg' class='bottom-left over imgs2' /><img src='images/espectaculos/adultos/4.jpg' class='bottom-right over imgs2' /><img src='images/espectaculos/adultos/5.jpg' class='top-left down imgs2' /><img src='images/espectaculos/adultos/6.jpg' class='top-right down imgs2' /><img src='images/espectaculos/adultos/7.jpg' class='bottom-left down imgs2' /><img src='images/espectaculos/adultos/8.jpg' class='bottom-right down imgs2' />");
	imgPos = 0;
	timeMgr = 700;
	changeImgAdult();
}

function changeImgAdult(){
	timeOut  = setTimeout(function(){
						var imgOver = $(".imgs2");
						jQuery(imgOver[imgPos]).fadeOut(300, function(){
														var imgDown = $(".down");
													  $(this).removeClass("over").addClass("down");
													  
													  
													  switch(imgPos){
														 case 0:
														 	jQuery(imgDown[imgPos]).removeClass("down").addClass("over");
															imgPos = 1;
															$(this).show();
															timeMgr = 700;
														 break;
														 case 1:
														 	jQuery(imgDown[imgPos]).removeClass("down").addClass("over");
															imgPos = 2;
															$(this).show();
														 break;
														 case 2:
														 	jQuery(imgDown[imgPos]).removeClass("down").addClass("over");
															imgPos = 3;
															$(this).show();
														 break;
														 case 3:
														 	jQuery(imgDown[imgPos]).removeClass("down").addClass("over");
															imgPos = 4;
															$(this).show();
														 break;
														 case 4:
														 	jQuery(imgDown[0]).removeClass("down").addClass("over");
															imgPos = 5;
															$(this).show();
														 break;
														 case 5:
														 	jQuery(imgDown[0]).removeClass("down").addClass("over");
															imgPos = 6;
															$(this).show();
														 break;
														 case 6:
														 	jQuery(imgDown[0]).removeClass("down").addClass("over");
															imgPos = 7;
															$(this).show();
														 break;
														 case 7:
														 	jQuery(imgDown[0]).removeClass("down").addClass("over");
															imgPos = 0;
															$(this).show();
															timeMgr = 5000;
														 break;
													  }
													  changeImgAdult();
													  });
						},timeMgr);
}

function replaceImgKid(){
	$("#title").removeClass("adultos").addClass("ninos");
	$("#piccasa2").attr('href', "https://picasaweb.google.com/105446411050016527143/EspectaculosParaNinos#");
	$("#pic").attr('href', "https://picasaweb.google.com/105446411050016527143/EspectaculosParaNinos#");
	var images = $("#images");
	images.html("<img src='images/espectaculos/ninos/1.jpg' class='top-left over imgs3' /><img src='images/espectaculos/ninos/2.jpg' class='top-right over imgs3' /><img src='images/espectaculos/ninos/3.jpg' class='bottom-left over imgs3' /><img src='images/espectaculos/ninos/4.jpg' class='bottom-right over imgs3' /><img src='images/espectaculos/ninos/5.jpg' class='top-left down imgs3' /><img src='images/espectaculos/ninos/6.jpg' class='top-right down imgs3' /><img src='images/espectaculos/ninos/7.jpg' class='bottom-left down imgs3' /><img src='images/espectaculos/ninos/8.jpg' class='bottom-right down imgs3' />");
	imgPos = 0;
	timeMgr = 700;
	changeImgKid();
}

function changeImgKid(){
	timeOut  = setTimeout(function(){
						var imgOver = $(".imgs3");
						jQuery(imgOver[imgPos]).fadeOut(300, function(){
														var imgDown = $(".down");
													  $(this).removeClass("over").addClass("down");
													  
													  
													  switch(imgPos){
														 case 0:
														 	jQuery(imgDown[imgPos]).removeClass("down").addClass("over");
															imgPos = 1;
															$(this).show();
															timeMgr = 700;
														 break;
														 case 1:
														 	jQuery(imgDown[imgPos]).removeClass("down").addClass("over");
															imgPos = 2;
															$(this).show();
														 break;
														 case 2:
														 	jQuery(imgDown[imgPos]).removeClass("down").addClass("over");
															imgPos = 3;
															$(this).show();
														 break;
														 case 3:
														 	jQuery(imgDown[imgPos]).removeClass("down").addClass("over");
															imgPos = 4;
															$(this).show();
														 break;
														 case 4:
														 	jQuery(imgDown[0]).removeClass("down").addClass("over");
															imgPos = 5;
															$(this).show();
														 break;
														 case 5:
														 	jQuery(imgDown[0]).removeClass("down").addClass("over");
															imgPos = 6;
															$(this).show();
														 break;
														 case 6:
														 	jQuery(imgDown[0]).removeClass("down").addClass("over");
															imgPos = 7;
															$(this).show();
														 break;
														 case 7:
														 	jQuery(imgDown[0]).removeClass("down").addClass("over");
															imgPos = 0;
															$(this).show();
															timeMgr = 5000;
														 break;
													  }
													  changeImgKid();
													  });
						},timeMgr);
}

