Event.observe(window, 'load', function() {
	$$('.hs_lbshow').each(function(s){
		var frameid = s.readAttribute('href');
		Event.observe(s, 'click', function(e){
			
			lbshow(frameid);
			e.stop();
		});
	});
	
	$$('.bringtofront').each(function(s){
		var frameid = s.readAttribute('href');
		Event.observe(s, 'click', function(e){
			
			bringtofront(frameid);
			e.preventDefault();
			e.stop();
		});
	});
	
	
	$$('.hideLightbox, .popup-close, .popupbox-img').each(function(s){
		Event.observe(s, 'click', function(e){
			hideLightbox();
			e.stop();
		});
	});
	
	initLightbox();
});


///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
var ss_resume;
var lightboxTop;
var lightboxLeft;
var animtimeout;
var showing_box;
function lbshow(theframe_id)
{
	if(!theframe_id) return;
	if(showing_box) return;
	
	// prep objects
	var objOverlay = document.getElementById('overlay');
	var objiFrame = document.getElementById(theframe_id);
	
	//alert('frame_'+theframe_id);
	
	
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();

	if (objiFrame) {
		showing_box = objiFrame;
		objiFrame.style.zIndex = '100';
		objiFrame.style.position = 'absolute';
		//alert('hi');
		
		var t_height = objiFrame.style.height.replace(/px/,"");
		var t_width = objiFrame.style.width.replace(/px/,"");
		
		//objiFrame.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - t_height ) / 2))+ 'px';
		//objiFrame.style.left = (((arrayPageSize[0] - 20 - t_width) / 2) + 'px');
		objiFrame.style.top = '160px';
		objiFrame.style.left = '40px';
		
		objiFrame.style.display = 'block';
	}

	//objiFrame.style.top = '100px';
	// set height of Overlay to take up whole page and show
	objOverlay.style.height = (arrayPageSize[1] + 'px');
	//objOverlay.style.display = 'block';
	Element.hide('overlay');
	new Effect.Appear('overlay', { duration: 1.0, from: 0.0, to: 0.8 });

	// preload image
	//imgPreload = new Image();

	//var thelink = objLink.href;


	//lightboxTop =  arrayPageScroll[1] + ((arrayPageSize[3] - 35 - imgPreload.height) / 2);
	//lightboxLeft = ((arrayPageSize[0] - 20 - imgPreload.width) / 2);



	
}

//
// hideLightbox()
//
function hideLightbox()
{
	clearTimeout(animtimeout);
	
//	var objAdvert = document.getElementById('ADVERT');
//	objAdvert.style.visibility = 'visible';

	new Effect.Fade('overlay', { duration: 0.4, from: 0.8, to: 0 });
	window.setTimeout('killbox()',400);
	// get objects
		if(showing_box)	{
		showing_box.style.display = 'none';
		showing_box = '';
	}
}

function killbox()
{
	var objOverlay = document.getElementById('overlay');
	//objOverlay.style.display = 'none';		

	
}

//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}



//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		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;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}


function initLightbox()
{
	showing_box = '';
	
	if (!document.getElementsByTagName){ return; }


	var objBody = document.getElementsByTagName("body").item(0);
	var objOverlay = document.createElement("div");
	objOverlay.setAttribute('id','overlay');
	objOverlay.onclick = function () {hideLightbox(); return false;}
	objOverlay.style.display = 'none';
	objBody.insertBefore(objOverlay, objBody.firstChild);
	
	var objOverlay = document.getElementById('overlay');
	if(objOverlay)
	{
		//objOverlay.onclick = function () {hideLightbox(); return false;}
		objOverlay.style.display = 'none';
		objOverlay.style.position = 'absolute';
		objOverlay.style.top = '0';
		objOverlay.style.left = '0';
		objOverlay.style.zIndex = '90';
	 	objOverlay.style.width = '100%';
	}

	
	var divs = document.getElementsByTagName("div");
	
	// loop through all div tags
	for (var i=0; i<divs.length; i++){
		var div = divs[i];

		if (div.getAttribute("class") && (div.getAttribute("class") == "popupbox"))
		{
			div.style.display = 'none';
			div.style.position = 'absolute';
			div.style.zIndex = 100;
			//alert(div.id);
			
			var tDivs = div.getElementsByTagName('div');
			if(tDivs)
			{
				for (var ii=0; ii<tDivs.length; ii++){
					var tDiv = tDivs[ii];
					if (tDiv.getAttribute("id") && (tDiv.getAttribute("id") == "force_show"))
					{
						//alert('sd');
						lbshow(div.id);
					}
				}
				
			}
			
		}
		
	}
	
	
}

