// Lightbox JS File
// Copyright 2006 Figureseven, Inc.

var loaded = false;
var origWidth = 0;
var origHeight = 0;

function lightBox(page) {

	document.body.scrollTop=0;

	myWidth = screenSize('width');
	myHeight = screenSize('height');
	
	document.body.style.overflow='hidden';
	//$('html').style.overflow='';

	mainBlackout = $('siteMainBlackout');
	theIframe = $('contentiframe');

	scrollDistance = getScrollXY();
	//alert(scrollDistance);
	mainBlackout.style.top=scrollDistance+'px';

	theIframe.style.width = '1000';
	theIframe.style.height = '';
	//theIframe.src=page;
	
	new Ajax.Request(page, {
 		method: 'get',
  		onSuccess: function(transport) {
		theIframe.style.display='none';
    	theIframe.innerHTML = transport.responseText
		mainBlackout.style.visibility='visible';
		mainBlackout.style.height=myHeight+'px';
		mainBlackout.style.width=myWidth+'px';
		resizeImageBox();
		}
	});

} //end func

function resizeImageBox() {
	if ($('contentiframe').getWidth() > 100) {
		resizeWin();
		theIframe.style.display='block';
	} else {
		setTimeout("resizeImageBox()",100);
	} //end else;
} 

function closeLightBox() {

	myWidth = screenSize('width');
	myHeight = screenSize('height');


	document.body.style.overflow='';
	//$('html').style.overflow='';

	mainBlackout = $('siteMainBlackout');
	theIframe = $('contentiframe');

	mainBlackout.style.visibility='hidden';
	mainBlackout.style.height=1+'px';
	mainBlackout.style.width=1+'px';

//	alert(document.frames['contentiframe']);
//	document.frames['contentiframe'].removeHistory();

	//loaded = true;
	//theIframe.src='/blank.html';
	//setTimeout("loaded = false;",500);

} //end func


function screenSize(axis) {

	  var myWidth = 0, myHeight = 0;
	  if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	  } else {
		if( document.documentElement &&
			( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		  //IE 6+ in 'standards compliant mode'
		  myWidth = document.documentElement.clientWidth;
		  myHeight = document.documentElement.clientHeight;
		} else {
		  if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			//IE 4 compatible
			myWidth = document.body.clientWidth;
			myHeight = document.body.clientHeight;
		  }
		}
	  }

	if (axis == 'width') {
		return myWidth;
	} else {
		return myHeight;
	} // end if
} //end function

function resizeWin(setOrig) {
	var scroll = false;
	
	myWidth = screenSize('width');
	myHeight = screenSize('height');

	mainBlackout = $('siteMainBlackout');


	if ($('contentiframe')) {
		theIframe = $('contentiframe');
		//theIframe.scrolling='no';
	
		//if (setOrig != null) { 
		origWidth = $(theIframe).getWidth();
		origHeight = $(theIframe).getHeight();
		//}
	
		//alert(origWidth + '  ' + origHeight)
	
		//theIframe.style.top=(myHeight-parseInt(theIframe.style.height))/2+'px';
		//theIframe.style.left=(myWidth-parseInt(theIframe.style.width))/2+'px';
		
		if((myWidth-parseInt(origWidth))/2 < 20) {
			theIframe.style.left=20+'px'; 
			theIframe.style.width=myWidth+'px'; 
			scroll = true; 
		} else { 
			theIframe.style.width=origWidth+'px'; 
			theIframe.style.left=(myWidth-parseInt(theIframe.style.width))/2+'px';
		}
		
		if((myHeight-parseInt(origHeight))/2 < 0) {
			theIframe.style.top=0+'px';
			theIframe.style.height=myHeight+'px';
			scroll = true; 
		} else { 
			theIframe.style.height=origHeight-2+'px'; 
			theIframe.style.top=(myHeight-parseInt(theIframe.style.height))/2+'px';
		}
		
		if(scroll == true) { 
			//theIframe.scrolling='auto'; 
		} else { 
			//theIframe.scrolling='no'; 
		}
		
		//window.status = theIframe.scrolling;
		
		if (mainBlackout.style.visibility=='visible') {
			
			mainBlackout.style.height=myHeight+20+'px';
			mainBlackout.style.width=myWidth+20+'px';
	
		} else {
			mainBlackout.style.height=1+'px';
			mainBlackout.style.width=1+'px';
		} //end else
		
		theIframe.style.width = '900px';
		//alert(theIframe.style.width);
		//theIframe.style.width=1000+'px';

	} //end if

} // end function

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return scrOfY;
}
