$(document).ready(function()
{
	
	var config = {    
     sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
     interval: 300, // number = milliseconds for onMouseOver polling interval    
     over: display_subs, // function = onMouseOver callback (REQUIRED)    
     timeout: 100, // number = milliseconds delay before onMouseOut    
     out: hide_gegga // function = onMouseOut callback (REQUIRED)    
};


	
	$.config = {};					   
	$.config.current_branch = 0;

	$(".main-btn").hoverIntent(config);
	
	/*
	$(".main-btn").hover(
		function () 
		{ 
			var current_id = this.id.replace("branch-button-", "");
			
			
			if($.config.current_branch != current_id)
			{
				hide_sub($.config.current_branch);
				display_subs(current_id);
			}
			
			
			
			
		}

	);
	*/
	
	
});


function display_subs()
{
	var id = this.id.replace("branch-button-", "");
	
	hide_sub($.config.current_branch);
	
	if($.config.current_branch != id)
	{
		if ( $("#sub-branch-" + id).length > 0 ) 
		{ 
			$("#branch-" + id).animate({ width: "150px"}, 100, 0, 
				function () 
				{ 
					$("#sub-branch-" + id).show("fast", 
						function() 
						{	  
							$("#branch-" + id).addClass("selected");  
							//$("#branch-label-" + id).show();  
						}
					);
				}
			);
		}
	}
	
	$.config.current_branch = id;
}
function hide_gegga()
{
	//var t=setTimeout("alert('You pressed the button 5 seconds ago!')",5000)
}

function hide_sub(id)
{
	
	//var id =  $.config.current_branch;
	//console.log('hiding-' + id);
	//$("#branch-label-" + id).hide();		
			$("#sub-branch-" + id).hide("fast", 
						function() 
						{	  
							//"#branch-label-" + id).show();  
							$("#branch-" + id).removeClass("selected"); 
							
							$("#branch-" + id).animate({ width: "100px"}, 100, 0);
						}
					); 
					
					
	/*
	$("#sub-branch-" + id).hide("fast", 
						function() 
						{	  
							//"#branch-label-" + id).show();  
							$("#branch-" + id).removeClass("selected"); 
							
							$("#branch-" + id).animate({ width: "100px"}, 100, 0);
						}
					); 
	*/				
				
			
}


/**
* Set a cursor to current sublevel
*
* @param int id current levels id
*
*/
function select_subnav(id)
{
	if ( $("#sub-branch-" + id).length > 0 ) 
	{ 
		$("#branch-" + id).animate({ width: "150px"}, 100, 0, 
			function () 
			{ 
				$("#sub-branch-" + id).show("fast", 
					function() 
					{	  
						$("#branch-" + id).addClass("selected");
					}
				);
			}
		);
	}
}
