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



function isObject(targetID){

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

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



function replaceSwfWithEmptyDiv(targetID){

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

   var el = $(targetID);

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


function loadSWF(targetID){

	//------------------------------//
	// Load SWF from below Embeds
	//------------------------------//


   if(isObject(targetID)){		
      replaceSwfWithEmptyDiv(targetID);
   }
   
  if(targetID == "motionFlash"){
	embedMotion();
  }else if (targetID == "interactiveFlash"){
	embedInteractive();
  }else if (targetID == "printFlash"){
	embedPrint();
  }else if (targetID == "identityFlash"){ 
	embedIdentity();
  }
   
}

function removeCurrentSWF(targetID){

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

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




/* ----------------------------- */
// Flash Embeds
/* ----------------------------- */


	
	
function getcurrentURLLocation (){
	var myLoc = String(document.location);
	var myIndex = myLoc.indexOf("/#");
	if(myIndex == -1){
		return String(document.location);
	}else{
		return myLoc.substring(0,myIndex+1);
	}
}	
	

function embedMotion (){

	//-----------//
	// Motion
	//-----------//

	var sendto = getcurrentURLLocation()+"#motion";
	var flashvars = {
						vid: "../video/motion.flv", 
						asratio: "true", 
						target:"_blank", 
						link1:sendto,linktext1:"Share Video", 
						link2:"http://www.dumbwaiterdesign.com/HD/Motion_H264.mov",linktext2:"View in HD",
						previewImage:"../images/motion-cap.jpg"
					};

	var params = {play:"true", loop:"true", wmode: "window", bgcolor: "#000000", allowFullScreen: "true", quality:"best"};
	var obj = swfobject.embedSWF("../swf/video.swf", "motionFlash", "625px", "351px", "9.0.0", null, flashvars, params );
	
}

function embedInteractive (){

	//-----------//
	// Interactive
	//-----------//
	
	var sendto = getcurrentURLLocation()+"#interactive";
	var flashvars = {
						vid: "../video/interactive.flv", 
						asratio: "true", 
						target:"_blank", 
						link1:sendto,linktext1:"Share Video", 
						link2:"http://www.dumbwaiterdesign.com/HD/Interactive_H264.mov",linktext2:"View in HD",
						link3:"http://www.drinkzzz.com/",linktext3:"View ZZZ Site",
						previewImage:"../images/interactive-cap.jpg"
					};

	var params = {play:"true", loop:"true", wmode: "window", bgcolor: "#000000", allowFullScreen: "true", quality:"best"};
	var obj = swfobject.embedSWF("../swf/video.swf", "interactiveFlash", "625px", "351px", "9.0.0", null, flashvars, params );

}

function embedPrint (){

	//-----------//
	// Print
	//-----------//
	
	var sendto = getcurrentURLLocation()+"#print";
	var flashvars = {
						vid: "../video/print.flv", 
						asratio: "true", 
						target:"_blank", 
						link1:sendto,linktext1:"Share Video", 
						link2:"http://www.dumbwaiterdesign.com/HD/Print_H264.mov",linktext2:"View in HD",
						previewImage:"../images/print-cap.jpg"
					};

	var params = {play:"true", loop:"true", wmode: "window", bgcolor: "#000000", allowFullScreen: "true", quality:"best"};
	var obj = swfobject.embedSWF("../swf/video.swf", "printFlash", "625px", "351px", "9.0.0", null, flashvars, params );

}

function embedIdentity (){

	//-----------//
	// Identity
	//-----------//

	var sendto = getcurrentURLLocation()+"#identity";
	var flashvars = {
						vid: "../video/identity.flv", 
						asratio: "true", 
						target:"_blank", 
						link1:sendto, linktext1:"Share Video", 
						link2:"http://www.dumbwaiterdesign.com/HD/Identity_H264.mov",linktext2:"View in HD",
						link3:"http://www.flyingfishmobile.com/",linktext3:"View Flying Fish Site",
						previewImage:"../images/identity-cap.jpg"
					};

	var params = {play:"true", loop:"true", wmode: "window", bgcolor: "#000000", allowFullScreen: "true", quality:"best"};
	
	var obj = swfobject.embedSWF("../swf/video.swf", "identityFlash", "625px", "351px", "9.0.0", null, flashvars, params );
	
}









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

function initSWF(targetID) 
{
	var flashElements = ['motion','interactive','print','identity'];
	for(var i= 0; i<4; i++){
		if(flashElements[i] != targetID ){
			removeCurrentSWF(flashElements[i]+"Flash"); 
			$(flashElements[i]+"Toggle").set('style','height:0px; display:block;');
		}
		else{
			loadSWF(targetID+"Flash");
			$(targetID+"Toggle").set('style','height:360px; display:block;');
		}
	}
	
}








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

window.onload = function() 
{
	var stretchers = $$('div.togglecontent');
	stretchers.setStyles( {'height': '0px', 'overflow': 'hidden', 'display' : 'block'} );
	var myLoc = String(document.location);
	var myIndex = myLoc.lastIndexOf("#");
	var playVid = myLoc.substring(myIndex+1);
	
	if(myIndex == -1){
		switchid("motion");
	}else{
		switchid(playVid);
	}
	
	Shadowbox.init();

	
}


