$(document).ready(function() {
  
  // $(".obf").each(function(){  
  //   var self = $(this);
  //   var email = this.tagName.toLowerCase() == 'a' ? self.attr('href') : self.html();
  //   email = email.replace(/[a-zA-Z]/g, function(c){return String.fromCharCode((c<="Z"?90:122)>=(c=c.charCodeAt(0)+13)?c:c-26);});
  //   if(this.tagName.toLowerCase() == 'a'){
  //     if(self.html() == self.attr('href')){
  //       self.html(email);
  //     }
  //     self.attr('href','mailto:'+email);
  //   }else{
  //     self.html(email)
  //   }
  // });

  $('input[type="text"][title]').focus(function(e){
    $(this).filter('.empty').val('').removeClass('empty');
  }).blur(function(e){
    $(this).filter(function(){return this.value == ''}).val($(this).attr('title')).addClass('empty');
  }).blur();
  
  $('#search-form').submit(function(e){
    var $f = $('#form_query');
    if($f.hasClass('empty') || $.trim($f.val()).length < 3){
      alert('Моля въведето поне 3 символа.');
      $f.focus();
      return false;
    }
    return true;
  });
  
  $('#add-bookmark').jFav();
  
  
  
  var news_max_height = 300;
  var $ticker = $("#recent-news ul");
  if ($ticker.height() > news_max_height) {
    $ticker.css({overflow: "hidden", height: news_max_height})

    function animator(currentItem) {
      var distance = currentItem.innerHeight();
      duration = (distance + parseInt(currentItem.css("marginTop"))) / 0.025;
      currentItem.animate({ marginTop: -distance }, duration, "linear", function() {
        currentItem.appendTo(currentItem.parent()).css("marginTop", 0);
        animator(currentItem.parent().children(":first"));
      }); 
    };

    $ticker.mouseenter(function() {
      $ticker.children().stop();
    }).mouseleave(function() {
      animator($ticker.children(":first"));
    }).mouseleave();
  };


  
});

