var scrolldelay;

function pageScrollL() {
    	window.scrollBy('-5',0); // horizontal and vertical scroll increments
    	scrolldelay = setTimeout('pageScrollL()',15); // scrolls every 100 milliseconds
		checkPos();
}

function pageScrollR() {
    	window.scrollBy('5',0); // horizontal and vertical scroll increments
    	scrolldelay = setTimeout('pageScrollR()',15); // scrolls every 100 milliseconds
		checkPos();
}

function stopScroll() {
//	alert(parseInt($('gallery').getStyle('width'))+' / Scroll:'+getScrollX()+' /winSize:'+getWinWidth())
	clearTimeout(scrolldelay);
}

function checkPos(mode) {
		if($('gallery') == null) return;
		var RightS = $('rightScroll');
		var LeftS = $('leftScroll');
		var Gallery = $('gallery');
			var galWidth = parseInt(Gallery.getStyle('width'))

		var Lfx = new Fx.Styles(LeftS, {duration:500, wait:false});
		if(getScrollX() > 0 && LeftS.getStyle('opacity') == '0') {
			Lfx.start({opacity:1})
		}
		else if(getScrollX() == 0){
			Lfx.start({opacity:0})
			if(mode != 'init') {stopScroll()}
		}

		var Rfx = new Fx.Styles(RightS, {duration:500, wait:false});
		if(mode == 'init' || (galWidth - getScrollX() - getWinWidth() > 0 && RightS.getStyle('opacity') == '0')) {
			//RightS.setStyle('display','')
			Rfx.start({opacity:1})
		}
		else if(galWidth - getScrollX() - getWinWidth() == 0) {
			//RightS.setStyle('display','none')
			Rfx.start({opacity:0})
			if(mode != 'init') {stopScroll()}
		}
}

function getWinWidth() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return myWidth;
//  window.alert( 'Height = ' + myHeight );
}

function getScrollX() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;

  
  }
//  return [ scrOfX, scrOfY ];
  return scrOfX;
}

/*
function ScrollDiv(id){
if(this==window)
  return new ScrollDiv(id); //ScrollDiv() called as a Function
  var elt=document.getElementById(id);
  var w=elt.offsetWidth;
  var s=elt.parentNode.offsetWidth;
  if(!w || !s || s>w){
    this.scroll=Function(""); return;}
  var divStyle=elt.style;
  var offset=0;
  var maxOffset=s-w;
  var timer=null;
  var self=this;
 
  this.scroll= function(dir,speed){
    var coef=1, S=speed;
    while(S--)coef*=2;
    if (timer)window.clearTimeout(timer);
    switch (dir){
      case 's': //stop
        break;
      case 'l': //left
        if(offset>maxOffset){
          offset-=coef;
          divStyle.left=Math.min(offset,0)+"px";
          timer=window.setTimeout(function(){self.scroll('l',speed)},25)}
        break;
      case 'r': //right
        if(0>offset){
          offset+=coef;
          divStyle.left=Math.max(offset,maxOffset)+"px";
          timer=window.setTimeout(function(){self.scroll('r',speed)},25)}
    }
  }
}
*/
