/* CSG Liudger 
  Edited on: 2012-01-13 17:47:58
  Description: Scripts
 */
$(document).ready(function(){
  // Menu scripts

  // Bij hover op hoofdmenu, bijhorende submenu tonen (anderen verbergen)
  $('#menu>ul>li>a').mouseenter(function() {
    $('#menu>ul>li.active_parent').removeClass('active_parent');
  });

  // Bij verlaten hoofdmenu
  $('#menu>ul>li>ul').mouseenter(function() {
    $(this).parent().addClass('active_parent');
  });

  // Bij verlaten menu, actieve submenu tonen (anderen verbergen)
  $('#menu').mouseleave(function() {
    $('#menu>ul>li.active_parent').removeClass('active_parent');
  });

//$('#menu>ul>li').hover(
//  function() { $('ul', this).css('display', 'block'); },
//  function() { $('ul', this).css('display', 'none'); });
//$('#menu>ul>li').hover(
//  function() { $('ul', $(this)).css('display', 'block'); },
//  function() { $('ul', $(this)).css('display', 'none'); });

$('#menu>ul>li').mouseover(  function() {
  $('#menu>ul>li>ul').css('display', 'none');
  $('ul', $(this)).css('display', 'block');
});
$('#menu>ul>li>ul').mouseover(  function() { $(this).css('display', 'block'); });
$('#menu>ul>li>ul').mouseout( function() {
  $(this).css('display', 'none');
});
$('#menu').mouseout( function() {
  $('#menu>ul>li>ul').css('display', 'none');
});

$('#menu>ul>li').mouseenter(function() {
$('#menu>ul>li>ul').each(function(index){
  var sub_width = $(this).width();
  var parent_width = $(this).parent().width();
  if (sub_width < parent_width) {
    $(this).width(parent_width);
  }
});});


  // Bannercycler scripts
  $('#bannercycler .slides').cycle({
    resume: true,
    fx: 'fade',
    timeout: 5000,
    pager: '#bannercycler .buttons',
    pagerEvent: 'mouseover',
    pauseOnPagerHover: true,
    pagerAnchorBuilder: function(idx, slide) { 
      return '#bannercycler .buttons div.button:eq(' + idx + ')'; 
    }
  });
 $('#bannercycler .left div').click(function (){
    document.location.href = $('a', this).attr('href');
  }).css('cursor', 'pointer');
  $('#bannercycler .right div').click(function (){
    document.location.href = $('.activeSlide a').attr('href');
  }).css('cursor', 'pointer');

  // Site columns hoogte bepalen
  var hSC = $('#site_columns').height();
  var hMI = $('#meer_info').height();
  var hNws = $('#nieuws').height();
  var hBD = $('#belangrijke_data').height();
  var hVC = $('#vrije_content').height();
  var hUL = $('#uitgelicht').height();
  var hLn = $('#links').height();
  var hCnt = $('#content').height();
  var hLeft = (hMI + 12 + 2);
  var hMid = (hVC + 12 + 2 + 6) + (hNws + 12 + 2);
  var hRight = (hUL + 45) + (hBD + 12 + 2 + 6) + (hLn + 12 + 2);
  var maxHeight = Math.max(hLeft,hMid,hRight,hCnt);
  $('#nieuws').height(maxHeight - 2 - 12 - (hVC + 12 + 2 + 6));
  if ((hCnt < 400) || (hCnt == 'null')) {
    if (hMI < maxHeight) $('#meer_info').height(maxHeight - 2 - 12);
    $('#links').height(maxHeight - 2 - 12 - (hUL + 45) - (hBD + 12 + 2 + 6));
  }
  if (hCnt < maxHeight) $('#content').height(maxHeight - 2 - 12);
  if (hSC < maxHeight) $('#site_columns').height(maxHeight + 6);

  // Bannercycler buttons vertical uitlijnen
  $('div.buttonContent').each(function(index){
    var ah = $(this).height();
    var ph = $(this).parent().height();
    var mh = (ph - ah) / 2;
    $(this).css('padding-top',mh + 'px');
    var aw = $(this).width();
  });
});
