function Menu () {
	this.sections = new Object;
	this.order = new Array;
	this.halt='n';
	}

Menu.prototype.addLinks = function MenuprototypeaddLinks () {
	for (section in this.sections) {
		h3 = document.getElementById(section+'Header');
		h3.innerHTML += ' | <a class="orderLink" href="" onclick="menu.moveUp(\''+section+'\'); return false;" title="use this to reorder the navigation sections">up</a>' 
		}
	}

Menu.prototype.moveUp = function MenuprototypemoveUp (divID) {	
	oldOrderIndex = this.sections[divID].orderIndex;
	oldTop = this.sections[divID].top;
	
	if (oldOrderIndex==0) return;
	
	otherId = this.order[oldOrderIndex-1]
	
	newOrderIndex = oldOrderIndex-1
	newTop = this.sections[otherId].top;
	
	this.sections[divID].orderIndex=newOrderIndex;
	this.sections[divID].el.style.zIndex = newOrderIndex;
	this.sections[divID].newTop=newTop;
	
	this.sections[otherId].orderIndex = oldOrderIndex;
	this.sections[otherId].el.style.zIndex = oldOrderIndex;
	this.sections[otherId].newTop = this.sections[otherId].top+this.sections[divID].height;
	
	//swap the divs in the order array
	this.order[oldOrderIndex] = otherId;
	this.order[newOrderIndex] = divID;
	
	this.sections[divID].slideTo(newTop)
	this.sections[otherId].slideTo(this.sections[otherId].newTop)
	}
	
Menu.prototype.addSection = function MenuprototypeaddSection (divID) {
	if (!document.getElementById(divID)) return;
	this.sections[divID] = new Section(divID);
	this.sections[divID].measure();
	}

Menu.prototype.moveEm = function MenuprototypemoveEm () {
	if (menu.halt!='n') return;
	this.reMeasure();
	for (section in this.sections) {
		this.sections[section].el.style.position='absolute';
		if (agt.indexOf('mac') != -1) this.sections[section].el.style.width='100%';
		this.sections[section].el.style.top=(this.sections[section].newTop)+'px';
		}
	}

Menu.prototype.calibrate = function Menuprototypecalibrate () {
	if (menu.halt!='n') return;
	var newOrder = new Array;
	for (section in this.sections) {
		var top = this.sections[section].top;
		var height = this.sections[section].height;
		
		t=0;
		for (sectionOrder in this.sections) {
			if (top>this.sections[sectionOrder].top)
				t+=1
			}
		newOrder[t] = section;
		this.sections[section].orderIndex = t;
		this.sections[section].el.style.zIndex = t;
		}
	this.order = newOrder;
		
	menu.moveEm()
	//this.report();
	}

Menu.prototype.reMeasure = function MenuprototypereMeasure () {
	// First we must get all the new heights
	for (section in this.sections) {
		this.sections[section].measure();
		}
	
	// var newTop = getMyProperty(document.getElementById('preferences'),'height'); // if prefs is not moveable
	var newTop = 0;
	// Now we can go through the order array and figure what the top of each should be
	for (i=0;i<this.order.length;i++) {
		if (i>0) newTop+=this.sections[this.order[i-1]].height 
		this.sections[this.order[i]].newTop = newTop;
		}
	}

Menu.prototype.report = function Menuprototypereport () {
	var reportStr ='';
	reportStr+= 'order: '+this.order.toString()+'\n';
	for (section in this.sections) {
		reportStr+= section+' top: '+this.sections[section].top+'\n';
		reportStr+= section+' height: '+this.sections[section].height+'\n';
		reportStr+= section+' path: '+this.sections[section].path.toString()+'\n';
		}
	alert(reportStr)
	}

function Section (divID) {
	this.id = divID;
	this.el = document.getElementById(divID);
	this.path = new Array;
	}

Section.prototype.measure = function Sectionprototypemeasure () {
	this.top = getMyProperty(this.el,'top');
	if (this.top.toString()=='NaN') menu.halt = 'y'
	this.height = getMyProperty(this.el,'height');
	}

Section.prototype.slideTo = function SectionprototypeslideTo (newTop) {
	if (newTop>-1) {
		menu.reMeasure();
		currTop = this.top;
		dist = newTop-currTop;
		steps = 3;
		if (document.all) steps = 15;
		stepDist = dist/steps;
		timeInc = 30;
		this.PathIndex = 0;
		for (i=0;i<steps;i++) {
			this.path[i] = currTop+parseInt(stepDist*(i+1));
			}
		}
	if (this.PathIndex<steps) {
		this.el.style.top = this.path[this.PathIndex]+'px';
		this.PathIndex+=1;
		setTimeout('menu.sections["'+this.id+'"].slideTo()',timeInc);
	} else {
		menu.moveEm()
		}
	}