$(document).ready(function() {
	
	//handles the "add_to_cart" button click
 	$('a.cart_add_link').each(function(arr) {
		$(this).click(
			function() {
				//alert('cart_button a click! -- number: ' + arr);
				var href=$(this).attr('href');
				var querystring = href.slice(href.indexOf('?')+1);
				//alert('href: ' + href + ' querystring: ' + querystring);
				$.get('/cart_add.php',querystring,get_cart_add_response);
				//$('a.cart_add_link').greybox(gbOptions);
				//$(this).greybox(gbOptions);
				return false;
				//$(this).greybox(gbOptions);
			}
		); // end click
		//set-up options for greybox iframe cart-View_window
		var gbOptions = {
			gbWidth: 200,
			gbHeight: 175,
			captionHeight: 15,
			gbHref: "/cart_added_window.php"
		};
		$(this).greybox(gbOptions);
	}); // end each
  
  	//ajax call to update cart - called from a.cart_add_link
	function get_cart_add_response(response) {
	 // retrieve the server's response 
	  	// if the response is long enough, we assuwe we just received
	  	// a server-side error report
	  	if(response.length > 5) {
			if ((response.substring(0,1)) == "<") {
				$('#div_cart').html(response + "<br/>");
		  	} 
		  	else {
				  $('#div_cart').html('Error Adding to Cart: ' + response + '<br/>');
		  	}
	  	}
	  	else {
			$('#div_cart').html('Error Adding to Cart: ' + response + '<br/>');
			//alert(data);
	  	}
	}
	
	
	/*	var cart_added_img = new Image();
	cart_added_img.src = 'images/btn_item_added_01.gif';
  	//on click swap "add cart" image to "item added" image
  	$('img.buy_button_new').each(function(arr) {
		$(this).click(
			function() {
				//var href=$('#cart_button a').attr('href');
				var href=$(this).attr('href');
				alert('cart_button image click! -- number: ' + arr);
				var querystring = href.slice(href.indexOf('?')+1);
				alert('href: ' + href + ' querystring: ' + querystring);
				$.get('cart_add.php',querystring,get_cart_add_response);
				$(this).attr('src',cart_added_img.src);
				return false;
			}
			
		); // end click
	}); // end each*/
  
}); // end ready
