var UK='UK';//uk
var EU='EU';//europe
var ROW='ROW';//rest of world

var A6BOOKLET='A6BOOKLET';
var POSTER='POSTER';
var TSHIRT='TSHIRT';

var BASESHIPPING={UK:1.00, EU:2.00, ROW: 2.50};//base shipping cost per package in uk
var WEIGHTSHIPPING={UK:0.02, EU: 0.03, ROW: 0.04};//additional shipping cost per gram. 0.02 pence per gram == £2 per 100grams
var ITEMWEIGHTS={A6BOOKLET:50, POSTER: 100, TSHIRT: 200};//item weights

	window.onload = function(){
		simpleCart.initialize();
		document.getElementById('selected_country').value = simpleCart.country;
		simpleCart.addEventToArray( [document.getElementById('select_country')] , function(event){
			simpleCart.country = document.getElementById('selected_country').value;
			createCookie('simpleCartCountry', ''+simpleCart.country, 30 );
			simpleCart.update();
		} , "click");
	}
	simpleCart.oldSave = simpleCart.save;
	simpleCart.save = function(){
		this.oldSave();
		createCookie('simpleCartCountry', ''+simpleCart.country, 30 );
	}
	simpleCart.oldLoad = simpleCart.load;
	simpleCart.load = function(){
		this.oldLoad();
		simpleCart.country = UK;
		if( readCookie('simpleCartCountry') ){
			var data = unescape(readCookie('simpleCartCountry'));
			simpleCart.country = data;
		}
	}
	
	
	//Hijack the old addToCart function so now it always redirects to the cart!
	ShelfItem.prototype.oldAddToCart = ShelfItem.prototype.addToCart;
	ShelfItem.prototype.addToCart = function(){
		this.oldAddToCart();
		window.location = ('./cart.html');
	}
	
	simpleCart.email = "saigon_honeys@yahoo.co.uk";
	simpleCart.checkoutTo = PayPal;
//	simpleCart.merchantId = "118575326044237";
//	simpleCart.checkoutTo = GoogleCheckout;
//	simpleCart.currency = USD;
	simpleCart.currency = GBP;
//  simpleCart.currency = EUR;
//	simpleCart.taxRate  = 0.08;
//	simpleCart.shippingFlatRate = 5.25;
	simpleCart.shippingQuantityRate = 0;


	//create a custom shipping function!
	simpleCart.shipping = function(){
		var me = simpleCart;
		me.shippingFlatRate = BASESHIPPING[me.country];
		if( parseInt(me.quantity,10)===0 )
			return 0;
		var shipping = 	parseFloat(me.shippingFlatRate) + 
					  	parseFloat(me.shippingTotalRate)*parseFloat(me.total) +
						parseFloat(me.shippingQuantityRate)*parseInt(me.quantity,10),
			nextItem,
			next;
		for(next in me.items){
			nextItem = me.items[next];
			if( nextItem.shipping ){
				if( typeof nextItem.shipping == 'function' ){
					shipping += parseFloat(nextItem.shipping());
				} else {
					shipping += parseFloat(nextItem.shipping);
				}
			}
		}
		
		return shipping;
	}
	CartItem.prototype.shipping=function(){
		// we are using a 'size' field to calculate the shipping,
		// so we first make sure the item has a size
		if(this.size){
			return this.quantity*WEIGHTSHIPPING[simpleCart.country];
		} else {
			// use a default of 0?
			return 0;//this.quantity*2.00;
		}
	}
	
	
	simpleCart.cartHeaders = ["Thumb_image_noHeader", "Name" , "Size_input_div_div", "Price" , "decrement_noHeader" , "Quantity", "increment_noHeader", "remove_noHeader", "Total" ];

