/* ----------------------------- */
// SWF REPLACEMENT
/* ----------------------------- */

function isObject(targetDiv){

	//------------------------//
	// Checks Embed
	//------------------------//

   var isFound = false;
   var el = $(targetDiv);
   
   if(el && (el.nodeName === "OBJECT" || el.nodeName === "EMBED")){
   
      isFound = true;
   }
   
   return isFound;
}



function replaceSwfWithEmptyDiv(targetDiv){

	//------------------------//
	// Replace Swf
	//------------------------//

   var el = $(targetDiv);

      var div = document.createElement("div");
      el.parentNode.insertBefore(div, el);
      swfobject.removeSWF(targetDiv);
      div.setAttribute("id", targetDiv);
      
}



function removeCurrentSWF(targetDiv){

	//------------------------------//
	// Remove Current Swf
	//------------------------------//

 	if(isObject(targetDiv)){
      replaceSwfWithEmptyDiv(targetDiv);
      
  	 }
}

/* ----------------------------- */
// Initialize Swf!
/* ----------------------------- */

function initSWF(targetID) 
{
	for(var i= 0; i<ids.length; i++){

		if(ids[i] != ids[targetID] ){
			removeCurrentSWF(ids[i]+"Flash"); 
			$(ids[i]+"Toggle").set('style','height:0px; display:block; border:none; padding:0;');
			$(ids[i]+"Tab").set('class','togglebtn');
		}
		else{
			loadSWF(targetID);
			$(ids[targetID]+"Tab").set('class','togglebtnselect');
			$(ids[targetID]+"Toggle").set('style','height:400px; display:block;');
		}
	}
	
}


function placeGallery ( gallerydivID , galleryURLocation ){
	var params = {salgin:"TopLeft",scale: "noScale" ,play:"true", loop:"true", wmode: "window", bgcolor: "#FAF3D7", allowFullScreen: "false", quality:"best"};
	var flashvars = { galleryList: galleryURLocation };
	swfobject.embedSWF("swf/dwd_gallery.swf", gallerydivID, "616", "400", "8.0.0", null, flashvars, params );

}


function loadSWF(targetID){

  if(isObject(ids[targetID])+'Flash'){ replaceSwfWithEmptyDiv(ids[targetID]+'Flash');}
  placeGallery( ids[targetID] +'Flash' , galleryPaths[targetID] );			   

}

// ID Switcher

function switchid(id){	

	hideallids();
	showdiv(id);
	initSWF(id);
	
}

function hideallids(){

	for (var i=0;i<ids.length;i++){
		hidediv([i]);
	}		  
}

function hidediv(id) {

	$(ids[id]+"Flash").style.display = 'none';
	
}

function showdiv(id) {

	$(ids[id]+"Flash").style.display = 'block';
	
}

/* ----------------------------- */
// OnLoad!
/* ----------------------------- */

window.onload = function() 
{

	switchid(0);
	/*var myLoc = String(document.location);
	var myIndex = myLoc.lastIndexOf("#");
	var playVid = myLoc.substring(myIndex+1);
	
	if(myIndex == -1){
		
	}else{
		switchid(playVid);
	}
	*/
	
	
}






