$(document).ready(function(){//doc ready
	//===============================
	//make the buttons snazzy
	//===============================
	$('.addToCart').mousedown(function() {
		$(this).removeClass('addToCart');
		$(this).addClass('addToCartClick');
		});
		
	$('.addToCart').mouseup(function() {
		$(this).removeClass('addToCartClick');
		$(this).addClass('addToCart');
		});

	$('.addToCart').click(function() {
		addItem($(this).val()+'|1');
		});		
	
	//===============================
	//auto shade the table
	//===============================
	$('.AutoShadeTables thead tr').addClass('RowHeading');
	$('.AutoShadeTables tbody tr:even').addClass('RowEven'); 
	$('.AutoShadeTables tbody tr:odd').addClass('RowOdd'); 
	$('.AutoShadeTables td').addClass('TablePadding'); 
	
	//mouseover class change
	//$('.AutoShadeTables tbody tr').mouseover(function(){
	//	$(this).addClass('RowOver'); 
	//	});
		
	//mouseout class change
	//$('.AutoShadeTables tbody tr').mouseout(function(){
	//	$(this).removeClass('RowOver'); 
	//	});

	//=================================================
	//display only the first 5 items in the RSS Feed
	//=================================================		
	//hide all but the top 5 of the rss feed lists
	$("#RSSFeed' li:nth-child(n+6)").hide();
	
	//if the div is clicked display all rss items then hide div
	 $("#displayAllRSS").click(function () { 
		$("#RSSFeed' li:nth-child(n+6)").show("normal");
		$(this).hide();
		});
	});//end of doc ready

	
function viewCart(){
	window.open('/cart/cart.php','','scrollbars=yes,menubar=yes,height=500,width=700,resizable=yes,toolbar=yes,location=no,status=no');
	return false;
}


function cookieExists(){
	if (document.cookie.length > 0 && getCookie('cart') != null) { 
		return true;}
	else{ 
		return false;}
}


function setCookie(name, value) {
	var expires = new Date ();
    expires.setTime (expires.getTime() + (1000 * 60 * 60 * 24 * 60));  //sets the date for 60 days
	if (!expires) expires = new Date();
    document.cookie = name + "=" + escape (value) + 
	"; expires=" + expires.toGMTString() +  "; path=/";
    } 

function getCookie(name) {
    var dcookie = document.cookie; 
    var cname = name + "=";
    var clen = dcookie.length;
    var cbegin = 0;
    while (cbegin < clen) {
        var vbegin = cbegin + cname.length;
        if (dcookie.substring(cbegin, vbegin) == cname) { 
            var vend = dcookie.indexOf (";", vbegin);
            if (vend == -1) vend = clen;
            return unescape(dcookie.substring(vbegin, vend));
            }
       cbegin = dcookie.indexOf(" ", cbegin) + 1;
       if (cbegin == 0) break;
       }
    return null;
    }
	
function delCookie (cookie_name){
    var cookie_date = new Date ( );  // current date & time
    cookie_date.setTime ( cookie_date.getTime() - 1 );
    document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
	}

function removeItem(cartItem){//function
	if(cookieExists("cart")){//if
		var cart = new Array();
		var value ="";
		cart=getCookie('cart').split(",");
		for(var i = 0; i < cart.length; i++){//for
			if(getItem(cart[i]) != getItem(cartItem)){
				value=value+cart[i]+",";}
			}//for
		//remove the last comma
		if(value.length > 0){
			value = value.substring(0,value.length - 1);
			setCookie('cart', value);}
		else{setCookie('cart', "");}
		}	//if
		
	}//function

function addItem(cartItem){//function
	var cart = new Array();
	var value ="";
	var quantity = 0;
	var exists ="";
	var item1 = "";
	var item2 = "";
	if(cookieExists()){//if
		cart=getCookie('cart').split(",");
		for(var i = 0; i < cart.length; i++){
			if(getItem(cart[i]) == getItem(cartItem)){exists="true";}
			}
			if(exists!="true"){
				value = getCookie('cart')+","+cartItem;
				setCookie('cart', value);
				}
	} //if
	else{
		setCookie('cart', cartItem);
		}			
		
	window.open('cart/cart.php','','scrollbars=yes,menubar=no,height=500,width=700,resizable=yes,toolbar=yes,location=no,status=no');	
}//function

// when you apply this function to a item|quantity it will
// return the item without the quantity	
function getItem(itemAndQuantity){
	var itemQuantity = new Array();
	itemQuantity = itemAndQuantity.split("|")
	return itemQuantity[0];
}	

// when you apply this function to a item|quantity it will
// return the quantity without the item
function getQuantity(itemAndQuantity){
	var itemQuantity = new Array();
	itemQuantity = itemAndQuantity.split("|")
	return itemQuantity[1];
}		