/*
* vertical news ticker
* Tadas Juozapaitis ( kasp3rito@gmail.com )
* http://plugins.jquery.com/project/vTicker
*/
(function(a){a.fn.vTicker=function(b){var c={speed:700,pause:4000,showItems:3,animation:"",mousePause:true,isPaused:false,direction:"up",height:0};var b=a.extend(c,b);moveUp=function(g,d,e){if(e.isPaused){return}var f=g.children("ul");var h=f.children("li:first").clone(true);if(e.height>0){d=f.children("li:first").height()}f.animate({top:"-="+d+"px"},e.speed,function(){a(this).children("li:first").remove();a(this).css("top","0px")});if(e.animation=="fade"){f.children("li:first").fadeOut(e.speed);if(e.height==0){f.children("li:eq("+e.showItems+")").hide().fadeIn(e.speed)}}h.appendTo(f)};moveDown=function(g,d,e){if(e.isPaused){return}var f=g.children("ul");var h=f.children("li:last").clone(true);if(e.height>0){d=f.children("li:first").height()}f.css("top","-"+d+"px").prepend(h);f.animate({top:0},e.speed,function(){a(this).children("li:last").remove()});if(e.animation=="fade"){if(e.height==0){f.children("li:eq("+e.showItems+")").fadeOut(e.speed)}f.children("li:first").hide().fadeIn(e.speed)}};return this.each(function(){var f=a(this);var e=0;f.css({overflow:"hidden",position:"relative"}).children("ul").css({position:"absolute",margin:0,padding:0}).children("li").css({margin:0,padding:0});if(b.height==0){f.children("ul").children("li").each(function(){if(a(this).height()>e){e=a(this).height()}});f.children("ul").children("li").each(function(){a(this).height(e)});f.height(e*b.showItems)}else{f.height(b.height)}var d=setInterval(function(){if(b.direction=="up"){moveUp(f,e,b)}else{moveDown(f,e,b)}},b.pause);if(b.mousePause){f.bind("mouseenter",function(){b.isPaused=true}).bind("mouseleave",function(){b.isPaused=false})}})}})(jQuery);

$(document).ready(function() {
  //News Ticker
$(function () {
	$('#topticker').vTicker({
		speed: 600,
		pause: 4500,
		animation: 'fade',
		mousePause: true,
		showItems: 1,
		height: 20,
		direction: 'up'
	});
});

  //Menu Navigation
  //$(".menu-inner a.menu-homepage").mouseover();
  $(".menu-inner a").mouseover(function() {
    $("#divO").css({left:$(this).position().left, width:$(this).width() + 5});
/*
    var currDivOPos = $("#divO").position().left;
    if (currDivOPos < 500)
//      $("#submenu").css("margin-left", ($("#submenu ul[style='display: inline;']").width() / 2) + currDivOPos -125).css("float","left");
    $("#submenu").css("float","left");
    else
      //$("#submenu").css("margin-left", 0).css("float","right");
*/
    currClassName= $(this).attr("class");
    var _pos=0;
    if (currClassName=="menu-videos")
      _pos=380;
    else if (currClassName=="menu-audios")
      _pos=252;
    else if (currClassName=="menu-photos")
      _pos=310;
    else if (currClassName=="menu-photos")
      _pos=310;
    else if (currClassName=="menu-keywords")
      _pos=335;
    else if (currClassName=="menu-yad")
      _pos=289;
    else if (currClassName=="menu-treatise")
      _pos=147;

    $("#submenu").animate({"right":_pos},100);

    $("#submenu .submenu-inner ul").css("display", "none");
    $("#submenu .submenu-inner ul[rel='" + $(this).attr("class") + "']").show();
  });

  //Search Box
  var searchContainer = $('#search');
  var searchBoxInput = $('.header-search-form .header-search-input');
  var searchBoxDefault = 'جستجو...';
  searchBoxInput.attr("value", searchBoxDefault);

  searchBoxInput.focus(function (e) {
    searchContainer.addClass("active");
  });
  searchBoxInput.blur(function (e) {
    searchContainer.removeClass("active");
  });

  searchBoxInput.focus(function () {
    if ($(this).val() == searchBoxDefault) $(this).attr("value", "");
    $(this).animate({width: '254px'}, 500);
  });
  searchBoxInput.blur(function () {
    if ($(this).val() == "") $(this).attr("value", searchBoxDefault);
    $(this).animate({
          width: '115px'
        }, 500);
  });

  $("input.header-search-button").click(function() {
    if ($("input.header-search-input").val() == searchBoxDefault) $("input.header-search-input").focus(); else location.href = '/search-result?q=' + decodeURIComponent($("input.header-search-input").val())
  });
  $("input.header-search-input").keypress(function(e) {
    var lkp = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
    if (e.keyCode == 13) {
      $("input.header-search-button").click();
    }
  });

  $("input.footer-search-button").click(function() {
    if ($("input.footer-search-input").val() == searchBoxDefault) $("input.footer-search-input").focus(); else location.href = '/search-result?q=' + decodeURIComponent($("input.footer-search-input").val())
  });
  $("input.footer-search-input").keypress(function(e) {
    var lkp = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
    if (e.keyCode == 13) {
      $("input.footer-search-button").click();
    }
  });

});
