	$(document).ready(function() {
		$('#search').click(function() {
			$(this).select();
		})


    // Auto-update sort order
    $('.paginator select').change(function() {
      $(this).parents('form').trigger('submit');
    });

    /*
		if($.browser.msie && parseInt($.browser.version)<8) {
			$('.box-info.first').prepend('<div class="first-before"></div>').append('<div class="first-after"></div>')
			$('.box-info.second').prepend('<div class="second-before"></div>').append('<div class="second-after"></div>')
			$('.box-info.third').prepend('<div class="third-before"></div>').append('<div class="third-after"></div>')
			// $('div.selectbox-wrapper').css('margin-top', '18px')
			// $('div.header-main-menu ul.menu li').css({'display': 'inline', 'zoom': 1})
			// $('div.site-content .box-info h3').css({'z-index': 2})
		}
		*/


    // IE7 fixes
    if($.browser.msie && parseInt($.browser.version)<8) {
      
      // Fix position of dropdown menus absolutely to stop them going off to top right
      $('ul.menu > li').each(function(i, item) {
        var x = $(item).offset().left + 8;
        var y = $(item).offset().top + 26;
        $(item).children('ul').css({position : 'absolute', left : x, top : y});
      });
    }

    // Fancybox popup on product images
    $('a[rel=fancybox]').fancybox({type: 'image'});

    // Only add gallery to product images if there's more than 1
    if($('.productgallery .main').children().length > 1) {
      $('.productgallery .main').cycle({
        pager:  '#gallerypager',
        timeout:  0,
        pagerAnchorBuilder: function(idx, slide) {
          var img = $(slide).attr('data-image');
          return '<li class="' + (idx ==0 ? 'first' : '') + '"><a href="#" title="Larger image" ><img src="image.php/' + img + '/99/99" width="99" height="99" /></a></li>';
        }
      });
    }

    /*
		$('.header-main-menu ul li').each(function(index) {
			var range = ($(this).offset().left)-($('.header-main-menu ul').offset().left);
			$('#tab-'+index).css('margin-left', range+22);
		});

		$('.header-main-menu .tab').each(function(index) {
			var lists = $('.header-main-menu #tab-'+index+' ul').size();
			$(this).css('width', (lists*$('.header-main-menu .tab ul').outerWidth()));
		});

		$('html').click(function() {
			$('.tab').hide();
			$('.header-main-menu ul li').removeClass('current');
		});

		var tabHover = 0;

		$('.header-main-menu .tab').hover(function() {
		}, function() {
			tabHover = 0;
			$('.tab').hide();
		})

		$('.header-top').hover(function() {
			$('.tab').hide();
		})

		$('#content').hover(function() {
			$('.tab').hide();
		})

		showTab = function(tab) {
			$('#tab-'+tab).fadeIn('fast')
		}

		$('.header-main-menu ul li').hover(function(event) {
				showTab($(this).index('.header-main-menu ul li'))
				tabHover = 1;
				$('.header-main-menu ul li').removeClass('current');
				$(this).addClass('current');
			event.stopPropagation();
		}, function() {
			if($(this).hasClass('current')) {
				$(this).removeClass('current');
			}
			if(tabHover==0) $('.tab').hide();
			tabHover = 0;
		});
		*/


		function product_slider_rotate(type) {
			var active = 0;

			$('ul.nav-product-slider li.dot').each(function(index) {
				if($(this).hasClass('active')) {
					active = index;
				}
			});

			if($('.product-slider ul').hasClass('landing-list')) { 
				var modifier = 5 
				if(type=='right') {
					count = 1;
				} 
				if(type=='left') {
					count = 0;
				} 
			} else {
				var modifier = 1
				if(type=="left") {	
					var count = active - 1
					if(count<0) { count = 4 }
				}
				if(type=="right") {	
					var count = active + 1
					if(count>4) { count = 0 }
				}	
			}		
			
			var margin = count * $('.product-slider li').outerWidth() * modifier
			$('.product-slider ul').stop(true, false).animate({'margin-left': -margin}, 1500)
			$('ul.nav-product-slider li.dot').removeClass('active')
			$('ul.nav-product-slider li.dot').eq(count).addClass('active')
		}
		
		$('.product-slider ul').stop(true, false).animate({'margin-left': 0},100)
		
		$('ul.nav-product-slider li.dot').click(function() {
			if($('.product-slider ul').hasClass('landing-list')) { 
				var modifier = 5 
			} else {
				var modifier = 1
			}
			var margin = $(this).index('ul.nav-product-slider li.dot') * $('.product-slider li ').outerWidth() * modifier
			$('.product-slider ul').stop(true, false).animate({'margin-left': -margin}, 1500)
			$('ul.nav-product-slider li.dot').removeClass('active')
			$(this).addClass('active')
		});
		
		$('.arrow-left').click(function() {		
			product_slider_rotate("left");
		});
		
		$('.arrow-right').click(function() {		
			product_slider_rotate("right");
		});
		
		if($('.carousel-content')[0]) {
			$('.carousel-content').cycle({
				fx:      'fade', 
				speed:    1500, 
				timeout:  9000,
				after: onBefore	
			});
		}
		
		
		$('.carousel-manage li').click(function() {
			$('.carousel-manage li').removeClass('active');
			$(this).addClass('active');
			$('.carousel-content').cycle($(this).index('.carousel-manage li'));
		});
		
		function onBefore(curr,next,opts) {
			$('.carousel-manage .active').removeClass('active');
			$('.carousel-manage li').eq(opts.currSlide).addClass('active');
		}
	});
