// ----------------------------------------
// Drop down menu script
// Programmed by: Frank Chu (DJ_Angel)
// Version: 1.0
// 
// Global variables used:
// IE, NS, timer
//
// ----------------------------------------

// Global variables
IE = document.all;
NS = document.layers;

// User-preset variables
ctrlLeft = 140;
ctrlTop = 100;
if (NS) ctrlTop = 95;

ctrlFntSize = "10pt";
ctrlFntFam = "Verdana, Arial, Helvetica";
ctrlFntColor = "#45ACF6";

separator = "  |  ";
sepFntColor = "#FFFFFF";

fntSize = "10pt";
fntFam = "Verdana, Arial, Helvetica";
borSize = 2;
borColor = "#EEEEEE";
borStyle = "inset";

bgOut = '#000000';
bgOver = '#0000BB';
fgOut = '#FFFFFF';
fgOver = '#FF0000';

ayMain = ['News','news.html','Our clan','clan.html','Strategy','strt.html','Downloads','downloads.html','AoK links','links.html']
aySub1 = []
aySub2 = ['Members','members.html','Allies','allies.html','Enemies','enemies.html']
aySub3 = ['Castle Rush','strt0.html','Super BOOM','strt1.html','blah','strt2.html']
aySub4 = ['ScreenShots','shots.html','Images','images.html','Taunts','taunts.html']
aySub5 = ['ageofkings.com','http://www.ageofkings.com','mrfixitonline.com','http://mrfixitonline.com']
Widths = [0,90,100,110,140];


// Script starts
str =  "<STYLE>"
str += "a.ctrllinks:link {color:"+ctrlFntColor+"}"
str += "a.ctrllinks:visited {color:"+ctrlFntColor+"}"
str += "a.ctrllinks:active {color:"+ctrlFntColor+"}"
str += "a.sublinks:link {color:"+fgOut+"}"
str += "a.sublinks:visited {color:"+fgOut+"}"
str += "a.sublinks:active {color:"+fgOut+"}"
str += ".ctrls {color:"+sepFntColor+";}"
str += ".ctrllinks {"
str += "font-family:"+ctrlFntFam+";"
str += "font-size:"+ctrlFntSize+";}" 
str += ".subs { position:absolute;"
str += "font-family:"+fntFam+";"
str += "font-size:"+fntSize+";"
str += "border:"+borSize+"px "+borColor+" "+borStyle+";"
str += (IE? "padding:3px;cursor:hand;":"") + "}"
if (NS) for (i=0; i<Widths.length; i++) str += "#Subs"+i+"{ width:"+Widths[i]+"; }"
str += "<\/STYLE>"
document.write(str);

