

window.onload = function()

{
	HtinyScrolling.init(); scrollTips.init();
	}




var HtinyScrolling = {
	brakeK: 3,		 //set here the coefficient of slowing down
	hash:null,		
	currentBlock:null,
	requestedX:5,
	init: function() {
  var lnks = document.getElementsByTagName('a');   
  var ilnks = 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 = 5;
  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;   
  HtinyScrolling.hash = targ.href.substr(targ.href.indexOf('#')+1,targ.href.length); 
  HtinyScrolling.currentBlock = document.getElementById(HtinyScrolling.hash);   
  if(!HtinyScrolling.currentBlock) return;
  HtinyScrolling.requestedX = HtinyScrolling.getElementXpos(HtinyScrolling.currentBlock); 
  HtinyScrolling.scroll(targ); 
  return false;
 },
 scroll: function(targ){
  var left  = HtinyScrolling.getScrollLeft();
  if(HtinyScrolling.requestedX > left) { 
   var endDistance = Math.round((HtinyScrolling.getDocumentWidth() - (left + HtinyScrolling.getWindowWidth())) / HtinyScrolling.brakeK);
   endDistance = Math.min(Math.round((HtinyScrolling.requestedX-left)/ HtinyScrolling.brakeK), endDistance);
   var offset = Math.max(2, Math.min(endDistance, HtinyScrolling.maxStep));
  } else { var offset = - Math.min(Math.abs(Math.round((HtinyScrolling.requestedX-left)/ HtinyScrolling.brakeK)), HtinyScrolling.maxStep);
  } window.scrollTo(left + offset, 0);  
  if(Math.abs(left-HtinyScrolling.requestedX) <= 1 || HtinyScrolling.getScrollLeft() == left) {
   window.scrollTo(HtinyScrolling.requestedX, 0);
   if(!document.all || window.opera) location.hash = HtinyScrolling.hash;
   //if(window.opera) {mark.change_colors(HtinyScrolling.hash, 30, 3500,'#aaaaaa','#fffbea');}
   //mark.change_opacity(HtinyScrolling.hash);
   //you can also call the function "mark.change_colors(HtinyScrolling.hash, fps, (duration in sec), #(color in hex), #(color in hex))" to change background color of selected section   
   HtinyScrolling.hash = null;
  } else  setTimeout(HtinyScrolling.scroll,HtinyScrolling.speed);   
 }
}
 
/* the mouse scrolling doesn't work with Opera, that hasn't a event associated to the mouse wheel */
 
var scrollTips = {

 dx : null,
 init : function() {
	 
  if (window.addEventListener) {
  window.addEventListener("DOMMouseScroll", this.mouseScroll, false);
  } else document.attachEvent("onmousewheel", this.mouseScroll); 
  var left = document.getElementById('left');
 },
 
 mouseScroll : function(e) {
  if (!e) var e = window.event;
  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)
  }
 }
}
 


