$.extend({
  getUrlVars: function(){
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
      hash = hashes[i].split('=');
      vars.push(hash[0]);
      vars[hash[0]] = hash[1];
    }
    return vars;
  },
  getUrlVar: function(name){
    return $.getUrlVars()[name];
  }
});


$(document).ready(function(){
  // only do this if not IE6
  if ($.browser.msie && $.browser.version=="6.0") {
  
  } else {

  $('#thumbnails').before('<img src="/images/Lexgrafix_leftarrow.png" id="leftarrow" /><img src="/images/Lexgrafix_rightarrow.png" id="rightarrow" />');
  $('#leftarrow')
    .bind('next', function () {
      $('#thumbnails').scrollTo('-=101px', {duration:600, easing:'swing'} );
    })
    .hover(function(){ 
        autoscrollingLeft = true;
      }, function(){ 
        autoscrollingLeft = false;
      }
    )
    .click(function(){ 
      $('#thumbnails').scrollTo('-=101px', {duration:600, easing:'swing'} ); 
    }
  );
  $('#rightarrow')
    .bind('next', function () {
      $('#thumbnails').scrollTo('+=101px', {duration:600, easing:'swing'} ); 
    })
    .hover(function(){ 
        autoscrollingRight = true;
      }, function(){ 
        autoscrollingRight = false;
      }
    )
    .click(function(){ 
      $('#thumbnails').scrollTo('+=101px', {duration:600, easing:'swing'} ); 
    }
  );

/*
  // start offset if offset set
  var offset = $.getUrlVar('offset');
  if (offset) {
    $('#thumbnails').scrollLeft(offset);
    
    // un-hide the container
    $('#products_nav').css({'position' : 'static', 'left' : 'auto', 'overflow' : 'hidden'});
    $('#footer').css({'marginTop' : '0'});
  }
*/

  // scroll to the selected product  
  var product = $.getUrlVar('product');
  if (product) { $('#thumbnails').scrollTo('[name='+product+']', {duration:1800, easing:'swing'}); }

/*  
  // capture links and add thumbnail menu offset
  $('a').click(function(e){
    
    // not the home page
    if ( $(this).attr('href').search("product") ) {
      e.preventDefault();
      window.location = $(this).attr('href') + '&offset=' + $('#thumbnails').scrollLeft();
    }
    
  });
*/

  }
  
});


var autoscrollingLeft = false;
var autoscrollingRight = false;

setInterval(function () {
  if (autoscrollingLeft) {
    $('#leftarrow').trigger('next');
  } else if (autoscrollingRight) {
    $('#rightarrow').trigger('next');
  }
}, 650);

