//regular increment
function increment(id,type,div,incrementer,paymentmethod,ischeckout,incrementForm,incrementField){

	incrementer = (typeof incrementer == "undefined") ?
     "" : incrementer;
	 
	 paymentmethod = (typeof paymentmethod == "undefined") ?
     "0" : paymentmethod;
	 
	incrementForm = (typeof incrementForm == "undefined") ?
     "" : incrementForm;
    
   	incrementField = (typeof incrementField == "undefined") ?
     "" : incrementField;
	 
	ischeckout = (typeof ischeckout == "undefined") ?
    "0" : ischeckout;
	 
	var basketheight = $("#quickbasket").height();
     
	if (basketheight < 60) {
		basketheight = 60;
	} else {
		basketheight = basketheight;
	}

	if(incrementer != ""){
		
		
		var incrementerbutton = $("#" + incrementer);
		
		$(incrementerbutton).html("Added");
		$(incrementerbutton).parent().addClass("addedtobasket");
		
		//alert(incrementerbutton.html());
		
		$(incrementerbutton).delay(8000, function(){
			$(this).html("Add to Basket");
			$(this).parent().removeClass("addedtobasket");
		});
		
		//var toHighlight = $(incrementerbutton).closest('div.family');

	}
	
	if(incrementField != "" && incrementForm != ""){
		var formvar = $(incrementForm);		
		var incrementBy			= $("select#" + incrementField).val(); 		
	} else {
		var incrementBy			= 1;
	}
	
	var summary = $("#" + div);
	
	summary.html('<div id="quickbasket" class="loading"></div>');
	
	$("#quickbasket").css({"height" : basketheight + "px"});
	
	var url = "/_templates/_ajax/_shop/ajax_shoppingCart.cfm";	
	
	summary.load(url, {"bisajax": "1", "nshopitemid": id, "sshopitemtype": type, "action": "increment", "npaymentmethod": paymentmethod, "bischeckout": ischeckout, "nincrementby": incrementBy});

}

// regular decrement
function decrement(id,type,div,action,paymentmethod,ischeckout){
	
	var basketheight = $("#quickbasket").height();
	
	action = (typeof action == "undefined") ?
    "decrement" : action;
	
	if(action == ""){
		var action = "decrement";
	}
	
	paymentmethod = (typeof paymentmethod == "undefined") ?
    "0" : paymentmethod;
	 
	ischeckout = (typeof ischeckout == "undefined") ?
     "0" : ischeckout;
	
	var summary = $("#" + div);
	
	summary.html('<div id="quickbasket" class="loading"></div>');
	
	$("#quickbasket").css({"height" : basketheight + "px"});
	
	var url = "/_templates/_ajax/_shop/ajax_shoppingCart.cfm";	
	
	$(summary).delay(500, function(){
		decrementFinal(id,type,div,action,url,paymentmethod,ischeckout);
	});
}

// final decrement
function decrementFinal(id,type,div,action,url,paymentmethod,ischeckout){
	
	var summary = $("#" + div);
	
	summary.load(url, {"bisajax": "1", "nshopitemid": id, "sshopitemtype": type, "action": action, "npaymentmethod": paymentmethod, "bischeckout": ischeckout});
}

//payment method calculator
function paymentmethod(div){
	var paymentmethodvar = $("select#npaymentmethod").val();
	
	var basketheight = $("#quickbasket").height();
     
	var summary = $("#" + div);
	
	summary.html('<div id="quickbasket" class="loading"></div>');
	
	$("#quickbasket").css({"height": basketheight + "px"});
	
	$(summary).delay(500, function(){
		paymentFinal(div,paymentmethodvar);
	});
	
	//enableDeliveryAddress();
}

function paymentFinal(div,paymentmethodvar){

	var url = "/_templates/_ajax/_shop/ajax_shoppingCart.cfm";

	var updatediv = $("#" + div);
	
	updatediv.load(url, {"bisajax": "1", "action": "paymentmethod", "bischeckout": 1, "npaymentmethod": paymentmethodvar});
	
	//enableDeliveryAddress ();	
}

function toggleBasket(){
	if($("#fullbasket").css("display") == "none"){
		var url = "/shop/_act/act_showBasket.cfm";
		showBasket();	
	} else {
		var url = "/shop/_act/act_hideBasket.cfm";
		hideBasket();
	}
	
	$.get(url);
}

function showBasket(){
	$("#shortbasket").hide();
	$("#fullbasket").show();
}

function hideBasket(){
	$("#fullbasket").hide();
	$("#shortbasket").show();	
}

function toggleRemove(row){
	var basketitemrow = $("#basketitem" + row);
	var	removecheckrow = $("#removecheck" + row);
	
	if($(removecheckrow).css("display") == "none"){
		var rowheight = $(basketitemrow).height();
	
		$(removecheckrow).css({"height": rowheight + "px"});
	}
	
	$(basketitemrow).toggle();
	$(removecheckrow).toggle();
}

function emptybasket(check){

	if (check == "true") {
	
		var url = "/_templates/_ajax/_shop/ajax_shoppingCart.cfm";
		
		$("#ajax_cart_content").load(url, {
			"bisajax": "1",
			"bResetCart": "true"
		});
	} else if(check == "cancel") {
		$("#baskettools").html('<div id="emptybasket"><a href="javascript:void(0);" onClick="emptybasket(\'false\');">Empty Basket</a></div><button type="submit" class="submitButton">Checkout</button>')
	} else {
		$("#baskettools").html('<div id="emptybasket">Empty Basket? <a href="javascript:void(0);" onClick="emptybasket(\'true\');" class="confirmremove">Yes</a> <a href="javascript:void(0)" onClick="emptybasket(\'cancel\');" class="basketcancel">Cancel</a></div>')
	}
}
