//Objeto PasaFotos

function PasaFotos(referer,capa,hHeader,hFooter,f) {
	this.referer = referer;
	this.owner = this;
	this.capa = capa;
	this.hHeader = hHeader;
	this.hFooter = hFooter;
	this.hPasaFotos = 0;
	this.wFotoCerrada = 0;
	this.navWidth = 0;
	this.navHeight = 0;
	this.stoPasaFotos = 0;
	this.srcs = null;
	
	this.init = function(referer,f){
		this.referer = referer;
		owner = this;
		this.srcs = [];
		$("#pasaFotos").wrap('<div id="pasaFotosWrapper" />');
		$("#pasaFotosWrapper").css({'overflow': 'hidden'});
		$("#pasaFotos img").wrap('<div class="foto" />');
		//Almaceno algunos datos asociados a las fotos
		$("#pasaFotos .foto img").each(function(index){
			owner.srcs[index] = $(this).attr('src');
			var ratio = $(this).attr('width') / $(this).attr('height');
			$(this).data('ratio',ratio);
			$(this).data('index',index);
			$(this).bind('mouseover',function(){ 
				clearTimeout(owner.stoPasaFotos);
				var i = index;
				var w = $(this).attr('width');
				owner.stoPasaFotos = window.setTimeout(function(){owner.setActivePic(i,w);},50);
			});
			$(this).bind('mouseout',function(){
				clearTimeout(owner.stoPasaFotos);
				owner.stoPasaFotos = window.setTimeout(function(){owner.setActivePic(null,0); },100);
			});
		});
	}
	
	this.resizePasaFotos = function(navWidth,navHeight){
		this.navWidth = navWidth;
		this.navHeight = navHeight;
		this.hPasaFotos = this.navHeight - hHeader - hFooter;
		this.wFotoCerrada = Math.floor(this.navWidth / $("#pasaFotos img").length);
		$("#pasaFotos .foto").css({'width': this.wFotoCerrada+'px', 'height': this.hPasaFotos+'px'});
		var wAcum = 0;
		$("#pasaFotos .foto img").each(function(index){
			var w = owner.hPasaFotos * $(this).data('ratio');
			wAcum += w;
			$(this).attr({'width': w+'', 'height': owner.hPasaFotos+''});
		});
		var wAux = this.wFotoCerrada * $("#pasaFotos img").length;
		$("#wrapper").css({'width': wAux+'px'});
		$("#pasaFotosWrapper").css({'height': this.hPasaFotos+'px'});
		$("#pasaFotos").css({'width': wAcum+'px'});
	}
	
	
	this.setActivePic = function(indexActivo,width) {
		clearTimeout(owner.stoPasaFotos);
		var delta = (width == 0) ? 0 : 1;
		owner.wFotoCerrada = Math.ceil((owner.navWidth-width) / ($("#pasaFotos img").length-delta));
		$("#pasaFotos .foto").each(function(index){
			$(this).stop(true,false);
			var w = (index == indexActivo) ? width : owner.wFotoCerrada;
			if ($.browser.msie) {
				//if (index == 0) alert(indexActivo);
				//$(this).css({ 'width': w+'px' });
				$(this).animate({ width: w+'px' },400,'swing');
			} else {
				$(this).animate({ width: w+'px' },400,'swing');
			}
		});
	}
	this.init(referer,f);
}
