/************************************************************************
/ Dropdown Functions/variables
/************************************************************************/

var dropdown_timeout = new Array();

function clear_dropdown_timeouts(){  
   for(key in dropdown_timeout ){  
    	clearTimeout(dropdown_timeout[key]);  
   }   
} 

function show_dropdown(index) {
	
	// Hide any open dropdowns
	$('.dropdown').hide();
	
	// Set Position of the current nav item
	var position =$('.drop').eq(index).position();
	
	// Set Height of the current nav item
	var height = $('.drop').eq(index).height();	
	
	// Create top and left positions of the dropdown
	var top = position.top + height;
	var left = position.left;
	
	// Set the CSS position of the dropdown
	$('.dropdown').eq(index).css('top',top);
	$('.dropdown').eq(index).css('left',left);
	
	// Show the dropdown
	$('.dropdown').eq(index).fadeIn(300);
	
}

function hide_dropdown(index) {
	
	$('.dropdown').eq(index).fadeOut(300);
	
}

/************************************************************************
/ Page load
/************************************************************************/

$(document).ready(function(){
	
	/************************************************************************
	/ Dropdowns
	/************************************************************************/
	
	// Hide all dropdowns on load
	$('.dropdown').hide();	
	
	// Roll over nav item, show dropdown
  	$('.drop').hover(function() {
  		var index = $('.drop').index(this);
  		show_dropdown(index);
  	},function() {
	  	var index = $('.drop').index(this);
	  	dropdown_timeout['timeout'] = setTimeout("hide_dropdown("+index+")",100);
  	});
	
	// Makes it so we can hover on top of the dropdown
  	$('.dropdown').hover(function() {
  		clear_dropdown_timeouts();
  	},function() {
  		var index = $('.dropdown').index(this);
  		dropdown_timeout['timeout'] = setTimeout("hide_dropdown("+index+")",100);
  	});	
	
});
