/************************************************************************
/ 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() {

	/************************************************************************
	/ Featured content tabs
	/************************************************************************/

	//When page loads...
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content

	//On Click Event
	$("ul.tabs li").click(function() {

		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active ID content
		return false;
	});
	
	/************************************************************************
	/ Dropdowns
	/************************************************************************/
	
	// Hide all dropdowns on load
	$('.dropdown').hide();	
	
	// Roll over nav item, show dropdown
  	$('.drop').hover(function() {
  		clear_dropdown_timeouts();
  		var index = $('.drop').index(this);
  		if(!$('.dropdown').eq(index).is(':visible')) {
  			show_dropdown(index);
  		}
  	},function() {
	  	var index = $('.drop').index(this);
	  	dropdown_timeout['timeout'] = setTimeout("hide_dropdown("+index+")",200);
  	});
	
	// 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+")",200);
  	});	

});
