// 
// shopping cart
//
// set behaviours once the DOM is ready
$(document).ready(function(){
						   
// paypal parameters here
var paypalparamstemplate = 
			'<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post" class="product_form">' +
		'		  <input type="hidden" name="cmd" 		value="_cart">' +
		'		  <input type="hidden" name="add" 		value="1">' +
		'		  <input type="hidden" name="business" 	value="james@emahofoundation.org">' +
		'		  <input type="hidden" name="item_name" 	value="[name]" class="item_name">' +
 		'		  <input type="hidden" name="amount" 		value="[amount]" class="item_amount">' +
		'         <input type="image" name="submit" src="images/store/btn_addtocart.png" class="imagebutton"/>' +
		'</form>';
var paypalviewcarttemplate = 
		'<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">' + 
          '<input type="hidden" name="cmd" value="_cart" />' + 
          '<input type="hidden" name="business" value="james@emahofoundation.org" />' + 
		  '<input type="image" name="submit" src="images/store/btn_checkout.png" class="imagebutton" />' +
          '<input type="hidden" name="display" value="1" />' + 
        '</form>';

$('#store tr').each(function(i){
				// is the table row
				var pName = $(this).find('.product_description').text();
				var pAmount = $(this).find('.product_price').text();
				if ( (pName!="") || (pAmount!="") ) { 
							var paramsforthisbutton = paypalparamstemplate.replace('[amount]', pAmount).replace('[name]', pName);
							$(this).find('.product_form').replaceWith(paramsforthisbutton);
				}
	});

$('.viewcart').replaceWith(paypalviewcarttemplate);

// change opacity of any image links when they are hovered over------------------------
		$('input.imagebutton').hover(
				function(){ $(this).css('opacity', 0.5);}, 
				function(){$(this).css('opacity', 1.0);
		});
		
// create behaviour to popup window for .popup links-----------------------------------
		$('a.popupproductimage').click(function(){ 
				window.open(this.href, 
				'_blank',
				'scrollbars=yes,resizable=yes,width=540	,height=440');
				return false;
		});

});// end of document ready