var Modal = {
	ON: false,
	overlay_id: 'modal_overlay',
	content_id: 'modal_content',
	print_style_idx: null,
	opts: {
		cWidth: '560',
		cHeight: '100'
	},
	show: function(url) {
		if(!Modal.ON) {
			$(document.body).append('<div id="'+Modal.overlay_id+'"></div><div id="'+Modal.content_id+'"><div class="preloader">Loading...</div></div>');
			$('#'+Modal.overlay_id).css({position: 'absolute', top: 0, left: 0, zIndex: 5000, backgroundColor: '#000000', opacity: '0'});
			$('select').hide();
			$(window).resize(Modal.position);
			$('.content').addClass('print_hide');
			$('#footer').addClass('print_hide');
		}
		
		$('#'+Modal.content_id).css({position: 'absolute', width: Modal.opts.cWidth+'px', height: 'auto', zIndex: 5001});
		Modal.position();
		$('#'+Modal.content_id).load(url, null, Modal.loaded);
		Modal.ON = true;
	},
	hide: function() {
		if(Modal.ON) {
			$('select').show();
			$('#'+Modal.overlay_id).remove();
			$('#'+Modal.content_id).remove();
			$('.content').removeClass('print_hide');
			$('#footer').removeClass('print_hide');
		}
		Modal.ON = false;
	},
	loaded: function() {
		Modal.position();
	},
	position: function() {
		var arrPageSize = Modal.pageSize();
		var arrPageScroll = Modal.pageScroll();
		
		$('#'+Modal.overlay_id).width(arrPageSize[0]);
		$('#'+Modal.overlay_id).height(arrPageSize[1]);
		
		var posLeft = arrPageScroll[0] + ((arrPageSize[2]/2) - ($('#'+Modal.content_id).width()/2));
		var posTop = arrPageScroll[1] + ((arrPageSize[3]/2) - ($('#'+Modal.content_id).height()/2));
		if(posTop < 5) {
			posTop = 5;
		}
		
		$('#'+Modal.content_id).css({left: posLeft, top: posTop});
	},
	pageSize: function() {
		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;
	},
	pageScroll: function() {

		var xScroll, yScroll;

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

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