$(document).ready(function()
{
	$('.comments form label[for]+input[type="text"],.comments form label[for]+textarea')
	.wrap('<div class=\"hover-wrap\" style=\"position:relative\"><\/div>')
	.focus(function(){$(this).prev().hide();})
	.blur(function(){if ( !this.value ) $(this).prev().show()})
	.each(function(){$(this).before( $(this).parent().prev() );
	if ( this.value ) $(this).prev().hide();});

	if ($('.slider').length > 0)
	{
		$('.slider').cycle({
			pause: 1
			,timeout: 12000
			,delay: -4000
		});
	}
	if ($('.new-releases>ul>li').length > 1)
	{
		$('.new-releases').append('<div class="pager">'
			+'</div><button class="prev"><<</button>'
			+'<button class="next">>></button>').addClass('ready');
		$('.new-releases>ul').cycle({
			fx: 'scrollHorz'
			,pause: 1
			,timeout: 0
			,next: '.new-releases .next'
			,prev: '.new-releases .prev'
			,pager: '.new-releases .pager'
		});
	}
//	if ($('.back-catalogue ul li').length > 1)
//	{
//		$('.back-catalogue').append('<div class="pager">'
//			+'</div><button class="prev"><<</button>'
//			+'<button class="next">>></button>');
//		$('.back-catalogue>ul').cycle({
//			fx: 'scrollHorz'
//			,pause: 1
//			,timeout: 0
//			,next: '.back-catalogue .next'
//			,prev: '.back-catalogue .prev'
//			,pager: '.back-catalogue .pager'
//		});
//	}
	if ($('.stills ul li').length > 1)
	{
		function onAfter(curr, next, opts)
		{
			var index = opts.currSlide;
			$('.stills .prev')[index == 0 ? 'hide' : 'show']();
			$('.stills .next')[index == opts.slideCount - 1 ? 'hide' : 'show']();
		}
		$('.stills').append('<button class="prev"><<</button><button class="next">>></button>');
		$('.stills ul').cycle({
			fx: 'scrollHorz'
			,pause: 1
			,timeout: 0
			,next: '.stills .next'
			,prev: '.stills .prev'
			,nowrap: 1
			,after:   onAfter
		});
	}

	if ($('.dvd-covers ul li').length > 6)
	{

		$('.dvd-covers').append('<button class="prev"><<</button><button class="next">>></button>');
		$('.dvd-covers:not(.dvd-covers.extended)').jCarouselLite({
			btnNext: '.next'
			,btnPrev: '.prev'
			,visible: 6
		});
	}

	// checkout form enhancement
	if ($("#different_postal_address").is(":checked")) // If checked
	{
		$("#alternative_postal_address").show("fast"); //show the hidden div
	}
	else
	{
		$("#alternative_postal_address").hide("fast"); //otherwise, hide it
	}
	$('#different_postal_address').click(function ()
	{
		$('div#alternative_postal_address').toggle();
	});

	// Commented out because we are not implementing a Jquery
	// sidebar basket in version 1 of the site
	
	//$('button#AddToBasket').click(function() // Add to Basket
	//{
	//	var filmTitle = $('.content>h1').text();
	//	var price = parseFloat($('#ItemPrice').text());
	//	var basketPnl = '<div id="BasketPnl" class="pnl basket">'+
	//		'<h5>YOUR BASKET</h5>'+
	//		'<h6>No. of items: <span class="qty">1</span></h6>'+
	//		'<ul class="purchases"></ul>'+
	//		'<p class="total"><strong>Total:</strong> &pound;<span id="Total">' + price + '</span></p>'+
	//		'<ul class="links">'+
	//			'<li class="continue"><a href="/shop/basket">View basket</a></li>'+
	//			'<li class="checkout"><a href="/shop/checkout" class="button">Checkout</a></li>'+
	//		'</ul>'+
	//	'</div>';
	//	var popup = '<div class="popup">'+
	//		'<h6>Just added to your basket</h6>'+
	//		'<p>1 x ' + filmTitle + '</p>'+
	//		'<p class="price"><strong>Price:</strong> &pound;'+ price + '</p>'+
	//	'</div>';
    //
	//	if ($('#BasketPnl').length == 0)
	//	{
	//		$('.sidebar>.navigation').after(basketPnl);
	//		$('.purchases').append('<li><span class="qty">1</span> x '+
	//			filmTitle + '<a href="#RemoveItem" id="Remove">Remove</a>' + popup + '</li>');
	//		$('.popup').delay(2000).fadeOut();
	//	}
	//	else
	//	{
	//		var qty = parseInt($('#BasketPnl>h6>.qty').text());
	//		qty++;
	//		$('.popup').fadeIn().delay(2000).fadeOut();
	//		$('#Total').text(price * qty);
	//		$('.qty').text(qty);
	//	}
	//	
	//});
	//
	//$('#Remove').live('click', function(e)
	//{
	//	var qty = parseInt($('#BasketPnl>h6>.qty').text());
	//	var itemPrice = parseFloat($('#ItemPrice').text());
	//	var totalPrice = parseFloat($('#Total').text());
	//	if (qty > 1)
	//	{
	//		qty--;
	//		$('#Total').text(parseFloat(totalPrice - itemPrice).toFixed(2));
	//		$('.qty').text(qty);
	//	}
	//	else
	//	{
	//		$(this).parent().remove();
	//		$('.qty').text(0);
	//		$('#Total').text(0);
	//		$('#BasketPnl ul.links').hide();
	//	}
	//	e.preventDefault();
	//});
});

