// Copyright © 2002 Kinky Logic

// wonky custom browser check ---

ns=0;ns6=0;ie=0;ie6=0;
if(navigator.appName.indexOf("Netscape") >= 0){
	if(parseFloat(navigator.appVersion) >= 5) ns6=1;
	else if(parseFloat(navigator.appVersion) >= 4) ns=1;
}

if(navigator.appName.indexOf("Microsoft") >= 0 || ns6){
	ie=1;
	if(navigator.appVersion.indexOf("MSIE 6")>= 0) ie6=1;
}

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

imgArrayMain = ["who","what","how"];
urlArrayMain = ["who/introduction.php","what/work.php","how/index.php"];
imgArraySub = {
	"who":["introduction","definition","difference","awardspress","contact"],
	"bios":["pam","justin"],
	"what":["websites","logos","print","packaging","outdoor","services","clients"],
	"how":["design","strategy","clientrel","philosophy"]
	};
urlArraySub = {
	"who":["introduction.php","definition.php","difference.php","awardspress.php","contact.html"],
	"bios":["pam.html","justin.html"],
	"what":["work.php?type=web","work.php?type=id","work.php?type=print","work.php?type=packaging","work.php?type=outdoor","services.php","clients.php"],
	"how":["index.php","strategy.php","clientrel.php","philosophy.php"]
	};

colour = {"who":"#990000","bios":"#990000","what":"#663366","portfolio":"#663366","how":"#669999"};
subWidth = {"who":1,"bios":1,"what":30,"portfolio":30,"how":60};

function makePage(sect,subsect,quote){
	makeImages(sect);
	document.write('<link rel=stylesheet href="../scripts/kinky.css"></head>');
	if(quote)document.write('<body onload="place();centerY(\'quote\');showItems(\'content\',\'logo\',\'quote\');" onresize="place();centerY(\'quote\');"');
	else document.write('<body onload="place();showItems(\'content\',\'logo\');" onresize="place();"');
	document.write('bgcolor="'+colour[sect]+'" style="margin:0;overflow:hidden;">');
	makeMainMenu(sect);
	makeSubMenu(sect,subsect);
	if(quote) makeQuote(quote);
	makeFooter();
	
}

// create images
function makeImages(sect){
	menuImg = new Object();
	
	for(i=0;i<imgArrayMain.length;i++){
		menuImg[imgArrayMain[i]] = new Image();
		menuImg[imgArrayMain[i]].src = "../pics/menu_"+imgArrayMain[i]+".gif";
		menuImg[imgArrayMain[i]+"on"] = new Image();
		menuImg[imgArrayMain[i]+"on"].src = "../pics/menu_"+imgArrayMain[i]+"_on.gif";
	}
	
	for(i=0;i<imgArraySub[sect].length;i++){
		menuImg[imgArraySub[sect][i]] = new Image();
		menuImg[imgArraySub[sect][i]].src = "pics/submenu_"+imgArraySub[sect][i]+".gif";
		menuImg[imgArraySub[sect][i]+"on"] = new Image();
		menuImg[imgArraySub[sect][i]+"on"].src = "pics/submenu_"+imgArraySub[sect][i]+"_on.gif";
	}

	menuImg.spacer = new Image();
	menuImg.spacer.src = "pics/submenu_spacer.gif";

	menuImg.circle = new Image();
	menuImg.circle.src = "pics/circle.gif";
	menuImg.circleon = new Image();
	menuImg.circleon.src = "pics/circle_on.gif";
}


function makeMainMenu(x){
	var a = imgArrayMain;
	var u = urlArrayMain;
	document.write('<table background="../pics/menu_bg.gif" width="100%" border=0 cellpadding=0 cellspacing=0><tr valign="top"><td width="4%"><img src="../pics/1pxspacer.gif" width="1"></td>');
	for(i=0;i<a.length;i++){
		if(x==a[i]) document.write('<td width="30%"><img src="../pics/menu_'+a[i]+'_on.gif" name="'+a[i]+'" border=0></td>');
		else document.write('<td width="30%"><a href="../'+u[i]+'" onMouseOut="imgOff(\''+a[i]+'\');" onMouseOver="imgOn(\''+a[i]+'\');"><img src="../pics/menu_'+a[i]+'.gif" name="'+a[i]+'" border=0></a>');
	}
	document.write('<td><img src="../pics/menu_circle.gif"></td></tr><tr><td colspan="5"><img src="../pics/1pxspacer.gif" height="8"></td></tr></table>');
}

