$(document).ready(function() {
  attach_button_handlers();
	attach_checkout_button();
});

function attach_button_handlers() {
		
	$('input.button').live('mouseover', function() {
		$(this).addClass('pointer');
		var img = $(this).css('background-image');
		img = img.replace('Brown', 'Black');
		$(this).css('background-image', img).css('color', 'white');
	}).live('mouseout',function() {
		$(this).removeClass('pointer');
		var img = $(this).css('background-image');
		img = img.replace('Black', 'Brown');
		$(this).css('background-image', img).css('color', 'black');
	});


	$('input[name=selected_payment_method]').click(function() {
		$(this).siblings().filter('div').not($(this).next().next().next()).slideUp('medium');
		$(this).next().next().next().slideDown('fast');
		//hide all of the divs that are not this one
	});

	$('input.continue').live('mouseover', function() {
		$(this).addClass('pointer');
		var img = $(this).css('background-image');
		img = img.replace('Brown', 'Black');
		$(this).css('background-image', img).css('color', 'white');
	}).live('mouseout', function() {
		$(this).removeClass('pointer');
		var img = $(this).css('background-image');
		img = img.replace('Black', 'Brown');
		$(this).css('background-image', img).css('color', 'black');
	});


	$('input[name=Update Quantities], input[name=Add Coupon]').mouseover(function() {
		$(this).addClass('pointer');
		var img = $(this).css('background-image');
		img = img.replace('White', 'Black');
		$(this).css('background-image', img).css('color', 'white');
	}).mouseout(function() {
		$(this).removeClass('pointer');
		var img = $(this).css('background-image');
		img = img.replace('Black', 'White');
		$(this).css('background-image', img).css('color', 'black');
	});

}

function updatePrice(id) {
    
    var url = 'shopping_cart.php?ajax=1&update_qty=1&product_id=' + id;

    url = url + '&qty=' + document.getElementById('qty_' + id).value;
    send(url);
    
    return false; 
}
function updateQty(id) {

		updatePrice(id);
    return false;
}

function attach_checkout_button() {
	$('input#final_checkout_button').live('click', checkout_button_clicked);

}
var already_checked_out = false;
function checkout_button_clicked() {
	if(already_checked_out) {
		alert('Your order is processing, please wait.');
		return false;
	}
	
	already_checked_out = true;
	
	return true;
}

