jQuery.noConflict();
(function($){

	$.fn.cartHover = function ( cartItems, duration ) {
		var cartLink = $(this),
		duration = duration || 500;
		
		//$(cartItems).hide();
		
		cartLink.live('mouseenter mouseleave', function (e) {
			if ( e.type === 'mouseover' ) {
				$(cartItems).fadeIn();
			} else {
				t = setTimeout(function () {
					$(cartItems).fadeOut();
				}, duration);
			}
		});
		
		$(cartItems).live('mouseenter mouseleave', function (e) {
			if ( e.type === 'mouseover') {
				clearTimeout(t);
				$(cartItems).show();
			} else {
				$(cartItems).fadeOut();
			}
		});
	};

	$(function(){
	
		$('.hover-link').cartHover('.cart-items');
	
		if ($('#media-content li h2 a img').length > 0) {
			$('#media-content li h2 a').lightBox();
		}
	
//Home page banner

		$('.banner-slide').not(':first').hide();
		$('#banner-navigation li a:first').addClass('selected');
			
		$('#banner-navigation li a').each(function (i,e) {
			$(e).click(function (event) {
				window.clearInterval(auto);
				$('.banner-slide:visible').fadeOut(1000);
				$('.banner-slide').eq(i).delay(1000).fadeIn(1000);
				$('#banner-navigation li a').removeClass('selected');
				$(e).addClass('selected');
				autoFunc();
				event.preventDefault();				
			});
		});
		
		var int = 0,
		autoFunc = function (i) {
			auto = window.setInterval(function(){
				(int<3) ? int++ : int=0;
				$('#banner-navigation li a').eq(int).click();
			},5000);
		};
		autoFunc();
		
//Login show/hide

		$('.sidebar-box .toggle').live('click', function (event) {
			if ($('#login-form').is(':visible')) {
				$(this).html('+');
			} else {
				$(this).text('-');
			}
			$('.sidebar-box #login-form').toggle();
			event.preventDefault();
		});

//Store Locator

		$('.stockists:first').show().siblings().hide();
		
		$('.South-East .stockist').hide();
		
		$('#Map area').click(function(event){
			var element = '.' + this.id.replace(' ','-');
			$(element).show().siblings().hide();
			event.preventDefault();
		}).hover(function(e){
			$('#popup').css({
				'top': e.pageY + 10,
				'left': e.pageX + 10
			}).text(this.id).show();
		},function(){
			$('#popup').hide();
		});
		
		$('.counties').change(function(){
			var element = '.' + $(this).val().replace(' ','-');
			$('.South-East .stockist').hide();
			$(element).show();
		});
		
		$('body').mousemove(function(e){
			$('#popup').css({
				'top': e.pageY + 10,
				'left': e.pageX + 10
			});
		});
		
		$('<div id="popup" />').hide().appendTo('body');

//Media Scroller

		$('#media-nav li a, .top').autoScroll();

	//$('#media-nav li a, .top').click(function(event){
//		var $htmlbody = $('html,body'),
//		topScroll = $htmlbody.scrollTop(),
//		hashOffset = $(this.hash).offset().top;
//		if (topScroll != hashOffset) {
//			$htmlbody.animate({
//				scrollTop: hashOffset
//			});
//		}
//		event.preventDefault();
//	});

//Product Page Image

		$('.more-views ul li a').click(function(event){
			$('#image').attr('src',this.href);
			//product_zoom = new Product.Zoom('image', 'track', 'handle', 'zoom_in', 'zoom_out', 'track_hint');
			event.preventDefault()
		});
	
		$price = $('.product-info-box .product-name-price .price');
		$('#product-options-wrapper select').change(function(){
			setTimeout(function(){Cufon($price);},1);
		});

//External Links

		$('a[rel="external"]').live('click',function(event){
			window.open(this.href);
			event.preventDefault();			   
		});
		
	});	  
})(jQuery);