/**
 * @author Ellier
 */

 var container;	// Container in html in which to place the content
 var bckDrop;	// Div that would cover the content behind
 var Content;	// Div to hold content
 var ContWidth;	// This div's width
 var ContHeight;// This div's height
 var opBck;		// This will be the Tween for the background
 var bckOpac; 	// This is the opacity for your backdrop
 var flashCont;	// Element to hold flash content
 var altCont;	// This variable is for alternative content if flash is not installed
 var getFlash;	// This variable holds the get flash image with the link
 var closeBtn;	// Close button
 var mediaURL;
 
 function initDisplay(url,w,h,op,cont) { // w=width, h=height, op=opacity, cont=container
 	if(!cont) {
		container = document.getElementsByTagName("body")[0];
	} else {
	 	container = cont;
	}
	
	if(!op) {
		bckOpac = 70;
	} else {
		bckOpac = op;
	}
	
	mediaURL = url;
	
	ContWidth = w;
	ContHeight = h;
	bckDrop = document.createElement("div");
	bckDrop.setAttribute("id", "bckDrop")
	bckDrop.style.position = "absolute";
	bckDrop.style.display = "block";
	bckDrop.style.top = 0;
	bckDrop.style.left = 0;
	bckDrop.style.width = "100%";
	bckDrop.style.height = "100%"; 		// Use overflow:hidden on the parent element for IE6 so it extends 100%
	bckDrop.style.background = "#000000";	
	bckDrop.style.opacity = 0;
	bckDrop.style.filter="Alpha(opacity=100)";


	Content = document.createElement("div");
	Content.setAttribute("id", "cntDiv");	
	Content.style.position = "absolute";
	Content.style.top = "50%";
	Content.style.left = "50%";
	Content.style.marginTop = (ContHeight/2)*-1 + "px"; // marginLeft is adjusted in the tween
	Content.style.display = "block";
	Content.style.width = 0;
	Content.style.height = ContHeight +"px";
	Content.style.background = "#000000";
	
	flashCont = document.createElement("div");
	flashCont.setAttribute("id","flashcontent");
	flashCont.style.position = "absolute";
	flashCont.style.padding = "10px";
	
	closeBtn = document.createElement("a");
	var cBtext = document.createElement("p");
	cBtext.innerHTML = "Close";
	closeBtn.appendChild(cBtext);
	closeBtn.style.fontSize = "12px";
	closeBtn.style.display = "block";
	closeBtn.style.padding = "2px";
	closeBtn.style.width = "50px";
	closeBtn.style.zIndex = "50";
	closeBtn.style.backgroundColor = "#000";
	closeBtn.style.color = "#FFF";
	closeBtn.style.position = "absolute";
	closeBtn.style.top = "-20px";
	closeBtn.style.right = "0px";
	closeBtn.style.overflow = "hidden";	// Only way to make it work on IE 6. otherwise it extends beyond its width
	closeBtn.href = "#";
	closeBtn.onclick = setBckClose;
		
	// Figuring out if the div is inserted into the body or a DIV
	if(container == document.getElementsByTagName("body")[0]) {
		var obj = container;
	} else {
		var obj = document.getElementById(container);
	}
	
	obj.appendChild(bckDrop);
	Content.appendChild(flashCont);
	obj.appendChild(Content);
	
	setBck();
 }
 
 function setBck() {
 	var cntSeq = new Sequence();
	var cntPar = new Parallel();
 	var t1 = new OpacityTween(document.getElementById('bckDrop'),Tween.regularEaseOut,0,bckOpac,1);
	var t2 = new Tween(document.getElementById('cntDiv').style,'width',Tween.strongEaseOut,0,ContWidth,1,'px');
	var t3 = new Tween(document.getElementById('cntDiv').style,'marginLeft',Tween.strongEaseOut,0,(ContWidth/2)*-1,1,'px');
	cntPar.addChild(t2);
	cntPar.addChild(t3);
	cntSeq.addChild(t1);
	cntSeq.addChild(cntPar);
		
	cntSeq.start();

	cntSeq.onMotionFinished = function() { 
			//Content.onclick = setBckClose;
			var so = new SWFObject(mediaURL, "mymovie", "320", "280", "9", "#000000");
			so.addParam("quality", "medium");
			so.useExpressInstall('Scripts/SWFObject/expressinstall.swf');
			so.write("flashcontent");
			
			Content.appendChild(closeBtn); // Add the close button
		
			var isFlash = document.getElementById("flashcontent").firstChild;
				if(isFlash == null) {
						altCont = document.createElement("p");
						altCont.innerHTML = "Flash not installed";
						altCont.style.color = "#999999";
						altCont.style.position = "relative";
						altCont.style.width = "94%";
						altCont.style.margin = "auto";
						altCont.style.marginTop = "40%";
						altCont.style.marginLeft = 0;						
						altCont.style.textAlign = "center";
						altCont.style.clear = "both";
						altCont.setAttribute("id","altCont");
						
						var flashLink="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash&promoid=BIOW";
						var imgLink="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif";
						
						getFlash = document.createElement("a");
						getFlash.href = flashLink;
						getFlash.target = "_Blank";
						getFlash.style.position = "relative";
						getFlash.style.marginTop = "40px";
						getFlash.style.width = "94%";
						getFlash.style.textAlign = "center";
						getFlash.style.margin = "auto";
						getFlash.style.display = "block";
						
						var getFlashImg = document.createElement("img");
						getFlashImg.src = imgLink;
						
						getFlash.appendChild(getFlashImg);
						Content.appendChild(altCont);						
						Content.appendChild(getFlash);
				
					}			
			};
 }
 
  function setBckClose() {
  	
	
	if(altCont) { 
		var obj = altCont.parentNode; obj.removeChild(altCont);
		var obj1 = getFlash.parentNode; obj.removeChild(getFlash);
		}
	
	var obj0 = closeBtn.parentNode;
	obj0.removeChild(closeBtn);	
	var obj1 = flashCont.parentNode;
	obj1.removeChild(flashCont);
	
 	var cntSeq = new Sequence();
	var cntPar = new Parallel();
 	var t1 = new OpacityTween(document.getElementById('bckDrop'),Tween.regularEaseOut,bckOpac,0,1);
	var t2 = new Tween(document.getElementById('cntDiv').style,'width',Tween.strongEaseOut,ContWidth,0,1,'px');
	var t3 = new Tween(document.getElementById('cntDiv').style,'marginLeft',Tween.strongEaseOut,(ContWidth/2)*-1,0,1,'px');
	cntPar.addChild(t2);
	cntPar.addChild(t3);
	cntSeq.addChild(cntPar);
	cntSeq.addChild(t1);
	cntSeq.start();
	
	cntSeq.onMotionFinished = function(){ removeAll();};
  }
  
  function removeAll(){

  	var obj1 = document.getElementById("cntDiv").parentNode;
	obj1.removeChild(document.getElementById('cntDiv'));
	var obj2 = document.getElementById("bckDrop").parentNode;
	obj2.removeChild(document.getElementById('bckDrop'));
  }
  
  