
var TIP;
var TIP_ID = -1;
var TIPS;

var NAV;
var NAV_IE = 0;
var NAV_NS = 1;
//var NAV_MZ = 3;
//var NAV_OT = 0xf;

var STATE_NATURAL	= 0;
var STATE_OVER	= 0;
var STATE_LOCKED	= 2;

var current_page = -1; // HOME 
var menu_configured = false;

var load_started = false;
var preloadFlag = false;
var menuItems;

var TAB_LIST;

var LOADED_LISTS = false;
var LOADED_LISTS_START = false;


var	DIRS;

// Constuuctor for MenuItem : a item in the main menu with a natural and over state
function MenuItem(tagname,natural,over,process,heading, status) {
	// members 
	this.status = status;
	this.tag = tagname;
	this.image_n = natural;
	this.image_o = over;
	this.process = process;
	this.heading = heading;

	// configure the item state 
	this.state = STATE_NATURAL; 
	
	// configure the image alt tag 
	document[this.tag+''].alt = this.status;

	// methods
	this.swap = swap;
	this.lock = lock;
	this.unlock = unlock;
	

	// cache the image 
	this.cache = newImage(over);
	this.cache = newImage(process);
	this.cache = newImage(heading);
}

function swap(toggle) { // true for over false for natural
	//if (document.images && (preloadFlag == true)) {
	if (preloadFlag == true) {
		if (((this.state == STATE_NATURAL) && (toggle)) || 
		    ((this.state == STATE_OVER) && (toggle))) { 
			document[this.tag+''].src = this.image_o;
			this.state = STATE_OVER;
		}
		else if (((this.state == STATE_OVER) && (!toggle)) ||
				 ((this.state == STATE_NATURAL) && (!toggle))) {
			document[this.tag+''].src = this.image_n;
			this.state = STATE_NATURAL;
		}
		else if (this.state == STATE_LOCKED)
			document[this.tag+''].src = this.image_o;
	}
}

function lock() {
	this.state = STATE_LOCKED;
	this.swap(true);
	// set heading
	document['heading'].src = this.heading;
	// set process
	document['PROCESS'].src = this.process;
}

function unlock() {
	this.state = STATE_OVER;
	this.swap(false);
}

function changeMenuImage(id,state) {
	if (preloadFlag == true) {
//		setStatus(menuItems[id].status);
		menuItems[id].swap(state);
	}
}
 
function getTagFor(id) { 
	if((id >= 0)&&(id < menuItems.length))
		return menuItems[id].tag;
	else 
		return 'none';
}

function loadLists() {
	if ((!LOADED_LISTS)&&(!LOADED_LISTS_START)) {
		LOADED_LISTS_START = true;
		TAB_LIST = new Array();
		
		DIRS = new Array();
		TIPS = new Array();
		
		var a_home = new Array();
		a_home[0]	= "home.htm";
		//a_home[1]	= "news0.htm";
		DIRS[MENU_HOME]		= "pages/home/";
		TAB_LIST[MENU_HOME] = a_home;
		TIPS[MENU_HOME] = "images/h_home.gif"; 

		var a_bio = new Array();
		a_bio[0] = "bio0.htm";
		//a_bio[1] = "bio1.htm";
		//a_bio[2] = "bio2.htm";
		//a_bio[3] = "bio3.htm";
		//a_bio[4] = "bio4.htm";
		DIRS[MENU_BIO]		= "pages/bio/";
		TAB_LIST[MENU_BIO] = a_bio;
		TIPS[MENU_BIO] = "images/h_bio.gif"; 

		var a_images = getImageArray();//new Array();

		DIRS[MENU_IMAGES]		= "";
		TAB_LIST[MENU_IMAGES] = a_images;
		TIPS[MENU_IMAGES] = "images/h_images.gif"; 

		var a_data = new Array();
		a_data[DATA_ROOT] = "data.htm";
		//a_data[1] = "data_video.htm";
		a_data[DATA_MP3] = "data_mp3.htm";
		//a_data[DATA_BIN] = "data_bin.htm";
		DIRS[MENU_DATA]		= "pages/data/";
		TAB_LIST[MENU_DATA] = a_data;
		TIPS[MENU_DATA] = "images/h_data.gif"; 

		/*var a_mail_order = new Array();
		a_mail_order[0] = "merch.htm";
		a_mail_order[1] = "album.htm";
		a_mail_order[2] = "tshirts.htm";
		a_mail_order[3] = "stickers.htm";
		a_mail_order[4] = "badges.htm";
		DIRS[MENU_MERCH]		= "pages/merch/";
		TAB_LIST[MENU_MERCH] = a_mail_order;
		TIPS[MENU_MERCH] = "images/h_mail_order.gif"; */

		var a_contact = new Array();			
		a_contact[0] = "contact.htm";
		DIRS[MENU_CONTACT]		= "pages/";
		TAB_LIST[MENU_CONTACT] = a_contact;
		TIPS[MENU_CONTACT] = "images/h_contact.gif"; 

		LOADED_LISTS = true;
	
	}
}

