window.onload = function() {
	MyroomguitarScr.init(); scrollTips.init();
	}

var MyroomguitarScr = {
	speed : 50,      //set here the scroll speed: when this value increase, the speed decrease. 
	maxStep: 150,	 //set here the "uniform motion" step for long distances
	brakeK: 3,		 //set here the coefficient of slowing down
	hash:null,		
	currentBlock:null,
	requestedX:0,
	init: function() {
		if(navigator.appVersion.indexOf('AppleWebKit')>0) {
			document.getElementById('arrows').style.display = 'none';
		}
		var lnks = document.getElementsByTagName('a');   
		for(var i = 0, lnk; lnk = lnks[i]; i++) {   
			if ((lnk.href && lnk.href.indexOf('#') != -1) &&  ( (lnk.pathname == location.pathname) ||
			('/'+lnk.pathname == location.pathname) ) && (lnk.search == location.search)) {  
			lnk.onclick = this.initScroll;   		
			}   
		}    
	},
	getElementXpos: function(el){
		var x = 0;
		while(el.offsetParent){  
			x += el.offsetLeft;    
			el = el.offsetParent;
		}	return x;
	},		
	getScrollLeft: function(){
		if(document.all) return (document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft;
		else return window.pageXOffset;   
	},	
	getWindowWidth: function(){
		if (window.innerWidth)	return window.innerWidth; 
		if(document.documentElement && document.documentElement.clientWidth) return document.documentElement.clientWidth;
	},
	getDocumentWidth: function(){
		if (document.width) return document.width;
		if(document.body.offsetWidth) return document.body.offsetWidth;
	},
	initScroll: function(e){
		var targ;  
		if (!e) var e = window.event;
		if (e.target) targ = e.target;
		else if (e.srcElement) targ = e.srcElement;   
		MyroomguitarScr.hash = targ.href.substr(targ.href.indexOf('#')+1,targ.href.length); 
		MyroomguitarScr.currentBlock = document.getElementById(MyroomguitarScr.hash);   
		if(!MyroomguitarScr.currentBlock) return;
		MyroomguitarScr.requestedX = MyroomguitarScr.getElementXpos(MyroomguitarScr.currentBlock); 
		MyroomguitarScr.scroll(targ); 
		return false;
	},
	scroll: function(targ){
		var left  = MyroomguitarScr.getScrollLeft();
		if(MyroomguitarScr.requestedX > left) { 
			var endDistance = Math.round((MyroomguitarScr.getDocumentWidth() - (left + MyroomguitarScr.getWindowWidth())) / MyroomguitarScr.brakeK);
			endDistance = Math.min(Math.round((MyroomguitarScr.requestedX-left)/ MyroomguitarScr.brakeK), endDistance);
			var offset = Math.max(2, Math.min(endDistance, MyroomguitarScr.maxStep));
		} else { var offset = - Math.min(Math.abs(Math.round((MyroomguitarScr.requestedX-left)/ MyroomguitarScr.brakeK)), MyroomguitarScr.maxStep);
		} window.scrollTo(left + offset, 0);  
		if(Math.abs(left-MyroomguitarScr.requestedX) <= 1 || MyroomguitarScr.getScrollLeft() == left) {
			window.scrollTo(MyroomguitarScr.requestedX, 0);
			if(typeof XULDocument != 'undefined') {
				location.hash = MyroomguitarScr.hash;
			}
			if(window.opera) {mark.change_colors(MyroomguitarScr.hash, 30, 3500,'#aaaaaa','#fffbea');}
			mark.change_opacity(MyroomguitarScr.hash);
			MyroomguitarScr.hash = null;
		} else 	setTimeout(MyroomguitarScr.scroll,MyroomguitarScr.speed);			
	}
}

 var scrollTips = {
	dx : null,
	init : function() {	
		if (window.addEventListener) {
		window.addEventListener("DOMMouseScroll", this.mouseScroll, false);
		} else 	window.onmousewheel = document.onmousewheel = this.mouseScroll;
	},

	mouseScroll : function(e) {
		if (!e) var e = window.event;
		if (window.opera) {delta = event.wheelDelta/120; delta = -delta;}
		if (e.wheelDelta <= 0 || e.detail>=0){  
		window.scrollBy(80,0);
		} else  window.scrollBy(-80,0) ; 
	} ,
	
	arrowScroll: function(val) {
		if(val==1) {
			window.scrollBy(70,0);
		} else {
			window.scrollBy(-70,0)
		}
	}
}