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 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;
}




var FlashLightbox = Class.create();

FlashLightbox.prototype = {
	initialize: function(){
	  
		if (!document.getElementsByTagName){ return; }
		var anchors = document.getElementsByTagName('a');

		// loop through all anchor tags
		for (var i=0; i<anchors.length; i++){
			var anchor = anchors[i];
			
			var relAttribute = String(anchor.getAttribute('rel'));
			
			// use the string.match() method to catch 'lightbox' references in the rel attribute
			if (anchor.getAttribute('href') && (relAttribute.toLowerCase().match('flashlb'))){
				anchor.onclick = function () {myFlashLightbox.start(this); return false;}
			}
		}
	  
		var objBody = document.getElementsByTagName("body").item(0);
		
		var objOverlay = document.createElement("div");
		objOverlay.setAttribute('id','f_overlay');
		objOverlay.style.display = 'none';
		objOverlay.onclick = function() { myFlashLightbox.hide(); return false; }
		objBody.appendChild(objOverlay);
	
		var objLightbox = document.createElement("div");
		objLightbox.setAttribute('id','f_lightbox');
		objLightbox.style.display = 'none';
		objLightbox.onclick = function() { myFlashLightbox.hide(); return false; }
		objBody.appendChild(objLightbox);
		
		var objDivFlashPlayer = document.createElement("div");
	 	objDivFlashPlayer.setAttribute('id', 'flashPlayerDiv');
	 	objLightbox.appendChild(objDivFlashPlayer);
	 /*	
	 	var objDivClose = document.createElement("div");
	 	objDivClose.style.marginTop = "10px";
	 	objDivClose.style.paddingTop = "10px";
	 	objDivClose.style.color = "white"; 	
	 	objDivClose.style.textAlign = "right";
	 	objDivClose.style.opacity = "1";
	 	objDivClose.onClick = function() { myFlashLightbox.hide(); return false; }
	 	objLightbox.appendChild(objDivClose);
	 	
	 	var objImgClose = document.createElement("img");
	 	objImgClose.src="./lightbox/images/closelabel.gif";
	 	objDivClose.appendChild(objImgClose);*/
	 	
	},
	
	start: function (flashLink){

	// show  
		var arrayPageSize = getPageSize();
		Element.setHeight('f_overlay', arrayPageSize[1]);
		new Effect.Appear('f_overlay', { duration: 0.2, from: 0.0, to: 0.8 });
		
		var arrayPageSize = getPageSize();
		var arrayPageScroll = getPageScroll();
		var lightboxTop = arrayPageScroll[1] + (arrayPageSize[3] / 15);
	
		Element.setTop('f_lightbox', lightboxTop);
		Element.show('f_lightbox');
		
		var FO = {	
 			movie:"./flash/flvplayer.swf",
	 		width:"824", height:"584", majorversion:"7", build:"0",
			bgcolor:"#FFFFFF", allowfullscreen:"true",
			flashvars:"file=" +  flashLink.getAttribute('href')
			};
		UFO.create(FO, "flashPlayerDiv");
		
		
	},

	hide: function() {
		Element.hide('f_lightbox');
  		new Effect.Fade('f_overlay', { duration: 0.2});

	}

}

function initFlashLightbox() { myFlashLightbox = new FlashLightbox(); }
Event.observe(window, 'load', initFlashLightbox, false);

