////////////////////////////////////////////////////////////////////////////////
// Autodoktori.cz - main script
////////////////////////////////////////////////////////////////////////////////

var msie = ($.browser.msie && $.browser.version < 9 ? true : false);





$(function(){

  //////////////////////////////////////////////////////////////////////////////
  // Main
  //////////////////////////////////////////////////////////////////////////////

  $(document).pngFix();

  $("a")
    .click(function(){
      $(this).blur();
    });



  //////////////////////////////////////////////////////////////////////////////
  // Sidebar
  //////////////////////////////////////////////////////////////////////////////

  // prodlužení sidebar-line
  $("div#sidebar")
    .each(function(){
      var sidebarheight = this.offsetHeight;
      var contentheight = $("div#content").get(0).offsetHeight;
      if(contentheight > sidebarheight)
      {
        if(contentheight > 340)
          $("div#sidebar-line-middle").css("height", contentheight-320);
      }
      else
        if(sidebarheight > 340)
          $("div#sidebar-line-middle").css("height", sidebarheight-320);
    });

  // přemistění a zobrazení selection divu při startu
  $("div#main-menu-selection").each(function(){
    var $this = $(this);
    $this.css("top", $("ul#main-menu a.selected").last().get(0).offsetTop +54)
    
    if(msie)
      $this.show();
    else
      $this.fadeIn();
  });

  // zobrazení/zmizení hover divu
  $("ul#main-menu")
    .mouseenter(function(){
      if(msie)
        $("div#main-menu-hover").show();
      else
        $("div#main-menu-hover").stop(true, true).fadeIn();
    })
    .mouseleave(function(){
      if(msie)
        $("div#main-menu-hover").hide();
      else
        $("div#main-menu-hover").stop(true, true).fadeOut();
    });

  // přemistění hover divu a zobrazení/skrytí useknutého textu
  $("ul#main-menu a")
    .mouseover(function(){
      var $this = $(this);
      var $top = this.offsetTop + 54;
      $("div#main-menu-hover").stop(true, true).animate({top: $top}, 300);

      if(!(msie && $.browser.version < 7))
      {
        $this.css("white-space", "nowrap");
        $this.stop(true, true).animate({width: 300}, 300);
      }
    })
    .mouseleave(function(){
      if(!(msie && $.browser.version < 7))
      {
        var $this = $(this);
        if($this.parent().parent().parent().hasClass("submenu"))
          var length = 150;
        else
          var length = 170;
        $this.stop(true, true).animate({width: length}, 300, 'linear', function(){
          $this.css("white-space", "normal");
        });
      }
    });

  // zobrazení/skrytí submenu, animace šipky
  $("ul#main-menu li.submenu > a")
    .click(function(){
      var $this = $(this);
        if(msie && $.browser.version < 8)
          $("ul", $(this).parent()).show(function(){
            window.location = $this.attr("href");
          });
        else
          $("ul", $(this).parent()).stop(false, true).slideDown(function(){
            window.location = $this.attr("href");
          });
      return false;
    })
    .mouseover(function(){
      var $this = $(this);
      $this
        .css("background-position", "160px -28px")
        .animate({backgroundPosition:"160px -8px"}, 150);
    })
    .mouseout(function(){
      var $this = $(this);
      $this
        .css("background-position", "160px 38px")
        .animate({backgroundPosition:"160px 18px"}, 150);
    });

    // zobrazení submenu, či ne
    $("ul#main-menu li.submenu > a")



  //////////////////////////////////////////////////////////////////////////////
  // News
  //////////////////////////////////////////////////////////////////////////////

  // prodlužení news-line
  $("div#news")
    .each(function(){
      var newsheight = this.offsetHeight
      if(newsheight > 120)
        $("div#news-line-middle").css("height", newsheight-120);
    });

  // zobrazení/zmizení hover divu
  $("div#news ul")
    .mouseenter(function(){
      if(msie)
        $("div#news-hover").show();
      else
        $("div#news-hover").stop(true, true).fadeIn();
    })
    .mouseleave(function(){
      if(msie)
        $("div#news-hover").hide();
      else
        $("div#news-hover").stop(true, true).fadeOut();
    });

  // přemistění hover divu a zobrazení/skrytí datumu
  $("div#news ul a")
    .mouseover(function(){
      var $top = this.offsetParent.offsetTop + 34;
      $("div#news-hover").stop(true, true).animate({top: $top}, 200);
      $("span", this).fadeIn(300);
    })
    .mouseleave(function(){
      $("span", this).fadeOut(300);
    });



  //////////////////////////////////////////////////////////////////////////////
  // Album
  //////////////////////////////////////////////////////////////////////////////

  // zobrazení/skrytí photo-over
  $("a.album")
    .mouseenter(function(){
      if(msie)
        $("span.album-over", this).show();
      else
        $("span.album-over", this).fadeIn();
    })
    .mouseleave(function(){
      if(msie)
        $("span.album-over", this).hide();
      else
        $("span.album-over", this).fadeOut();
    });



  //////////////////////////////////////////////////////////////////////////////
  // Photogallery
  //////////////////////////////////////////////////////////////////////////////

  // zobrazení/skrytí photo-over
  $("a.photo")
    .mouseenter(function(){
      if(msie)
        $("span.photo-over", this).show();
      else
        $("span.photo-over", this).fadeIn();
    })
    .mouseleave(function(){
      if(msie)
        $("span.photo-over", this).hide();
      else
        $("span.photo-over", this).fadeOut();
    });

  // fancybox
	$("a.photo:has(img)").attr('rel', 'photogallery').fancybox({
    "titleShow": false,
    "overlayOpacity": 0.8,
    "padding": 1
  });



});





