
var req;
var which;
function retrieveURL(url) {
if (window.XMLHttpRequest) { // Non-IE browsers
  req = new XMLHttpRequest();
  req.onreadystatechange = processStateChange;
  try {
	req.open("GET", url, true);
  } catch (e) {
	alert(e);
  }
  req.send(null);
} else if (window.ActiveXObject) { // IE
  req = new ActiveXObject("Microsoft.XMLHTTP");
  if (req) {
	req.onreadystatechange = processStateChange;
	req.open("GET", url, true);
	req.send();
  }
}
}
function processStateChange() {
if (req.readyState == 4) { // Complete
  if (req.status == 200) { // OK response
	eval(req.responseText);
  } else {
	alert("Problem: " + req.statusText);
  }
}
}

var videoLoggedIn;
retrieveURL("videologinfiles/check.php");

var HS = 0;
var VS = 0;
var brow;

window.onscroll = function updateScroll(){

	if (window.innerWidth) {
		// All browsers but Internet Explorer
		HS = window.pageXOffset; VS = window.pageYOffset;
		}
		else if(document.documentElement && document.documentElement.clientWidth){
		// These are for Internet Explorer 6 when a DOCTYPE is defined
		HS = document.documentElement.scrollLeft;
		VS = document.documentElement.scrollTop;
		brow = "ie1";
		}
		else if (document.body.clientWidth) {
		brow = "ie2";
		// These are for Internet Explorer 5/6 without a DOCTYPE
		HS = document.body.scrollLeft; VS = document.body.scrollTop;
	}
}

var vidDiv = document.getElementById("videopopup");
var dimmer = document.getElementById("videodimmer");


function closePlayer(){
	if(document.getElementById("flashheader")){
		document.getElementById("flashheader").style.visibility = "visible";
	}
	loadPlayer("1", "http://www.amberproduction.com/nothing.swf");
	vidDiv.style.display	= "none";
	vidDiv.style.innerHTML	= "";
	dimmer.style.display 	= "none";
}

function playVideo(openThis){
		if(videoLoggedIn == 1){
			if(document.getElementById("flashheader")){
			document.getElementById("flashheader").style.visibility = "hidden";
		}
		vidDiv.style.display 	= "inline";
		vidDiv.style.zIndex 	= "16500";
		dimmer.style.display 	= "block";

		// Dim background
		dimmer.style.background = "#000";
		
		if(!brow) dimmer.style.opacity = "0.7";
		else dimmer.style.filter = "alpha(opacity=70)";
		
		dimmer.onclick = function(){ closePlayer(); }

		vidDiv.innerHTML = "<div id='playerProper'>Loading player...</div><img src='/img/close.png' alt='' id='closebutton' />";
		document.getElementById("closebutton").style.cursor = "pointer";
		document.getElementById("closebutton").onclick = function(){ closePlayer(); }
		
		document.getElementById("playerProper").innerHTML = "<p>Your Flash Player is out of date.</p>";
		vidDiv.style.position = "absolute";
		vidDiv.style.color = "#fff";
		if(!brow){
			// Not Explorer (Fixed @ CSS)
			vidDiv.style.left = window.innerWidth / 2 - (790 / 2) + "px";
		}
		else{
			// Explorer
			vidDiv.style.left = document.body.offsetWidth / 2 - (790 / 2) + "px";
			dimmer.style.top = 0 + "px";
			//dimmer.style.height = dimmer.offsetHeight + VS + "px";
			dimmer.style.height = document.body.offsetHeight + "px";
			dimmer.style.filter = "alpha(opacity=70)";
		}
		vidDiv.style.top = VS + 100 + "px";
		vidDiv.style.width = "790px";
		vidDiv.style.height = "250px";

		setTimeout("loadPlayer('"+openThis+"')", 50);
		}
	else{
		promptForPassword(openThis);
	}
	
}
if(document.getElementById("videoLoginFormDiv")){
	var videoLoginFormDiv = document.getElementById("videoLoginFormDiv");
}
function promptForPassword(openThis){
	videoLoginFormDiv.style.display = "inline";

	videoLoginFormDiv.style.border = "solid 1px #000";
	videoLoginFormDiv.style.padding = "10px";
	videoLoginFormDiv.style.background = "#000";
	videoLoginFormDiv.style.color = "#fff";
	videoLoginFormDiv.style.top = VS + 100 + "px";

	videoLoginFormDiv.innerHTML = "<p>Please enter password for the video player: </p><input type='password' name='videoLoginPassword' id='vlinput' /><p><a href='#' onclick='checkPassword(document.getElementById(\"vlinput\", \""+openThis+"\").value); return false;' style='color: #fff;'>Go &raquo;</a></p><p>Request password from kare.hellen@amberproduction.com</p>";
	
	if(!brow){
		// Not Explorer (Fixed @ CSS)
		videoLoginFormDiv.style.left = window.innerWidth / 2 - (videoLoginFormDiv.offsetWidth / 2) + "px";
	}
	else{
		// Explorer
		videoLoginFormDiv.style.left = document.body.offsetWidth / 2 - (videoLoginFormDiv.offsetWidth / 2) + "px";
	}
	
	return false;
}

function checkPassword(pass, openThis){
	videoLoginFormDiv.style.display = "none";
	retrieveURL("videologinfiles/checkPassword.php?password=" + pass + "&openThis=" + openThis);
}

function loadPlayer(openThis, swfFile){
	if(!swfFile){
		swfFile = "http://www.amberproduction.com/flash/videoplayer.swf";
	}
	var flashvars = {
	xmlUrl: "http://www.amberproduction.com/video.xml",
	initOpen: openThis
	};
	var params = {
	wmode: "transparent"
	};
	var attributes = {};
	swfobject.embedSWF(swfFile, "playerProper", "790", "470", "9.0.28", "swf/expressInstall.swf", flashvars, params, attributes);
}
