/**************************************************************** 
	EKUANA folio application
	v0.2
	14.07.2007
	all righta reserved


*****************************************************************/


//global variables

//var folio = "";
//var imgTotal = 0;
//var imgCurrent = 0;
//var imgPath = "vault/"+vault+"/";
var typeoffolio = "";
//end global varibales
var appFolio = {
	init:function(){
		
		folioraw = "<%=request.querystring('folio')%>";
		if(folioURL !="none"){
			folio = folioURL.split("_")[1];
		} else {
			folio = "Photo1";	
		}
		console.log('init folio app: '+folio);
		imgTotal = 0;
		imgCurrent = "imgload";
		imgPath = "vault/"+vault+"/"+folio+"/";
		//clean up existing artist
		//$('photographe_nom').update(nomPhotographe);
		//$('menubar_folio2').update('');
		
		
		//load folios
		appCategories = $A(folioCategories);
		appFolio.setupCat();
	
	},
	

	
	setupCat:function(){
		counterid = 0;
		//update nom photographe
		var text_nom = nomPhotographe+" - "+titrePhotographe;
		new Insertion.Bottom('nomArtiste',text_nom);
		//$('siteweb').href=urlSiteweb;
		
		appCategories.each(function(catName){
			var foliotype = catName.split("_")[0];
			var folioname = catName.split("_")[1];
			var foliotitle = eval(folioname+"_title");
			var menuText = "<a href='"+langvar+".asp?id="+vault+"&amp;folio="+catName+"' class='menu3' id='"+folioname+"'>"+foliotitle+"</a>"	;
			
			//insert categories into menu container folio2
			new Insertion.Bottom('menubar_folio2',menuText);
			
			counterid++;
			//create array for folios in this category
			
			
			//debug
			console.log("Setup Category: "+catName);
			console.log(menuText);
			
		});
		
		//insert production menu option
		//insert categories into menu container folio2
		
		//var menuText = "<a href='"+langvar+".asp' class='menu3' id='production'>Production</a>"	;
		//new Insertion.Bottom('menubar_folio2',menuText);
		
		//SETUP folio
		console.log("setup first folio: "+appCategories.first());
		
		 // check if first folio or not;
		 defaultFolio = appCategories.first().split("_")[1];
		 console.log("setup first folio name: "+defaultFolio);
		 if(folioURL=="none"){appFolio.setupFolio(appCategories.first(), "prodstate");
		 }else
			{appFolio.setupFolio(folioURL, "foliostate")};
	
	},
	
	setupFolio:function(catName,stateId){
		//clean up
		var foliotype = catName.split("_")[0];
		var foliotitle = catName.split("_")[1];
		$(foliotitle).toggleClassName('menu5');
		$('thumbnav').innerHTML="";
		$('credits_details').innerHTML="";
		console.log("folio type: "+foliotype);
		
		var folioList = $A(eval(foliotitle));
	if(foliotype =="img") {	
		//BEGIN IMAGE FOLIO SETUP
		typeoffolio = "img";
		//$('stripes_img').show();
		//$('stripes_video').hide();
		$('videoplayer').hide();
		$('img_container').show();
		$('prod_services').hide();
		folio = foliotitle;
		var imgnumber = 0	
		folioList.each(function(catName){
			thumbimg = "<img src='"+imgPath+"thumbs/"+folioList[imgnumber]+"' class='thumb1' id='thumb_"+imgnumber+"' onmouseover='appFolio.chgImg(&#39;main_image_"+imgnumber+"&#39;);$(&#39;prod_services&#39;).hide();'  />";						
			new Insertion.Bottom('thumbnav',thumbimg);
			console.log("imgname: "+folioList[imgnumber]);
			imgnumber++;
		});
		
		// adjust last 2 images
		
		if(imgnumber>=10){
		var imglast = imgnumber-2;
		$('thumb_'+imglast).style.marginRight="4px";
		imglast = imgnumber-3;
		$('thumb_'+imglast).style.marginRight="4px";};
		//setup first image
		appFolio.preLoad(folioList);
		appFolio.chgImg('main_image_0');
		//preload rest of folio
		
		//debug
		console.log("Setup Folios for: "+catName);
		console.log("List of images for folio: "+folioList);
		//END IMAGE FOLIO SETUP
	  }
	  //BEGIN VIDEO SETUP
	  if(foliotype =="video"){
   	    typeoffolio = "video";
		//$('stripes_img').hide();
 	    //$('stripes_video').show();
  		$('videoplayer').show();
		$('prod_services').hide();
		$('img_container').hide();
		  
		folio = foliotitle;
		var imgnumber = 0	
		folioList.each(function(catName){
			thumbsrc = folioList[imgnumber].split(".")[0]+".png";					
			thumbimg = "<img src='vault/"+vault+"/video/thumbs/"+thumbsrc+"' class='thumb1' id='thumb_"+imgnumber+"' onclick='appFolio.chgVideo(&#39;"+catName+"&#39;,"+imgnumber+");'  />";						
			new Insertion.Bottom('thumbnav',thumbimg);
			console.log("videoname: "+folioList[imgnumber]);
			imgnumber++;
		});
		
		
	
		
		// adjust last 2 images
		
		if(imgnumber>=10){
		var imglast = imgnumber-2;
		$('thumb_'+imglast).style.marginRight="4px";
		imglast = imgnumber-3;
		$('thumb_'+imglast).style.marginRight="4px";};
		//setup first video
		appFolio.chgVideo(folioList[0],0);
		//preload rest of folio
		
		//debug
		console.log("Setup Folios for: "+catName);
		console.log("List of images for folio: "+folioList);		  
	  }
	  
	  	//adjust production or not
		if(stateId=="prodstate"){
			$('prod_services').show();
			$('credits_details').hide();
			$('img_container').hide();
			
		}
	  
	},
	
	chgVideo : function(videoid,imgid){
		
		console.log("chgVideo to "+ videoid);
		//credits routine somewhere here;
		//video format mp4 480 x 358
		
		$('videoplayer').innerHTML="<embed type='video/mp4' src='vault/"+vault+"/video/"+videoid+"' name='plugin' height='100%' width='100%'>";
		$('videocredits').innerHTML = eval(folio+"_credits_"+(imgid+1));
	},
	
	/*
	nextImg:function(){
		
		(imgCurrent<imgTotal) ? imgNext = imgCurrent+1 : imgNext = 0;
		
		appFolio.chgImg(imgPath+folio[imgNext]);
		
		//debug
		console.log("Current imagearray no: "+imgCurrent);
		console.log("Next image number is:"+imgNext);
	
		imgCurrent = imgNext;
		appFolio.updateNo(imgCurrent,'currentImg');
	},

	prevImg:function(){
		
		(imgCurrent<1) ? imgPrev = imgTotal : imgPrev = imgCurrent-1;
		
		appFolio.chgImg(imgPath+folio[imgPrev]);
		
		//debug
		console.log("Current imagearray no: "+imgCurrent);
		console.log("Prev image number is:"+imgPrev);
	
		imgCurrent = imgPrev;
		appFolio.updateNo(imgCurrent,'currentImg');
	},
	*/
	chgImg:function(newID){
		$('credits_details').show();
		$('img_container').show();
		//$('prod_services').hide();
		$(imgCurrent).hide();
		$(newID).show();
		imgCurrent = newID;
		//$('main_image').src = imgPath+imageID;
		//setTimeout("$('main_image').show();",200);
		//Effect.Appear('main_image',{duration:1.0});
		
		//change credits
		imgnumber = eval((newID).split("_")[2]);
		imgnumber++;
		$('credits_details').innerHTML = eval(folio+"_credits_"+imgnumber);
		
		//console.log("changing image to : "+imageID);
	},
	
	preLoad:function(folioImg){
		//add path to images
		var imglistText = "";
		imgCounter=0;
		folioImg.each(function(imgName){
							   
			MM_preloadImages(imgPath+imgName);
			console.log("Images to preload: "+imgPath+imgName);
			console.log("Images to preload: "+imgPath+imgName);
			var imgHTML="<img src='"+imgPath+imgName+"' width='100%' height='100%' id='main_image_"+imgCounter+"' style='display:none;'/>";
			new Insertion.Bottom('preloadimg',imgHTML);
			imgCounter++;

			
		});
		//preload images

	}
	
	
};





