/******************/
/* Menu functions */
/******************/
window.Menu = {
	delay		: 600,
	timer		: null,
	menuitem	: null,
	
	/**
	 * apply
	 * @param	string	selector
	 */
	apply: function( selector ) {
		$(selector).hover(Menu.open, Menu.setTimer);
		$(document).click(Menu.close);
	},
	
	/** 
	 * cancelTimer
	 */
	cancelTimer: function() {
		if(Menu.timer)	{
			clearTimeout(Menu.timer);
     		Menu.timer = null;
		}
	},
	
	/**
	 * setTimer
	 */
	setTimer: function() {
		Menu.timer = window.setTimeout(Menu.close, Menu.delay);
	},
		
	/** 
	 * close
	 * @param	string	current_menu_id
	 */
	close: function( current_menu_id ) {
		if(Menu.menuitem)	{
			if(Menu.menuitem.data("menuID") != current_menu_id)	
			{
				$("div", Menu.menuitem).css({ height: 'auto', zIndex: "" }).stop().hide();
				$(Menu.menuitem).removeClass("hover");
			}
		}
	},
			
	/** 
	 * open
	 */
	open: function() {
		current_menu = $(this);
		
		current_menu.addClass("hover");
		
		// uniek menu id per submenu, dit om bij het sluiten te checken of niet de actieve wordt gesloten
		if(!current_menu.data("menuID"))	{
			current_menu.data("menuID", (Math.random() +''+ Math.random()).replace(/\./g,""))
		}
		
		Menu.cancelTimer();
		Menu.close( current_menu.data("menuID") );
		Menu.menuitem = current_menu;
		
		$("div", Menu.menuitem).css({ height: 'auto', zIndex: 100 }).stop().show();	
	}

};


/*****************************************************************/
/* Functie om hele blokken klikbaar te maken, en hover toevoegen */
/*****************************************************************/
$.fn.hoverClick = function()
{
	this.each(function()
	{
		if($("a:first", this).length)
		{
			$(this).hover(
				function() { $(this).addClass("hover").css("cursor", "pointer"); },
				function() { $(this).removeClass("hover").css("cursor", "pointer"); }
			);
			
			$(this).attr("title", $("a:first", this).attr("title"));
			
			$(this).click(function(){
				window.location = $("a:first", this).attr("href");
			});
		}
	});
	
	return this;
};

/***********************/
/* Input default tekst */
/***********************/
(function($){ 
$.fn.inputDefaultText = function( options )
{	
	var defaults = {
		default_txt: ""
	};
	
	var options = $.extend(defaults, options);

	// set default text
	if ( $(this).val() == "" )
		$(this).val( options.default_txt );

	// add behaviour at focus and blur
	$(this).focus( function() 
	{ 
		if ( $(this).val() == "" || $(this).val() == options.default_txt )
			$(this).val(""); 
	});
	
	$(this).blur( function() 
	{ 
		if ( $(this).val() == "" )
			$(this).val( options.default_txt );
	});
};
})(jQuery);


/****************/
/* Bg transform */
/****************/
(function($) {
	$.extend($.fx.step,{
	    backgroundPosition: function(fx) {
            if (fx.state === 0 && typeof fx.end == 'string') {
                var start = $.curCSS(fx.elem,'backgroundPosition');
                start = toArray(start);
                fx.start = [start[0],start[2]];
                var end = toArray(fx.end);
                fx.end = [end[0],end[2]];
                fx.unit = [end[1],end[3]];
			}
            var nowPosX = [];
            nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
            nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];
            fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];

           function toArray(strg){
               strg = strg.replace(/left|top/g,'0px');
               strg = strg.replace(/right|bottom/g,'100%');
               strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
               var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
               return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
           }
        }
	});
})(jQuery);

/********************************/
/* Animeren van de competenties */
/********************************/
function animateCompetenties()
{
	$("ul#competenties li a").not(".actief").hover(
		function() { $(this).stop().animate({ opacity: 0 }); },
		function() { $(this).stop().animate({ opacity: 1 }); }
	);
}
