/* Horizontal Tiny Scrolling - a smooth scrolling script for horizontal websites
(the brother of the vertical "Tiny Scrolling")
by Marco Rosella - http://www.centralscrutinizer.it/en/design/js-php/horizontal-tiny-scrolling
                v0.6 - February 14, 2007
				
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA				
*/

/* the mouse scrolling doesn't work with Opera, that hasn't a event associated to the mouse wheel */

var NS = (navigator.appName=="Netscape")?true:false;   

var safari = false;
var ua = navigator.userAgent.toLowerCase();
if (ua.indexOf('safari/') != -1){
	safari = true;
}

init();

function init () {	
	if (window.addEventListener) {
	window.addEventListener("DOMMouseScroll", this.mouseScroll, false);
	} else document.attachEvent("onmousewheel", this.mouseScroll); 
}

//***************************************
// scroller til siden ved musescroll
//***************************************
function mouseScroll(e) {
	endPosition = document.body.scrollLeft;
	if (!e) 
		var e = window.event;
	if (e.wheelDelta <= 0 || e.detail>=0) {  
		window.scrollBy(80,0);
		//setTimeout(moveForward,1000);
	} else {
		window.scrollBy(-80,0);
		//setTimeout(moveBackward,1000);
	}
}

//***************************************
// scroller til venstre ved klik på pil
//***************************************
var scrollLeftInterval;
function clickDownScrollLeft(e) {
	if(!safari) {
		scrollLeft();
		scrollLeftInterval = window.setInterval('scrollLeft()', 10);
	} else {
		window.scrollBy(-400,0);
	}

}

function clickUpScrollLeft(e) {
	if(!safari) {
		scrollLeftInterval = window.clearInterval(scrollLeftInterval);
	}
}

function scrollLeft() {
	window.scrollBy(-40,0);
}

//***************************************
// scroller til hojre ved klik på pil
//***************************************
var scrollRightInterval;
function clickDownScrollRight(e) {
	if(!safari) {
		scrollRight();
		scrollRightInterval = window.setInterval('scrollRight()', 10);
	} else {
		window.scrollBy(400,0);
	}
}

function clickUpScrollRight(e) {
	if(!safari) {
		scrollRightInterval = window.clearInterval(scrollRightInterval);
	}
}

function scrollRight() {
	window.scrollBy(40,0);
}

//***************************************
// scroller til siden ved piletast down
//***************************************
document.onkeydown = KeyCheck;    
function KeyCheck(e) {
	var KeyID = (window.event) ? event.keyCode : e.keyCode;
	switch(KeyID) {
		//venstre piletast
		case 37:
			window.scrollBy(-80,0);
			
		break;
		//venstre piletast
		case 39:
			window.scrollBy(80,0);
			
		break;
		//venstre piletast
		case 38:
			window.scrollBy(-80,0);
			
		break;
		//venstre piletast
		case 40:
			window.scrollBy(80,0);
			
		break;
	}
}

//***************************************
// udfører selve flytningen af elementerne
//***************************************
var endPosition = 0;
var speed = 20;
var spot = 0;
var ease = 0;
var offset = 0;
var inScroll = false;

window.onscroll = moveMenu;
function moveMenu() {
	if(!inScroll) {
		inScroll = true;
		setTimeout(moveMenuTo,1000);
	}
	//hvis IE
	if(!NS) {
		//document.getElementById('arrowButtons').style.left = document.body.clientWidth-100;
		position = document.body.clientWidth-100;
		document.getElementById('arrowButtons').style.left = ( position + ( ignoreMe2 = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ) );
	}
}

function moveMenuTo() {
		styleObj=document.getElementById('menu').style;
		styleObj1=document.getElementById('topbanner').style;
		styleObj2=document.getElementById('bundramme').style;
		styleObj3=document.getElementById('breadcrumb').style;
		
		if(NS)
			offset = window.pageXOffset;
		else
			offset = document.body.scrollLeft;
		
		if (spot < offset) {   // check if at right stop point
			if(spot < offset-2000) {
				spot = offset-2000;
			} else {
				spot+=speed;
			}
		}
		if (spot > offset) {    // check if at right stop point
			if(spot > offset+2000) {
				spot = offset+2000;
			} else {
				spot-=speed;
			}
		}
		styleObj.left=spot+"px";
		styleObj1.left=spot+"px";
		styleObj2.left=spot+"px";
		styleObj3.left=spot+"px";
		dif = Math.abs(spot-offset);
		if(dif > 0) {
			if(dif < 200) {
				speed -= 1;
				if(speed<1)
					speed = 1;
				//ease = 200-dif;
			}
			else {
				speed = 20;
				//ease = 0;
			}
			setTimeout(moveMenuTo,ease);
		} else {
			speed = 20;
			inScroll = false; // elementet er på plads og scroll er afsluttet
		}
}


