var Menu = Class.create({
	initialize: function() {
		$$("a.fly").invoke("observe", "mouseover", this.handleMouseOver.bindAsEventListener(this));
		$$("a.fly").invoke("observe", "mouseout",  this.handleMouseOut.bindAsEventListener(this));
		$$("a.fly").invoke("observe", "click", function(evnt) {evnt.stop();});	// Don't follow menu links (don't add a # to the URL)
		$$("a.fly").invoke("observe", "focus", function(){this.blur();});		// Don't add a focus border to the menu links when clicking on them
	},
	
	handleMouseOver: function(evnt) {
		var id = evnt.element().up("li").id;
		mIn(id);	// Call Flyout
	},
	
	handleMouseOut: function(evnt) {
		var id = evnt.element().up("li").id;
		mOut(id);	// Call Flyout
	}
});


document.observe('dom:loaded', function() {
	// Load Menu Observers
	new Menu();
});

Event.observe(window, 'load', function() {
	// Flyout
	if (typeof FlyLyr != 'undefined' && FlyLyr.on) {
	    flyDefs({
			position: "CSS",
			showImage: function (img, lyr) {
			    img.className = 'over';
			},
			hideImage: function (img, lyr) {
			    img.className = '';
			}
	    });
	}
	var ul = document.getElementById ('nomenus');
	if (ul) {
	    ul.id = 'menus';
	}
			
	// Execute tumblr script
	window.myTumblr = new tumblrBadge();	// Has to be window.variablename
	
	// Get better version of the images
	$$("img.lazyload").each(function(ele) {
		ele.writeAttribute("src", ele.readAttribute("src").gsub("/30/","/"));
	});
});

