
//****************************************************************************************
//Narnoo.com Client Video Light box
//Version 2.1 Updated 10/04/09
//info@narnoo.com
//Developed by: James Wells
//****************************************************************************************
window.onload = rules();
//********************************
//Injects the CSS into the webpage
//********************************
function rules(){
var headID = document.getElementsByTagName("head")[0];         
var cssNode = document.createElement('link');
cssNode.type = 'text/css';
cssNode.rel = 'stylesheet';
cssNode.href = 'http://www.moa.narnoo.com/css/narnoovideo-box.css';
headID.appendChild(cssNode);
}
//********************************
//Set variables
//********************************
var vid_id;
var vid;
var user;
var user_id;
//setup skin..
var noooverlay_window;
var noolight_window;
var noowindow_close;
var noowindow_box;
//fadein
var noobackground;
var noobox;
var windowWidth, windowHeight;
var leftSpace, topspace;
var topMarginWidth, leftMarginWidth;

//**********************************
//Get Page Height
//**********************************

function heritageTv(vid){

		vid_id=vid;
		
		if (self.innerHeight) {	// all except Explorer
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth; 
			} else {
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		
		
		leftSpace = ((windowWidth - 543) / 2);
		topSpace = ((windowHeight - 379) / 2);
		
		leftMarginWidth = ((leftSpace /windowWidth)*100);
		topMarginWidth = ((topSpace /windowHeight)*100);
		setnarnooWindow();
}

//**********************************
//Set Window DOM
//**********************************

function setnarnooWindow(){

noooverlay_window = document.createElement("div");
noolight_window = document.createElement("div");
noowindow_close = document.createElement("div");
noowindow_box = document.createElement("div");

noooverlay_window.id = "noolayout";
noolight_window.id = "noowindow-box";
noowindow_close.id = "noowinclose-box";
noowindow_box.id = "noomedia-box";
noowindow_close.setAttribute("onclick","deactivatevideo()");
noowindow_close.style.cursor = 'pointer';

document.body.appendChild(noooverlay_window);
document.body.appendChild(noolight_window);
noolight_window.appendChild(noowindow_close);
noolight_window.appendChild(noowindow_box);
initvideoFade();

}
//********************************
//Starts Fade In
//********************************

function initvideoFade() {
	noobackground = document.getElementById('noolayout');
	noobackground.style.display = 'block';
 	noobackground.style.visibility = 'visible';
	
	for (var i=0;i<8;i++)
		setTimeout('setOpacity('+i+')',30*i);
	
	setVisiblevideoElements();
}

function setOpacity(value)
{
	noobackground.style.opacity = value/10;
	noobackground.style.filter = 'alpha(opacity=' + value*10 + ')';
}
//********************************
//Displays media contents
//********************************
function setVisiblevideoElements()
{
	
	noobox = document.getElementById('noowindow-box');
	noobox.style.display = 'block';
	noobox.style.visibility = 'visible';
	noobox.style.left = leftMarginWidth+'%';
	noobox.style.top = topMarginWidth+'%';
	loadVideo();
	
}
//********************************
//Loads the video media
//********************************
function loadVideo()
{
	//Set video in iFrame.
	noowindow_box.innerHTML = "<iframe width=\"543px\" height=\"328px\" scrolling=\"no\" frameborder=\"0\" src=\"http://www.vmedia.narnoo.com/heritagetv.php?vid="+vid_id+"\"></iframe>";
	//Set Close Window.
	noowindow_close.innerHTML="<table width=\"543\" height=\"18\" ><tr class=\"nooclose\"><td align=\"right\"><a href=\"javascript:deactivatevideo()\">X Close Window</a></td></tr></table>";
	
}
//********************************
//Deactivates Lightbox
//********************************
function deactivatevideo(){
 
  var p = document.body;	
  
  noolight_window.removeChild(noowindow_box);
  noolight_window.removeChild(noowindow_close);
  p.removeChild(noolight_window);
  p.removeChild(noooverlay_window);
  
  noobackground.style.opacity = '0';
  noobackground.style.filter = 'alpha(opacity=0)';
  noobackground.style.display = 'none';
  noobackground.style.visibility = 'hidden';
  noowindow_box.innerHTML = "";
  noowindow_close.innerHTML = "";
}