//jQuery.noConflict();
jQuery(document).ready(function($) 
{
/* dynamic blocks*/

/* new product 
if($('.newProduct').length)
{
 $('.newProduct .bceBlocksList').each(function(){
    $(this).remove();    
 })       
 $('.newProduct').append('<div class="loadBlock"><img src="http://img.oede.by/new/img/shares/bigload.gif" alt="Загрузка.." /></div>');
 
 $.getJSON('http://www.oede.by/backend/blocks/block/new_product?callback=?',{},function(obj){     
     $('.newProduct').replaceWith(obj.data);
 })

}

if($('.romanticBlock').length)
{
 $('.romanticBlock .bceBlocksList').each(function(){
    $(this).remove();    
 })       
 $('.romanticBlock').append('<div class="loadBlock"><img src="http://img.oede.by/new/img/shares/bigload.gif" alt="Загрузка.." /></div>');
 
 $.getJSON('http://www.oede.by/backend/blocks/block/romantic?callback=?',{},function(obj){     
     $('.romanticBlock').replaceWith(obj.data);
 })

}
*/


/*--------userbar---------*/
    $('#log-in').hover(function(){
        $(this).css('background','url(http://img.oede.by/st/img/log-in-h.png) no-repeat')
    },function(){
        $(this).css('background','url(http://img.oede.by/st/img/log-in.png) no-repeat')
    })

    $('.userbar').live({
        mouseenter:
        function(){
            $(this).find('#user-block').css('background','url(http://img.oede.by/st/img/users/userbarBtn-h.png) no-repeat top left');
            $('.userbar-actions').show();
        },
        mouseleave:
        function(){
            $(this).find('#user-block').css('background','url(http://img.oede.by/st/img/users/userbarBtn.png) no-repeat top left');
            $('.userbar-actions').hide(); 
        }
    });
    /*--------userbar---------*/

 /* comments */

    $('#addComment').live('click',function(){
        var ref= $(this)    
        var comment = $('#comment').val();
        var url = $('#pageUrl').val();
        var parentId = ref.attr('parent_id');
        var padd = 0;
        var commentForm = $('.comForm');
        
        if(!comment){
            if($('#errorComm').length){
                $('#errorComm').html('Пожалуйста, введите комментарий');
            } else {
                $('#addComment').after('<span id="errorComm">Пожалуйста, введите комментарий</span>');
            }
        }
   
        if(parentId != 0){
            padd = $('.articleComment[comm_id="'+$(this).attr('parent_id')+'"]').css('padding-left');
            padd = parseInt(padd) + 10;
        }

        if(comment && url){
        
            params = {
                text:comment,  
                path:url,
                padding:padd, 
                parentId:parentId
            }
        
            ref.html('<img src="http://www.school.oede.by/modules/comments/design/img/ajax-loader.gif"/>');
            $.post('http://oede.by/backend/comments/addComment',params,function(obj){
                if(obj.success){
                    if(parentId == 0){
                        if($('.articleComment').length){
                            $('.articleComment:last').after(obj.comment);
                        } else {
                            $('.commTitle').after(obj.comment);
                            $('.comForm').removeClass('noBorder').removeClass('noPadding');
                        }
                    } else {
                        if($('.articleComment[parent_id="'+parentId+'"]').length){
                            $('.articleComment[parent_id="'+parentId+'"]:last').after(obj.comment);
                        } else {
                            $('.articleComment[comm_id="'+parentId+'"]').after(obj.comment);
                        }
                        $('.articleComment[comm_id="'+parentId+'"]').find('.remote').attr('class','reply').html('ответить &darr;');
                    }
          
                    //вставляем форму
                    $('.comForm').each(function(){
                        $(this).remove();
                    });
                    
                    commentForm.find('#addComment').attr('parent_id',0);
                    $('.articleComment:last').after(commentForm);
            
                    count = parseInt($('#countComm').html())+1;
                    $('#countComm').html(count);
                    $('#countComm').removeClass('unvisible');
                    $('#name').val('')
                    $('#comment').val('');
                } else {
                    $('body').append(obj.error);
                }
                
                ref.html('<img src="http://img.oede.by/st/img/btn/addComment.gif">');
            },'json');
        }
    });

    $('#comment').live('keydown',function(){
        $('#errorComm').remove();
    });

    $('.reply').live('click',function(){
        var ref = $(this);
        var comm = ref.parents('.articleComment');
        var parentId = comm.attr('comm_id');

        var commentForm = $('.comForm');
       
        commentForm.find('#addComment').attr('parent_id',parentId);
       
        $('.comForm').each(function(){
            $(this).remove();
        });

        comm.after(commentForm);
       
        $('.remote').html('ответить &darr;').attr('class','reply');
        ref.html('отменить &uarr;').attr('class','remote');


    });

    $('.remote').live('click',function(){
        var ref = $(this);
        var commentForm = $('.comForm');

        commentForm.find('#addComment').attr('parent_id',0);
        
        ref.html('ответить &darr;').attr('class','reply');
        $('.comForm').each(function(){
            $(this).remove();
        });

        $('.articleComment:last').after(commentForm);

    });

    $('#getSmile').live('click',function(){
        var ref= $(this);
        if(ref.parent().next().is(':visible'))
        {
            ref.parent().next().slideUp();
            ref.html('смайлики +');
        }
        else {
            ref.parent().next().slideDown();
            ref.html('смайлики -');
        };
    });

    $('.smile').live('click',function(){
        var smile = $(this).attr('smile');
        var html = $('#comment').val();
        $('#errorComm').remove();
        $('#comment').val(html+smile);
    });
    
    $('#addComment img').live({
        mouseenter:
        function(){
            $(this).attr('src','http://img.oede.by/st/img/btn/addComment-h.gif');
        },
        mouseleave:
        function(){
            $(this).attr('src','http://img.oede.by/st/img/btn/addComment.gif');
        }
    });
       
    

    /* comments */


    /* start Tooltip */
     
    $(function() {
    $('#tooltiper a').tooltip({
        track: true,
        delay: 0,
        showURL: false,
        fade: 200
    });
    });
    /* end Tooltip */
	 
    $('.centerColumn ul').attr('type','square');
    
    $('.searchRecipeBut').click(function(){
        $('.searchForm').remove();    
        $('body').append('<div style="position: absolute; top: 20%; z-index: 999999; left: 42%; color:#fff; font-weight:bold; text-align:center "><img width="150px" src="http://img.oede.by/new/img/loading.gif" alt="Идёт поиск рецепта"><br>Пожалуйста, подождите...</div>');    
    })
    
    $('#search').focus(function(){
        $(this).val('');
    
    })    

    $('#receiptName').click(function(){
        $(this).val("");  
    }) 

    $('.searchIcon').click(function(){
        $('#cse-search-box1').submit();
    
    })
    
    /* start PopUps */
    
    $('.closeEnter').click(function(){
            $('.enterFormOverlay').css('display','none');
            $('body').css({'overflow':'auto'});    
            $(this).parent().css('display','none'); 
            $('.subscribe_message').html('');
	    $('html').css({'overflow':'auto'});
    })      
    
    $('.searchRecipe').click(function(){
    if ($.browser.msie && $.browser.version == 6) {      
        alert("Для корректной работы нашего сайта требуется браузер выше 6 версии. Пожалуйста, переустановите браузер");}    
        $('body').css('overflow','hidden');
	$('html').css('overflow','hidden'); 
        $('.enterFormOverlay').css('display','block');  
        $('.searchForm').css('display','block');
    })    
   
    $('#expandedsearch').click(function(){
        $('.enterFormOverlay').css('display','block');  
        $('.searchForm').css('display','block');  
    })
        
    $('.enter').click(function(){
            $('.enterFormOverlay').css('display','block');
            $('body').css({'overflow':'hidden'});
	    $('html').css({'overflow':'hidden'});    
            $('.enterForm').css('display','block');
    })

    $('.sendmail').click(function(){
            $('.enterFormOverlay').css('display','block');
            $('body').css({'overflow':'hidden'});
	    $('html').css({'overflow':'hidden'});   
            $('.sendmailForm').css('display','block');
    })
    
    $('.feed').click(function(){
            $('.enterFormOverlay').css('display','block'); 
            $('body').css({'overflow':'hidden'});
	    $('html').css({'overflow':'hidden'});    
            $('.feedBack').css('display','block');
    })
    
    $('#message').focus(function(){
       $(this).val("");         
    })
    
    $('#send').click(function(){
        var message = $('#message').val();
        var form = $(this).parent().parent().parent();    
        if((message == "") || (message == "Введите Ваше сообщение") ) {
            $(this).parent().parent().parent().find('.subscribe_message').html('Пожалуйста, введите сообщение').css('color','red');
        } else {
            form.find('.subscribe_message').html('Подождите..').css('color','red');            
            $.ajax({
                type:'GET',
                url:'http://www.oede.by/feedback/feedback.php',
                data: 'message=' + message,
                success: function(){ 
                    form.find('.subscribe_message').html('Ваше сообщение отправлено').css('color','#8CA019');                
                    form.find('#message').val("Введите Ваше сообщение");
                }
            });
        }        
    }) 
       
    /* end PopUps */
    

	
    
    /* print version */
    initPrintVersion();
   
    /* favorite */
    initFavorites();
	 			
	// setup the drop downs
	$('#navbar ul > li').hoverIntent(
		// mouseover so show the drop down
		function()
		{
			// make the nav item have the over state
			$('> .sub-menu', this).toggle();
			$('.open', this).css('background','url(http://img.oede.by/new/img/menuUp.jpg) no-repeat');
			if($(this).hasClass('shops')){
			$(this).css('background','url(http://img.oede.by/new/img/menuBackgroundShops.png) no-repeat 0px 3px');
				} else if($(this).hasClass('publications')){
			$(this).css('background','url(http://img.oede.by/new/img/menuBacjgroundPublications.png) no-repeat 0px 3px');
				} else if(!$(this).hasClass('factsMenu')&&!$(this).hasClass('forumMenu') && !$(this).hasClass('about') && !$(this).hasClass('sharesMenu') && !$(this).hasClass('schoolMenu')){
			$(this).css('background','url(http://img.oede.by/new/img/menuBackgroundRecipes.png) no-repeat 0px 3px');
			}
			$('.menuTitle',this).css('border','none');

				
		},
		// mouseout so hide the drop down
		function()
		{
            //remove the over state on the nav item
			$('> .sub-menu', this).toggle();
			$('.open', this).css('background','url(http://img.oede.by/new/img/menuDown.jpg) no-repeat');
			$(this).css('background','none');
			$('.menuTitle',this).css('border-bottom','1px solid #A6A6A6');

		}
	);
	
	
	// IE fun
	if(isIE())
	{
		$('#navbar li li').hover(
			function()
			{
				$(this).addClass('hover_ie');
			},
			function()
			{
				$(this).removeClass('hover_ie');
			}
		);	
	}
	
	
	zIndexWorkaround();

    /* Newsletter */
    
    $("img#subscribe").click(function(){
     
     var name = $('.sendmailForm #name').val();
     
     var email = $('.sendmailForm #email').val();
     
     //Валидация формы
     
        if((name == "")&(email == "")) $('.subscribe_message').html('Пожалуйста, введите имя и email.').css('color','red').show();
        
        else if(name == "") $('.subscribe_message').html('Пожалуйста, введите имя.').css('color','red').show();
       
        else if(email == "") $('.subscribe_message').html('Пожалуйста, введите email.').css('color','red').show();
        
        else if(!(/^([a-zA-Z0-9_  .\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(email))) $('.subscribe_message').html('Неверный email!').css('color','red').show();
        
        else if((name != "")&(email != "")&(/^([a-zA-Z0-9_  .\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(email))) {
        
            $('.subscribe_message').html('Подождите..').css('color','#8CA019').show(); 
            
            $.ajax({
                    type:'GET',
                    url:'http://www.oede.by/sendmail/sendmailAjax.php',
                    data: "name=" + name + "&email=" + email,
                    complete: function(data){if (data.getResponseHeader('Content-Length') != 31) $('.subscribe_message').css('color','#8CA019').html('Спасибо, за подписку.<br>Вам выслано письмо.').show();
                                               else $('.subscribe_message').html('Вы уже подписаны.').css('color','red').show();;
                                              }
                  });  
              
        $('input#name').attr("value","");  
        
        $('input#email').attr("value","");                           

    return false;

        }
    });	
	


	function isIE()
	{
    	if(navigator.userAgent.match(/MSIE \d\.\d+/))
        return true;
    	return false;
	}

	function zIndexWorkaround()
	{
	    // If the browser is IE,
	    if(isIE())
	    {
	        /*
	        ** For each div with class menu (i.e.,
	        ** the thing we want to be on top),
	        */
	        $(".sub-menu").parents().each(function() {
	            var p = $(this);
	            var pos = p.css("position");
	
	            // If it's positioned,
	            if(pos == "relative" ||
	               pos == "absolute" ||
	               pos == "fixed")
	            {
	                /*
	                ** Add the "on-top" class name when the
	                ** mouse is hovering over it, and remove
	                ** it when the mouse leaves.
	                */
	                p.hover(function() {
	                        $(this).addClass("on-top");
	                    },
	                    function() {
	                        $(this).removeClass("on-top");
	                    });
	            }
	        });
	    }
	}

    /* print version*/
    function initPrintVersion() 
    {
        jQuery('.print-version a.showPrint').click(function () {

            window.open('/print.html','_blank','scrollbars=yes,width=800,height=600,left=0,top=0, toolbar=yes, titlebar = yes, status = yes, resizeable = no, menubar = yes,location = yes, directories = yes, fullscreen = yes');

            return false;
        });
    }
    
    function getPrintContent() 
    {
            var szResult = '';
            szResult += '<h1>' + jQuery('.contentNamePublication').html() + '</h1>';
            szResult += '<div>';
            szResult += '<div style="float:left;margin:5px"><img src="' + jQuery('.contentImg img').attr('src') +'"/></div>';
            szResult += '<div> ' + jQuery('.textContent').html() + ' </div>';
            szResult += '</div>';
            return szResult;
    }
 
    /* favorites */
    function initFavorites() 
    {

        jQuery('.favorites').click(function() {
            var szName = jQuery('.contentNamePublication').html();
            var szUrl = window.location;
            jQuery.post('/stuff/favorites_rpc.php','name=' + szName + '&url=' + szUrl,function (result) {
                if (result == 'Ok') {
                    alert('Ссылка добавлена в избранное')
                }
                else if (result == 'Already') {
                    alert('Ссылка добавлена в избранное')
                }
                else 
                {
                    alert('Эта функция доступна только для зарегистрированных пользователей');
                }
            })
            return false;
        });
        jQuery('.deleteFavorites').click(function () {
            var nResult = confirm('Вы уверены, что хотите удалить эту ссылку?');
            if (!nResult) {
                return false;
            }
            var nId = this.getAttribute('rel');
            jQuery.post('/stuff/favorites_rpc.php','id=' + nId,function (result) {
                var nResult = window.parseInt(result);
                if (nResult > 0) {
                    jQuery('a.deleteFavorites[rel=' + nResult +']').each(function () {
                        jQuery(this.parentNode).remove();
                    });
                }
                else {
                    alert('Удаление ссылки не удалось, обновите страницу')
                }

            });
            return false;
        })

      //recalculate
      $('#minusRec').click(function(){

	var portion = $('#portion').val();
	if(parseInt(portion) >1){
	  $('#portion').val(parseInt(portion)-1);
	} else {
	  $('#portion').val(1);
	}
	  
      });

      $('#plusRec').click(function(){

	var portion = $('#portion').val();
	$('#portion').val(parseInt(portion)+1);
	  
      });

    $('#portion').keypress(function(e){
    
	var portion = $('#portion').val();

	if(portion == '' && e.which == 48)
	{
	  return false;
	}
	if((e.which<48 || e.which>57) && e.which!=8)
	{
	  return false;
	}
    })
    

    $('#recalculate').click(function(){
      var countPerson = parseInt($('#countPerson').val());
      var portion = parseInt($('#portion').val());
      var text = 'порций';
      if(portion == 0)
      {
	portion=1;
	$('#portion').val('1');
      }
      k = 1;
      while($('.countProduct_'+k).length)
      {
	  prod = $('.countProduct_'+k).html();
	  val = parseInt((prod/countPerson)*portion);
	  $('.countProduct_'+k).html(val);
	  
	k++;
      }
      $('#countPerson').val(portion);

      var reg = /1$/;
      if(reg.test(portion))
      {
	text = 'порцию';
      }
      var reg = /[2-4]$/;
      if(reg.test(portion))
      {
	text = 'порции';
      }

      $('#portionCount').html(portion);
      $('#portionText').html(text);
      
    })

    }    
      
  //advanced search

 $('.more-advanced-search').toggle( function(){
	var ref = $(this);
	ref.parent().parent().find('.more-text').slideUp();
	ref.parent().parent().find('.arrowAS').attr('src','http://img.oede.by/new/img/advancedSearch/block-advanced-search-arr.gif').attr('alt','&darr;');
      },
	function(){
	var ref = $(this);
	ref.parent().parent().find('.more-text').slideDown();
	ref.parent().parent().find('.arrowAS').attr('src','http://img.oede.by/new/img/advancedSearch/block-advanced-search-arr2.gif').attr('alt','&uarr;');
 });

 $('.more-advanced-search-result').toggle( 
	function(){
	var ref = $(this);
	$('.block-advanced-search-title').css('margin','0 0 11px');
 	ref.html('Свернуть');
	$('.criteria-result').slideDown();
	ref.parent().parent().find('.arrowAS').attr('src','http://img.oede.by/new/img/advancedSearch/block-advanced-search-arr2.gif').attr('alt','&uarr;');
  },function(){
	  var ref = $(this);
	  ref.html('Развернуть');
	  $('.block-advanced-search-title').css('margin','0');
	  $('.criteria-result').slideUp();
	  ref.parent().parent().find('.arrowAS').attr('src','http://img.oede.by/new/img/advancedSearch/block-advanced-search-arr.gif').attr('alt','&darr;');
	});

 $('.more-advanced-search-noresult').toggle( 
	function(){
	  var ref = $(this);
	  ref.html('Развернуть');
	  $('.block-advanced-search-title').css('margin','0');
	  $('.criteria-noresult').slideUp();
	  ref.parent().parent().find('.arrowAS').attr('src','http://img.oede.by/new/img/advancedSearch/block-advanced-search-arr.gif').attr('alt','&darr;');
	},function(){
	var ref = $(this);
	$('.block-advanced-search-title').css('margin','0 0 11px');
 	ref.html('Свернуть');
	$('.criteria-noresult').slideDown();
	ref.parent().parent().find('.arrowAS').attr('src','http://img.oede.by/new/img/advancedSearch/block-advanced-search-arr2.gif').attr('alt','&uarr;');
  });



  //autosuggeststing
  var optionsRec = {
	  script: "/backend/autosuggest/recipe?",
	  varname: "s",
	  json: true,
	  maxresults: 10,
	  shownoresults:true,
	  noresults: 'Поиск не дал результатов' ,
	  callback: function (obj) {window.location = '/recipe/foto/' +obj.id + '/';}


  };
  new bsn.AutoSuggest('recipeNameAS', optionsRec);
  new bsn.AutoSuggest('receiptName', optionsRec);

  var optionsFood = {
	  script: "/backend/autosuggest/foodstuff?",
	  varname: "s",
	  json: true,
	  maxresults: 10,
	  shownoresults:true,
	  noresults: 'Поиск не дал результатов',
	  callback: function (obj) { 
	    var count = parseInt($('#foodCount').val()); 
	    $('#hiddenFoodId'+count).val(obj.id); 
	  } 
  };
  
  var itemsFood = $('.addFoodstuff');
  var i = 1;
  itemsFood.each(function(){
  
    new bsn.AutoSuggest('foodstuff'+i, optionsFood);
    i++;

  })




  $('#addProduct ').click(function(){
      var count = parseInt($('#foodCount').val());
      count++;
      $('#foodstuffTable').append('<tr><td><input type="text" class="addFoodstuff" id="foodstuff'+count+'" autocomplete="off"><input type="hidden" id="hiddenFoodId'+count+'" name="items[]" value="" /></td><td><img class="deleteRow" src="http://img.oede.by/new/img/deleteRow.gif" alt="удалить ингедиент" title="удалить ингедиент" ></td></tr>');
      new bsn.AutoSuggest('foodstuff'+count, optionsFood);

      $('#foodCount').val(count);
});


  $('.deleteRow').live('click',function(){
    var ref= $(this);
    ref.parent().parent().remove();
    var count = parseInt($('#foodCount').val());
    count--;
    $('#foodCount').val(count);
  });


/* Recipe Page*/

$('.recieptcategory li a').click(function(){
  var ref = $(this);
  var catId = ref.attr('id');
  var active = $('a.active').attr('id');
  
  $('a.active').css('background','url("http://img.oede.by/new/img/recipe/page/categories/notactive/'+active+'.gif") no-repeat scroll right center');
  $('.active').removeClass('active');

  ref.addClass('active');
  ref.parent().addClass('active');
  
 // $('.c2').html('<div style="text-align:center;margin-top:20%"><img src="http://img.oede.by/new/img/recipe/page/ajax-loader.gif"/></div>');
  $.post('/backend/frontajax/getRecipeCategories',{cat:catId},function(data){

      $('#rep1').html(data.subcategories);
      $('#galleryCatRec .belt').html(data.belt);
      $('#allRecByCat').html(data.viewall);
  },'json');

});


$('#12').css('background','url(http://img.oede.by/new/img/recipe/page/categories/notactive/12.gif) no-repeat center right 10px');
$('#13').css('background','url(http://img.oede.by/new/img/recipe/page/categories/notactive/13.gif) no-repeat center right');
$('#14').css('background','url(http://img.oede.by/new/img/recipe/page/categories/notactive/14.gif) no-repeat center right');
$('#15').css('background','url(http://img.oede.by/new/img/recipe/page/categories/notactive/15.gif) no-repeat center right');
$('#16').css('background','url(http://img.oede.by/new/img/recipe/page/categories/notactive/16.gif) no-repeat center right');
$('#17').css('background','url(http://img.oede.by/new/img/recipe/page/categories/notactive/17.gif) no-repeat center right');
$('#20').css('background','url(http://img.oede.by/new/img/recipe/page/categories/notactive/20.gif) no-repeat center right');
$('#9').css('background','url(http://img.oede.by/new/img/recipe/page/categories/notactive/9.gif) no-repeat center right');
$('#18').css('background','url(http://img.oede.by/new/img/recipe/page/categories/notactive/18.gif) no-repeat center right');



$('#12').hover(function(){
  $(this).css('background','url(http://img.oede.by/new/img/recipe/page/categories/active/12.gif) no-repeat center right');

}, function(){
  if($(this).attr('class') != 'active'){
   $(this).css('background','url(http://img.oede.by/new/img/recipe/page/categories/notactive/12.gif) no-repeat center right');
  }
});


$('#13').hover(function(){

  $(this).css('background','url(http://img.oede.by/new/img/recipe/page/categories/active/13.gif) no-repeat center right');

}, function(){
  if($(this).attr('class') != 'active'){
   $(this).css('background','url(http://img.oede.by/new/img/recipe/page/categories/notactive/13.gif) no-repeat center right');
  }
});



$('#14').hover(function(){

  $(this).css('background','url(http://img.oede.by/new/img/recipe/page/categories/active/14.gif) no-repeat center right');

}, function(){
  if($(this).attr('class') != 'active'){
   $(this).css('background','url(http://img.oede.by/new/img/recipe/page/categories/notactive/14.gif) no-repeat center right');
  }
});


$('#15').hover(function(){

  $(this).css('background','url(http://img.oede.by/new/img/recipe/page/categories/active/15.gif) no-repeat center right');

}, function(){
  if($(this).attr('class') != 'active'){
   $(this).css('background','url(http://img.oede.by/new/img/recipe/page/categories/notactive/15.gif) no-repeat center right');
  }
});


$('#16').hover(function(){

  $(this).css('background','url(http://img.oede.by/new/img/recipe/page/categories/active/16.gif) no-repeat center right');

}, function(){
  if($(this).attr('class') != 'active'){
   $(this).css('background','url(http://img.oede.by/new/img/recipe/page/categories/notactive/16.gif) no-repeat center right');
  }
});

$('#17').hover(function(){

  $(this).css('background','url(http://img.oede.by/new/img/recipe/page/categories/active/17.gif) no-repeat center right');

}, function(){
  if($(this).attr('class') != 'active'){
   $(this).css('background','url(http://img.oede.by/new/img/recipe/page/categories/notactive/17.gif) no-repeat center right');
  }
});

$('#18').hover(function(){

  $(this).css('background','url(http://img.oede.by/new/img/recipe/page/categories/active/18.gif) no-repeat center right');

}, function(){
  if($(this).attr('class') != 'active'){
   $(this).css('background','url(http://img.oede.by/new/img/recipe/page/categories/notactive/18.gif) no-repeat center right');
  }
});

$('#20').hover(function(){

  $(this).css('background','url(http://img.oede.by/new/img/recipe/page/categories/active/20.gif) no-repeat center right');

}, function(){
  if($(this).attr('class') != 'active'){
   $(this).css('background','url(http://img.oede.by/new/img/recipe/page/categories/notactive/20.gif) no-repeat center right');
  }
});


$('#9').hover(function(){

  $(this).css('background','url(http://img.oede.by/new/img/recipe/page/categories/active/9.gif) no-repeat center right');

}, function(){
  if($(this).attr('class') != 'active'){
   $(this).css('background','url(http://img.oede.by/new/img/recipe/page/categories/notactive/9.gif) no-repeat center right');
  }
});



var active = $('a.active').attr('id');
$('a.active').css('background','url(http://img.oede.by/new/img/recipe/page/categories/active/'+active+'.gif) no-repeat center right');

 $('.activeSubcat').live('click',function(){
    var url = $(this).attr('url');
    document.location.href = url;
    //window.open(url,"newWin", "width=800,height=600,menubar=yes,location=yes,resizable=yes,scrollbars=yes");
  });	

    jQuery('.activeSubcat').hover(function(){
        jQuery(this).css('background','#f3f3f3');
    },function(){
        jQuery(this).css('background','none');
    });




/* Recipe Page*/



/* Fridge */
       
$('#foodCountFridge').val('3');  
var optionsFoodFridge = {
	  script: "/backend/autosuggest/foodstuff?",
	  varname: "s",
	  json: true,
	  maxresults: 10,
	  shownoresults:true,
	  noresults: 'Поиск не дал результатов',
	  callback: function (obj) { 
	    var count = parseInt($('#foodCountFridge').val()); 
            $('#hiddenFoodId'+count).val(obj.id);
            var itemsFood = $('.addFoodstuffFridge');
              var i = 1;
              item = false;
              itemsFood.each(function(){
                val = $('#foodstuff'+i).val();  
                if(!item && val){
                    item = val;
                } else if(val) {
                    item += '&&'+val;
                }  
                i++;            
              })            
             
            $.post('/backend/frontajax/getCountRecipeInFridge',{items:item},function(obj){
                if(obj.success){
                    $('#recipes_found').html(obj.html);   
                } else {
                    $('#recipes_found').html('0'); 
                }
            },'json')
            
	  } 
  };
  
  var itemsFood = $('.addFoodstuffFridge');
  var i = 1;
  itemsFood.each(function(){
    new bsn.AutoSuggest('foodstuff'+i, optionsFoodFridge);
    i++;
  })

    $('#holod_add').live('click',function(){
      var count = $('#foodCountFridge').val();
      count++;      
      $('.holod_element_second').after('<img src="http://img.oede.by/new/img/holod/delete.png" class="deleteHolod"><div style="" class="holod_element">'+
'<input type="text" class="addFoodstuffFridge" name="elem[]" id="foodstuff'+count+'" autocomplete="off"></div>');
      new bsn.AutoSuggest('foodstuff'+count, optionsFoodFridge);
      $('#foodCountFridge').val(count);  
    });
    
    $('.deleteHolod').live('click',function(){
       ref = $(this);
       ref.next().remove();
       ref.remove();
       var count = parseInt($('#foodCountFridge').val());
       count--;  
       $('#foodCountFridge').val(count);       
    });
  
/* Sorts*/

    $('.sortLink').click(function(){
       url = $(this).attr('url');
       document.location.href = url;
        
    });

})


function print(url)
{
        var cont = $('#forPrint').html();
        print= open("", "printWindow");
        
        print.document.open();
        print.document.write('<html><head><title>Печать</title>');
        print.document.write('<link rel="stylesheet" href="http://img.oede.by/new/css/print.css" type="text/css"></link></head><body>');
        print.document.write('<div class="logo"><img src="http://img.oede.by/new/img/logoMail.jpg" alt="Oede.by" /><span>Адрес страницы в интернете: <a href="http://www.oede.by'+url+'">http://www.oede.by'+url+'</a></span></div><a href="javascript:window.print()">Печатать</a><hr>');
        print.document.write(cont);
        print.document.write('</body></html>');
        print.document.close();
}








