$(document).ready(function(){
	$("#tree").treeview({
		collapsed: true,
		unique: true,
		persist: "location"
		//persist: "cookie"
	});
	$(".favs").treeview({
		collapsed: false,
		unique: true,
		persist: "cookie"
		//persist: "cookie"
	});
});

	function js_update_cart(){
		var parameter_string = '';
		allNodes = $(".process");
		for(i = 0; i < allNodes.length; i++) {
			var tempid = allNodes[i].id;
			var temp = new Array;
			temp = tempid.split("_");
			var real_id = temp[2];
			var real_value = allNodes[i].value;
			parameter_string += real_id +':'+real_value+',';
		}

		var params = 'ids='+parameter_string;
		$.ajax({
			type: "post",url: "cart/update.html",data: params,dataType: "json",
			beforeSend: function(){$("#ajax_loading").css("display", "block");},
			success: function(html){
				$("#ajax_loading").css("display", "none");
				//$("#cart_message").html(html);
				$.jGrowl(html.message, { life: 10000 });
				$("#totalprice").html(html.totalprice);
				$.each(html.item, function(i, price){
					$("#li_total_"+i).html(price);
				});

				$.each(html.price, function(i, price){
					$("#li_price_"+i).html(price);
				});
			}
		});
	}

	function js_remove_product(id){
		var params = 'id='+id;
		$.ajax({
			type: "post",url: "cart/remove.html",data: params,dataType: "json",
			beforeSend: function(){$("#ajax_loading").css("display", "block");},
			success: function(html){
				$("#ajax_loading").css("display", "none");
				//$("#cart_message").html(html);
				$.jGrowl(html.message, { life: 10000 });
				$("#totalprice").html(html.totalprice);
				$("tr#li_row_"+id).remove();
			}
		});
	}

	function js_remove_fav(id){
		var params = 'id='+id;
		$.ajax({
			type: "post",url: "favorites/remove.html",data: params,dataType: "json",
			beforeSend: function(){$("#ajax_loading").css("display", "block");},
			success: function(html){
				$("#ajax_loading").css("display", "none");
				//$("#cart_message").html(html);
				$.jGrowl(html.message, { life: 10000 });
				$("tr#li_row_"+id).remove();
			}
		});
	}

	function js_favorite_product(id){
		var params = 'id='+id;
		$.ajax({
			type: "post",url: "favorites/add.html",data: params,dataType: "json",
			beforeSend: function(){$("#ajax_loading").css("display", "block");},
			success: function(html){
				$("#ajax_loading").css("display", "none");
				$.jGrowl(html.message, { life: 10000 });
			}
		});
	}

	function js_add_product(id){
		var params = 'id='+id;
		$.ajax({
			type: "post",url: "cart/add.html",data: params,dataType: "json",
			beforeSend: function(){$("#ajax_loading").css("display", "block");},
			success: function(html){
				$("#ajax_loading").css("display", "none");;
				//$("#cart_message").html(html);
				$.jGrowl(html.message, { life: 10000 });
			}
		});
	}

	function js_add_fav_cart(id){
		var params = 'id='+id+'&qnt='+document.getElementById('qnt'+id).value;
		$.ajax({
			type: "post",url: "cart/add.html",data: params,dataType: "json",
			beforeSend: function(){$("#ajax_loading").css("display", "block");},
			success: function(html){
				$("#ajax_loading").css("display", "none");;
				//$("#cart_message").html(html);
				$.jGrowl(html.message, { life: 10000 });
			}
		});
	}

function addBookmark(url, title)
{
 if (!url) url = location.href;
 if (!title) title = document.title;

 //Gecko
 if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) window.sidebar.addPanel (title, url, "");
 //IE4+
 else if (typeof window.external == "object") window.external.AddFavorite(url, title);
 //Opera7+
 else if (window.opera && document.createElement)
 {
var elem = document.createElement('a');
					elem.setAttribute('href',url);
					elem.setAttribute('title',title);
					elem.setAttribute('rel','sidebar');
					elem.click();
 }
 else return false;

 return true;
}

