// main.js

var arrPageSizes;

$(document).ready(function(){
	arrPageSizes = ___getPageSize();
	
	$(".activerow").bind("click", function(){
		window.location = $(this).find("a").attr("href");
		return false;
	});
});

function overlay_in()
{
	$('#jquery-overlay').css({
			backgroundColor:	'#3c0b45',
			opacity:			0.8,
			width:				arrPageSizes[0],
			height:				arrPageSizes[1]
	}).fadeIn();
}

function overlay_out()
{
	$('#jquery-overlay').fadeOut(function() { $('#jquery-overlay').hide(); });
}

$(window).resize(function() {
	get_page_sizes();
});

function get_page_sizes()
{
	var arrPageSizes = ___getPageSize();

	$('#jquery-overlay').css({
		width:		arrPageSizes[0],
		height:		arrPageSizes[1]
	});
}

function ___getPageSize() {
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		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
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			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 = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
};

var windowState = (function(){
	var readScroll = {scrollLeft:0,scrollTop:0};
	var readSize = {clientWidth:0,clientHeight:0};
	var readScrollX = 'scrollLeft';
	var readScrollY = 'scrollTop';
	var readWidth = 'clientWidth';
	var readHeight = 'clientHeight';
	function otherWindowTest(obj){
		if((document.compatMode)&&
				(document.compatMode == 'CSS1Compat')&&
				(document.documentElement)){
			return document.documentElement;
		}else if(document.body){
			return document.body;
		}else{
			return obj;
		}
	};
	if((typeof this.innerHeight == 'number')&&
			(typeof this.innerWidth == 'number')){
		readSize = this;
		readWidth = 'innerWidth';
		readHeight = 'innerHeight';
	}else{
		readSize = otherWindowTest(readSize);
	}
	if((typeof this.pageYOffset == 'number')&&
			(typeof this.pageXOffset == 'number')){
		readScroll = this;
		readScrollY = 'pageYOffset';
		readScrollX = 'pageXOffset';
	}else{
		readScroll = otherWindowTest(readScroll);
	}
	return {
getScrollX:function(){
			return (readScroll[readScrollX]||0);
		},
getScrollY:function(){
			return (readScroll[readScrollY]||0);
		},
getWidth:function(){
			return (readSize[readWidth]||0);
		},
getHeight:function(){
			return (readSize[readHeight]||0);
		}
	};
})();