$(function(){
	/*
	 * Set up product image rotator
	 */
	var timer;
		
	var products = $('ol#product-range li > a:first-child');
	products.each(function(){
		var product = $(this);
		product
			.data('info',product.siblings('div').remove())
			.append('<span></span>')
			.mouseover(function(){
				$(this).each(hoverProduct);
				clearTimeout(timer);
			});
	});
	
	nextProduct(0,5000);
	
	function nextProduct(i,t) {
		timer = setTimeout(function(){
			products.eq(i).each(hoverProduct);
			nextProduct(i+1 < products.length ? i+1 : 0, t);
		},t);
	}
	
	function hoverProduct() {
		$('div#product-range-info').html($(this).data('info'));
		$(this).parent('li').find('span').fadeTo(150,1).end().siblings().find('span').fadeTo(150,0.5);
	}
	
	
	/*
	 * Initialise popup box for TV advert
	 */
	var tvbutton = $('#btn-tv');
	tvbutton.fancybox({
			type:'iframe',
			href:tvbutton.attr('href')+'?popup',
			padding:0, 
			width:800,
			height:450,
			overlayShow:true,
			autoDimensions:true
		});
		
	$('#other-markets').hover(function(){
		$(this).children('a').addClass('hover').siblings('div').fadeIn(100);
	},function(){
		$(this).children('a').removeClass('hover').siblings('div').fadeOut(100);		
	}).children('a').click(function(){
		return false;
	});

});
