$(function() {
	// Focus form elements where required.
	$('.focus').focus();

	// Text input hints.
	$(":text:not([value])").labelify({ labelledClass: "labelHighlight" });
	$("input[type=search]:not([value])").labelify({ labelledClass: "searchHighlight" });

	// Add relevant classes for IE for the Home page zone list.
	$('#zoneQuickList li:nth-child(3n)').addClass('lastRow');
	$('#zoneQuickList li:nth-child(3n+1)').addClass('firstRow');

	// Similarly for the Prices drop-down nav.
	$('#pricesDrop li:nth-child(2n)').addClass('lastRow');
	$('#pricesDrop li:nth-child(2n+1)').addClass('firstRow');

	// Cycle through the Home page promo images, using Cycle Lite.
	$('#cycle').cycle({
		delay: 800,
		speed: 1000,
		pause: 1
	});

	// Reveal zone nav when hovering over the Prices navigation.
	$('#primaryNavigation .zoneNav').hover(
		function(){
			$('#zoneNav').show();
		},
		function(){
			$('#zoneNav').hide();
		}
	);

	// Add product to basket options.
	$("a.x-productSpec").fancybox({
		'width'					: 900,
		'height'				: 700,
		'centerOnScroll': true
	});

	// This adds options to URLs, so if the user has JavaScript enabled, we know we're rendering things inside a fancybox.
	$("a.x-add-xml-param").each(function() {
		this.href = this.href + "?xml=true";
	});
	

	// Hub tour video.
	$("#tour-hub").click(function() {
		$.fancybox({
			'centerOnScroll': true,
			'padding'				: 45,
			'autoScale'			: false,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'width'					: 680,
			'height'				: 495,
			'href'					: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type'					: 'swf',
			'swf'						: {
			'wmode'					: 'transparent',
			'allowfullscreen'	: 'true'
			}
		});

		return false;
	});

	// Tabbed navigation.
	$(".tabContent").hide();
	$("ul.tabs li:first").addClass("selected").show();
	$(".tabContent:first").show();

	$("ul.tabs li").click(function() {

		$("ul.tabs li").removeClass("selected");
		$(this).addClass("selected");
		$(".tabContent").hide();

		var activeTab = $(this).find("a").attr("href");
		$(activeTab).fadeIn();
		return false;
	});

	// Open 'special' links in new windows.
	$("a.newWindow").append(' <em>(New window)</em>').attr('target', '_blank');

});
