/*
Site: Landen auf Wasser
HTTP: www.landen-auf-wasser.de
Date: 2008-05-11
*/




/*
Site - Scroll - Initialize
*/
$(document).ready(
  function() {

    // LOCAL
    siteScroll_naviMain_position();
    siteScroll_content_position();
    siteScroll_content_scrollTo();

  }
);




/*
LOCAL
Scroll - Navigation Main - Position
*/
function siteScroll_naviMain_position() {

  var naviMain_container = $("div.header");
  var naviMain_content = $("#block-menu-2");
  var naviMain_cache = $("#cache");

  // SET HEIGHT AND WIDTH OF NAVIGATION
  naviMain_container.css("height", naviMain_container.outerHeight() + "px");
  naviMain_container.css("width", naviMain_container.width() + "px");

  // GET POSITION OF NAVIGATION ...
  // var naviMain_container_position = naviMain_container.offset();

  // MOVE NAVIGATION TO END OF DOM (div#cache) ...
  naviMain_cache.append(naviMain_content);

  // POSITION THE NAVIGATION (fixed)
  naviMain_content.css({ position: "fixed", left: "440px", top: "80px",  zIndex: "100" });
  /*
  ** Note: The values here are hard coded, because the positioning does not work in combination with the back-button of the browser.
  ** naviMain_content.css({ position: "fixed", left: naviMain_container_position.left + 10, top: navMain_container_position.top,  zIndex: "100" });
  */

};


/*
LOCAL
Scroll - Content - Position
*/
function siteScroll_content_position() {

  var content_position_trigger = $("#page-head");
  var content_position_display = $("#content");

  // POSITION CONTENT
  var content_position_trigger_height = content_position_trigger.outerHeight() - 5 + "px";
  content_position_display.css("margin-top", content_position_trigger_height);

};


/*
LOCAL
Scroll - Content - Scroll To ...
*/
function siteScroll_content_scrollTo() {

  // HANDLE ANCHOR LINKS DIRECTING TO SECTIONS ON OTHER PAGES
  if (window.location.href.indexOf("#") != -1) {
    var content_static_height = $("#animation").outerHeight() + $("#page-head").outerHeight();
    var content_scroll_position = $("#" + window.location.href.substr(window.location.href.indexOf("#") + 1)).offset();
    var content_scroll_calculation = content_scroll_position.top - content_static_height + 5;
    $.scrollTo(content_scroll_calculation, {duration:1000});
  }

  // HANDLE ANCHOR LINKS DIRECTING TO SECTIONS ON THE CURRENT PAGE
  var string_url_site = window.location.href.substring(window.location.href.lastIndexOf("/")+1);
  if (string_url_site.indexOf("#") != -1) {
    string_url_site = string_url_site.substr(0, string_url_site.indexOf("#"));
  }

  $("a").each(
    function () {
      var string_url_href = $(this).attr("href").substring($(this).attr("href").lastIndexOf("/")+1);
      if (string_url_href.indexOf("#") != -1) {
        string_url_href = string_url_href.substr(0, string_url_href.indexOf("#"));
      }
      if (string_url_site == string_url_href) {
        $(this).click(
          function () {
            var content_static_height = $("#animation").outerHeight() + $("#page-head").outerHeight();
            var content_scroll_position = $($(this).attr("href").substr($(this).attr("href").indexOf("#"))).offset();
            var content_scroll_calculation = content_scroll_position.top - content_static_height + 5;
            $.scrollTo(content_scroll_calculation, {duration:2000});
            return false;
          }
        )
      }
    }
  )
};