function preloadImages() {
	if (document) {
		if ((document.images)&&(!load_started)) {
			load_started = true;
			var load = newImage(IMG_LOAD);
			document['PROCESS'].src = IMG_LOAD;
			//document['SK_INDEX'].background = "images/tex02.gif";

			loadLists();
			menuItems = new Array();
			menuItems[MENU_HOME] = new MenuItem("b_home",		
				"images/blank.gif","images/pointer.gif","images/w_home.gif","images/hb_home.gif","home"); 
			menuItems[MENU_BIO] = new MenuItem("b_bio",		
				"images/blank.gif","images/pointer.gif","images/w_bio.gif","images/hb_bio.gif","biography"); 
			menuItems[MENU_IMAGES] = new MenuItem("b_images",		
				"images/blank.gif","images/pointer.gif","images/w_images.gif","images/hb_images.gif","image gallery"); 
			menuItems[MENU_DATA] = new MenuItem("b_data",		
				"images/blank.gif","images/pointer.gif","images/w_data.gif","images/hb_data.gif","public data"); 
			//menuItems[MENU_MERCH] = new MenuItem("b_mail_order",	
			//	"images/blank.gif","images/pointer.gif","images/w_mail_order.gif","images/hb_mail_order.gif","mail order"); 
			menuItems[MENU_CONTACT] = new MenuItem("b_contact",	
				"images/blank.gif","images/pointer.gif","images/w_contact.gif","images/hb_contact.gif","contact"); 
			preloadFlag = true;
			
//			if (!menu_configured)
//				getCurrentState();
//			window.focus();
			var tabf = newImage(TAB_FRONT);
			var taba = newImage(TAB_BACK);
			var tabn = newImage(TAB_FALSE);
			var tabsa = newImage(TAB_FRONTA);
			var tabsb = newImage(TAB_FRONTB);

			ClearTabs();
			//SetTabs();
			
			getPage();
			var wait = newImage(IMG_WAIT);
			wait = newImage(IMG_WAIT2);
			
			initToolTips();
			
			SetProcess(IMG_WAIT);
		}
	}
}

function SetProcess(pro) {

	document['PROCESS'].src = pro;
}

function BoxClick(page) {
	if (current_page != page) {
		menuItems[page].lock();
		
		if(current_page > -1)
			menuItems[current_page].unlock();
		current_page = page;
		ClearTabs();
		SetTabs();

	}
	else if (current_page != MENU_IMAGES)
	{		
		ClearTabs();
		SetTabs();
	}	
}

function getPage() {
	frm = window.frames["SK_BODY"];
	if (frm) {
		var id = extractId();
		if (id != 0) {
			BoxClick(id);
		}
		else { 
			BoxClick(frm.getId());

			if (current_page != MENU_IMAGES) {
				tab_current = frm.getTabId();
				SetTabs();
			}
		}
	}
	else { 
		BoxClick(extractId());
	}
}

function JumpTo(page, tab) {
	BoxClick(page);
	tab_current = tab;
	SetTabs();
}

