/*

Script voor LVA site

(C) 2004-2010 vizi. Alle rechten voorbehouden.

DOM, ECMA-262 en Javascript compatible manier om mouseovers te 
genereren of popupvenster te openen zonder enige scripting in XHTML.

DOM mouseoverscript gebaseerd op het voorbeeldscript op:
http://www.readinged.com/articles/javascriptdom/

Plaats:
root/scripts/lva.js

Laatst gewijzigd:
31 oktober 2010

Leer, steel niet!

*/

$(function()
{
  // Verzendknop op formulier contactpagina en
  // bibliotheeklink op projectoverzichten.
  $("#verzend, #projecten-bibliotheek").mouseover(function()
  {
    var newSrc = $(this).attr('src').replace('.gif', '_aan.gif');
    $(this).attr('src', newSrc);
  }).mouseout(function()
  {
    var newSrc = $(this).attr('src').replace('_aan.gif', '.gif');
    $(this).attr('src', newSrc);
  });
  

  // Themanav-mouseover op themapagina.
  $("a.themaover").mouseover(function()
  {
    $("#info-"+($(this).attr("id").substring(7))).css(
    {
      'visibility': 'visible'
    });
    
    $(this).addClass("themahighlight");
    $("a.themaover:not('.themahighlight') img").each(function()
    {
      var newSrc = $(this).attr('src').replace('middel.jpg', 'middel-blauw.jpg');
      $(this).attr('src', newSrc);
    });
    
  }).mouseout(function()
  {
    $("#info-"+($(this).attr("id").substring(7))).css(
    {
      'visibility': 'hidden'
    });
    $(this).removeClass("themahighlight");
    $("a.themaover img").each(function()
    {
      var newSrc = $(this).attr('src').replace('-blauw.jpg', '.jpg');
      $(this).attr('src', newSrc);
    });
  });

  // Project-mouseover op archiefpagina.
  $("a.archiefover").mouseover(function()
  {
    var thisArchief = $(this).parent().parent().parent().parent().attr("id").substring(7),
        thisImg = $("#img" + thisArchief),
        thisPath = $(this).attr("pathname");
    if (thisPath.substring(0,1) !== '/') { thisPath = "/" + thisPath; }
    thisImg.attr("src", 'http://' + $(this).attr("hostname") + '/media' + thisPath + '/middel.jpg');
  
  }).mouseout(function()
  {
    var thisArchief = $(this).parent().parent().parent().parent().attr("id").substring(7),
        thisImg = $("#img" + thisArchief);
        thisImg.attr("src", '/beeld/archief_' + thisArchief + '.gif');
  });
  
  // Projectnavigatie met flow.
  $("#projectnav, #archief .projectnav").addClass("flow").prepend("<span class=\"flow-prev\" />").append("<span class=\"flow-next\" />");
  
  var selProject = $("#tekst h2").text().toLowerCase();
  $("#projectnav strong").each(function()
  {
    if ($(this).text().toLowerCase() == selProject)
    {
      var selItem = $(this).parent().parent(),
          selItemTop = selItem.position().top,
          selParent = selItem.parent(),
          selParentTop = selParent.position().top,
          moveBy = 0;
      selItem.addClass("selected");

      if (selItemTop-selParentTop > 250) // Height of image minus the two arrow bars.
      {
        moveBy = parseInt((selParentTop - selItemTop) / 150) * 150;
        selItem.parent().animate({ 'top': moveBy },10);
      }
    }
  });
  
  $("#projectnav span, #archief .projectnav span").mouseover(function()
  {
    $(this).addClass("flow-over");
  }).mouseout(function()
  {
    $(this).removeClass("flow-over");
  });
  
  $("#projectnav span.flow-prev, #archief .projectnav span.flow-prev").click(function()
  {
    var navList = $(this).parent().find("ul"),
        navPos = navList.position(),
        navTop = navPos.top;
    
    if (navTop < -125)
    {
      navList.animate({ 'top': '+=150' },500);
    }
    else if (navTop < 25)
    {
      navList.animate({ 'top': '25' },500);
    }
    else
    {
      navList.animate({ 'top': '35' },100,function()
      {
        navList.animate({ 'top': '25' },100);
      });
    }
  });
  
  $("#projectnav span.flow-next, #archief .projectnav span.flow-next").click(function()
  {
    var navRoom = $(this).parent().height(),
        navList = $(this).parent().find("ul"),
        navHeight = navList.height(),
        navPos = navList.position(),
        navTop = navPos.top,
        navMax = navRoom - 25 - navHeight;
    
    if (navTop > (navMax+150))
    {
      navList.animate({ 'top': '-=150' },500);
    }
    else if (navTop > navMax)
    {
      navList.animate({ 'top': navMax },500);
    }
    else
    {
      navList.animate({ 'top': navMax-10 },100,function()
      {
        navList.animate({ 'top': navMax },100);
      });
    }
  });

});

