/*******************************************************************************************
/* necesita: jquery.js e slideshow.css
/* feito por jorge con jquery e css
*******************************************************************************************/
$(document).ready(function(){
	$("#slideShow ul").css({"display":"none"})
});

$(window).bind("load", function(){
	var slideShow = $( "#slideShow" );
	var backgroundColorOnClick = "#756201";
	var slideShowPrev = slideShow.find("#slideShowPrev");
	var slideShowNext = slideShow.find("#slideShowNext");
	slideShowPrev.bind("focus",function(){this.blur();});
	slideShowNext.bind("focus",function(){this.blur();})
	var anchoSlideShow = slideShow.outerWidth() -  ( slideShowPrev.outerWidth() + slideShowNext.outerWidth() );
	var UlSlideShow = slideShow.find("ul");
	UlSlideShow.css({"display":"inline"});
	if(UlSlideShow.css("margin-left")){
		var marginLeftIni = parseInt( UlSlideShow.css("margin-left").toLowerCase().split("px").join(""));
	}
	var Nfotos = UlSlideShow.find("li").each(function(i){return this;}).length ; 
	var anchoLI = UlSlideShow.find("li:first").outerWidth();
	var anchoFoto = UlSlideShow.find("li:first img").outerWidth();
	var anchoUlSlideShow = ( Nfotos * anchoLI );
	if( anchoSlideShow < anchoUlSlideShow ){
		UlSlideShow.width( anchoUlSlideShow );
		var Nfoto = 0;
		slideShowNext.bind("click", function(){
			if( ( Nfoto * anchoLI ) < (anchoUlSlideShow - ( anchoSlideShow + marginLeftIni )) ){
				Nfoto ++;
				UlSlideShow.animate({ 
					marginLeft: parseInt( ( -1 * ( anchoLI * Nfoto ) ) + ( marginLeftIni ) ) + "px"
				}, 500 );
			}
		});
		slideShowNext.bind("mousedown", function(){
			this.backgroundColor = $(this).css("background-color");
			$(this).css({"background-color":backgroundColorOnClick});
		});
		slideShowNext.bind("mouseup mouseout", function(){
			$(this).css({"background-color": this.backgroundColor });
		});
		slideShowPrev.bind("click", function(){
			if( Nfoto > 0 ){
				UlSlideShow.animate({ 
					marginLeft: parseInt( (-1 * (anchoLI * Nfoto)) + ( anchoLI + marginLeftIni ) ) + "px"
				}, 500 );
				Nfoto --;
			}
		});
		slideShowPrev.bind("mousedown", function(){
			this.backgroundColor = $(this).css("background-color");
			$(this).css({"background-color":backgroundColorOnClick});
		});
		slideShowPrev.bind("mouseup mouseout", function(){
			$(this).css({"background-color": this.backgroundColor });
		});
	}else{
		var marginLeft = ( anchoSlideShow - anchoUlSlideShow ) / 2 + ( slideShowPrev.outerWidth());
		UlSlideShow.css({ "margin-left" : marginLeft+"px" });
	}
});