/*
 *
 * Modry Las common JS script
 * Version 0.2
 *
 */

$(document).ready(function() {

	// Ensure that hover generates a nice DIV fill on the menu
	$("div.top_menu, div.menu").hover(function(e) {
		var div_class = $(this).find("a").attr("class");
		$(this).addClass("menu_link_hovered");
		if (div_class.search("top_menu") !== -1) {
			$(this).find("a").addClass("menu_link_hovered");
			}
	},function(e){
		$(this).removeClass("menu_link_hovered");
		$(this).find("a").trigger('blur')
						 .removeClass("menu_link_hovered");
	});
	
	// The same for keyboard navigation (with one snag - when navigate with keyboard AND mouse at the same time, can get unexpected results - DIV highliht + anothe A highlihgt
	// Need to use addClass / removeClass rather than toggleClass because it clashes with the mouse hovering
	$("a.top_menu_link, div.menu a").bind("focus", function(e){
		e.preventDefault;
        $(this).parent().addClass("menu_link_hovered");
   	})
   	.bind("blur", function(e){
		e.preventDefault;
        $(this).parent().removeClass("menu_link_hovered");
   	});

	// Handle the DIV click on the menu
	$("div.top_menu, div.menu").click(function(e) {
		e.preventDefault();
		var link_dest = $(this).find("a").attr("href");
		var link_class = $(this).find("a").attr("class");
		window.document.location = link_dest;
	});
	
	 $.fn.wait = function(time, type) {
	        time = time || 1000;
	        type = type || "fx";
	        return this.queue(type, function() {
	            var self = this;
	            setTimeout(function() {
	                $(self).dequeue();
	            }, time);
	        });
	    };

	// Animate the flyover link entrance
	$("div#top_menu_element_1").wait().show('slow');
});

