jQuery.noConflict();
(function ($) {

	jQuery.fn.cartHover = function (cartItems, duration) {
		var cartLink = $(this),
		t;
		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 () {
	
		var $body = $('html, body'),
		    hasBeenClicked = false,
		    tabs = $('.tabs a'),
		    createMessage = function (text, type) {
		        return '<ul class="messages"><li class="' + type + '-msg"><ul><li>' + text + '</li></ul></li></ul>';
		    };
			
		//category page		
		
		$('.more').click(function (e) {
			$(this).hide().nextAll().show();
			e.preventDefault();
		});
		
		$('.less').click(function (e) {
			$(this).hide().prevUntil('.more').hide();
			$('.more', $(this).parent()).show();
			e.preventDefault();
		});
		
		
		$('.cart-container .enquiry').cartHover('.cart-items');
			   
		$('#IsDeliverySame').change(function (event) {
			if (document.customerform.IsDeliverySame.checked) {
				$('.billing-details .input-text, .billing-details select').attr('disabled', 'disabled');
			} else {
				$('.billing-details .input-text, .billing-details select').removeAttr('disabled');
			}
			event.preventDefault();
		});
	
		//category navigation
		if ($('#nav').length) {
			$('#nav > li').bind('mouseenter', function (event) {
				hasBeenClicked = false;
				$('.pager select').hide();
				$(this).siblings('li').removeClass('over').children('ul').hide();
				$(this).addClass('over').children('ul').show();
			}).bind('mouseleave', function (event) {
				$('.pager select').show();
				if (hasBeenClicked === false) {
					$(this).removeClass('over').children('ul').hide();
				}
			}).bind('click', function (event) {
				if ($(this).children('ul').length) {
					hasBeenClicked = true;
					$('.pager select').show();
					$(this).addClass('over').children('ul').show();
					event.preventDefault();
					event.stopPropagation();
				}
			});
			
			$('#nav li li').bind('click', function (event) {
				var el = this,
				visibility = $(el).children('ul').css('display');
				hasBeenClicked = true;
				if (visibility === 'block') {
					$(el).children('ul').fadeOut();
					return false;
				}
				if ($(el).children('ul').length > 0) {
					$(el).siblings().removeClass('over');
					$(el).addClass('over');
					if ($(el).siblings('li').children('ul:visible').length > 0) {
						$(el).siblings('li').children('ul:visible').fadeOut(function () {
							$(el).children('ul').fadeIn();
						});
					} else {
						$(el).children('ul').fadeIn();
					}
					return false;	
				}
				event.stopPropagation();
			});
		
			$body.bind('click', function (event) {
				hasBeenClicked = true;
				$('#nav li').removeClass('over');
				$('#nav li ul').hide();
			});
		}
		
		if (tabs.length) {
			tabs.click(function (event) {
				tabs.removeClass('selected').filter(this).addClass('selected');
				$('#tab-content').html(createMessage('Loading&hellip;', 'loading')).load(this.href + ' #content-box', function (response, status, xhr) {
					if (status === 'error') {
						$('#tab-content').html(createMessage('An error has occured. ' + xhr.status + ' ' + xhr.statusText, 'error'));
					}
				});
				event.preventDefault();
			}).eq(0).addClass('selected').click();
		}
	
		//External Links
	
		$('a[rel="external"], #links a').live('click', function (event) {
			window.open(this.href);
			event.preventDefault();
		}); 
	
	});
	
}(jQuery));

Cufon('h1, h2, h3, h4, h5, h6, dt');