﻿// On body load.
_newsid = 0;

$(document).ready(function() {

  // Zet menu item op active.
  var url = (window.location.href).toString().split("/");
  url = url[url.length - 1];
  if (url.indexOf("?") > -1) { //sloop querystring eraf
    url = url.split("?")
    url = url[0];
  }
  $("li > a[href*='" + url + "']").parent().attr('class', 'active');
  Cufon.now();

  $("#menu li").mouseover(function() {
    $(this).addClass("now");
    Cufon.refresh();
  });
  $("#menu li").mouseout(function() {
    $(this).removeClass("now");
    Cufon.refresh();
  });

  // News onclick.
  $(".newslist").each(function() {
    $(this).click(function() {
      loadNews(this);
    })
  })

  loadCarousel();
});

function loadNews(source) {
    $(".newsactive").removeClass("newsactive");
    $(source).find("h3").addClass("newsactive");

    var news;
    news = $(source).attr("id").replace("news-", "");
    
    if (news != _newsid) {
      _newsid = news;
      $.ajax({
        type: "GET",
        dataType: "xml",
        url: "/includes/ajaxnews.asp?i=" + news,
        success: function(data) {
          xmldoc = $(data);
          $("#left").css("display", "none");
          // Loop door de XML output heen.
          $("#left").html('<h2 class="newsheader">' + $(xmldoc).find("titel").text() + "</h2><p>" + $(xmldoc).find("text").text() + "</p>");
          $("#left").fadeIn("slow");
          loadCarousel();
          //$('#mycarousel img').css({ width: '415px' }); 
        }
      })
    }
}

function loadCarousel() 
{
  if ($('#mycarousel li').length > 1) {
    var instance = $('#mycarousel').jcarousel({
      auto: 0,
      wrap: 'both',
      scroll: 1,
      initCallback: mycarousel_initCallback
    });

    if (instance.reload) { instance.reload(); }
  }
}

function mycarousel_initCallback(carousel) {
  // Disable autoscrolling if the user clicks the prev or next button.
  carousel.buttonNext.bind('click', function() {
    carousel.next();
    carousel.startAuto(0);
  });

  carousel.buttonPrev.bind('click', function() {
    carousel.next();
    carousel.startAuto(0);
  });

  // Pause autoscrolling if the user moves with the cursor over the clip.
  carousel.clip.hover(function() {
    carousel.stopAuto();
  }, function() {
    carousel.startAuto();
  });
};
