var aEvents = Array(
                Array('scrollleft', 'mouseover', galleryScrollRight, true),
                Array('scrollleft', 'mouseout', galleryScrollStop, true),
                Array('scrollright', 'mouseover', galleryScrollLeft, true),
                Array('scrollright', 'mouseout', galleryScrollStop, true)
              );

var iLayerRightIE;

function galleryScrollLeft() {
  
  var oScroller = document.getElementById('scroller'); 
  var iScrollerWidth;
  var iLayerLeft;
  var iLayerRight;

  
  if( oScroller.offsetWidth <= 710 ) { return; }
  
  if( iLayerLeft == undefined ) { iLayerLeft = oScroller.offsetLeft; }
 
  if( window.getComputedStyle ) {
    
    iScrollerWidth = parseInt( document.defaultView.getComputedStyle( oScroller, null ).getPropertyValue('width') );
    iLayerRight    = parseInt( document.defaultView.getComputedStyle( oScroller, null ).getPropertyValue('right') );
    
  } else if( oScroller.currentStyle ) {
    
    iScrollerWidth = ( oScroller.currentStyle['width'] == 'auto' ) ? oScroller.offsetWidth : parseInt( oScroller.currentStyle['width'] );
    
    if( iLayerRightIE == undefined ) {
      
      iLayerRightIE = ( oScroller.currentStyle['right'] == 'auto' ) ? ( iLayerLeft + iScrollerWidth ) : parseInt( oScroller.currentStyle['right'] );
      
    }
    
    iLayerRight = ( oScroller.currentStyle['right'] == 'auto' ) ? Math.abs( ( iLayerLeft + iScrollerWidth ) - iLayerRightIE ) : parseInt( oScroller.currentStyle['right'] );
      
  }
  
  if( ( iScrollerWidth - 710 ) % 2 == 0 ) {
    
    if( iLayerRight == ( iScrollerWidth - 710 )  ) { galleryScrollStop(); return; }
    
  } else {
    
    if( iLayerRight == ( ( iScrollerWidth - 710 ) +1 ) ) { galleryScrollStop(); return; }
    
  }  

  iLayerLeft          -= 2;
  oScroller.style.left = iLayerLeft+'px';
  timeout              = setTimeout('galleryScrollLeft()', 10);
  
}

function galleryScrollRight() {
  
  var iLayerLeft;
  var oScroller = document.getElementById('scroller');
 
  if( iLayerLeft == undefined ) { iLayerLeft = oScroller.offsetLeft; }
  if( iLayerLeft == 20 ) { galleryScrollStop(); return; }
    
  iLayerLeft += 2;
  
  oScroller.style.left = iLayerLeft+'px';
      
  timeout = setTimeout('galleryScrollRight()', 10);
  
}

function galleryScrollStop() {
  
  var oScroller = document.getElementById('scroller');
  
  if( timeout != 'undefined' ) {
    
    clearTimeout( timeout );
    
  }
  
}

function addScrollerEvent( oElement, sEvent, fCallback ) {
  
  try {
    
    if( sEvent.search(/on/i) > -1 ) { sEvent = sEvent.replace(/on/i, ''); }
   
    if( oElement.addEventListener ) {
      
      oElement.addEventListener( sEvent, fCallback, false );
      
    } else if( oElement.attachEvent ) {
      
      oElement.attachEvent( 'on'+sEvent, fCallback );
      
    } else {
      
      //throw error
            
    }
    
  } catch( oError ) {
    
  }
  
}

function AttachScrollEvents() {
  
  for( t in aEvents ) {
    
    if( aEvents[t][3] == true ) {
      
      oElement = document.getElementById( aEvents[t][0] );
      addScrollerEvent( oElement, aEvents[t][1], aEvents[t][2] );
    } else if( aEvents[t][3] == false ) {
      
      oElement = aEvents[t][0];
      addScrollerEvent( oElement, aEvents[t][1], aEvents[t][2] );
    } else {
      //fout
	
    }
    
    
    
  }
  
}

addScrollerEvent( window, 'load', AttachScrollEvents );
