/*
   written by:  Dean Edwards
      contact:  mailto://dean@NERD.co.uk
         date:  22.04.2000
    copyright:  © 2000, WellWicked Records
*/

// constants

	var MAXFLASH 	= 12;

// variables

	var messages	= new Array(6);
	var clicked		= false;

// initialise

	messages[0] 	= "Home page";
	messages[1] 	= "New releases, WellWicked on tour, Nüw Idol and more...";
	messages[2] 	= "Artist biographies and discographies";
	messages[3] 	= "WellWicked releases (RealAudio samples available here)";
	messages[4] 	= "wellwickedness";
	messages[5] 	= "WellWicked links";
	messages[6] 	= "Contact information";

	var menus 		= new Menus(self);
	var button		= null;	// currently selected button

// objects

function Menus(parent) {
	this.length 		= 2;
	this[0] 			= new Menu(parent, 0, LARGE);
	this[1] 			= new Menu(parent, 1, SMALL);
	
	this.flash 			= true;

	// methods
	this.refresh			= _refresh;

	return this;
}

function Menu(parent, index, size) {
	this.index 			= index;
	this.size 			= size;
	this.messages 		= parent.messages;
	this.buttons 		= new Buttons(this);
	this.length 		= this.buttons.length;
	return this;
}

function Buttons(parent) {
	this.length 		= 6;
	if (parent.size == SMALL) this[0] = new Button(parent, 0, "home");
	this[1] 			= new Button(parent, 1, "news");
	this[2] 			= new Button(parent, 2, "nuwidol");
	this[3] 			= new Button(parent, 3, "traxx");
	this[4] 			= new Button(parent, 4, "ness");
	if (parent.size == SMALL) {
		this[5] = new Button(parent, 5, "links");
		this[6] = new Button(parent, 6, "contact");
	}

	return this;
}

function Button(parent, index, name) {
	this.index 			= index;

	// inherit
	this.menu 			= parent;
	this.size 			= parent.size;
	this.message 		= parent.messages[this.index];

	// properties
	this.name 			= name;
	this.icon 			= new Icon(this);
	this.caption 		= new Caption(this, name);
	this.ready 			= READY;
	this.href	 		= root + ((name == "home") ? HOME : name + SLASH + INDEX);

	// methods
	this.large			= _large;
	this.small			= _small;

	this.highlight		= _highlight;
	this.reset			= _reset;

	return this;
}

function Icon(parent) {
	// inherit
	this.size 		= parent.size;

	//properties
	this.name 		= ICO + K_ + parent.menu.index + K_ + parent.index;

	if (this.size == SMALL) {
		this.width 	= 40;
		this.height = 40;
	} else {
		this.width 	= 80;
		this.height = 80;
	}

	this.hi 		= new Image(this.width, this.height);
	this.hi.src 	= root + THEMES + theme + buttonColour + ICO + HI + this.size + GIF;
	this.lo 		= new Image(this.width, this.height);
	this.lo.src 	= root + THEMES + theme + buttonColour + ICO + LO + this.size + GIF;

	return this;
}

function Caption(parent, name) {
	// inherit
	this.size 			= parent.size;

	// properties
	this.name 			= CAP + K_ + parent.menu.index + K_ + parent.index;

	this.hi 			= new Image();
	this.lo 			= new Image();

	if (name == "home") {
		this.hi.src 	= root + IMAGES + _invert + CAP + HI + this.size + GIF;
		this.lo.src 	= root + IMAGES + _invert + CAP + LO + this.size + GIF;
	} else {
		this.hi.src 	= root + parent.name + SLASH + IMAGES + _invert + CAP + HI + this.size + GIF;
		this.lo.src 	= root + parent.name + SLASH + IMAGES + _invert + CAP + LO + this.size + GIF;
	}

	return this;
}

// object methods

function _refresh() {
	for (var i = 0; i < 2; i++) for (var j = 0; j < menus.length; j++) if (menus[i].buttons[j]) menus[i].buttons[j].reset();
}

function _large() {
	if (this.size == LARGE) return this;
	else if (this.index > 0 && this.index < 5) return menus[0].buttons[this.index];
}

function _small() {
	if (this.size == SMALL) return this;
	else return menus[1].buttons[this.index];
}

function _highlight() {
	with (this) {
		setSrc(icon.name, icon.hi.src);
		setSrc(caption.name, caption.hi.src);
	}
}

function _reset() {	
	with (this) {
		setSrc(icon.name, icon.lo.src);
		setSrc(caption.name, caption.lo.src);
	}
}

function setSrc(name, src) {
	var img = document.images[name];
	if (img) img.src = src;
}

// HTML interface

function menu_on(i, j) {
	if (clicked) return;
	if (menus) button = menus[i].buttons[j];
	if (clicked || !button) return true;
	button.highlight();
	window.status = button.message;
	return true;
}

function menu_off() {
	if (clicked || !button) return;
	window.status = button.ready;
	button.reset();
	button = null;
}

function menu_click(A) {
 	if (ie4 && A) A.blur();
	if (clicked || !menus || !button || !menus.flash) return;
	A.href = VOID0;
	window.status = CLICK;
	clicked = true;
	flash(0);
}

function flash(step) {
	if (!button) return;
	
	if (step == MAXFLASH) {
		button.reset();
		window.location = button.href;
		button = null;
		clicked = false;
		return;
	}

	if (step % 2 == 0) {
		if (button.small()) button.small().highlight();
		if (button.large()) button.large().highlight();
	} else {
		if (button.small()) button.small().reset();
		if (button.large()) button.large().reset();
	}

	setTimeout('flash(' + ++step + ')', 100);
}