var fns = {
    menu: function(ident) {
	 $("#btn_"+ident).mouseover(function() {
      $('#value_'+ident).removeClass('top_menu_value');
	  $('#value_'+ident).addClass('top_menu_value_hover');
     }).mouseout(function(){
	  $('#value_'+ident).removeClass('top_menu_value_hover');
	  $('#value_'+ident).addClass('top_menu_value');
     });
    },
	getOrder: function() {
	 
	 $.ajax({
     type: "POST",
     url:  "ajax.php",
     data: "action=getorder",
     dataType:"html",
     success: function(msg){
		 if (msg){
		var object = eval('(' + msg + ')');	
		$('#top_cart_count').html(object[0].count);
		$('#top_cart_cost').html(object[0].price);
		alert('Товар добавлен к Вашему списку.');
		}
     }
    });
	},
	saveOrder: function(price, price_id, product_id, type) {
	 var amount = $('#amount' + price_id).val();
	 $.ajax({
     type: "POST",
     url:  "ajax.php",
     data: "action=saveorder&product_id="+product_id+"&price_id="+price_id+"&amount="+amount+"&type="+type+"&price="+price,
     dataType:"html",
     success: function(msg){
		 if (msg == 'present'){alert('Данный товар уже есть в списке!');}else{fns.getOrder(product_id);};
	}
    });
	},
	setStatus: function(category_id, status) {
	 
	 $.ajax({
     type: "POST",
     url:  "ajax.php",
     data: "action=setstatus&category_id="+category_id+"&status="+status,
     dataType:"html"
    });
	},
	setProductStatus: function(product_id, status) {
	 
	 $.ajax({
     type: "POST",
     url:  "ajax.php",
     data: "action=setproductstatus&product_id="+product_id+"&status="+status,
     dataType:"html"
    });
	},
	setProductThumb: function(product_id, filename) {
	 
	 $.ajax({
     type: "POST",
     url:  "ajax.php",
     data: "action=setproductthumb&product_id="+product_id+"&filename="+filename,
     dataType:"html"
    });
	}
}

$(document).ready(function(){
	
	$(".admin_active_check").click(function() {
	 var id = $(this).val();
	 var status = 0;
	 var checked = $(this).attr('checked');
	 if (checked){status=1;}
	  fns.setStatus(id, status);
	 });
	 $(".admin_active_check_product").click(function() {
	 var id = $(this).val();
	 var status = 0;
	 var checked = $(this).attr('checked');
	 if (checked){status=1;}
	  fns.setProductStatus(id, status);
	 });
	 $(".drop_menu").click(function() {
	 $(this).next().toggle('fast');
	 });
	 $(".news_list_text").click(function() {
	 var newsId = $(this).find('span').attr('id');
	 window.location = "news_view/"+ newsId +"/";
	 });
	 $(".news_block_text").click(function() {
	 var newsId = $(this).find('span').attr('id');
	 window.location = "news_view/"+ newsId +"/";
	 });
	 $(".tone_select").change(function() {	 
	 var itemId = $(this).attr('id');
	 var html = "<img src='fotos/tones/"+ itemId +"/"+ $(this).val() +"' width='50'/>"; 
	 $('#tone_image'+itemId).html(html);
	 });
	
});


