$(function(){

    var config = {    
         sensitivity: 8, // number = sensitivity threshold (must be 1 or higher)    
         interval: 10,  // number = milliseconds for onMouseOver polling interval    
         over: doOpen,   // function = onMouseOver callback (REQUIRED)    
         timeout: 50,   // number = milliseconds delay before onMouseOut    
         out: doClose    // function = onMouseOut callback (REQUIRED)    
    };
    
    function doOpen() {
        $(this).addClass("hover");

		var strCode = $(this).attr('id').replace("menuitem_", "");

		$.ajax(
		{
    		method: "get",
    		url: "downloadxmlmenu.pp?r=" + getRandom(),
    		dataType: "xml",
    		data: "code=" + strCode,
    		success: function(data) {
    			generateDropdownCallback(data, strCode);
    		},
    		error: function() { 
    			alert('xml error');
    		}
		});
    }

	function generateDropdownCallback(data, strCode)
	{
		var strResult = "";
		var blnLiNostyleOpened = false;

		$(data).find('page').each(function()
		{
			var strID					= $(this).find("id").text();
			var strLabel				= $(this).find("label").text();
			var intIsUitgelicht			= $(this).find("isuitgelicht").text();
			var intIsUitgelichtLastItem	= $(this).find("isuitgelichtlastitem").text();

			if (intIsUitgelicht==0)
			{
				strResult += "<li><a href='" + strID + ".pp'>&raquo; " + strLabel + "</a></li>";
			}
			else
			{
				if (!blnLiNostyleOpened)
				{
					strResult += "<li class='nostyle'>"; // open nostyle
					strResult += "<ul class='uitgelicht'>"
					strResult += "<h1>Uitgelicht</h1>";
					blnLiNostyleOpened = true;
				}

				strResult += "<li><a href='" + strID + ".pp'>&raquo; " + strLabel + "</a></li>";

				if (intIsUitgelichtLastItem==1)
				{
					strResult += "<div class='clear'></div>"
					strResult += "</ul>";
					strResult += "</li>"; // close nostyle
				}

			}
			
			strResult += "<div class='clear'></div>"

		});

		if (strResult!="")
		{		
			$("#dropdown_" + strCode).html(strResult);
			$('#dropdown_' + strCode).fadeIn(100); //$('ul.dropdown:first',this).css('visibility', 'visible');
		}

	}

    function doClose() {
        $(this).removeClass("hover");
        $('ul.dropdown',this).hide();
    }

    $("ul.submenu li").hoverIntent(config);
    

});
