﻿$(document).ready(function () {

  changeView3D();
  setClientHover();

  // Kleur menu item oranje als het huidige categorie is.
  var menulink = window.location.href;
  $("#menu a").each(function () {
    if (menulink.indexOf(this.href) > -1) {
      $(this).parent().addClass("active");
    }
  });
  $("#top_menu a").each(function () {
    if (menulink.indexOf(this.href) > -1) {
      $(this).parent().addClass("active");
    }
  });
  $("#top_menu li").click(function () {
    window.location = $(this).find("a").attr("href");
    return false;
  });

  var browser = parseInt(jQuery.browser.version);
  if (browser == 6) { //only when ie6
    $("#menu").css("margin-right", "11px");
  }


  if ($('#headbanner').length > 0) {
    $('#headbanner').cycle({
      fx: 'fade',
      pager: '#headbannernav ul',
      pagerAnchorBuilder: function (idx, slide) {
        return '<li><a href="#">' + (idx + 1) + '</a></li>'
      },
      timeout: 7000
    });
  }


  if ($('#box_3d_shots').length > 0) {
    $('#box_3d_shots').cycle({
      fx: 'fade',
      next: '#box_3d_nav #btn_next',
      prev: '#box_3d_nav #btn_prev',
      timeout: 7000
    });
  }

});


function setClientHover() {
  $("#clientbar img").each(function () {
    $(this).mouseover(function (event) {
      $(this).attr("src", $(this).attr("src").replace(".gif", "") + "_h.gif");
    });
    $(this).mouseout(function (event) {
      $(this).attr("src", $(this).attr("src").replace("_h.gif", ".gif"));
    });
  });
}

function changeView3D() {

  $("#box_3d_nav a[href!='#']").click(function (event) {
    $("#box_3d_nav a.show").removeClass("show");
    $(this).addClass("show");
    var versie = $(this).attr('id').toUpperCase();

    $("#box_3d_shots img").each(function (index, element) {
      var i = $(element).attr("src");
      var index = i.lastIndexOf("_");
      var new_source = i.replace(i.substr(index + 1), versie+".jpg");
      $(element).attr("src", new_source);
    });

  });

}
