//jQuery.noConflict();
//jQuery(document).ready(function($){
$(document).ready(function() {
	$("#column1 div.content").mouseover(function() {
		$(this).css("backgroundImage", "url(_template/standard/graphics/arrow-accent.gif)");
	});
	$("#column1 div.content").mouseout(function() {
		$(this).css("backgroundImage", "url(_template/standard/graphics/arrow-medium.gif)");
	});

	// dissolve messages after 4 seconds with effect
	setTimeout(function(){
		$(".effect").effect('blind', {}, 500);
	}, 4000);

	// add lightbox to foto's
	$("#fotos a").fancybox({
		transitionIn : 'elastic',
		transitionOut : 'elastic',
		speedIn : 600, 
		speedOut : 200, 
		overlayShow : false
	});

	// add tab functionality
	$("#tabs").tabs();

	// add datepicker
	$(".datepicker").datepicker({
		dateFormat: 'dd/mm/yy',
		changeMonth: true,
		changeYear: true,
		showWeek: true,
		numberOfMonths: 1,
		showAnim: 'fadeIn',
		showOtherMonths: true,
		selectOtherMonths: true
	});
	var dates = $("#start, #end").datepicker({
		dateFormat: 'dd/mm/yy',
		defaultDate: "+1w",
		changeMonth: true,
		showWeek: true,
		numberOfMonths: 1,
		showAnim: 'fadeIn',
		onSelect: function(selectedDate) {
		if (this.id == "start" && $("#end").val() == "") {
			$("#end").val($("#start").val());
		}
		var option = this.id == "start" ? "minDate" : "maxDate";
		var instance = $(this).data("datepicker");
		var date = $.datepicker.parseDate(instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings);
		dates.not(this).datepicker("option", option, date);
	}
	});
	var dates2 = $("#start2, #end2").datepicker({
		dateFormat: 'dd/mm/yy',
		defaultDate: "+1w",
		changeMonth: true,
		showWeek: true,
		numberOfMonths: 1,
		showAnim: 'fadeIn',
		onSelect: function(selectedDate) {
		if (this.id == "start2" && $("#end").val() == "") {
			$("#end2").val($("#start2").val());
		}
		var option = this.id == "start2" ? "minDate" : "maxDate";
		var instance = $(this).data("datepicker");
		var date = $.datepicker.parseDate(instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings);
		dates2.not(this).datepicker("option", option, date);
	}
	});

	$('#foto').cycle({
		fx: 'fade',
		pause: 1,
		speed: 4000,
		timeout: 8000
	});
});

function setTab(tab) {
	$("#tabs").tabs("option", "selected", (tab > 0 ? tab - 1 : 0));
}

window.onload = function() { CLIO_loadMenu(); }
window.onresize = function() { 
  CLIO_menu = null;
  CLIO_baseMenu = null;
  CLIO_subMenu = null;
  CLIO_dropdown = null;
  CLIO_Nodes = new Array();
  n=0;
  CLIO_loadMenu();
}

var CLIO_menuTimer, CLIO_subMenuTimer, CLIO_menu, CLIO_aMenu, CLIO_aSubMenu, CLIO_baseMenu, CLIO_subMenu, CLIO_dropdown;
var CLIO_Nodes = new Array();
var n=0;

var dropdown_split = 8;	  		// aantal items dat maximaal onder elkaar getoond wordt in een dropdown menu
var dropdown_width = 185; 		// breedte van een dropdown a item
var dropdown_height = 25; 		// hoogte van een dropdown a item

var submenu_shift = 40; 		// aantal pixels dat elk submenu naar links wordt geplaatst

var CLIO_timeout_base = 3500; 	// tijd totdat base menu weer wordt getoond.
var CLIO_timeout = 500; 		// tijd totdat dropdown menu wordt verborgen

function Node(obRef)
{
  this.obRef = obRef;
  this.timeRef = null;
}

