function add2cart(a) {

	var src = $(a).attr('href');

	if($(a).hasClass('del'))
	{
		$(a).find("img").attr("src","/i/ico-buy.png");
		$(a).attr('href', src.replace("act=add", "act=del"));
		//$(a).attr('href', src.replace("lineNum=0", "lineNum="+$(a).parent().find(".priceDropDown option:selected").attr("line")));
	}
	else
	{
		//$(a).find("img").attr("src","/i/ready.png");
		//$(a).attr('href', src.replace("act=del", "act=add"));	
	}
  	//$(a).toggleClass('del');
  	
  	var url = $(a).attr('href');
  	
  	$("#cart").load(url,{}, function(){});
  	
  	$.gritter.add({
				// (string | mandatory) the heading of the notification
				title: 'Добавлено в корзину!',
				// (string | mandatory) the text inside the notification
				text: 'Товар добавлен в корзину.<br><a href="/bin/">Перейти к оформлению заказа</a>.'
	});
  	
  	return false;
}

function sendmessage(txt){
	var txt2 = new Array();
	txt2 = txt.split(""); 
	var mycount = 4;
	var newstring = "";
	for(i=txt2.length-1;i>=0;i--){
		if(mycount!=1){
			newstring = txt2[i] + newstring;
			mycount--;
		} else {
			newstring = txt2[i] + " " + newstring;
			mycount =3;
		}
	}
	return newstring;
}

function setFirstPrice(id){
	$(".moneySpan"+id).html(sendmessage($("#"+id+" option:first").val()));
}

$(document).ready(function(){
	$(".priceDropDown").change(function(){
		var curID = $(this).attr("id");
		//	show new price
		$(this).parent().find("span").html(sendmessage($("#"+curID+" option:selected").val()));
		//	add new price to query_string
		var src = $(this).parent().find(".add").attr('href');
		if($(this).parent().find(".add").hasClass("del")){
			var hrefPattern = "/cms/modules/shop/?act=del&item="+curID+"&quantity=1&obj="+$(this).attr("obj")+"&main=1&lineNum=";
		} else {
			var hrefPattern = "/cms/modules/shop/?act=add&item="+curID+"&quantity=1&obj="+$(this).attr("obj")+"&main=1&lineNum=";
		}
		$(this).parent().find(".add").attr("href",hrefPattern+$("#"+curID+" option:selected").attr("line"));
		$(this).parent().find(".del").attr("href",hrefPattern+$("#"+curID+" option:selected").attr("line"));
	});
});
