function Menu(menuid,contentid,helperid,loaderid) {
	this.contentid = contentid;
	this.elements = {
		menu: jQuery(document.getElementById(menuid)),
		content: jQuery(document.getElementById(contentid)),
		helper: jQuery(document.getElementById(helperid)),
		loader: jQuery(document.getElementById(loaderid))
	};
	
	var menu = this;
	var helper = this.elements.helper;
	jQuery("a",this.elements.menu).hover(function() {
		var txt = jQuery("span",this).html();
		menu.showInHelper(txt);
	},function() {
		menu.hideHelper();
	}).click(function() {
		helper.stop(true,true).hide();
		menu.load(this.href);
		jQuery(this).blur();
		return false;
	});
};

Menu.prototype.contentid = null;
Menu.prototype.url = null;
Menu.prototype.xhr = null;
Menu.prototype.elements = null;
Menu.prototype.speed = "slow";

Menu.prototype.showContent = function(speed) {
	if( typeof(speed) == "undefined" ) speed = this.speed;
	this.elements.content.show("drop",{direction: "down",distance:"200px",XXeasing:"bounceEaseOut"},speed);
};

Menu.prototype.hideContent = function(speed,cb) {
	if( typeof(speed) == "undefined" ) speed = this.speed;
	else if( typeof(speed) == "function" ) {
		cb = speed;
		speed = this.speed;
	}
	this.elements.content.hide("drop",{direction: "down",distance:"200px"},speed,cb);
};

Menu.prototype.load = function(url) {
	if( url !== null && typeof(url.href) === "string" ) url = url.href;
	if( this.url != url ) {
		this.url = url;
		var self = this;
		if( this.xhr !== null ) this.xhr.abort();
		this.xhr = jQuery.get(url, function(data) { self.loaded(data); });
		// TODO display AJAX visual indicator
		this.elements.loader.fadeIn("fast");
	}
};

Menu.prototype.loaded = function(data) {
	this.xhr = null;
	var newcontent = jQuery("#"+this.contentid,data).html();
	// TODO Update history
	if( this.elements.content.css("display") != "none" ) {
		var self = this;
		this.hideContent(function() {
			self.fillAndShowContent(newcontent);
		});
	}
	else {
		this.fillAndShowContent(newcontent);
	}
};

Menu.prototype.fillAndShowContent = function(newcontent) {
	this.elements.content.html(newcontent);
	this.showContent();
	// TODO hide AJAX visual indicator
	this.elements.loader.fadeOut("fast");
};

Menu.prototype.showInHelper = function(message) {
	var helper = this.elements.helper;
	var helperid = helper.attr("id");
	helper.find("#"+helperid+"_inner").html(message).end().show("drop",{direction: "down"},"slow");
};

Menu.prototype.hideHelper = function() {
	this.elements.helper.stop(true,true).hide();
};


function imgZoom() {
	jQuery("img.thumbnail").imgZoom({showOverlay:false});
};




jQuery(function($) {
	var helperid = "menutag";
	jQuery("<div id='" + helperid + "'></div>").append("<div id='" + helperid + "_inner'></div>").appendTo("body");
	jQuery("<div id='ajax-loader'></div>").append("<img src='images/ajax-loader.gif' width='35' height='35' />").appendTo("body");
	window.menu = new Menu("blobs","inner_content",helperid,"ajax-loader");
	
	var ie55 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 5.5") != -1);
	var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);
	
	if( ie55 || ie6 ) {
		$(document).pngFix();
//		$("#browserNotice").css({margin: "30px 10px 0px 10px", display: "block"}).load("obsolete.html");
	}
	else {
		var back  = $("#anim-foot");
		var mid   = $("#anim-foot-mid");
		var front = $("#anim-foot-front");
		var i = 0, j = 0, k = 0;
		setInterval(function() {
			i += 1; if( i >= 396 ) i -= 396;
			j += 2; if( j >= 760 ) j -= 760;
			k += 3; if( k >= 670 ) k -= 670;
			back.css("background-position",i+"px 0");
			mid.css("background-position",j+"px 0");
			front.css("background-position",k+"px 0");
		},75);
	}
	
//	$("#menuExpl").append(" (<b>το δεντράκι στο κάτω μέρος της σελίδας</b>)")
	
	var blobs = $("#blobs li");
	var animBlob = blobs.length;
	var timeout = null;
	var blobHighlight = function() {
		if( animBlob === 0 ) {
			menu.showInHelper("<span style='font-size:0.8em'>Πατήστε τα φύλλα του δέντρου</span>")
		}
		if( animBlob < blobs.length ) {
			var li = $(blobs[animBlob]);
			var bg = li.css("top");
			if( bg.length == 3 ) bg = "0"+bg;
			var bg = "transparent url(images/menu.gif) -" + li.css("left") + " -2" + bg + " no-repeat";
			var a = $("a",blobs[animBlob]);
			var savedbg = a.css("background");
			if( typeof(savedbg) != "string" ) savedbg = "";
			a.css("background",bg);
			setTimeout(function() {
				a.css("background",savedbg);
			},200);
			animBlob += 1;
			timeout = setTimeout(blobHighlight,320);
		}
		else {
//			menu.hideHelper();
		}
	};
	$("#sign").hover(function() {
		animBlob = 0;
		if( timeout != null ) {
			clearTimeout(timeout);
			timeout = null;
			
		}
		timeout = setTimeout(blobHighlight,50);
	},function() {
	});
});

