/**
 * @author Gregor Aisch
 * @publisher webvariants GbR
 * @website http://www.webvariants.de/
 * @contact info - webvariants - de
 * 
 * This script uses the prototype library. It must be loaded before this file is loaded.
 * You can find prototype from http://www.prototypejs.org/
 */

if (Prototype.Version) {
	document.observe('dom:loaded', function() {
		if (!$('bar')) return;
		$('bar').trueContentHeight = $('bar').offsetHeight;
		$('bar').style.height = Math.max($('content').offsetHeight, $('bar').offsetHeight)+'px';
		window.onscroll = function() {
			
			var innerHeight = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight;
			var pageYOffset = window.pageYOffset ? window.pageYOffset : document.documentElement.scrollTop;
			var headerHeight = $('header').offsetHeight;
			if ($('bar').trueContentHeight > innerHeight + pageYOffset - $('header').offsetHeight) {
				
				$('bar').style.backgroundAttachment = 'scroll';
				$('bar').style.backgroundPosition = 'left '+(Math.max($('bar').trueContentHeight - 172, innerHeight + pageYOffset - $('header').offsetHeight - 172))+'px';
			} else {
				$('bar').style.backgroundAttachment = 'fixed';
				$('bar').style.backgroundPosition = ($('page').offsetLeft+200)+'px bottom';
			}
		};
		window.onscroll();
		window.onresize = window.onscroll;
	});
}