
document.strayorange = {
	bgImage : new Image(),
	pageScrollHandler: function (event) { 
		var scrollableHeight = document.strayorange.bgImage.naturalHeight - window.innerHeight;
		if (window.scrollMaxY > scrollableHeight) { 
			var bgPosition = - scrollableHeight * window.pageYOffset / window.scrollMaxY;
			document.body.style.backgroundPosition = "center " + bgPosition + "px";
			document.body.style.backgroundAttachment = "fixed";
		} else /* if (window.scrollMaxY > 0) */ {
			document.body.style.backgroundPosition = "center top";
			document.body.style.backgroundAttachment = "scroll";
		}
	},
	onLoadHandler : function (event) {
		//var bgURL = /url\((.*)\)/.exec(window.getComputedStyle(document.body, "background-image"));
		//document.strayorange.bgImage.src = bgURL[1];
		document.strayorange.pageScrollHandler();
	}, 

	pageWidth : function() {return window.innerWidth != null ? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null; },
	pageHeight : function() {return  window.innerHeight != null ? window.innerHeight : document.documentElement && document.documentElement.clientHeight ?  document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null; },
	posLeft : function() {return typeof window.pageXOffset != 'undefined' ? window.pageXOffset : document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0; },
	posTop : function() {return typeof window.pageYOffset != 'undefined' ? window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0; },
	posRight : function() {return posLeft()+pageWidth();} ,
	posBottom : function() {return posTop()+pageHeight();}	
};

document.strayorange.bgImage.src = "aeq-image.php?mode=fillw&w="+document.strayorange.pageWidth()+"&ifile=bg2.jpg";
document.body.style.backgroundImage = "url("+document.strayorange.bgImage.src+")";
document.body.style.backgroundAttachment = "scroll";
document.body.style.backgroundPosition = "center top";

if (window.addEventListener) {
	window.addEventListener('scroll', document.strayorange.pageScrollHandler, true);
	window.addEventListener('load', document.strayorange.onLoadHandler, false);
} else {
	window.onscroll = document.strayorange.pageScrollHandler;
	window.onload = document.strayorange.onLoadHandler; 
}	

