//Global declarations and functions

var toLoad
var strings = {"ca":{"showvid":"veure video","hidevid":"tancar video"},"es":{"showvid":"ver video","hidevid":"cerrar video"},"en":{"showvid":"show video","hidevid":"hide video"}}

function videoGallery(aVids){
	var sv = document.getElementsByClassName( "showVid" );
	 sv.each(function(svt,idt){
		  svt.href = "javascript:showSwf("+idt+");";
		  svt.className = "showVid";
		  svt.innerHTML = strings[lang]["showvid"];
			svt.idVid = idt;
			svt.video = aVids[idt];
	 });
}

function showSwf(id){
	if($("titular")){ $("titular").style.display = "block"; $("titular").innerHTML=aName[id+1]}
	var effct = new fx.Height( "videoHolder" , {duration: 300, onComplete: function()
   {
		 var sv = document.getElementsByClassName( "hideVid" );
		 sv.each(function(svt,idt){
			 svt.href = "javascript:showSwf("+svt.idVid+");";
			 svt.className = "showVid";
			 svt.innerHTML = strings[lang]["showvid"];
		 })
		 var sv = document.getElementsByClassName( "showVid" );
		 sv.each(function(svt,idt){
			if(svt.idVid==id){
			  svt.href = "javascript:hideSwf("+svt.idVid+");";
			  svt.className = "hideVid";
			  svt.innerHTML = strings[lang]["hidevid"];
			}
		 })
		  embedSwf(sv[id].video);
   }});
	effct.custom( 0 , 280 );
	effct.toggle();
}

function hideSwf(id){
	if($("titular")){ $("titular").style.display = "none";}
	$("videoHolder").innerHTML = '';
	var effct = new fx.Height( "videoHolder" , {duration: 300, onComplete: function()
   {
		this.el.innerHTML = '';
		  var sv = document.getElementsByClassName( "hideVid" );
		  sv.each(function(svt,idt){
			  svt.href = "javascript:showSwf("+svt.idVid+");";
		    svt.className = "showVid";
		    svt.innerHTML = strings[lang]["showvid"];
		 });
		}});
	effct.custom( 280 , 0 );
	effct.toggle();
}

function embedSwf(docu){
	var video = document.getElementById('videoHolder');
	var docum = docu ? docu : toLoad;
	var flSnip ='<p><object type="application/x-shockwave-flash" data="swf/FlowPlayer.swf" width="320" height="263" id="FlowPlayer"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="swf/FlowPlayer.swf" /><param name="quality" value="high" /><param name="scale" value="noScale" /><param name="wmode" value="transparent" /><param name="flashvars" value="videoFile=' + docum + '&autoPlay=true"/></object></p>';
	video.innerHTML = flSnip;
}


//the main function, call to the effect object
function init(){
	
	/*toLoad = file;*/
	
	if(toLoad==""){
	 var lnk = document.getElementById("showVid");
	 lnk.style.display = "none";
	}/*else{
	 var sv = document.getElementsByClassName( "showVid" );
	 sv.each(function(svt,idt){
		  svt.href = "javascript:showSwf("+idt+");";
		  svt.className = "showVid";
		  svt.innerHTML = strings[lang]["showvid"];
			svt.idVid = idt;
			svt.video = aVids[idt];
	 });
	}*/
	
	var stretchersMain = document.getElementsByClassName('stretcherMain'); //div that stretches
	var togglesMain = document.getElementsByClassName('displayMain'); //h3s where I click on
  
	var subStretchers01 = document.getElementsByClassName('subStretcher01'); //div that stretches
	var subToggles01 = document.getElementsByClassName('subDisplay01'); //h3s where I click on

	var subStretchers02 = document.getElementsByClassName('subStretcher02'); //div that stretches
	var subToggles02 = document.getElementsByClassName('subDisplay02'); //h3s where I click on
	
	//accordion effect Main
	var myAccordionMain = new fx.Accordion(
		togglesMain, stretchersMain, {opacity: true, duration: 400, onComplete: function(elm,toggler){
			if(toggler.id!="toggled"){
				toggler.id = "toggled";
			}else{
				toggler.id = '';
			}
				
			}}
	);
	
	//accordion effect Sub 01
	var myAccordionSub01 = new fx.Accordion(
		subToggles01, subStretchers01, {opacity: true, duration: 400}
	);
	
	//accordion effect Sub 02
	var myAccordionSub02 = new fx.Accordion(
		subToggles02, subStretchers02, {opacity: true, duration: 400}
	);
	
	//hash function main
	function checkHashMain(){
		var foundMain = false;
		togglesMain.each(function(h3, i){
			if (window.location.href.indexOf(h3.title) > 0) {
				myAccordionMain.showThisHideOpen(stretchersMain[i]);
				foundMain = true;
			}
		});
		return foundMain;
	}
	
	if (!checkHashMain()) myAccordionMain.showThisHideOpen(stretchersMain[0]);

	function checkHashSub01(){
		var foundSub01 = false;
		subToggles01.each(function(h4, i){
			if (window.location.href.indexOf(h4.title) > 0) {
				myAccordionSub01.showThisHideOpen(subStretchers01[i]);
				foundSub01 = true;
			}
		});
		return foundSub01;
	}
	//hash function sub 01
	if (!checkHashSub01()) myAccordionSub01.showThisHideOpen(subStretchers01[0]);
	
	//hash function sub 02
	function checkHashSub02(){
		var foundSub02 = false;
		subToggles02.each(function(h4, i){
			if (window.location.href.indexOf(h4.title) > 0) {
				myAccordionSub02.showThisHideOpen(subStretchers02[i]);
				foundSub02 = true;
			}
		});
		return foundSub02;
	}
		
	if (!checkHashSub02()) myAccordionSub02.showThisHideOpen(subStretchers02[0]);
	
		
	//embedSwf(file);
	//toggleVideo();
}
