﻿$(document).ready(function () {
  // Kleur menu item oranje als het huidige categorie is.
  menulink = window.location.href;

  $(".menu-background a").each(function () {
    if (menulink.indexOf(this.href) > -1) {
      $(this).css("color", "#FF6D00");
    }
  });

  $("#right_content").height($("#content_left").height() - 50);

  //Handle menu
  /*
  focusMenu(determineCurrentIndex(), true, true);
  $('#menu li:not(.active)').hover(function () {
  focusMenu($('#menu li').index(this), false, true);
  }, function () {
  focusMenu($('#menu li').index(this), false, false);
  });
  */


  // Determine active menu item
  var currenturl = document.location.pathname.toString().toLowerCase();
  currenturl = ((currenturl == '/index.asp') ? '/' : currenturl);
  $('#menu li a').each(function (index, element) {
    if ($(element).attr('href') == currenturl)
      element.className = element.className + "_active";
  });


  // menu uitklappen
  $("a.realisatie").hover(function () { //When trigger is clicked...
    $(this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click
    $(this).parent().hover(function () {
    }, function () {
      $(this).parent().find("ul.subnav").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
    });
  });



  //Banner fade
  if ($('#headbanner').length > 0) {
    $('#headbannernav ul').html('');
    $('#headbanner').cycle({
      fx: 'fade',
      pager: '#headbannernav ul',
      pagerAnchorBuilder: function (idx, slide) {
        return '<li><a href="#">' + (idx + 1) + '</a></li>'
      },
      next: '#headbannernav #next',
      prev: '#headbannernav #prev',
      timeout: 7000
    });
  }

  //Blocks
  $('#ds_blocks .dblock').click(function () {
    document.location = $('a', this).attr('href');
  });
});

function determineCurrentIndex() {
  var index = null;
  var currenturl = document.location.pathname.toString().toLowerCase();
  currenturl == '/' || currenturl == '/index.asp' ? index = 0 : index = null;
  if (!index) {
    $('#menu li a').each(function () {
      if ($(this).attr('href') == currenturl) {
        index = $('#menu li').index($(this).parent());
        return false;
      }
    });
  }
  return index;
}

function focusMenu(index, lock, focus) {
  if (index != null) {
    var image = $('#menu li:eq(' + index + ') img').get(0);
    if (!image.origurl) { image.origurl = $(image).attr('src') }
    if (lock) { $(image).closest('li').addClass('active') }
    focus ? $(image).attr('src', image.origurl.toString().split('.')[0] + '_select.gif') : $(image).attr('src', image.origurl);
  }
}