var appPromo = {
	init:function(){
		promoTotal = promo_img.length-1;
		console.log("total images in promo : "+promoTotal);
		promoCurrent = 0;
		promoNext = 0;
		promoPath = "vault/rodeo/promo/";
		//appPromo.chgPromo(promoPath+promo_img[0]);
		
		appPromo.chgCredits(promoCurrent);
		appPromo.preLoad();
		$('prod_promo_0').show();
		slideshow_play = true;
		appPromo.slideshow();
		
	},
	
	preLoad:function(){
		var imglistText = "";
		imgCounter = 0;
		promo_img.each(function(imgName){
							   
			MM_preloadImages(promoPath+imgName);
			console.log("Images to preload: "+promoPath+imgName);
			var imgHTML="<img src='"+promoPath+imgName+"' width='435' height='100%' id='prod_promo_"+imgCounter+"' style='display:none;'/>";
			new Insertion.Bottom('preloadimg',imgHTML);
			imgCounter++;
		});
		//preload images		
	},
	nextPromo:function(){
		if(slideshow_play==true){clearTimeout(time_appear)};
		slideshow_play = false;
		(promoCurrent<promoTotal) ? promoNext = promoCurrent+1 : promoNext = 0;
		
		appPromo.chgPromo(promoPath+promo_img[promoNext]);
		appPromo.chgCredits(promoNext);
		//
		promoCurrent = promoNext;
		
		
	},
	prevPromo:function(){
		if(slideshow_play==true){clearTimeout(time_appear)};
		slideshow_play = false;
		(promoCurrent<1) ? promoPrev = promoTotal : promoPrev = promoCurrent-1;
		
		appPromo.chgPromo(promoPath+promo_img[promoPrev]);
		appPromo.chgCredits(promoPrev);
		
		promoCurrent = promoPrev;
	
	},
	chgPromo:function(oldID,newID){

		//var_newimage = "prod_promo_"+imageID;
		console.log("imageID:"+oldID+"->"+newID);
		$('prod_promo_'+oldID).hide();
		//$('prod_promo').src = imageID;
		Effect.Appear('prod_promo_'+newID,{duration:0.5});
		
	},
	chgCredits:function(currentID){
		//$('prod_details').update("Promo credits for #"+currentID);
		$('prod_details').update(eval('promo_credits_'+currentID));
	},
	slideshow:function(){
		(promoCurrent<promoTotal) ? promoNext = promoCurrent+1 : promoNext = 0;
		
		appPromo.chgPromo(promoCurrent,promoNext);
		appPromo.chgCredits(promoNext);
		//
		promoCurrent = promoNext;
		if(slideshow_play==true){time_appear = setTimeout('appPromo.slideshow();',6000);};
	
	}
};



