var imgASIN = '';
function add_to_cart_ajax(asins, items, itemid, qty, price)
	{
	imgASIN = asins;
	var blackout = document.createElement('div');
	blackout.id = 'blackout';
	blackout.style.position = 'absolute';
	blackout.style.top = '0px';
	blackout.style.left = '0px';
	blackout.style.height = document.getElementById('footer').offsetTop + 'px';
	blackout.style.width = '100%';
	blackout.style.background = '#2C2C2C';
	blackout.style.zIndex = '4';
	blackout.style.opacity = '.4';
	document.body.appendChild(blackout);
	
	if(document.getElementById('wp_product_lgimg') && document.getElementById('wp_product_lgimg').style.display == 'block')
		{
		document.getElementById('wp_product_lgimg').style.display = 'none';
		}
	document.getElementById('wp_products_add2cartimg_'+asins).style.display = 'none';
	document.getElementById('wp_products_add2cartmsg_'+asins).style.display = 'block';
	document.getElementById('wp_products_add2cartmsg_'+asins).innerHTML = 'adding to cart...';
	if(document.getElementById('wp_product_msgbox'))
		{
		var title = document.getElementById('wp_product_msgbox_title');
		var content = document.getElementById('wp_product_msgbox_content');
		var footer = document.getElementById('wp_product_msgbox_footer');
		content.innerHTML = 'Adding <strong>'+document.getElementById('item').value+'</strong> [<strong>'+document.getElementById('asin').value+'</strong>] to your shopping cart...';
		title.innerHTML = 'Adding '+document.getElementById('asin').value+' to your shopping cart...';
		document.getElementById('wp_product_msgbox').style.display = 'block';
		}
	
	var xmlhttp=new XMLHttpRequest();
	xmlhttp.onreadystatechange= function() 
		{ 
		if (xmlhttp.readyState==4)
		if (xmlhttp.status==200)
			read_add_to_cart(xmlhttp);
		}
	var myStr = "asin=" + asins
					+ "&item=" + items
					+ "&itemid=" + itemid
					+ "&qty=" + qty
					+ "&price=" + price
					+ "&type=AJAX";
	xmlhttp.open("POST","http://www.cookwarebuzz.com/wp-content/themes/arthemia/add_to_cart.php",true);
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	xmlhttp.send(myStr);	
	}
	
function read_add_to_cart(req)
	{
	//document.getElementById('wp_product_msgbox_title').innerHTML = 'YOUR SHOPPING CART';
	if(document.getElementById('wp_product_msgbox'))
		{
		document.getElementById('wp_product_msgbox').style.display = 'none';
		}
	var intE = 0;
	var intS = req.responseText.indexOf("[wp_products_output]") + 20;
	intE = req.responseText.indexOf("[/wp_products_output]");
	//alert(req.responseText.substring(intS,intE));
	//document.getElementById("wp_product_msgbox_content").innerHTML = req.responseText.substring(intS,intE);
	intS = req.responseText.indexOf("[item]") + 6;
	intE = req.responseText.indexOf("[/item]");
	var id = req.responseText.substring(intS,intE);
	intS = req.responseText.indexOf("[qty]") + 5;
	intE = req.responseText.indexOf("[/qty]");
	var qty = req.responseText.substring(intS,intE);
	if(id.length > 0)
		{
		if(document.getElementById("wp_products_header_view_cart"))
			{
			document.getElementById('wp_products_add2cartmsg_'+imgASIN).innerHTML = 'getting cart count...';
			wp_products_cart_count();
			}
		else
			{
			wp_products_get_sidebar_cart();
			}
		}
	}

function wp_products_cart_count()
	{
	var xmlhttp=new XMLHttpRequest();
	xmlhttp.onreadystatechange= function() 
		{ 
		if (xmlhttp.readyState==4)
		if (xmlhttp.status==200)
			read_cart_count(xmlhttp);
		}
	var myStr = "count=y";
	xmlhttp.open("POST","http://www.cookwarebuzz.com/wp-content/plugins/wp_products/wp_products_script_get_cart_count.php",true);
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	xmlhttp.send(myStr);
	}
function read_cart_count(req)
	{
	//alert(req.responseText);
	var intE = 0;
	var intS = req.responseText.indexOf("[items]") + 7;
	intE = req.responseText.indexOf("[/items]");
	var strOutput = '<img src="http://www.cookwarebuzz.com/wp-content/plugins/wp_products/images/cart_15w_x_15w.png" align="top" /> View Cart ('+req.responseText.substring(intS,intE)+')';
	document.getElementById("wp_products_header_view_cart").innerHTML = strOutput;
	if(!document.getElementById('wp_product_cart_ad'))
		{
		wp_products_get_sidebar_cart();
		}
	}
	
function wp_products_get_sidebar_cart()
	{
	if(document.getElementById('wp_products_add2cartmsg_'+imgASIN))
		{
		document.getElementById('wp_products_add2cartmsg_'+imgASIN).innerHTML = 'loading side cart...';
		}
	var xmlhttp=new XMLHttpRequest();
	xmlhttp.onreadystatechange= function() 
		{ 
		if (xmlhttp.readyState==4)
		if (xmlhttp.status==200)
			read_wp_products_get_sidebar_cart(xmlhttp);
		}
	var myStr = "getcart=y";
	xmlhttp.open("POST","http://www.cookwarebuzz.com/wp-content/plugins/wp_products/wp_products_script_sidebar_cart.php",true);
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	xmlhttp.send(myStr);
	}

function read_wp_products_get_sidebar_cart(req)
	{
	///alert(req.responseText);
	var intE = 0;
	var intS = req.responseText.indexOf("[wp_products_output]") + 20;
	intE = req.responseText.indexOf("[/wp_products_output]");
	if(intE > 0)
		{
		document.getElementById("wp_products_sidebar_cart").innerHTML = req.responseText.substring(intS,intE);
		}
	if(document.getElementById('wp_products_add2cartimg_'+imgASIN))
		{
		document.getElementById('wp_products_add2cartmsg_'+imgASIN).style.display = 'none';
		document.getElementById('wp_products_add2cartimg_'+imgASIN).style.display = 'block';
		}
	try
		{
		if(document.getElementById('blackout'))
			{
			//document.getElementById('blackout').style.display = 'none';
			document.body.removeChild(document.getElementById('blackout'));
			}
		}
	catch(err)
		{
		alert(err);
		//Handle errors here
		}
	}
	
function wp_products_load_cart()
	{
	if(!document.getElementById("wp_product_content_Reviews") && !document.getElementById('wp_product_cart_ad'))
		{
		wp_products_get_sidebar_cart();
		}
	}
	

/*
if (window.addEventListener){
  window.addEventListener("load", function() { myExtension.init(); }, false);
} else if (window.attachEvent){
  window.attachEvent("load", function() { myExtension.init(); }, false);
}

//window.addEventListener("load", function() { myExtension.init(); }, false);

var myExtension = {
  init: function() {
    var appcontent = document.getElementById("appcontent");   // browser
    if(appcontent)
      appcontent.addEventListener("DOMContentLoaded", myExtension.onPageLoad, true);

  },

  onPageLoad: function(aEvent) {
    var doc = aEvent.originalTarget; // doc is document that triggered "onload" event
    // do something with the loaded page.
    // doc.location is a Location object (see below for a link).
    // You can use it to make your code executed on certain pages only.
    wp_products_cart_count();
  }
}
*/



setTimeout('wp_products_cart_count()', 1500);
	

	