$(document).ready(function () {
	Mu=$("#Menu");
	M=$("#Rubricator");
	Ml=M.find("li");
	Mh=M.find("h2");
	Ms=M.get(0).style;
	var timer, p=1, s=[], s1=[], s2=[], w=[], m=[], f=[], f1=[], M1s=[], M1p=[], df=0.9;
	wm=M.get(0).clientWidth+1;
		
	function RubricatorResize() {
		if(M.get(0).clientWidth!=wm) {
			wm=M.get(0).clientWidth;
			if(wm<1050) {
				Mh.addClass("res1024");
			}
			else if(wm>1345) {
				Mh.addClass("res1600");
			}
			else {
				Mh.removeClass();
			}
		}
	}
	RubricatorResize();
	$(window).resize(function() {RubricatorResize();});

	G = document.getElementById("Greeting");
	if(G) {
		Mu.get(0).style.display="none";
		Ms.display="none";
		$("#Greeting h1").click(function () {
			RubricatorResize();
			$(this).parent("div").fadeOut("fast", function() {M.fadeIn("slow"); Mu.fadeIn("slow");});
		});
	}

	change = function(j) {
		var sw=0, d=0;
		if(s2[j]>s1[j]) {s1[j]++;}
		else if(s2[j]<s1[j]) {s1[j]--;}
		switch(s1[j]) {
			case -7: f[j]=0.7; break;
			case -4: f[j]=0.8; break;
			case 1: f[j]=1; break;
			case 4: f[j]=1.1; break;
			case -2: f[j]=0.9; break;
			case 7: f[j]=1.2; break;
		}
		w[j]=13.97+0.635*s1[j];
		m[j]=(12.7-w[j])*0.5;
		do {
			sw=sw+w[d];
			d++;
		}  while (d < 7);
		M1s[j].marginTop = m[j]+"%";
		M1s[j].width = w[j]+"%";
		if(f[j]!=f1[j]) {M1s[j].fontSize = f[j]+"em"; f1[j]=f[j];}
		M1p[j].opacity = 0.25+0.02*s1[j];
		M1p[j].filter = 'alpha(opacity=' + (0.25+0.02*s1[j])*100 + ')';
		Ms.left = -(sw-88.9)/2+"%";
		if(s1[j]!=s2[j]) {setTimeout("change("+j+")",20);}
		else if(s1[j]==-2 && p==1) {
			M1s[j].paddingTop = '';				 
			M1s[j].marginTop = '';				 
			Ms.marginBottom = '';				 
			M1s[j].backgroundImage = '';
		}
 	};

	Ml.each(function(i) {
		M1s[i]=$(this).get(0).style;
		M1p[i]=$(this).find("p").get(0).style;
		s1[i]=-2;
		w[i]=12.7;
		$(this).bind("mouseenter", function(){
			$(this).get(0).className = "hover";
			var j=0;
			do {
				s[j]=Math.abs(j-i)*-1;
				if(s[j]==-1) {s2[j]=1;}
				else if(s[j]==-2) {s2[j]=-2;}
				else if(s[j]==-3) {s2[j]=-5;}
				else if(s[j]<=-4) {s2[j]=-8;}
				else if(s[j]==0) {s2[j]=7;}
				if(s1[j]!=s2[j]) {setTimeout("change("+j+")",1);}
				j++;
			} while (j < 7);
		}).bind("mouseleave", function(){$(this).get(0).className = "";});
	})

	M.bind("mouseenter", function(){
		if(timer) {clearTimeout(timer);}
		if(p==1) {
			$(this).get(0).style.marginBottom = 275+"px";
			p=0;
			Ml.each(function(i) {
				$(this).get(0).style.paddingTop = 100+"px";
				$(this).get(0).style.marginTop = 0;
				$(this).get(0).style.backgroundImage = 'none';
			});
		}
	}).bind("mouseleave", function(){
		timer = setTimeout("startPos()",1000);
	}).find("a").click(function() {
		obj = $(this).attr("href").replace(/(\/)|(\.html)/ig,"");
		$("#Container").fadeOut("slow", function() {
			$("<div id="+obj+" style='display:none'></div>").load("/"+obj+".html .Popup, #levelup, .copyright", function() {
				$("a.logo").click(function() {
					$("#"+obj).fadeOut("normal", function() {$(this).remove("#"+obj); $("#Container").fadeIn("slow");});
					return false;
				});
			}).appendTo("body").fadeIn("slow");
		});
		return false;
	});

	startPos = function() {
		Ml.each(function(i) {
			p=1;
 			s2[i]=-2;
			setTimeout("change("+i+")",1);
		})
	}
});
