
//****************************************************************************************
//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/narnooprint-box.css';
headID.appendChild(cssNode);
}
//********************************
//Set variables
//********************************
var print_id;
var pid;
var user;
var user_id;
//setup skin..
var noopoverlay_window;
var nooplight_window;
var noopwindow_close;
var noopwindow_box;
//fadein
var noopbackground;
var noopbox;
var pwindowWidth, pwindowHeight;
var leftMarginpWidth;
var topMarginpWidth;
var pleftSpace;
var ptopSpace;

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

function narnooPrint(user,pid){

user_id=user;
print_id=pid;
		
		if (self.innerHeight) {	// all except Explorer
			if(document.documentElement.clientWidth){
				pwindowWidth = document.documentElement.clientWidth; 
			} else {
				pwindowWidth = self.innerWidth;
			}
			pwindowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			pwindowWidth = document.documentElement.clientWidth;
			pwindowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			pwindowWidth = document.body.clientWidth;
			pwindowHeight = document.body.clientHeight;
		}	
		
		
		pleftSpace = ((pwindowWidth - 800) / 2);
		ptopSpace = ((pwindowHeight - 600) / 2);
		
		leftMarginpWidth = ((pleftSpace /pwindowWidth)*100);
		topMarginpWidth = ((ptopSpace /pwindowHeight)*100);
		
		setnarnoopWindow();
}

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

function setnarnoopWindow(){

noopoverlay_window = document.createElement("div");
nooplight_window = document.createElement("div");
noopwindow_close = document.createElement("div");
noopwindow_box = document.createElement("div");

noopoverlay_window.id = "nooplayout";
nooplight_window.id = "noopwindow-box";
noopwindow_close.id = "noopwinclose-box";
noopwindow_box.id = "noopmedia-box";
noopwindow_close.setAttribute("onclick","deactivateprint()");
noopwindow_close.style.cursor = 'pointer';

document.body.appendChild(noopoverlay_window);
document.body.appendChild(nooplight_window);
nooplight_window.appendChild(noopwindow_close);
nooplight_window.appendChild(noopwindow_box);
initprintFade();

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

function initprintFade() {
	noopbackground = document.getElementById('nooplayout');
	noopbackground.style.display = 'block';
 	noopbackground.style.visibility = 'visible';
	
	for (var i=0;i<8;i++)
		setTimeout('setpOpacity('+i+')',30*i);
	
	setVisibleprintElements();
}

function setpOpacity(value)
{
	noopbackground.style.opacity = value/10;
	noopbackground.style.filter = 'alpha(opacity=' + value*10 + ')';
}
//********************************
//Displays media contents
//********************************
function setVisibleprintElements()
{
	
	noopbox = document.getElementById('noopwindow-box');
	noopbox.style.display = 'block';
	noopbox.style.visibility = 'visible';
	noopbox.style.left = leftMarginpWidth+'%';
	noopbox.style.top = topMarginpWidth+'%';
	loadPrint();
	
}
//********************************
//Loads the print media
//********************************
function loadPrint()
{
	//Set video in iFrame.
	noopwindow_box.innerHTML = "<iframe width=\"800px\" height=\"600px\" scrolling=\"no\" frameborder=\"0\" src=\"http://www.pmedia.narnoo.com/pprint.php?id="+user_id+"&pid="+print_id+"\"></iframe>";
	//Set Close Window.
	noopwindow_close.innerHTML="<table width=\"800\" height=\"18\" ><tr class=\"noopclose\"><td align=\"center\"><a href=\"javascript:deactivateprint()\">X Close Window</a></td></tr></table>";
	
}
//********************************
//Deactivates Lightbox
//********************************
function deactivateprint(){
 
  var pb = document.body;	
  
  nooplight_window.removeChild(noopwindow_box);
  nooplight_window.removeChild(noopwindow_close);
  pb.removeChild(nooplight_window);
  pb.removeChild(noopoverlay_window);
  
  noopbackground.style.opacity = '0';
  noopbackground.style.filter = 'alpha(opacity=0)';
  noopbackground.style.display = 'none';
  noopbackground.style.visibility = 'hidden';
  noopwindow_box.innerHTML = "";
  noopwindow_close.innerHTML = "";
}
