var interval;

var home = function()
{
	var thisClass = this;


	this.init = function()
	{		
		
		// Destacados Home
		$("#slideshow").css("overflow", "hidden");
		
		$("ul#slides").cycle
		(
			{
				fx: 'scrollHorz',
				pause: 1,
				prev: '#prev',
				next: '#next',
				timeout: 10000 
			}
		);
		
		if ( $("#slides li").length > 1)
		{
			$("#slideshow").hover
			(
					function() { $("ul#nav").fadeIn(); },
					function() { $("ul#nav").fadeOut(); }
			);
		}	
		
		
		
		// Destacados Productos		
		$("ul#slidesSecundaria").cycle
		(
			{
				fx: 'fade',
				pause: 1,
				prev: '#prevSecundaria',
				next: '#nextSecundaria',
				timeout: 5000,
				pager:  '#navSecundaria',
				before: function()
				{  
					thisClass.changeImage( this.id.replace('slide_','') );
				} 
			}
		);
		
		$(".galeriaSecundaria .buttons a").click( function(){ thisClass.manualChangeImage(this.id.replace('oferta_button_','')) } );
		
	}

	this.changeImage = function(i)
	{		
		$(".galeriaSecundaria .buttons a").each
		(
			function(i,elem)
			{
				var id = elem.id.replace('oferta_button_','');
				document.getElementById("oferta_titulo_"   + id).style.display = "none";
				document.getElementById("oferta_button_" + id).className = "none";	
			}
		);
		
		document.getElementById("oferta_titulo_"   + i).style.display = "block";
		document.getElementById("oferta_button_" + i).className = "selected";		
	};
	
	this.manualChangeImage = function(i)
	{		
		thisClass.changeImage(i);
		
		$("ul#slidesSecundaria").cycle('pause');
		$('#navSecundaria a:eq(' + parseInt(i - 1)  + ')').trigger('click');
		
	};

	this.init();
}

$(document).ready( function() { new home(); } );