var appStudio = {
	init:function(){
		imgTotal = 0;
		imgPath = "vault/"+vault+"/";
		currentHolder = 1;
		studioImg = $A(studio2);
		
		var imgnumber = 0	
		studioImg.each(function(){
			thumbimg = "<img src='vault/"+vault+"/thumbs/"+studioImg[imgnumber]+"' class='thumb1' id='thumb_"+imgnumber+"' onclick='appStudio.chgImg(&#39;"+studioImg[imgnumber]+"&#39;);'  />";						
			new Insertion.Bottom('studionav',thumbimg);
			
			imgnumber++;
		});
		//set first images
		appStudio.chgImg(studioImg[0]);
		//appStudio.chgImg(studioImg[1]);
	
	},
	chgImg : function(imgname){
		/*var imgGo = 0;
		if(currentHolder==1){
			imgGo = 1;
			currentHolder = 2;
		} else {
			imgGo = 2;
			currentHolder = 1;
		};*/
		$('studioimg_1').innerHTML = "<img src='"+imgPath+imgname+"' width='390' height='260' />";
		
	}
};

/***************************************************
/AJAX RELATED SCRIPTS
****************************************************/
var feedback = {
	begin: 	function(message){
		$('feedback_container').show();
		$('feedback').innerHTML = "<img src='images/spinner_feedback1.gif' /><br />"+message;
	},
	end:	function(message){
		$('feedback').innerHTML = message;
		Effect.Fade('feedback_container',{duration:2});
	},
	fail:	function(message){
		$('feedback').innerHTML = message;
		Effect.Pulsate('feedback_container');
	},
	fade: function(){
		Effect.Fade('feedback_container',{duration:2});
	}
};


