﻿$().ready(function(){
	Banner.init();
});


Banner =
{	
	Items:null,
	current:-1,
	rotatorHandler:null,	
	
	init:function()
	{		            
		Banner.Items=$(".bannerItems .item");
		Banner.Items.hide();																
		Banner.BannerAnimation();
		Banner.Start();		
		Banner.onMouseBanner();		
	},	
	
	Start: function(){
		bannerDuration=4000;
	
		if (Banner.Items != null){
			if (Banner.Items.length>0){
				Banner.rotatorHandler=setInterval(Banner.BannerAnimation,bannerDuration)
			}		
		}		
	},
	
	BannerAnimation: function(){
		
		if(Banner.current>-1){
		$(Banner.Items[Banner.current]).animate({																						 
																opacity:0,
																fontSize:"0em",
																height:"0px",
																paddingBottom:"0px",
																width:"0px"
															 },1000,"swing",function(){this.style.display="none"})
		}
		
		Banner.current++;
		if (Banner.current>Banner.Items.length-1) Banner.current=0;
		
		if (Banner.Items[Banner.current]){ 
			$(Banner.Items[Banner.current]).css({
																	opacity:0,
																	fontSize:"0em",
																	height:"0px",
																	paddingBottom:"0px",
																	width:"0px"																																				 
															 })									
			
			Banner.Items[Banner.current].style.display="block";
			$(Banner.Items[Banner.current]).animate({																						 
																	opacity:1,
																	fontSize:"1em",																	
																	marginLeft:"38px",
																	marginRight:"25px"																	
																 },1000,"swing",function(){this.style.filter=""})			
		}
	},
	
	onMouseBanner: function(){
		$(".bannerItems .item").mouseover(function()
		{
			//Paramos la rotación cuando nos presentamos 
			//sobre la imagen en cuestión
			clearInterval(Banner.rotatorHandler);
		});
		
		$(".bannerItems .item").mouseout(function()
		{		
			Banner.Start();
		});
	}
}