// JavaScript Document
$(function(){
    
	$('#contentFrameBody .heightspacer') .css({'height': (($(window).height()) - 322)+'px'});
	
    $(window).resize(function(){
        $('#contentFrameBody .heightspacer') .css({'height': (($(window).height()) - 322)+'px'});
    });
	
	// stel de ui buttons in
	$(".ui-button").button();
	
	/**
	 *  Set de menuconfig en initialiseer de hover functionaliteit
	 */
	var config = {
		 sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)
		 interval: 0, // number = milliseconds for onMouseOver polling interval
		 over: megaHoverOver, // function = onMouseOver callback (REQUIRED)
		 timeout: 50, // number = milliseconds delay before onMouseOut
		 out: megaHoverOut // function = onMouseOut callback (REQUIRED)
	};
	
	$("ul#mainMenu li .sub").hide();//.css({'left':'-10000px'}); //Fade sub nav to 0 opacity on default
	$("ul#mainMenu li").hoverIntent(config); //Trigger Hover intent with custom configurations
	
	
	$("#searchForm .search-field").innerLabel();
});


/**
 *  Javascript voor MegaMenu
 */
//On Hover Over
function megaHoverOver(){
    //$(this).find(".sub").stop().fadeTo('fast', 1).show(); //Find sub and fade it in
	
	$(this).addClass("hover");
	$(this).find(".sub").stop().slideDown('fast');
    (function($) {
        //Function to calculate total width of all ul's
        jQuery.fn.calcSubWidth = function() {
            rowWidth = 0;
            //Calculate row
            $(this).find("ul").each(function() { //for each ul...
                rowWidth += $(this).width(); //Add each ul's width together
            });
        };
    })(jQuery); 

    if ( $(this).find(".row").length > 0 ) { //If row exists...

        var biggestRow = 0;	

        $(this).find(".row").each(function() {	//for each row...
            $(this).calcSubWidth(); //Call function to calculate width of all ul's
            //Find biggest row
            if(rowWidth > biggestRow) {
                biggestRow = rowWidth;
            }
        });

        //$(this).find(".sub").css({'width' :biggestRow}); //Set width
        $(this).find(".row:last").css({'margin':'0'});  //Kill last row's margin

    } else { //If row does not exist...

        $(this).calcSubWidth();  //Call function to calculate width of all ul's
        //$(this).find(".sub").css({'width' : rowWidth}); //Set Width

    }
}
//On Hover Out
function megaHoverOut(){
	$(this).removeClass("hover");
  	$(this).find(".sub").stop().slideUp('fast');
}


$.fn.innerLabel = function(options) {  
 	var defaults = {  
		label : false
	};  
	
		
	// extend options with the default options
	var options = $.extend(defaults, options);  
	
	return this.each(function(){ 
		// als een label is ingesteld, label gebruiken
		if(options.label){
			label = options.label	
		}else{// ander de titel van het vel gebruiken
			label = $(this).attr("title");	
		}
		
		if($(this).val() == ""){
			$(this).val(label);	// leegmaken
			$(this).addClass("innerlabel");
		}
		
		$(this).focus(function(){
			if($(this).val() == label){
				$(this).val("");	// leegmaken
				$(this).removeClass("innerlabel");
			}
		});
		$(this).blur(function(){
			if($(this).val() == ""){
				$(this).val(label);	// leegmaken
				$(this).addClass("innerlabel");
			}			  
		});
		return this;
	});  
};
