/*
 *
 * Modry Las common script
 * Version 0.1
 *
 */

$(document).ready(function() {

	// Ensure that hover generates a nice DIV fill
	$("div#flyover, div.menu").hover(function(e) {
		$(this).addClass("menu_link_hovered");
	},function(e){
		$(this).removeClass("menu_link_hovered");
		$(this).find("a").trigger('blur');
	});

	// 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
	$("div#flyover a, 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
	$("div#flyover, div.menu").click(function(e) {
		e.preventDefault();
		var link_dest = $(this).find("a").attr("href");
		var link_class = $(this).find("a").attr("class");
		// ensure new windows are opened as such
		if (link_class.search("new_window") !== -1) {
			var link_id = $(this).find("a").attr("id");
			var attributes = '';
			if (link_id === 'a_flyover') {
				attributes = 'width=500, height=500';
			}
			newWindow = window.open(link_dest, link_id, attributes);
			newWindow.focus();
		} else {
			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);
	        });
	    };

	// Show the flyover in a more interesting way
	//alert("almost there");
	$("div#flyover").slideDown(1500)
/*
 */ 
					.wait()
					.hide('fast')
					.wait()
					.show('slow')
					.wait()
					.hide('fast')
					.wait()
					.fadeIn('slow')
					.wait()
					.hide('fast')
					.wait()
					.show("blind", { direction: "horizontal" }, 1000)
					.wait()
					.hide('fast')
					.wait()
					.show("blind", { direction: "vertical" }, 1000);
/*
*/
					
});