document.Menus = []
document.Menus.timer = null;
onload = function() {
    if (!IE && !NS) return;
    var temp = "";
    for (i=0; i<separator.length; i++)
	temp += (n=separator.charAt(i))==" "? "&nbsp;":n;
    separator = temp;

    if (NS) var ctrl = new Layer(screen.width,window);
    else {
	document.body.insertAdjacentHTML("beforeEnd","<DIV STYLE='position:absolute;'>");
	var ctrl = document.body.children[document.body.children.length-1];
    }
    ctrl.setup = CtrlSetup;
    ctrl.setup();

    for (i=0; i<ayMain.length; i+=2) {
	var obj, subObj;
	var str = ""
	var w = Widths[i/2];

	if (NS) obj = new Layer(w,window);
	else {
	    document.body.insertAdjacentHTML("beforeEnd","<DIV STYLE='position:absolute;width:"+w+"px;'>");
	    obj = document.body.children[document.body.children.length-1];
	}
	document.Menus[i/2] = obj;
	obj.ctrl = ctrl;
	obj.nextTop = 0;
	obj.ay = eval("aySub" + ((i/2)+1));
	if (IE) for (j=0; j<obj.ay.length; j+=2) obj.innerHTML += "<DIV CLASS='subs' STYLE='width:"+w+";'>"+obj.ay[j]+"</DIV>";
	for (j=0; j<obj.ay.length; j+=2) {
	    subObj = NS? new Layer(w,obj):obj.children[j/2];
	    subObj.setup = SubSetup;
	    subObj.setup(obj,i,j);
	}
	ctrl.write(ayMain[i],ayMain[i+1],i);
	obj.setup = MainSetup;
	obj.setup();
	ctrl.l = NS? ctrl.left+ctrl.clip.width:ctrl.offsetLeft+ctrl.offsetWidth;
    }
    document.loaded = true;
}
function CtrlSetup() {
    this.str = "";
    this.l = ctrlLeft;
    this.t = ctrlTop;
    if (NS) {
	this.left = ctrlLeft;
	this.top = ctrlTop;
    }
    else {
	this.style.pixelLeft = ctrlLeft;
	this.style.pixelTop = ctrlTop;
    }
    (NS? this:this.style).visibility = "visible";
    this.write = function(txt,href,ind) {
	this.str += "<A HREF='"+href+"' CLASS='ctrllinks' ONMOUSEOVER='drop("+ind/2+")' ONMOUSEOUT='pull("+ind/2+")'>"+txt+"</A>" + (ind==ayMain.length-2? "":separator)
        this.finishWrite(this.str);
    }
    this.finishWrite = function(txt) {
	if (NS) {
	    with(this.document) {
		open();
		write("<SPAN CLASS='ctrls'>"+txt+"</SPAN>");
		close();
	    }
	}
	else this.innerHTML = "<SPAN CLASS='ctrls'>"+txt+"</SPAN>";
    }
}
function MainSetup() {
    if (NS) {
	this.left = this.ctrl.l;
	this.top = this.ctrl.t+this.ctrl.clip.height+5;
    }
    else {
	this.style.pixelLeft = this.ctrl.l;
	this.style.pixelTop = this.ctrl.t+this.ctrl.offsetHeight+5;
    }
    (NS? this:this.style).visibility = "hidden";
    this.onmouseover = function() { clearTimeout(document.Menus.timer); }
    this.onmouseout = function() {
	if (NS || !event.fromElement.mother.contains(event.toElement))
	    document.Menus.timer = setTimeout('(NS? el:el.style).visibility = "hidden"',50);
    }
}
function SubSetup(par,indI,indJ) {
    this.mother = par;
    this.href = par.ay[indJ+1];
    if (NS) {
	this.document.href = this.href;
	this.visibility = "inherit";
	this.bgColor = bgOut;
	this.top = par.nextTop;
	with (this.document) {
	    open();
	    write("<SPAN ID='Subs"+(indI/2)+"' CLASS='subs'><A CLASS='sublinks' HREF='"+this.href+"'>"+par.ay[indJ]+"</A></SPAN>");
	    close();
	}
    }
    else {
	with (this.style) {
	    pixelTop = par.nextTop;
	    backgroundColor = bgOut;
	    color = fgOut;
	}
    }
    this.onmouseover = function() { this.hover(1); }
    this.onmouseout = function() { this.hover(0); }
    this.hover = function(hov) {
	if (NS) this.bgColor = hov? bgOver:bgOut;
	else {
	    this.style.backgroundColor = hov? bgOver:bgOut;
	    this.style.color = hov? fgOver:fgOut;
	}
	status = hov? this.href:"";
    }
    if (NS){
	this.document.captureEvents(Event.MOUSEDOWN);
	this.document.onmousedown = function() { location.href = this.href; }
    }
    else this.onclick = function() { location.href = this.href; }
    par.nextTop += NS? this.clip.height-borSize:this.offsetHeight-borSize;
}
function drop(ind) {
    if (!document.loaded) return;
    clearTimeout(document.Menus.timer)
    for (i=0; i<document.Menus.length; i++) (NS? document.Menus[i]:document.Menus[i].style).visibility = "hidden";
    el = document.Menus[ind];
    (NS? el:el.style).visibility = "visible";
}
function pull(ind) {
    if (!document.loaded) return;
    el = document.Menus[ind]
    document.Menus.timer = setTimeout('(NS? el:el.style).visibility = "hidden"',50)
}