$(document).ready(function(){
    $(".accordion h3").click(function(){
        $(this).next("ul").slideToggle("fast")
        .siblings("ul:visible").slideUp("fast");
        $(this).toggleClass("active");
        $(this).siblings("h3").removeClass("active");
     });
 
 });
 function addtocart(id, value) {
	$.post("/addtocart.php", {'id':id, 'count':value}, function(data)
	{
		var dom = parseXML(data).firstChild;
		var text = 'Товар добавлен в <a href="bag.html">корзину</a>. Всего товаров: '+dom.getAttribute('count')+
		' на сумму '+dom.getAttribute('cost')' рублей';
		$('#bagcount').html(dom.getAttribute('count'));
		$('#bagcost').html(dom.getAttribute('cost'));
		$('#messagebox').html(text).dialog({width: 200, height: 100});
	});
	return false;	
}

function product(id) {
	$.get('/product.php', {'id':id}, function(data)
	{
		data = '<div class="scrolledt">'+data+'</div>';
		var title = $('h3', data).html();
		$('#productinfo').html(data).dialog({title:title, width: 600, height: 400});
	});
	return false;
}

function delfromcart(id) {
	$.post("/delfromcart.php", {'id':id}, function(data)
	{
		var dom = parseXML(data).firstChild;
		var text = 'Товар удален из <a href="bag.html">корзины</a>. Всего товаров: '+dom.getAttribute('count')+
		' на сумму '+dom.getAttribute('cost')' рублей';
		$('#bagcount').html(dom.getAttribute('count'));
		$('#bagcost').html(dom.getAttribute('cost'));
		$('#messagebox').html(text).dialog();
	});
	return false;	
}

function parseXML(text) {
	try {
		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async="false";
		xmlDoc.loadXML(text);
	} catch(e) {
		try { //Firefox, Mozilla, Opera, etc. 
			parser=new DOMParser();
			xmlDoc=parser.parseFromString(text,"text/xml");
		}
		catch(e) {alert(e.message)}
	}
	return xmlDoc;
}
