
$(function(){


	
	
	$('.images img:first').addClass('prdImage');
	
	// get the original product image source
	var origImage = $('.prdImage').attr('src');
	
	// do the swapping here
	$('#thumbnails li img').hover(function(){
		$('.prdImage').attr('src', this.src);
		$(this).css('cursor', 'pointer');
	},function() { 
		$('.prdImage').attr('src', origImage); // reset back to the original image src
	});


// Basket Popup
	var title = $.trim( $('h2').text() );
	var size = 	$.trim( $('.content ul dl .selected').text() );
	var price = 	$('.content .price:not(".was")').text();
	var basketcontents	= $('.basket-items').html();
	var imageSrc	=	$('.images img:first').attr('src');
	var format			=	$('dd.format').text();
	
	if (size.length>0) { 
		size = $.trim( '<span>Size: ' + $('.content ul dl .selected').text() ) + '</span>';
	}
	
	if (format.length>0) { 
		format = '<p class="format">&#40;' + $.trim( $('dd.format:first').text() ) + '&#41;</p>';
	}
	
	
	$('#bask_popup').prepend('<div id="overlay"></div>');
	
	if ( $('.digital').length > 0 ) {
		$('#popup').prepend('<h4>1 item was added to your basket</h4><img class="digital-image" src="' + imageSrc + '" alt="' + title + '" width="200" height="200" /><p class="to-buy">' + basketcontents + '</p>');
	} else {
			$('#popup').prepend('<h4>1 item was added to your basket</h4><img src="' + imageSrc + '" alt="' + title + '" width="200" height="200" /><p class="title">' + title + '</p>' + size + format + '<p class="price">' + price + '</p><p class="to-buy">Your basket contains ' + basketcontents + '</p>');
	}

	if ( $('#bask_popup').length > 0 ) {
	
		$('#bask_popup').fadeIn('slow', function() {
			
			var myTimeOut;
			myTimeOut = setTimeout(function(){
				$('#bask_popup').fadeOut('slow');
			}, 7000);
		  
			$('#popup').mouseenter(function(){
			  clearTimeout(myTimeOut);
			});

		});
		
		$('#bask_popup').click(function() {
			$(this).fadeOut();
		});
		
		$("#popup").click(function(e) {
		   e.stopPropagation();
		});
		
	}



});
