var site = {
	
	init : function() {
		
		$(".popup").each(function() {
			$(this).click(function(e) {
				e.preventDefault();
				site.popup(this.href, 800, 600);
			});
		});
		
		$(".close").click(function(e) {
			e.preventDefault();
			$(".layer").hide();
			$("#screen").hide();
		})
	},
	
	popup : function(url, width, height) {
		window.open(url, "popup", "status = 1, height =" +  height + ", width =" + width + ", resizable = 1" )
	},
	
	layer : {
		
		obj : null,
		ajaxData : null,
	
		set : function(obj) {
			
			site.layer.obj = obj;
			site.layer.align(site.layer.obj);
			
			$(window).resize(function() {
				site.layer.align(obj)
			});
		},
		
		align : function(obj) {
			
			var box = obj;
			
			$(box).css({"top" : site.vCenter(box) + "px", "left" : site.hCenter(box, box.parent()) + "px"});
		},
		
		// finds the window xOffset/yOffset of the user's window (Helper function for vCenter)
		screenPosition : function () {
			if( typeof( window.pageYOffset ) == 'number' ) {
				//Netscape compliant
				return [ window.pageXOffset, window.pageYOffset ];
			} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
				//DOM compliant
				return [ document.body.scrollLeft, document.body.scrollTop ];
			} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
				//IE6 standards compliant mode
				return [ document.documentElement.scrollLeft, document.documentElement.scrollTop ];
			} else {
				return [ -1, -1 ];
			}
		},
		
		// finds window height of the user's screen (Helper function for vCenter)
		screenSize : function () {
			var vpW = 0, vpH = 0;
			if (typeof window.innerWidth != 'undefined')
			{ return [ window.innerWidth, window.innerHeight ]; }
			else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0)
			{ return [ document.documentElement.clientWidth, document.documentElement.clientHeight ]; }
			else
			{ return [ document.getElementsByTagName('body')[0].clientWidth, document.getElementsByTagName('body')[0].clientHeight ]; }
		}
	},
	
	// centers the layer to the user's screen (Could be used for other types of elements that need to be centered to the user's screen)
	vCenter : function (selector) {
		var wPosition = site.layer.screenPosition();
		var wSize = site.layer.screenSize();
		var top = ((wSize[1] / 2) - ($(selector).height() / 2)) + wPosition[1];
		top = (top < 0) ? 100 : top;
		
		return top;
	},
	
	// center an obj based on its container's width
	hCenter : function (obj, container) {
		
		var left = (container.width() - obj.width() ) / 2 + container.scrollLeft();
		
		return left;
	}
}