function extractId() {
	var loc = new String(document.location).toLowerCase();
	var index = loc.indexOf( "?" );
	
	if ( index != -1 )  {
		index = loc.indexOf( "page" ,index);

		if ( index != -1 ){
			
			index = loc.indexOf( "=" ,index);
			var ind = loc.indexOf( ":sub=" ,index);
		
			var item;
			var sub;

			if(ind != -1) {
				item = loc.substring(index+1,ind);
				sub = loc.substring(ind+5,loc.length);
			}
			else {
				item = loc.substring(index+1,loc.length);
				sub = false;
			}

			//alert("Page: " + item + " Sub: " + sub);

			if (item == "home") {
				window.frames["SK_BODY"].location = DIRS[MENU_HOME]+TAB_LIST[MENU_HOME][0];
				return MENU_HOME;
			}
			else if (item == "news") {
				window.frames["SK_BODY"].location = DIRS[MENU_HOME]+TAB_LIST[MENU_HOME][1];
				return MENU_HOME;
			}
			else if (item == "bio") {
				if (sub != false)
					window.frames["SK_BODY"].location = DIRS[MENU_BIO]+sub;
				else 
					window.frames["SK_BODY"].location = DIRS[MENU_BIO]+TAB_LIST[MENU_BIO][0];

				return MENU_BIO;
			}
			else if (item == "img") {
				window.frames["SK_BODY"].location = "pages/gallery/images.htm";
				return MENU_IMAGES;
			}
			else if (item == "contact") {
				window.frames["SK_BODY"].location = DIRS[MENU_CONTACT]+TAB_LIST[MENU_CONTACT][0];
				return MENU_CONTACT;
			}
			else if (item == "data" )
			{
				window.frames["SK_BODY"].location = DIRS[MENU_DATA]+TAB_LIST[MENU_DATA][DATA_ROOT];
				return MENU_DATA;
			}
			else if (item == "mp3" )
			{
				window.frames["SK_BODY"].location = DIRS[MENU_DATA]+TAB_LIST[MENU_DATA][DATA_MP3];
				return MENU_DATA;
			}
/*			else if (item == "bin" )
			{
				window.frames["SK_BODY"].location = DIRS[MENU_DATA]+TAB_LIST[MENU_DATA][DATA_BIN];
				return MENU_DATA;
			}*/
		}
	}
	return MENU_HOME;
}

function getList(page) {
	if (LOADED_LISTS) {
		return TAB_LIST[page];
	}
	else 
		return false;
}
		
var tab_offset = 0;		// offset on the display 
var tab_current = 0;	// current index 
var tab_start = 15;	// current index 	
var tab_len	= 0;
var TAB_NOW;

function SetTabs() {
	var t_tabs = TAB_LIST[current_page];
	
	tab_len = t_tabs.length;

	if (((tab_len > 1) && (current_page != MENU_IMAGES)) || 
		((current_page == MENU_IMAGES) && (tab_len > 2))) {
		var len = 16 - (tab_len);
		
		for (var i=0; i<len; i+=1) {
			document['TAB'+i].src = IMG_BLANK;
			document['TAB'+i].style.cursor = "default";
		}			
		for (var i=len; i<16; i+=1) {
			document['TAB'+i].src = TAB_BACK;
			document['TAB'+i].style.cursor = "pointer";
		}			
		tab_start = len;
		
		var tab_selected = len + tab_current;
		if ((tab_selected >= 0)&&(tab_selected < 16)) {
		
			if (current_page == MENU_IMAGES) {				
				document['TAB'+tab_selected].src = TAB_FRONTA;
				document['TAB'+tab_selected].style.cursor = "default";
				var x = tab_selected + 1; 
				document['TAB'+x].src = TAB_FRONTB;
				document['TAB'+x].style.cursor = "default";
			}
			else {
				document['TAB'+tab_selected].src = TAB_FRONT;
				document['TAB'+tab_selected].style.cursor = "default";
			}
		}
	}
}

function UpdateTabExtras() {
	window.frames["SK_BODY"].SetVar(VAR_TABS,true);
	
	if (tab_current == 0)
		window.frames["SK_BODY"].SetVar(VAR_PREV,false);
	if (tab_current >= tab_len-2)
		window.frames["SK_BODY"].SetVar(VAR_NEXT,false);
}