var ajx = {
	getArtist :  function(artist){
	
	//feedback.begin('getting memo info...');
	new Ajax.Updater('whiteboard', 'folioinfo/rodeo_'+artist+'.asp',
				{parameters:	{},
				evalScripts: true,
				onComplete:function(){/*alert('done');*/},
				onFailure:function(){alert('Error with your request');}
				});
	}
};



/*END ****************************************************/
var gui = {
	
	downBar:function(){
		new Effect.Move ('tabs_container',{ x: 135, y: 540, mode: 'absolute'});
		var guiInv = $$('.guiInv');
		guiInv.invoke('hide');
		$('credits_container').hide();
		
	},
	upBar:function(){
		new Effect.Move ('tabs_container',{ x: 135, y: 511, mode: 'absolute'});
		var guiInv = $$('.guiInv');
		$('credits_container').show();
		guiInv.each(function(el){
			new Effect.Appear(el, {duration:1.0});					 
		});
		
	},
	
	showBio:function(){
		//$('expo_container').hide();
		//gui.downBar();
		$('img_container','stripes_img').invoke('show');
		$('preloadimg','videoplayer','credits_details','thumbnav','stripes_video','videocredits').invoke('hide');
		new Effect.Appear('bio_container', {duration:1.0});
	},
	
	hideBio:function(){
		$('bio_container').hide();
		if(typeoffolio == "img"){
		$('preloadimg','credits_details','thumbnav', 'img_container','stripes_img').invoke('show');}
		else {
			$('img_container','stripes_img').invoke('hide');
			$('preloadimg','videoplayer','videocredits','thumbnav','stripes_video').invoke('show');
			
			
		}
		//gui.upBar();

	},
	
	resetBioExpo:function(){
		// used to hide sections and credits when new folio is setup
		$('bio_container').hide();
		$('expo_container').hide();
		//moded copy of upbar() added conditional on credits_details;
		new Effect.Move ('tabs_container',{ x: 135, y: 511, mode: 'absolute'});
		var guiInv = $$('.guiInv');
		$('credits_container').show();
		guiInv.each(function(el){
			
			if(el.id!='credits_details'){
			console.log("gui thing : "+el.id);
			new Effect.Appear(el, {duration:1.0})};					 
		});
		$('credits_container').hide();
		
	},
	toggleBio:function(){
		$('bio').toggleClassName('menu4');
		if($('bio_container').visible()==true){
			gui.hideBio();
			}
			else {
				gui.showBio();};
		
	},
	
	showExpo:function(){
		$('bio_container').hide();
		gui.downBar();
		new Effect.Appear('expo_container', {duration:1.0});
	},
	
	hideExpo:function(){
		$('expo_container').hide();
		gui.upBar();

	},
	toggleExpo:function(){
		if($('expo_container').visible()==true){
			gui.hideExpo();
			}
			else {
				gui.showExpo();};
		
	}
	
};


col1 = 5;
col2 = 10;
col3 = 15
var appMaking = {

	init:function(){
	
		// make thumbnail sections
		
		makingVid = $A(makingVideos);
		var counterVid = 0;
		thumbHTML = "<div class='video_liste'>";
		
		makingVid.each(function(){
			if(counterVid==col1|| counterVid==col2 || counterVid==col3){
				thumbHTML = thumbHTML + "</div><div class='video_liste'>";
			};
			thumbHTML = thumbHTML+"<a href='"+langvar+".asp?vid="+counterVid+"'><img src='vault/rodeo/making/"+makingThumbs[counterVid]+"' border='0' class='video_thumb' /></a>";
			
			counterVid++;
							   
		});
		
		thumbHTML = thumbHTML + "</div>";
		$('video_index').innerHTML = thumbHTML;
	
		// load current credits
		$('making_credits').innerHTML=eval("makingCredit_"+currentVideo);
		
		// load current video from querysrting
		$('currentVid').innerHTML="<embed type='video/mp4' src='vault/rodeo/making/"+makingVideos[currentVideo]+"' name='plugin' height='100%' width='100%'>";
		
	
	}

}
//other functions
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

