// -----------------------------------------------------------------------------------
// 
// This page coded by Scott Upton
// http://www.uptonic.com | http://www.couloir.org
//
// Associated API copyright 2002, Travis Beckham (www.squidfingers.com)
//
// -----------------------------------------------------------------------------------
// Quicktime Video adaptation by Matias Etchevarne
// http://www.etchevarne.net
// version 06/2006
// -----------------------------------------------------------------------------------


fullscreen=function(){
	self.moveTo(0,0);self.resizeTo(screen.availWidth,screen.availHeight);
	}

API=new Detect();

loadAPI=function(){
	API.Container=new HTMLobj('portfolioSlider');
	API.Photo=new HTMLobj('imagen');
	API.PhotoContainer=new HTMLobj('imagenPortfolio');
	API.LoadImg=new HTMLobj('cargando');
cyclePhoto(photoId);
}


onload=loadAPI;

initFade=function(){
	API.PhotoContainer.show();
	var fade_timer=setInterval('startFade()',1000);
	startFade=function(){
		if(API.Container._tweenRunning==false){
		clearInterval(fade_timer);
		var adv_timer=setInterval('permitNextPrev()',500);
		permitNextPrev=function(){
			if(API.Photo._fadeRunning==false){
				clearInterval(adv_timer);
;
				for(var i=0; i<photoNum;i++){
						restoreThumbLinks(i);}
			}else{
			return;
			}
			}
	API.LoadImg.setSrc("/images/c.gif");
	API.Photo.fadeIn(0,15,33);
	vervideo()
	}else{
		return;
		}
	}
}

restoreThumbLinks=function(thumbId){
	thisThumb="Thumb"+thumbId;
	thisCyclePhoto = function(){
		if(photoId !== thumbId){
			cyclePhoto(thumbId);
			photoId = thumbId;
		}
	}
	document.getElementById(thisThumb).onclick=thisCyclePhoto;
}

falsify=function(){
	return false;
}






changeElementClass=function(objId,setClass){
	document.getElementById(objId).className=setClass;
}


toggleActiveThumb=function(newThumb){
	var oldThumb=activeThumb;
	if(oldThumb&&newThumb)changeElementClass(oldThumb,'');
	if(newThumb)changeElementClass(newThumb,'selected');
	activeThumb=newThumb;
}




cyclePhoto=function(photoId){
	API.LoadImg.setSrc("/images/loading_ani.gif");
	var newThumb="Thumb"+photoId;
	toggleActiveThumb(newThumb);
	API.Photo.hide();
	API.Photo.setOpacity(0);
	var wNew=photoArray[photoId][1];
	if (photoArray[photoId][0].toString().substring(0, 5) == 'video') {
		var hNew=Number(photoArray[photoId][2])+35;
	} else {
		var hNew=photoArray[photoId][2];
	}
	var wCur=API.Container.getWidth()-borderSize;
	var hCur=API.Container.getHeight()-borderSize;
	setTimeout('API.Container.tweenTo(easeInQuad, ['+wCur+', '+hCur+'], ['+wNew+','+hNew+'], 7)',500);
	var newPhoto=photoDir+photoArray[photoId][0];
	API.Photo.setSrc(newPhoto);
			API.Photo.sizeTo(wNew,hNew);
	document.getElementById('imagen').onload=initFade;
	for(var i=0;i<photoNum;i++){
		document.getElementById('Thumb'+i).onclick=falsify;
		}
	var imagen=photoArray[photoId][0];
	var movie = document.getElementById('movie');
	if (imagen.toString().substring(0, 5) == 'video') {
		stopMovie();
	} else {
		stopMovie();
		movie.style.left='-3000px';
	}	
}

vervideo = function (){
	stopMovie();
	var imagen=photoArray[photoId][0];
		var wNew=photoArray[photoId][1];
	var hNew=photoArray[photoId][2];
	var quevideo=photoArray[photoId][3];
	var movie = document.getElementById('movie');
	esvideo = imagen.toString().indexOf("video");
	if (esvideo != -1) {
		var numerodevideo = imagen.toString().substring(5, 6);
	}
	if (imagen.toString().substring(0, 5) == 'video') {
			if (document.pelicula) {
				movie.style.left='0';
				if (document.pelicula) {
	 				document.pelicula.SetURL(photoDir+quevideo)
 				}	
 				if (document.peliculapc) {
 				document.peliculapc.SetURL(photoDir+quevideo)
 				}			
			}
			else {
				contenedor = document.getElementById('movie');
				contenedor.innerHTML = ''
				movie.style.left='0';
				var myQTObject = new QTObject(photoDir+quevideo, "peliculapc", wNew, hNew);
				myQTObject.addParam("autostart", "true");
				myQTObject.addParam("EnableJavaSript", "true");
				myQTObject.addParam("name", "pelicula");
				innerHTML = myQTObject.write("movie");
				}
			} 
	else {
		stopMovie();
		movie.style.left='-3000px';
	}
	
	
	
		if (imagen.toString().substring(0, 5) == 'flash') {
			if (document.pelicula) {
				movie.style.left='0';
				if (document.pelicula) {
	 				document.pelicula.SetURL(photoDir+quevideo)
 				}	
 				if (document.peliculapc) {
 				document.peliculapc.SetURL(photoDir+quevideo)
 				}			
			}
			else {
				contenedor = document.getElementById('movie');
				contenedor.innerHTML = ''
				movie.style.left='0';
				swfobject.embedSWF(photoDir+quevideo, "movie", "peliculapc", "9.0.0");
				/*var myQTObject = new QTObject(photoDir+quevideo, "peliculapc", wNew, hNew);
				myQTObject.addParam("autostart", "true");
				myQTObject.addParam("EnableJavaSript", "true");
				myQTObject.addParam("name", "pelicula");
				innerHTML = myQTObject.write("movie");*/
				}
			} 
	else {
		stopMovie();
		movie.style.left='-3000px';
	}
	
	
	
}

stopMovie=function (){
	if (document.pelicula) {
 		document.pelicula.Stop();
 		}
 	if (document.peliculapc) {
 		document.peliculapc.Stop();
 		}
}
