$(document).ready(function() {
    $('head').append('<link media="screen, projection, tv" href="/css/jquery.treeview.css" type="text/css" rel="stylesheet">');

    cart.init();
    
    var table = $('.price_table');
    if (table.length > 0 && !table.hasClass('item_view')) {
        table.find('tr').hover(
            function() {$(this).addClass('hovered_tr');},
            function() {$(this).removeClass('hovered_tr');}
        );
    }

    $("div.left").find('ul.submenu').treeview({
        control: "#treecontrol",
        url: "/price/xget_tree/",
		persist: "cookie"
    })
});

cart = {
	init: function(options) {
		this.options = {
			alias: 'price',
			debug: 0
		}
	
		if (options && options !== undefined) jQuery.extend(this.options, options);
		
		this.alias = this.options.alias;
		this.debug = this.options.debug;

		return this;
	},
	
	add: function(goods_id) {
		if (!goods_id) return;
		$.get('/'+cart.alias+'/add_cart/'+goods_id+'/1/', function(res) {
			if (res=='error') return;
			$('#cart').html(res);
		});
	},
	
	del: function(cart_id, goods_id) {
		if (!cart_id || !goods_id) return;
		$.getJSON('/'+cart.alias+'/del_cart/'+cart_id+'/'+goods_id+'/1/', function(res) {
			if (res.status=='error') return;
			$('#cart').html(res.cart);
		});
	}
}
