/*
	file name: pixelmodule_video.js
	  version: 2010-02-22
	   author: Pixelmodule Inc.,
	  website: http://pixelmodule.com
	    email: contact@pixelmodule.com
	
	Pixelmodule Video Javascript
    Copyright ©2010 PIXELMODULE Inc., All Right Reseverd.

*/

var _pixelmodule_video_id = "pixelmodule_video_obj";
var _pixelmodule_video_player = "cgi/pixelmodule_video.swf";
var _pixelmodule_video_bin = "../videos/";
var _pixelmodule_video_opened = false;

function pixelmodule_VideoDo(command, args) 
{
		if (!_pixelmodule_video_opened)
		{
			if (command == "play") 	
			{ 
				document.getElementById("pixelmodule_video_bg").style.visibility = "visible";
				document.getElementById("pixelmodule_video_backdrop").style.visibility = "visible";
				document.getElementById("pixelmodule_video_size").style.visibility = "visible";
	
				var varis = { file: _pixelmodule_video_bin+args, aspect:3 };
				var params = { wmode:"gpu", allowFullScreen:"true" };
				swfobject.embedSWF(_pixelmodule_video_player, _pixelmodule_video_id, "640", "360", "10.0.0", "cgi/expressInstall.swf", varis, params); 

				_pixelmodule_video_opened = true;
			}
		}
		
		var obj = swfobject.getObjectById(_pixelmodule_video_id);
	
		if (command == "aspect"	)	{ obj.aspect(args)	}
		if (command == "play"	) 	{ obj.play(args) 	}

}

function pixelmodule_VideoClose()
{
	if(isObject(_pixelmodule_video_id)) { replaceSwfWithEmptyDiv(_pixelmodule_video_id)}
	document.getElementById("pixelmodule_video_bg").style.visibility = "hidden";
	document.getElementById("pixelmodule_video_backdrop").style.visibility = "hidden";
	document.getElementById("pixelmodule_video_size").style.visibility = "hidden";
	 _pixelmodule_video_opened = false;
}

function isObject(targetID)
{
   var isFound = false;
   var el = document.getElementById(targetID);
   if(el && (el.nodeName === "OBJECT" || el.nodeName === "EMBED"))
   {
      isFound = true;
   } // end if
   return isFound;
} // close function


function replaceSwfWithEmptyDiv(targetID){
   var el = document.getElementById(targetID);
   if(el){
      var div = document.createElement("div");
      el.parentNode.insertBefore(div, el);

      swfobject.removeSWF(targetID);

      div.setAttribute("id", targetID);
   }
}
 

function addPixelmoduleVideoHandlers() 
{
	var a = document.getElementById("pixelmodule_video_bg");
	if (a) {
		a.onclick = function() {
			pixelmodule_VideoClose(); 
			return false;
		};
	}
	var b = document.getElementById("pixelmodule_video_backdrop");
	if (b) {
		b.onclick = function() {
			pixelmodule_VideoClose(); 
			return false;
		};
	}
	
}
swfobject.addLoadEvent(addPixelmoduleVideoHandlers);


