
LightBox = function() {

	//container
	this.outerDiv = DIV({'class':'lightbox'});
	setNodeAttribute(this.outerDiv, "id", "lightbox");
	this.outerDiv.style.position = "absolute";
	this.outerDiv.style.top = "0px";
	this.outerDiv.style.left = "0px";
		
	//mask
	this.mask = DIV();
	this.mask.style.position = "absolute";
	this.mask.style.top = "0px";
	this.mask.style.left = "0px";
	this.mask.style.width = "100%";
	this.mask.style.height = "100%";
	this.mask.style.backgroundColor = "#333333";
	this.mask.style.opacity = "0.95";
	this.mask.style.filter = "alpha(opacity=90)";
	this.outerDiv.appendChild(this.mask);
	
	//main window
	this.innerDiv = DIV({'class':'image'});
	this.innerDiv.style.position = "absolute";
	this.innerDiv.style.top = "0px";
	this.innerDiv.style.left = "0px";
	this.innerDiv.style.width = "500px";
	this.innerDiv.style.height = "550px";
	this.innerDiv.style.border = "5px solid #000";
	this.innerDiv.style.backgroundColor = "#fff";
	this.outerDiv.appendChild(this.innerDiv);
	
	this.image = IMG();
	this.image.style.position = "absolute";
	this.image.style.top = "0px";
	this.image.style.left = "0px";
	this.image.style.width = "500px";
	this.image.style.height = "500px";
	this.image.style.borderBottom = "2px solid #000";	
	this.innerDiv.appendChild(this.image);
	
	this.title = DIV({'class':'title'});
	this.title.style.position = "absolute";
	this.title.style.top = "500px";
	this.title.style.left = "0px";
	this.title.style.width = "400px";
	this.title.style.height = "50px";	
	this.title.style.fontSize = "20px";
	this.title.style.padding = "10px 0px 0px 20px";
	this.innerDiv.appendChild(this.title);
	
	var email = IMG({src:"images/mail_send.png", alt:"email"});
	email.style.position = "absolute";
	email.style.top = "500px";
	email.style.left = "400px";
	email.style.width = "50px";
	email.style.height = "50px";
	email.style.cursor = "pointer";
	email.title = "Email this item";
	connect(email, "onclick", this, this.sendEmail);
	this.innerDiv.appendChild(email);
	
	var close = IMG({src:"images/delete.png", alt:"x"});
	close.style.position = "absolute";
	close.style.top = "500px";
	close.style.left = "450px";
	close.style.width = "50px";
	close.style.height = "50px";
	close.title = "Close window";
	close.style.cursor = "pointer";
	connect(close, "onclick", this, this.close);
	this.innerDiv.appendChild(close);
	
};

LightBox.prototype.open = function(imageUrl, title) {

	var lb = $('lightbox');
	if(!lb) {
		document.body.appendChild(this.outerDiv);
	}
	
	//determine window width and height
	var w = getWindowWidth();
	var h = getWindowHeight();
	
	//set width/height on this.outerDiv
	this.outerDiv.style.width = w + "px";
	this.outerDiv.style.height = h + "px";
	
	//center this.innerDiv
	this.innerDiv.style.top = ((h/2)-275) + "px";
	this.innerDiv.style.left = ((w/2)-250) + "px";				
	
	//set this.image src
	this.image.src = imageUrl;
	//update titlebar
	replaceChildNodes(this.title, title || "");

	this.outerDiv.style.display = "block";
	
};

LightBox.prototype.close = function() {
	this.outerDiv.style.display = "none";
};

LightBox.prototype.sendEmail = function() {

};




/**
 * Utility function to get the height of the current window (browser)
 * across multiple browsers
 */
function getWindowHeight() {	
	var ih = parseInt(window.innerHeight);						//FF, Opera, Safari, etc	
	var ch = parseInt(document.body.clientHeight);				//IE quirks	
	var dch = parseInt(document.documentElement.clientHeight);	//IE strict
	if(ih) return ih;
	else if(ch) return ch;
	else return dch;
}

/**
 * Utility function to get the width of the current window (browser)
 * across multiple browsers
 */
function getWindowWidth() {	
	var iw = parseInt(window.innerWidth);						//FF, Opera, Safari, etc
	var cw = parseInt(document.body.clientWidth);				//IE quirks	
	var dcw = parseInt(document.documentElement.clientWidth);	//IE strict
	if(iw) return iw;
	else if(cw) return cw;
	else return dcw;
}