CLIO_loadMenu = function()
{
	
  CLIO_menu = document.getElementById("menu").childNodes;

  for (i in CLIO_menu)
  {
    if (CLIO_menu[i].nodeName == "LI" && CLIO_menu[i].parentNode.id == "menu")
    {
      CLIO_menu[i].onmouseover=function()
      {
        CLIO_showMenu(this);
      }
      CLIO_menu[i].onmouseout=function()
      {
        CLIO_menuTimer = setTimeout("CLIO_showBaseMenu()", CLIO_timeout_base);
      }

      // show baseMenu
      if (CLIO_menu[i].id == "base")
      {
        CLIO_baseMenu = CLIO_menu[i];
        CLIO_showMenu(CLIO_baseMenu);
      }

      // add actions to submenu's
      CLIO_subMenu = CLIO_menu[i].getElementsByTagName("LI");
      for (j in CLIO_subMenu)
      {
      	// change color for active submenu
        if (CLIO_subMenu[j].id == "submenu_base")
        {
          CLIO_subMenu[j].className += " submenu_base";
        }

        if (CLIO_subMenu[j] && CLIO_subMenu[j].nodeName == "LI" && CLIO_subMenu[j].parentNode.parentNode.parentNode.id && CLIO_subMenu[j].parentNode.parentNode.parentNode.id == "menu")
        {
          // controleren of er dropdowns aanwezig zijn
          var CLIO_dropdown = CLIO_subMenu[j].getElementsByTagName("LI");

          CLIO_subMenu[j].onmouseover=function()
          {
            CLIO_showSub(this);
          }
          
          if ( CLIO_dropdown.length > 0 )
          {
            CLIO_subMenu[j].className += " submenu";
            CLIO_subMenu[j].onmouseout=function()
            {
              CLIO_subMenuTimer = setTimeout("CLIO_hideSub()", CLIO_timeout);
            }

            // CLIO_dropdown items in meerdere rijen plaatsen als er meer dan 'dropdown_split' items zijn
            if ( CLIO_dropdown.length > dropdown_split )
            {

              for (k in CLIO_dropdown)
              {
                if (k >= (Math.round(CLIO_dropdown.length / 2)))
                {
                  //alert(Math.round(CLIO_dropdown.length/2));
                  CLIO_dropdown[k].style.left = dropdown_width+"px";
                  CLIO_dropdown[k].style.top = "-" + (Math.round(CLIO_dropdown.length / 2))*dropdown_height + "px";
                  
                  CLIO_dropdown[k].parentNode.style.width = (2*dropdown_width)+"px";
                  CLIO_dropdown[k].parentNode.style.height = (Math.round(CLIO_dropdown.length / 2))*dropdown_height + "px";
                }
              }
            }

          }
          else
          {
            CLIO_subMenu[j].onmouseout=function()
            {
              CLIO_hideSub();
            }
          }

          // adjust position of menu's
          if (CLIO_subMenu[j].style && CLIO_subMenu[j].parentNode.style && CLIO_subMenu[j].parentNode.nodeType == 1)
          {
            //CLIO_subMenu[j].parentNode.style.left = (Math.round((document.body.clientWidth / 2)) - 432 + (n*90)) + "px";
            CLIO_subMenu[j].parentNode.style.marginLeft = "-"+(n*submenu_shift)+"px";
          }
        }
      }
      n++;
    }
  }
}

function CLIO_showMenu(item)
{
  if (CLIO_aMenu != null)
  {
    CLIO_hideMenu(CLIO_aMenu);
  }
  clearTimeout(CLIO_menuTimer);
  item.className += " do_hover";
  CLIO_aMenu = item;
}

function CLIO_hideMenu(item)
{
  item.className = item.className.replace(new RegExp("do_hover\\b"), "");
}

function CLIO_showBaseMenu()
{
  if (CLIO_baseMenu)
  {
    CLIO_showMenu(CLIO_baseMenu);
  }
}

function CLIO_showSub(item)
{
  if (CLIO_aSubMenu != null)
  {
    CLIO_hideSub();
  }
  if (CLIO_subMenuTimer)
  {
    clearTimeout(CLIO_subMenuTimer);
  }
  item.className += " do_hover";
  CLIO_aSubMenu = item;
}

function CLIO_hideSub()
{
  if (CLIO_aSubMenu != null)
  {
    CLIO_aSubMenu.className = CLIO_aSubMenu.className.replace(new RegExp("do_hover\\b"), "");
    CLIO_aSubMenu = null;
  }
}
