jQuery(document).ready(function(){

	jQuery(".menu").menu()

});

//////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2009, Alexander Blomen <info@ablomen.nl>			
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this
//   list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice, this
//   list of conditions and the following disclaimer in the documentation and/or 
//   other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
// POSSIBILITY OF SUCH DAMAGE.
//////////////////////////////////////////////////////////////////////////////////////

jQuery.fn.menu	=	function(options){

	var settings	=	jQuery.extend({
	
		timeout:		100
		
	}, options);
	
	var functions	=	{
	
		item_over:	function(item){
		
			jQuery(item).addClass("mouse_is_over_this_element");
			jQuery(item).addClass("hover");
		
		},
	
		item_out:	function(item){
			
			jQuery(item).removeClass("mouse_is_over_this_element");
			
			if(jQuery(item).hasClass(".hassub")){
			
				functions.item_out_timed(item, 0);
			
			}else{
			
				jQuery(item).removeClass("hover");
				
			}
		
		},
		
		item_out_timed:	function(item, elapsed){
		
			if(elapsed < settings.timeout){
			
				if(jQuery(item).hasClass("mouse_is_over_this_element")){
				
					return(false);
				
				}else{
				
					elapsed	+=	settings.timeout / 4;
					
					setTimeout(function(){ functions.item_out_timed(item, elapsed); }, settings.timeout / 4);
				
				}
			
			}else{
			
				jQuery(item).removeClass("hover");
			
			}
		
		}
	
	};
	
	jQuery(".item, .subitem", this).hover(
	
		function(){
			
			functions.item_over(jQuery(this));
		
		},
		function(){
		
			functions.item_out(jQuery(this));
	
		}
	
	);
	
	// ie fix for sub-sub menus
	jQuery(".submenu", this).each(function(){
	
		var biggest	=	0;
	
		jQuery(" > .subitem a", this).each(function(){
		
			if(parseInt(jQuery(this).width()) > biggest){
			
				biggest	=	parseInt(jQuery(this).width());
			
			}
		
		});
		
		jQuery(" > .subitem", this).css({"zoom": 1, "width": biggest+"px"});
	
	});
	
	// onclick for menu item padding etc
	jQuery(".subitem", this).click(function(){
	
		if(jQuery("a:first", this).attr("target") == "_blank"){
		
			window.open(jQuery("a:first", this).attr("href"));
		
		}else{
		
			window.location	=	jQuery("a:first", this).attr("href");
		
		}
	
	});

}

