/* Scroller.js by Tobias Jacksteit 2009 */
var scroller = null;
var scrollTime = 50;
var scrollAmount = 20;

function scrollInit() {
	var height = parseInt( document.getElementById( 'content_scroll' ).scrollHeight );
	var offset = parseInt( document.getElementById( 'content' ).offsetHeight != undefined ? document.getElementById( 'content' ).offsetHeight : '424px' );
	var currPos = parseInt( document.getElementById( 'content_scroll' ).style.top != undefined && document.getElementById( 'content_scroll' ).style.top != '' ? document.getElementById( 'content_scroll' ).style.top : '0px' );
	if( height < offset ) {
		document.getElementById( 'scroll_up' ).style.display = 'none';
		document.getElementById( 'scroll_down' ).style.display = 'none';
	} else {
		if( window.addEventListener ) {
			document.getElementById( 'tile' ).addEventListener( "MouseWheel", scrollWheel, false );
			document.getElementById( 'tile' ).addEventListener( "DOMMouseScroll", scrollWheel, false );
		} else {
			document.getElementById( 'tile' ).onmousewheel = scrollWheel;
		}
	}
}

function scroll( scrollFunc ) {
	if( scroller != null ) {
		clearInterval( scroller );
		scroller = null;
	}
	if( scrollFunc != null ) {
		scroller = setInterval( scrollFunc, scrollTime );
	}
}

function scrollDown( onlyOnce ) {
	scrollFunc = function() {
		var height = parseInt( document.getElementById( 'content_scroll' ).scrollHeight );
		var offset = parseInt( document.getElementById( 'content' ).offsetHeight != undefined ? document.getElementById( 'content' ).offsetHeight : '424px' );
		var currPos = parseInt( document.getElementById( 'content_scroll' ).style.top != undefined && document.getElementById( 'content_scroll' ).style.top != '' ? document.getElementById( 'content_scroll' ).style.top : '0px' );
		if( height + currPos > offset ) {
			document.getElementById( 'content_scroll' ).style.top = ( currPos - scrollAmount ) + 'px';
		}
	};
	scrollFunc();
	if( onlyOnce == undefined ) {
		scroll( scrollFunc );
	}
}

function scrollUp( onlyOnce ) {
	scrollFunc = function() {
		var height = parseInt( document.getElementById( 'content_scroll' ).scrollHeight );
		var offset = parseInt( document.getElementById( 'content' ).offsetHeight != undefined ? document.getElementById( 'content' ).offsetHeight : '424px' );
		var currPos = parseInt( document.getElementById( 'content_scroll' ).style.top != undefined && document.getElementById( 'content_scroll' ).style.top != '' ? document.getElementById( 'content_scroll' ).style.top : '0px' );
		if( currPos < 0 ) {
			document.getElementById( 'content_scroll' ).style.top = ( currPos + scrollAmount ) + 'px';
		}
	};
	scrollFunc();
	if( onlyOnce == undefined ) {
		scroll( scrollFunc );
	}
}

function scrollStop() {
	scroll();
}

function scrollToTop() {
	document.getElementById( 'content_scroll' ).style.top = '0px';
}

function scrollWheel( evt ) {
	if( !evt ) {
		evt = window.event;
	}
	if( evt.wheelDelta ) {
		var delta = evt.wheelDelta / 120;
		if( window.opera ) {
			//delta = -delta;
		}
		delta = Math.round( delta );
	} else if( evt.detail ) {
		var delta = - evt.detail / 3;
	}
	
	if( delta > 0 ) {
		scrollUp( true );
	} else if( delta < 0 ) {
		scrollDown( true );
	}
}

if( window.onload != undefined ) {
	var tempOnLoad = window.onload;
}
if( window.addLEventListener ) {
	window.addEventListener( "load", scrollInit, false );
} else {
	window.onload = function() {
	scrollInit();
	if( tempOnLoad != undefined ) {
		tempOnLoad();
	}
}
}