var num = 0;

$(document).ready(function() {
//$.preloadCssImages();
$.ajaxSetup({type: 'POST'});
$("img[src='/img/del.gif']").click(function(){
    
    
    if(!confirm('Вы уверены?'))
        {
        return false;
        }


});
$('div.tree-button')
  .toggle(
  function(){
      $(this).removeClass('tree-open');
      $(this).addClass('tree-close');
      $(this).parent().find('div.tree-content').slideDown('normal');
  },
  function(){
      $(this).removeClass('tree-close');
      $(this).addClass('tree-open');
      $(this).parent().find('div.tree-content').slideUp('normal');
  }
);

$('a.agroup')
  .toggle(
  function(){
      $(this).removeClass('grey');
      $(this).addClass('green-bg');
      $(this).parent().parent().find('div.details').slideDown('normal');
  },
  function(){
      $(this).removeClass('green-bg');
      $(this).addClass('grey');
      $(this).parent().parent().find('div.details').slideUp('normal');
  }
);


$("#add_ing_link").click(function () {
	//Создаём через плагин facebook select
	$("#ingredient_name_dflk3erkfddflflekdme").fcbkcomplete({
		json_url: "/database/ingredients",
		cache: false,
		filter_case: false,
		filter_hide: false,
		firstselected: true,
		filter_selected: false,
		maxitems: 10,
		delay:800,
		newel: false        
	});		 

	$('#add_foo').animate( { "height" : 0 }, $(this).hide() );

	var input = $("#ingredient_name_dflk3erkfddflflekdme_annoninput");
	var height = input.height();
	input.height(0);
	input.animate( { "height" : height } );
	
});


});



function removeFindElement(divNum)
{
  $('#'+divNum).remove();
  var num = parseInt($("#findValue").val());
  $('#findValue').val(num - 1);
}

function setMailToLink (attr, mail)
{
	$("a[mailTo="+ attr +"]").attr('href', "mailto:"+ mail);
}



/* прототип js-класса для эффекта аккордеон */
function animSwitchClass (p_root, p_callback)
{
	var root = p_root;
	var callback = p_callback;
	
	this.switchThis = function (p)
	{
		var inner = $(p).closest("[state]");
		
		root.find("[state]").each(function() {
			hide ( $(this) );
		});
		
		if (inner.css('display') == 'none') {
			show (inner);
		}
		else {
			hide (inner);
		}
	
	}
	
	function show (p)
	{
		if (callback) {
			callback (true, p);
		}
		
		var height = p.height();
		p.height(0);
		p.show();
		p.animate( { "height" : height }, function() { p.css('height', '')} );
		
	}
	
	function hide (p)
	{
		if (callback) {
			callback (false, p);
		}
		
		if ( p.css('display') != 'none' ) {
			var height = p.height();
			p.animate( { "height" : 0 }, function() { p.hide(); p.height(height); } );
		}
		
	}
	
	
}