$('#carousel .image').cycle({ 
                      fx:     'fade', 
                      timeout: 7000,
                      speed: 600,
                      before:  onBefore,
                      after:   onAfter,
                      pager:'#pager',
                      next:   '#browse-next',
                      prev:   '#browse-prev'
                   });
 
function onBefore() { 
	$('#carouselbox').height($('#carouselbox').innerHeight());
    $('.info').fadeOut(200);
}

function onAfter() { 
    $('.'+this.id).fadeIn(200);
	$('#carouselbox').height('');
}


$(document).ready(function() {
    $('.hoverable').hover(function() {
      $(this).addClass('onhover');
    }, function() {
      $(this).removeClass('onhover');
    });
    


    $('.folded li h2').click(function() {
    	if (!$(this).parent().is('.open')) {
    		$(this).parent().addClass('open');
    		$(this).parent().find('.fold').slideDown();
    	} else {
    	    $(this).parent().removeClass('open');
    		$(this).parent().find('.fold').slideUp();
    	}
    });
});



$(function(){
    //Get our elements for faster access and set overlay width
    var div = 	$('.product div.gallery');
    ul = $('.product ul.photos'),
    
    // unordered list's left margin
    ulPadding = 100;

    ul.width(ul.find('li').width() * ul.find('li').length);
    //alert(ul.find('li').width() * ul.find('li').length);
    //Get menu width
    var divWidth = div.width();

    //Remove scrollbars
    div.css({overflow: 'hidden'});

    //Find last image container
    var lastLi = ul.find('li:last');

    div.scrollLeft(200);
    
    //When user move mouse over menu
    div.mousemove(function(e){

      //As images are loaded ul width increases,
      //so we recalculate it each time
      var ulWidth = (ul.find('li').width() * ul.find('li').length) + ulPadding;

      var left = (e.pageX - div.offset().left) * (ulWidth-divWidth) / divWidth;
      div.scrollLeft(left);
    });
});

$(document).ready(function(){
  $('#search .field').focus(function() { $(this).val(''); });
  $('#search .button').click(function(e) { $('#frm-search').submit(); e.preventDefault(); });
});