function makeSubMenu(l,x){
	var a = imgArraySub[l];
	var u = urlArraySub[l];
	document.write('<br /><table width="100%" cellpadding=0 cellspacing=0 border=0><tr valign=top>');
	document.write('<td width="'+subWidth[l]+'%" background="../pics/submenu_line.gif"><img src="../pics/1pxspacer.gif"></td><td align="left" nowrap=1>');
	for(i=0;i<a.length;i++){
		if(x==a[i]) document.write('<img src="pics/circle_on.gif" name="'+a[i]+'" border=0>');
		else document.write('<a href="'+u[i]+'" onMouseOut="imgCircleOff(\''+a[i]+'\',\''+x+'\');" onMouseOver="imgCircleOn(\''+a[i]+'\');"><img src="pics/circle.gif" name="'+a[i]+'" border=0></a>');
	}
	document.write('<br><img src="pics/submenu_'+x+'.gif" name="menuword" border=0>');
	document.write('</td></tr></table>');
}

function makeQuote(quote){
	document.write('<div id="quote" style="visibility:hidden;width:100%;"><table width="100%" cellpadding="10" cellspacing="0" border="0"><tr>');
	document.write('<td align="right"><img src="'+quote+'"></td>');
	document.write('</tr></table></div>');
}

function makeFooter(){
	document.write('<div id="logo">');
	document.write('<a href="../kinky.html"><img src="pics/logo.gif" border="0"></a>');
	document.write('</div>');
}

// simple rollovers --------------

function imgOn(){
	var i = arguments.length;
	while(i--){
		document[arguments[i]].src = menuImg[arguments[i]+"on"].src;
	}
}

function imgOff()  {
	var i = arguments.length;
	while(i--){
		document[arguments[i]].src = menuImg[arguments[i]].src;
	}
}

function imgCircleOn(img){
	document[img].src = menuImg.circleon.src;
	document.menuword.src = menuImg[img].src;
}

function imgCircleOff(img,x){
	document[img].src = menuImg.circle.src;
	document.menuword.src = menuImg[x].src;
}


// moving stuff ------------------


function winHeight(){
	return (ns || ns6) ? window.innerHeight : (ie6) ?  document.documentElement.clientHeight : document.body.clientHeight;
}

function place(){
	centerY("content",176,1.7);
	bottomY("logo");
}
	
function centerY(targ,lim,offset){
	if(!lim)lim=176;
	var t = getItem(targ);
	if(ns) t.style = t;
	if(!offset) offset=2;
	var y = (winHeight()/offset) - (getHeight(t)/2);
	moveToY(t,((y>lim)?y:lim));
}

function bottomY(targ){
	var t = getItem(targ);
	if(ns) t.style = t;
	var y = winHeight() - getHeight(t);
//	var min = 176+getHeight(getItem('content'));
	moveToY(t,y);
}

function getItem(targ){
	if(ns6) return document.getElementById(targ);
	else if(ns) return eval("document."+targ);
	else return eval(targ);
}

function moveToY(t,y){
	if(!t) return 0;
	if(ns) t.top = y;
	else t.style.top = y+"px";
}

function getHeight(targ) {

	if(!targ) return -1;
//	var t = getItem(targ);
	if(ns6)	return targ.offsetHeight;
	else if(ie){ return (targ.style.pixelHeight) ? targ.style.pixelHeight : targ.clientHeight; }
	else if(ns){ return (targ.document.Height) ? targ.document.Height : targ.clip.bottom - targ.clip.top; }
	return -1;
}

function showItems(){
	if(!t) return 0;
	var t,i=arguments.length;
	while(i--){
		t = getItem(arguments[i]);
		if(ns) t.style = t;
		t.style.visibility = "visible";
	}
}

// misc --------------

function openWin(loc,name,param){
	window.open(loc,name,param);
}