
window.addEvent('load', function() {
	//imagePreloader('assets/images/button-free-quote-over.png');


});

window.addEvent('domready', function() {

	// make sure the footer is stuck to the bottom
	var mid = $('div_mid');
	var foot = $('footer');
	if(mid && foot) {
		var ftop = $(document.body).getScrollHeight() - foot.getHeight();
		var val = ftop - mid.getTop();
		mid.setStyle('min-height', val);
	}

});


function imagePreloader(imgsrc) {
	if(!window.__imagePreloader) window.__imagePreloader = [];
	var i = window.__imagePreloader.length;
	window.__imagePreloader[i] = new Image();
	window.__imagePreloader[i].src = imgsrc;
}


function menuExpand(id) {
	var submenu = $(id);
	if(!submenu) return true;
	else {
		if(submenu.getStyle('display') == 'block') {
			new Fx.Tween(submenu, {
				duration: 100,
				onComplete: function() {
					submenu.setStyle('display', 'none');
				}
			}).start('height', 1);
		} else {
			submenu.setStyles({
				height: 1,
				overflow: 'hidden',
				display: 'block'
			});
			new Fx.Tween(submenu, {
				duration: 100
			}).start('height', submenu.getScrollHeight());
		}
		return false;
	}
}

function test(v) {
	try { console.log(v); } catch(e) {};
}

function showOverlay() {
	var div = $('divOverlay');
	if(!div) {
		with( div = $(document.createElement('div')) ) {
			id = 'divOverlay';
			setStyle('position', 'absolute');
			setStyle('display', 'none');
			setStyle('z-index', 90);
			setStyle('background', '#4F4F4F');
			setStyle('top', 0);
			setStyle('left', 0);
			setStyle('opacity', 0);
		}
		document.body.appendChild(div);
	}

	if(div.getStyle('display') == 'block') return;

	div.setStyle('opacity', 0);
	div.setStyle('display', 'block');

	div.setStyle('width', getPageSize().windowWidth);
	div.setStyle('height', getPageSize().windowHeight);

	new Fx.Tween(div, {
		duration: 500
	}).start('opacity', 0.4);
}

function hideOverlay() {
	var div = $('divOverlay');
	if(!div || div.getStyle('display') == 'none' ) return;

	new Fx.Tween(div, {
		duration: 500,
		onComplete: function() {
			div.setStyle('display', 'none');
		}
	}).start('opacity', 0);

}
























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

	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 = {
		'pageWidth':	pageWidth,
		'pageHeight':	pageHeight,
		'windowWidth':	windowWidth,
		'windowHeight':	windowHeight
	}
	return arrayPageSize;
}



