$.fn.navigatable = function() {
	var self = this;
	
	current_tab = null;
	timer = null;
	
	search_box_label = null;
	
	var sub_nav_items = '#tours a, #sports a, #athletes a, #shows a, #search a';
	var normal_items = '#home a, #news a, #shop a';
	
	$(sub_nav_items, this).hover(
		function() {
			clearTimeout(timer);
			
			clearMenu();
			
			current_tab = $(this);
			
			$(this).addClass('hover');
			
			$('#dropdown > .dropdown-menu').hide();
			
			$('#dropdown').show();
			$('#dropdown' + '-' + $(this).parent().attr('id')).show();
		},
		
		function() {
			timer = setTimeout(clearMenu, 1000);
		}
	);
	
	$(normal_items, this).hover(
		function() {
			clearMenu();
		},
		
		function() {
		}
	);
	
	$('#dropdown').hover(
		function() {
			clearTimeout(timer);
		},
		
		function() {
			timer = setTimeout(clearMenu, 1000);
		}
	);
	
	function clearMenu() {
		if(current_tab !== null) {
			current_tab.removeClass('hover');
		}
		
		$('#dropdown').hide();
	}
	
	$('#search-dropdown form input[name=search_theme_form]').focus(function() {
		if(search_box_label === null) {
			search_box_label = $(this).val();
		}
		
		if(search_box_label === $(this).val()) {
			$(this).val('');
		}
	});
	
	$('#search-dropdown form input[name=search_theme_form]').blur(function() {
		var box = $('#search-dropdown form input[name=search_theme_form]');
		if(box.val() === '') {
			box.val(search_box_label);
		}
	});
}

$(function () {
	$('#navigation').navigatable();
});







