// JavaScript Document

function updateBasket(action,id, product) {
	var ref = "ajax/basket.php";
	ref += "?action="+action+"&product=" + product + "&id=" + id; 

	RunAJAX(
		ref, 
			
	//onAjaxCompleted
		function (resultXML) {
			setBasketCount(resultXML);
		}, 
		
	//onAjaxProgress
		function () {
			setBasketLoading();
		}, 
		
	//onAjaxError
		function (code, s) {
			//basketStatus("<span style='color:red;'>" + code + ": " + s + "</span>");
		}
	);
}

function setBasketLoading() {
	//blink("basketstatus",	5, 0.6, "#ffffff","#FBD6E7");
	new Effect.Pulsate($("basketstatus"))
	$("basketstatus").innerHTML = "Loading ...";
}

function setBasketCount(xmlObj) {
	var count = xmlObj.responseXML.firstChild.getAttribute("count")
	if (count == 0) {
		$("shopping_basket").style.visibility = "hidden";		
	} else {
		$("shopping_basket").style.visibility = "visible";
		$("basketstatus").innerHTML = "You have <b>" + count + "</b> items in your basket";
	}
}

function init() { //called by <BODY onload="init();">
	updateBasket();
}

function buyNow(action,id, product) {
	updateBasket(action,id, product);
	//location.href = "checkout.php";
	setTimeout("gotoCheckout()",1000);
}
function gotoCheckout() {
	location.href = "checkout.php";
}
/*
function blink(obj, times, interval, normalColor, blinkColor) {
	var blinkOn = times;
	
	function swapBlink() {
		if (blinkOn > 0){
			if (blinkOn % 2 == 0) {
				$(obj).style.backgroundColor = normalColor;
			} else {
				$(obj).style.backgroundColor = blinkColor;
			}
			blinkOn--;
		} else {
			$(obj).style.backgroundColor = normalColor;
			pe.callback	= function(){};
		}
	}
	var pe = new PeriodicalExecuter(swapBlink, interval);
}
		
*/