/*
 * When rolling from one option link to another technically the mouseOut state is triggered
 * so by waiting a fraction of a second before hiding the dropdown menu
 * we give enough time for the mouseOver trigger to be called, which then cancels the function to hide the dropdown menu
 * This was previously causing a stuttering effect in Chrome as the menu was hidden and shown repeatedly when scrolling from option link to option link
 */
function hide_dropdown_menu( id ){

	// Wait 1/1000th of a second before resetting the categories and tabs to their original state
	eval( id+"_timer_to_hide_dropdown_menu=setTimeout(\"show_dropdown_menu('"+id+"', 'dropdown_hide', false)\",1)" );
	
}

function show_dropdown_menu( id, class_name, max_height ){	
		
	//When the dropdown options are first shown, set the height and overflow based on the height of the options
	//Keep track of the dropdown menu in a variable
	var variable_name="show_dropdown_menu_"+id;
	
	// Halt the timer's countdown to hide the dropdown menu
	if( class_name=='dropdown_show' && eval( "typeof "+id+"_timer_to_hide_dropdown_menu!='undefined'" ) ){
		eval( "clearTimeout("+id+"_timer_to_hide_dropdown_menu)" );
	}
	
	if( eval("typeof "+variable_name+"=='undefined'") ){
	
		// If this dropdown menu has options
		if( document.getElementById(id+"_inner") ){
			
			//1
			//Hide the options to prevent the jumping effect from the height being changed from a larger to smaller height
			document.getElementById(id+"_outer").style.opacity="0.0";
			document.getElementById(id+"_outer").style.filter="alpha(opacity=0)";
		
			//Show or hide the menu
			document.getElementById( id ).className=class_name;
	
			//DEBUGGING
			//alert( document.getElementById(id+"_inner").offsetHeight+" > "+max_height );
			
			//2
			
			var inner_width=eval(document.getElementById(id+"_inner").offsetWidth);
			document.getElementById(id+"_outer").style.width=(inner_width)+"px";
	
			//If the inner div's height is greater than the max height, set the outer div's height to 100px and set the overflow to auto
			if( document.getElementById(id+"_inner").offsetHeight>max_height ){
	
				//Accommodate for the scrollbar by adding some width
				document.getElementById(id+"_outer").style.width=(inner_width+20)+"px";
	
				document.getElementById(id+"_outer").style.height=max_height+"px";
				document.getElementById(id+"_outer").style.overflow="auto";
	
			}
		
			//3
			if( document.getElementById(id+"_test_top")!=null ){
				
				//Determine whether or not the title width exceeds the inner width
				var title_width=eval(document.getElementById(id+"_title").offsetWidth);
				//alert(title_width+">"+inner_width+"="+document.getElementById(id+"_outer").style.width);
				if( title_width>inner_width ){
				
					var width=document.getElementById(id+"_outer").style.width.split("px");
					width=eval(width[0]);
					width-=1;
					
				}else{
				
					var width=title_width-3;
					
				}
				document.getElementById(id+"_test_top").style.width=width+"px";
				
			}
			
			//Record that the dropdown menu options size has been set
			eval( variable_name+"=true" );
			
			//3
			//Hide the options to prevent the jumping effect from the height being changed from a larger to smaller height
			document.getElementById(id+"_outer").style.opacity="1.0";
			document.getElementById(id+"_outer").style.filter="alpha(opacity=100)";
	
		}else{
			
		}
			
		//Show or hide the menu
		document.getElementById( id ).className=class_name;
	
	}else{
	
		//Show or hide the menu
		document.getElementById( id ).className=class_name;
	
	}
	
}

