jQuery(document).ready(function($){

  $('button, input[type=submit], input[type=button]')
    .bind('mouseover focus', function(){ $(this).addClass('hover'); })
    .bind('mouseout blur', function(){ $(this).removeClass('hover'); })
    .bind('focus', function(){ $(this).addClass('focus'); })
    .bind('blur', function(){ $(this).removeClass('focus'); });

  
  $('#home .box')
    .bind('mouseenter', function(){ $(this).find('img').stop().animate({ opacity: .2 }, 500); })
    .bind('mouseleave', function(){ $(this).find('img').stop().animate({ opacity: 1 }, 1000); })
    .find('img').css({ opacity: 1 });

  $('#content a:has(img)').filter('[href*=".jpg"],[href*=".gif"],[href*=".png"]')
    .each(function(){ $(this).lightBox(); });
  $('#content .gallery a').lightBox();
  
  //lightbox
  $('.thatcart-images a').lightBox();
  $('.thatcart-images span.image-medium')
    .css({ cursor: 'pointer' })
    .click(function(){
      $('.thatcart-images .selected a').trigger('click');
    });

  //photo changer
  $('.thatcart-images ul li a')
    .bind('mouseover', function(){
      if(!$(this).parent().hasClass('selected')) {
        $('.thatcart-images ul li').removeClass('selected');
        $(this).parent().addClass('selected');
        newImg = $(this).attr('medium');
        newCaption = $(this).attr('title');
        $('.thatcart-images .image-medium img')
          .stop()
          .animate({ opacity: 0 }, 300, function(){
            $(this)
              .after('<div class="loading"></div>')
              .parent().find('.loading').hide().fadeIn(300);
            $(this)
              .attr('src', newImg)
              .load(function(){
                $(this)
                  .parent().find('.loading').remove();
                $(this)
                  .stop()
                  .animate({ opacity: 1 }, 600)
                  .parent().find('.caption').html(newCaption);
              })
              .error(function(){
                $(this)
                  .parent().find('.caption').html('Image not found.')
                  .parent().find('.loading').remove();
              });
          })
          .parent().find('.loading').remove();
      }
      return false;
  });
    
});

