jQuery(function ($) {
    $(document).ready(function () {      
     
      $('#slidingThumbs ul').before('<li style="width: 190px"></li>');
      
      $('#header ul').cycle({
            fx: 'fade',
            speed: 3000,
            timeout: 3000,
            before:  onBefore,
            after:   onAfter 
        });
      
      $("#gallery li:first").show();
      
      $('#gallery #next').click(function(event) {
        $('#primaryimage img').hide();
              event.preventDefault();         // cancel click through
              // get current list item
              var currli = $('#gallery li:visible');
              // get next list item
              var nextli = currli.next();
              // if nextli length is 0, make it equal to first li
              if (nextli.length == 0) {
                  nextli = currli.siblings(':first');
              }
              currli.slideUp('slow');
              nextli.slideDown('slow');
        return false;
      });
      
        $('#gallery #prev').click(function(event) {
                  $('#primaryimage img').hide();
          event.preventDefault();         // cancel click through
          // get current list item
          var currli = $('#gallery li:visible');
          // get next list item
          var nextli = currli.prev();
          // if nextli length is 0, make it equal to first li
          if (nextli.length == 0) {
              nextli = currli.siblings(':last');
          }
          currli.slideUp('slow');
          nextli.slideDown('slow');
        return false;
      });
      
    });
});

function onBefore() {   
  var currli = $('#slidingThumbs li:visible:first');
  
  if($(currli).html() != "")
    $('#slidingThumbs ul').last().append('<li>' + $(currli).html() + '</li>');
  
  $(currli).animate({
    opacity: 0,
    'margin-left': '-=205'
  }, 2000, function() {
    $(currli).remove();
  });
} 
function onAfter() { 

}