function TabClick(tab) { 
	var tab_temp = tab_offset+tab-tab_start;//(tab_offset) - tab;
	if(tab_temp < 0)
		return;
	//SetTab(tab_offset+tab-tab_start,true);//(tab_offset) - tab;
	SetTab(tab_temp,true);	
}

function SetTab(tab,exten) { 
	var len = TAB_LIST[current_page].length;

	if (tab >= len)
		tab = tab - len;
	if (tab < 0)
		tab = tab + len;

	if (tab_current != tab)
	{
		tab_current = tab;

		if (current_page == MENU_IMAGES)
			if (tab_current >= TAB_LIST[current_page].length-1)
				tab_current = tab_current - 1;

		SetTabs();
		Display(exten);	
	}
}

function IncrementTab(move) {
	SetTab(tab_current+move,false);
}

function ClearTabs() {
	tab_offset = 0;
	tab_current = 0;
	tab_start = 15;

	if(!document.images)
		return;
		
	for (var i=0; i<16; i+=1) {
		document['TAB'+i].src = IMG_BLANK;
		document['TAB'+i].style.cursor = "default";
//		document['TAB'+i].style-cursor = "default;";
	}
}

function Display(exten) { 

	if (!LOADED_LISTS)
	{
		loadLists();
		setTimeout("Display()", 200);
		return;
	}
	var t_tabs = TAB_LIST[current_page];

	frm = window.frames["SK_BODY"];
	if (frm) {
		if ((current_page != MENU_IMAGES)&&(!exten)) {
			if (frm.location != t_tabs[tab_current])
				frm.location = t_tabs[tab_current];
		}
		else if (current_page != MENU_IMAGES)
			frm.location = DIRS[current_page] + t_tabs[tab_current];
		else  {
			frm.setImageIndex(t_tabs,tab_current,tab_current+1);
//			frm.setImage(t_tabs[tab_current],t_tabs[tab_current+1]);
			return t_tabs;
		}
	}
}
var TIP_OFFSET = 12; // - OFFSET form cursor
var TIP_LOCKED = false;

function initToolTips() {
	// scan for netscape

	var n = navigator.userAgent.indexOf('MSIE');
	if (n >= 0) 
		NAV = NAV_IE;
	else// { 
		NAV = NAV_NS;

	TIP = document.getElementById('TIP');//document['TIP'];

	var img;
	for (var i=0; i<TIPS.length; i+=1) {
		img = newImage(TIPS[i]);
	}

	if (!document.layers&&!document.all)
		event="test"
//	window.document.onmousemove=mouseMove;
}

/*function mouseMove(e)
{
	if ((TIP_ID != -1)&&(!TIP_LOCKED)) {
		TIP_LOCKED = true;
		var off = (NAV == NAV_NS)?event.PageX:event.clientX;
		TIP.style.left = off + TIP_OFFSET;
//		TIP.style.left = TIP_OFFSET;
		TIP.style.top=(NAV == NAV_NS)?e.clientY:event.clientY;
		TIP.style.visibility = "visible";
	}
}*/

//function setTipPosition(lock) {
//	TIP.style.left = lock.style.left + lock.width + 2;
//	TIP.style.top = lock.style.top;
//}/

function TipOver(ID, image,e) { 
	if ((TIP_LOCKED)||(TIP_ID == ID)||(NAV == NAV_NS))
		return;

	TIP_ID = ID;

//	TIP_OFFSET = document[image].style.left;
//	TIP_OFFSET = document.getElementById(image).style.left;
//	setTipPosition(document[image]);
	document['TIP_IMG'].src = TIPS[ID];
//	TIP_LOCKED = false;

//	var off = 
	TIP.style.left = (NAV == NAV_NS)?e.PageX:e.clientX + TIP_OFFSET;
//	TIP.style.left = off + TIP_OFFSET;
//	TIP.style.left = TIP_OFFSET;
	TIP.style.top=(NAV == NAV_NS)?e.clientY:e.clientY;
	TIP.style.visibility = "visible";

//	mouseMove(e)

	TIP_LOCKED = true;
	
}

function TipOut(ID) { 
	if (TIP_ID == ID) {
		TIP_ID = -1;
		TIP_LOCKED = false;
		TIP.style.visibility = "hidden";
	}
}


