

function MenuMover(name, divId) { // name = name of this instance; divId = name of div to control
	this.name = name;
	this.divId = divId;
	this.targetX = 560;
	this.targetY = 193;
	this.currX = 560;
	this.currY = 193;
	this.targetH = 1;
	this.targetW = 100;
	this.currH = 1;
	this.currW = 100;
	this.mvinterval = window.setInterval(this.name+".intervalController()", 60);
	this.getDiv().controller = this;
	this.setShrinkTimeout();
	this.refreshDivPos();	
}

var p = MenuMover.prototype;

//---------------------------------------

p.div_onMouseOver = function() {
	this.clearShrinkTimeout();
}
p.div_onMouseOut = function() {
	this.setShrinkTimeout();
}

//---------------------------------------

p.clearShrinkTimeout = function() {
	clearTimeout(this.shrinkTimer);
}
p.setShrinkTimeout = function() {
	this.clearShrinkTimeout();
	this.shrinkTimer = window.setTimeout(this.name+".setTarget(560,193,100,1)", 1300);
}

p.fillDiv = function(nameList, hrefList) {
	var theDiv = this.getDiv();
	var out = "";
	for (var i=0; i<nameList.length; i++) {
		out += '<a href="' + hrefList[i] + '">' + nameList[i] + '</a><br>';	
	}
	theDiv.innerHTML = out;
}
p.setState = function(stateId) {
	var state = this.menuStateList[stateId];
	this.setTarget(state.x, state.y, state.w, state.h);
	this.fillDiv(state.nameList, state.hrefList);
	this.clearShrinkTimeout();	
}
p.setMenuStateList = function(menuStateList) {
	this.menuStateList = menuStateList;
}
p.intervalController = function() {
	this.moveTowardsTarget();
}
p.setTarget = function(x, y, w, h) {
	this.targetX = x;
	this.targetY = y;
	this.targetW = w;
	this.targetH = h;
	this.show();
}
p.moveTowardsTarget = function() {
	this.currX += (this.targetX - this.currX) * 0.3;
	this.currY += (this.targetY - this.currY) * 0.3;
	this.currW += (this.targetW - this.currW) * 0.4;
	this.currH += (this.targetH - this.currH) * 0.4;
	if (Math.random() < 0.1 && this.currH <10) {
		this.hide();
	}
	this.refreshDivPos();
}
p.refreshDivPos = function() {
	var theDiv = this.getDiv();
	theDiv.style.left = this.currX;
	theDiv.style.top = this.currY;
	theDiv.style.width = this.currW;
	theDiv.style.height = this.currH;
}
p.getDiv = function() {
	return document.getElementById(this.divId);
}
p.show = function() {
	this.getDiv().style.visibility = "visible";
}
p.hide = function() {
	this.getDiv().style.visibility = "hidden";
}

function MenuState(x, y, w, h, nameList, hrefList) {
	this.x = x;
	this.y = y;
	this.w = w;
	this.h = h;
	this.nameList = nameList;
	this.hrefList = hrefList;
}
//--------------------------------------------------------------------------------------


this.init = function() {
	this.bleh = new MenuMover("bleh", "menu");
	
	var menuStateList = new Array();
	menuStateList["capabilities"] = new MenuState(420, 210, 120, 40, ["News coverage","Sports coverage"], ["news_coverage.php","sports_coverage.php"]);
	menuStateList["work"] = new MenuState(520 ,215, 150, 60, ["Big stories","Funny stories","How we've helped"], ["big_stories.php","funny_stories.php","how_helped.php"]);
	menuStateList["local"] = new MenuState(610,213, 120, 60, ["Royals","Glos. attractions", "Local links"], ["royal_links.php","glos_attractions.php","local_links.php"]);
	
	bleh.setMenuStateList(menuStateList);	
}

this.over = function(name) {
	document.images["img_"+name].src = "images/menuitem_"+name+"_over.gif";
}
this.out = function(name) {
	document.images["img_"+name].src = "images/menuitem_"+name+".gif";
}


