	var currentGalleryImg = null;

	$(document).ready(function() {
		
		//
		//	Logo click = home!
		//
		var link = $("h1").find("a").attr("href");
		if(link){
			$('h1').css('cursor', 'pointer');
			$("h1").click(function() {
				window.location = link;
			});
		}
		

		$('.onelink a').click(function(e){
			e.preventDefault();
		});
		$('.onelink').click(function(){
			window.location = $(this).find("a").attr("href");
		});
		$('.onelink').hover(function(){
				$(this).addClass("onelinkover");
			}, function(){
				$(this).removeClass("onelinkover");
			});
		
		if( $("#shoppingBag input").attr("value") > 0 ){
			$("#shoppingBag #checkoutNow").show();
			$("#shoppingBag #viewBagLink").show();
		}
		
		
		$('td.actions a.remove').click(function(e){
			e.preventDefault();
			var parentrow = $(this).parents('.itemrow');
			if( confirm("Are you sure you want to remove this from your bag?\n" + parentrow.find('.item').text() + "\n(color: " + parentrow.find('.color').text() + ", size: " + parentrow.find('.size').text() + ")") ){
				
				$.ajax({
					url: '/action/bag/remove/' + parentrow.attr("id") + '/',
					type: 'GET',
					dataType: 'html',
					timeout: 1000,
					error: function(){ alert('Error removing from cart.'); },
					success: function(html){
						if(html=="false") alert('Error removing from cart.');
						else{
							parentrow.remove();
							updateBagTable();
						}
					}
				});
			}
		});
		
		$('.checkout').click(function(e){
//			e.preventDefault();
		});
	
	});
	
	function updateBagTable(){
		if( $('.itemrow').attr("id") ){
			var totalprice = 0;
			$('.itemrow td.price .pricenum').each(function(){
				totalprice += Number($(this).text());
			});
			
			$('.totalprice div').text("$"+totalprice);
		}
		else{
			$('tbody').append('<tr><td colspan="5" class="emptybag">Your bag is empty!</td></tr>');
			$('tfoot tr').remove();
			$('.checkout').hide();
		}
	}
