var itemsInStore = [
	{'SKU':'INS64619','productName':'Digital Album Preorder','category':'preorder','unitPrice':'9.99'},
	{'SKU':'INS64620','productName':'Standard CD Preorder','category':'preorder','unitPrice':'12.99'},
	{'SKU':'INS64621','productName':'CD/DVD Combo Preorder','category':'preorder','unitPrice':'19.99'},
	{'SKU':'INS64622','productName':'Vinyl Album Preorder','category':'preorder','unitPrice':'24.99'},
	{'SKU':'INS64623','productName':'Limited Edition Box Set','category':'preorder','unitPrice':'49.99'}
];
function getStoreItem(skuID) {
	for (var i=0; i<itemsInStore.length; i++) {
		console.log('compare '+skuID+' against store item list: '+itemsInStore[i].SKU);
		if (itemsInStore[i].SKU.indexOf(skuID)>=0) { console.log('found match, returning '+itemsInStore[i].productName); return itemsInStore[i]; }
	}
	return null;
}
function addItemCookie(value) {
	var date = new Date();
	date.setTime(date.getTime()+(1*24*60*60*1000));
	var expires = "; expires="+date.toGMTString();
	if (value.indexOf('/add/')>=0) { value = value.substring(5); }
	var oldvalue = readCookie('CART-ITEMS');
	if (oldvalue!=null && oldvalue!='') {
		value = oldvalue+','+value;
	}
	document.cookie = "CART-ITEMS="+value+expires+"; path=/";
}
function updateCartCookies() {
	var skus = $('div.checkout_item .item_count input');
	var skuList = new Array();
	for (i=0; i<skus.length; i++) {
		for (j=0; j<$(skus[i]).attr('value'); j++) {
			skuList.push($(skus[i]).attr('id'));
		}
	}
	var date = new Date();
	date.setTime(date.getTime()+(1*24*60*60*1000));
	var expires = "; expires="+date.toGMTString();
	document.cookie = "CART-ITEMS="+skuList.join(',')+expires+"; path=/";
}
function saveShippingDetails(shipping,tax,total,city,state,country) {
	var date = new Date();
	date.setTime(date.getTime()+(1*24*60*60*1000));
	var expires = "; expires="+date.toGMTString();
	document.cookie = "CARTSHIPPING="+shipping+expires+"; path=/";
	document.cookie = "CARTTAX="+tax+expires+"; path=/";
	document.cookie = "CARTTOTAL="+total+expires+"; path=/";
	document.cookie = "CARTCITY="+city+expires+"; path=/";
	document.cookie = "CARTSTATE="+state+expires+"; path=/";
	document.cookie = "CARTCOUNTRY="+country+expires+"; path=/";
}
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function clearCart() {
	document.cookie='CART-ITEMS=;expires=-1';
	document.cookie='CARTSHIPPING=;expires=-1';
	document.cookie='CARTTAX=;expires=-1';
	document.cookie='CARTTOTAL=;expires=-1';
	document.cookie='CARTCITY=;expires=-1';
	document.cookie='CARTSTATE=;expires=-1';
	document.cookie='CARTCOUNTRY=;expires=-1';
}
$(document).ready(function(){
	//$('#top_space #logo_huge a.titleName img').attr('src','http://onefastmove.com/images/kerouac_header.gif');
	$('#bottom_wrapper').append('<br style="clear:both;" />');
	$('#logo_huge').after('<a href="http://link.brightcove.com/services/player/bcpid30065720001?bctid=34615004001" target="_blank"><img class="view_trailer" src="http://onefastmove.com/images/blank.gif" alt="view trailer" /></a>');
	var img = jQuery.trim($('#logo_huge a').html());
	$('#logo_huge a').html(img);
	img = jQuery.trim($('#col_498 .section a').html());
	$('#col_498 .section a').html(img);
	img = jQuery.trim($('#col_498 div.html_include').html());
	$('#col_498 div.html_include').html(img);
	$('#col_260 .staff_pick_small .info').append('<br clear="all" />');
	$('#col_260 .staff_pick_small .info a.product_name').each(function (i) {
		//alert($(this).html());
		var prodinfo = new Array();
		prodinfo = $(this).html().split(' (');
		//alert(prodinfo[0]);
		$(this).html('<b>'+prodinfo[0]+'</b><em></em>');
	});
	$('a.cart_total').attr('href','/cart');
	$('a.item_number').attr('href','/cart');
	$('#col_1000 a.artist_name').hide();
	$('#col_1000 table td').css('padding-left','10px');
	$('#col_760 #ItemForm #checkout a.artist_name').replaceWith('<span class="artist_name">'+$('#col_760 #ItemForm #checkout a.artist_name').text()+'</span>');
	$('#col_760 #ItemForm #checkout .item_title a.product_name').replaceWith('<span class="product_name">'+$('#col_760 #ItemForm #checkout .item_title a.product_name').text()+'</span>');

	$("a.type[href*='/add/INS']").each(function(i){ $(this).attr('onclick','addItemCookie("'+$(this).attr('href')+'")'); });
	$("a.price[href*='/add/INS']").each(function(i){ $(this).attr('onclick','addItemCookie("'+$(this).attr('href')+'")'); });
	$("a.product_name[href='/cart/clear']").click(clearCart);
	$("a:contains('Update Cart')").attr('href','javascript:updateCartCookies();document.ItemForm.submit();');

//	$("#BillCountry").html("<option	value='US'>United States</option>");
//	$("#ShipCountry").html("<option value='US'>United States</option>");
});
