/******************/
/* Menu functions */
/******************/
window.Menu = {
	delay		: 1500,
	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 text 														  */
/* - $("#input_element").inputDefaultText({ default_txt:"My Default Text" }); */
/******************************************************************************/
(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 );
		$(this).css("color", "#aaa");
	}

	// add behaviour at focus and blur
	$(this).focus( function() 
	{ 
		if ( $(this).val() == "" || $(this).val() == options.default_txt )
		{
			$(this).val(""); 
			$(this).css("color", "#333");
		}
	});
	
	$(this).blur( function() 
	{ 
		if ( $(this).val() == "" )
		{
			$(this).val( options.default_txt );
			$(this).css("color", "#aaa");
		}
	});
};
})(jQuery);

/**********/
/* Easing */
/**********/
jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend( jQuery.easing,
{
	def: 'easeOutQuad',
	swing: function (x, t, b, c, d) {
		//alert(jQuery.easing.default);
		return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	},
	easeOutBounce: function (x, t, b, c, d) {
		if ((t/=d) < (1/2.75)) {
			return c*(7.5625*t*t) + b;
		} else if (t < (2/2.75)) {
			return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
		} else if (t < (2.5/2.75)) {
			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
		} else {
			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
		}
	}
});

