// gIAnTroBOt, js base - last updated 21.03.2002
// http://www.giantrobot.co.uk
// rich@giantrobot.co.uk
// this file is heavily commented it may add to the download time but in the long run its worth it
//
// Inspiration = Sebastien Chevrel
// the browser detection method is taken from his dhtml_base.js
// http://www.sebchevrel.com
// seb@sebchevrel.com
//
// FEATURES
// browser detection
// browser window width - getWinWidth()
// browser window height - getWinHeight()
// go to new page - newUrl(target,url) 
// centered pop up - popWinC(URL,name,w,h)
// standard pop up - popWin(URL,name,w,h)
// close window - closeWin(target) - for use across frames
// move window - moveWin(x,y)
// resize window - resizeWin(w,h)
// swap image - swapImage(imgName,theSrc,theLayer)
// preload images array - with example of required code for HTML doc
// X scroll Pos - curScrollX(window)
// Y scroll Pos - curScrollY(window)
// set X scroll pos - setScrollX(window,value)
// set Y scroll pos - setScrollY(window,value)
// get scroll height - scrollH(window)
// get scroll width - scrollW(window)
// show/hide Layer - layerVis(name,visibility)
// Zindex of layer - layerZindex(name,level)
// Alpha level of layers - layerAlpha(name,value)
// Move layer - moveLayer(name,x,y)
// Get layer x pos - getLayerX(name)
// Get layer y pos - getLayerY(name)
// resize layer - resizeLayer(name,w,h)
// get Layer height - getlayerHeight(name)
// get Layer width - getlayerWidth(name)
// write HTML to a layer - writeLayer(name,code)
// clip Layer - clipLayer(which,left,top,right,bottom)
// mousemoveH(evt)
// startMouseCapture(handler)
// background fade - fadebg(targetHEX)
//
//
//
// pre set variables to prevent errors
// first for the browser type
isNav=false;
isW3C=false;
isExp=false;
isOpera=false;
isNOT=false;
isMac=false;
// capture the height & width of the viewers screen
screenWidth = screen.width;
screenHeight = screen.height;

// now begin
// browser detection
browser=navigator.appName;
version=navigator.appVersion;
useragent=navigator.userAgent;
Vmajor=parseInt(navigator.appVersion);
Vminor=parseFloat(navigator.appVersion);

if (useragent.indexOf('Opera') != -1) {
	isOpera=true;
	pre='all';
	suff='.style';
}
else if (browser=="Netscape") {
	if (Vmajor==4)
	{
		isNav=true; pre='layers.'; suf='';
		window.captureEvents(Event.RESIZE);	// handle the resize bug on NN
	}
	else if (Vmajor>=5)	isW3C=true;
	else isNOT=true;
}
else if (browser=="Microsoft Internet Explorer") {
	if ( version.indexOf('MSIE 5.0; Macintosh;') != -1 )  {
		isExp=true;
		pre='all.';
		suf='.style';
	}
	// IE 4 to 5.5 return 4 as the version
	else if ( (Vmajor==4) ) {
		isExp=true;
		pre='all.';
		suf='.style';
	}
	else isNOT=true;
} else {
	isW3C=true;
}

if (version.indexOf('Mac') != -1) isMac=true;

if (isNav) {
	document.captureEvents(Event.RESIZE);
	window.onresize=resizeH;
	window.onresize=document.reload;
}
//---------------------------------------------------------------------------------
// get browser window width
function getWinWidth(){
	if (isExp) {
		return document.body.clientWidth;
	}
	else if (isNav || isW3C || isOpera) {
		return window.innerWidth;
	}
}
//---------------------------------------------------------------------------------
// get browser window height
function getWinHeight(){
	if (isExp) {
		return document.body.clientHeight;
	}
	else if (isNav || isW3C || isOpera) {
		return window.innerHeight;
	}
}
//---------------------------------------------------------------------------------
// go to new page
function newURL(url){
	newPage = url
	window.location.href = newPage
}
//---------------------------------------------------------------------------------
//centered pop up window
function popWinC(URL,name,w,h){
	var winPosX = (screen.width - w) / 2;
	var winPosY = (screen.height - h) / 2;
	props = 'height='+h+',width='+w+',top='+winPosY+',left='+winPosX;
	var popUp=window.open(URL,name,props);
	popUp.focus();
}
//---------------------------------------------------------------------------------
//standard pop up window
function popWin(URL,name,w,h){
	props = 'height='+h+',width='+w;
	var popUp=window.open(URL,name,props);
	popUp.focus();
}
//---------------------------------------------------------------------------------
// close window
function closeWin(target){
	target.close()
}
//---------------------------------------------------------------------------------

// move window
function moveWin(x,y){
	window.moveTo(x,y)
}
//---------------------------------------------------------------------------------
// resize window
function resizeWin(w,h){
	self.resizeTo(w,h)	
}
//---------------------------------------------------------------------------------
// swap image
function swapImage(imgName,theSrc,theLayer) {
	if (!theLayer) theLayer=''; else theLayer+='document.';
	// the above takes care of layers in NN 4, unused in IE
	if (isNav) {
		eval("document." +theLayer+ "images."+imgName+".src='"+theSrc+"'");
	} else {
		eval("document.images."+imgName+".src='"+theSrc+"'");
	}
}
//---------------------------------------------------------------------------------
// preload images array
var imageArray=new Array()
function loadImages(){
	for (i=0;i<loadImages.arguments.length;i++){
	imageArray[i]=new Image()
	imagesArray[i].src=loadImages.arguments[i]
	}
}
// example of code within head of page 
//loadImages('1.gif','2.gif')
//---------------------------------------------------------------------------------
//X scroll pos
function curScrollX(window) {
	if (isNav || isW3C || isOpera) {
		return eval(window+'.pageXOffset');
	}
	else if (isExp) {
		return eval(window+'.document.body.scrollLeft');
	}
}
//---------------------------------------------------------------------------------
//Y scroll pos
function curScrollY(window) {
	if (isNav || isW3C || isOpera) {
		return eval(window+'.pageYOffset');
	}
	else if (isExp) {
		return eval(window+'.document.body.scrollTop');
	}
}
//---------------------------------------------------------------------------------
//set X scroll pos
function setScrollX(window,value) {
	if (isNav || isW3C || isOpera) {
		return eval (window+'.scrollTo('+value+',0)');
	}
	else if (isExp) {
		return eval(window+'.document.body.scrollLeft='+value);
	}
}
//---------------------------------------------------------------------------------
//set Y scroll pos
function setScrollY(window,value) {
	if (isNav || isW3C || isOpera) {
		return eval (window+'.scrollTo(0,'+value+')');
	}
	else if (isExp) {
		return eval(window+'.document.body.scrollTop='+value);
	}
}
//---------------------------------------------------------------------------------
//get scroll height
function scrollH(window) {
	if (isNav || isW3C || isOpera) {
		return eval(window+'.document.height');
	}
	else if (isExp) {
		return eval(window+'.document.body.scrollHeight');
	}
}
//---------------------------------------------------------------------------------
//get scroll width
function scrollW(window) {
	if (isNav || isW3C) {
		return eval(window+'.document.width');
	}
	else if (isExp) {
		return eval(window+'.document.body.scrollWidth');
	}
}
//---------------------------------------------------------------------------------
//show/hide Layer - layerVis(name,visi)
function layerVis(name,visi) {
	if (isNav || isExp) {
		eval ('document.'+pre+name+suf+'.visibility="'+visi+'"');
		return;
	}
	else if (isW3C || isOpera) {
		obj=document.getElementById(name);
		obj.style.visibility=visi;
	}
}
//---------------------------------------------------------------------------------
// Zindex of layers
function layerZindex(name,level) {
	if (isNav || isExp) {
		eval ('document.'+pre+name+suf+'.zIndex="'+level+'"');
		return;
	}
	else if (isW3C || isOpera) {
		obj=document.getElementById(name);
		obj.style.zIndex=level;
	}
}
//---------------------------------------------------------------------------------
// Alpha level of layers
function layerAlpha(name,value) {
	if (isNav || isExp) {
		eval ('document.'+pre+name+suf+'.filters.alpha.opacity="'+value+'"');
		return;
	}
	else if (isW3C || isOpera) {
		obj=document.getElementById(name);
		obj.style.alpha=value;
	}
} 
//---------------------------------------------------------------------------------
//  moveLayer
function moveLayer(name,x,y) {
	if (isExp)	{
		eval ('document.'+pre+name+suf+'.pixelLeft='+x);
		eval ('document.'+pre+name+suf+'.pixelTop='+y);
		return;
	}
	else if (isNav) {
		eval ('document.'+name+'.moveTo('+x+','+y+')');
		return;
	}
	else if (isW3C) {
		obj=document.getElementById(name);
		obj.style.left=x+'px';
		obj.style.top=y+'px';	
		return;
	}
	else if (isOpera) {
		obj=document.getElementById(name);
		obj.style.left=x;
		obj.style.top=y;	
	}
}
//---------------------------------------------------------------------------------
// get layer x pos
function getLayerX(name) {
	if (isExp) {
		return eval ('document.'+pre+name+suf+'.pixelLeft');
	}
	else if (isNav) {
		return eval ('document.'+pre+name+suf+'.left');
	}
	else if (isW3C) {
		obj=document.getElementById(name);
		style=getComputedStyle(obj,null); // computed style vs. style definition
		return parseInt(style.getPropertyValue('left')); // we need to parse 'px' out
	}
	else if (isOpera) { // broken
		obj=document.getElementById(name);
		return (obj.style.pixelLeft);
	}
}
//---------------------------------------------------------------------------------
// get layer y pos
function getLayerY(name) {
	if (isExp) {
		return eval ('document.'+pre+name+suf+'.pixelTop');
	}
	else if (isNav) {
		return eval ('document.'+pre+name+suf+'.top');
	}
	else if (isW3C) {
		obj=document.getElementById(name);
		style=getComputedStyle(obj,null); // computed style vs. style definition
		return parseInt(style.getPropertyValue('top')); // we need to parse 'px' out
	}
	else if (isOpera) { // broken
		obj=document.getElementById(name);
		return (obj.style.pixelTop);
	}


}
//---------------------------------------------------------------------------------
// resize layer
function resizeLayer(name,w,h) {
	if (isExp) {
		eval ('document.'+pre+name+suf+'.pixelWidth='+w);
		eval ('document.'+pre+name+suf+'.pixelHeight='+h);
	}
	else if (isNav) {
		eval ('document.'+pre+name+suf+'.resizeTo('+w+','+h+')');
	}
}
//---------------------------------------------------------------------------------
// get Layer height
function getlayerHeight(name) {
	if (isExp) {
		return eval ('document.'+pre+name+suf+'.pixelHeight');
	}
	else if (isNav) {
		return eval ('document.'+pre+name+suf+'.clip.height');
	}
	else if (isW3C) {
		obj=document.getElementById(name);
		style=getComputedStyle(obj,null);
		return parseInt(style.getPropertyValue('height'));
	}
	else if (isOpera) {	// broken
		obj=document.getElementById(name);
		return (obj.style.pixelHeight);
	}

}
//---------------------------------------------------------------------------------
// get layer width
function getlayerWidth(name) {
	if (isExp) {
		return eval ('document.'+pre+name+suf+'.pixelWidth');
	}
	else if (isNav) {
		return eval ('document.'+pre+name+suf+'.clip.width');
	}
	else if (isW3C) {
		obj=document.getElementById(name);
		style=getComputedStyle(obj,null);
		return parseInt(style.getPropertyValue('width'));
	}
	else if (isOpera) { // broken
		obj=document.getElementById(name);
		return (obj.style.pixelWidth);
	}

}
//---------------------------------------------------------------------------------
// write html to layer
function writeLayer(name,code) {
	if (isNav) {
		eval('document.'+name+'.document.open()');
		eval('document.'+name+'.document.write(code)');
		eval('document.'+name+'.document.close()');
		}
	else if (isExp) {
		eval('document.all.'+name+'.innerHTML=code');
	}
	else if (isW3C) {
		obj=document.getElementById(name);
		// this is a non-compliant netscape hack supported by Gecko/Mozilla,
		// necessary to allow writing markup in a layer
		obj.innerHTML=code;
		/* this is the DOM way, but only support TextNodes in Mozilla
		while (obj.firstChild) obj.removeChild(obj.firstChild);
		node=document.createTextNode(code);
		obj.appendChild(node);*/
	}
	else if (isOpera) {
		obj=document.getElementById(name);
		obj.style.innerHTML=code;
	}
}
//---------------------------------------------------------------------------------
//clipLayer
function clipLayer(which,left,top,right,bottom) {
	if (isNav) {
		eval('document.'+pre+which+'.clip.top='+top);
		eval('document.'+pre+which+'.clip.bottom='+bottom);
		eval('document.'+pre+which+'.clip.left='+left);
		eval('document.'+pre+which+'.clip.right='+right);
	} else if (isExp ) {
		eval('document.'+pre+which+'.style.clip = "rect('+top+'px '+right+'px '+bottom+'px '+left+'px)"');
	} else if (isW3C || isOpera) {
		obj=document.getElementById(which);
		obj.style.clip='rect('+top+'px '+right+'px '+bottom+'px '+left+'px)';
	}
}
//---------------------------------------------------------------------------------
//
// mouse pointer 
mouseX=0;
mouseY=0;
//
function mousemoveH(evt) {
	if (isNav) {
		mouseX=evt.pageX;
		mouseY=evt.pageY;
	} 
	else if (isExp) {
		mouseX=window.event.clientX;
		mouseY=window.event.clientY;
	}
	else if (isW3C) {
		mouseX=evt.clientX;	
		mouseY=evt.clientY;
	}
	else if (isOpera) {
		mouseX=window.event.clientX;
		mouseY=window.event.clientY;
	}
	return true;
}
//
function startMC(handler) {
	if (isNav) document.captureEvents(Event.MOUSEMOVE);
	if (handler) document.onmousemove=handler;
	else document.onmousemove=mousemoveH;
//	if (isW3C) document.addEventListener(Event.MOUSEMOVE,mousemoveH,true);
}
//fadebg() set up your starting RGB value in the newRGB variable
var ts=5
//var newRGB='FFFFFF'
//
function fadebg(targetRGB){
//
if(!isExp){
document.bgColor=targetRGB
}else{
//
if(!targetRGB){
tHEX=String(tHEX).toString(16)
}else{
tHEX=targetRGB.toString(16)
}
var tempHEX=String(newRGB)
var cHEX=tempHEX.toString(16)
//
var cHEX_r = parseInt(cHEX.substring(0, 2), 16)
var tHEX_r = parseInt(tHEX.substring(0, 2), 16)
var cHEX_g = parseInt(cHEX.substring(2, 4), 16)
var tHEX_g = parseInt(tHEX.substring(2, 4), 16)
var cHEX_b = parseInt(cHEX.substring(4, 6), 16)
var tHEX_b = parseInt(tHEX.substring(4, 6), 16)
//
var r_dif = Math.round((tHEX_r-cHEX_r)/ts)
if (Math.abs(r_dif)<1) {
	cHEX_r = tHEX_r
} else {
	cHEX_r += r_dif
}
var g_dif = Math.round((tHEX_g-cHEX_g)/ts)
if (Math.abs(g_dif)<1) {
	cHEX_g = tHEX_g
} else {
	cHEX_g += g_dif
}
var b_dif = Math.round((tHEX_b-cHEX_b)/ts)
if (Math.abs(b_dif)<1) {
	cHEX_b = tHEX_b
} else {
	cHEX_b += b_dif
}
//
cHEX_r = cHEX_r.toString(16)
cHEX_g = cHEX_g.toString(16)
cHEX_b = cHEX_b.toString(16)
//
while (cHEX_r.length<2) {
cHEX_r = "0"+cHEX_r
}
while (cHEX_g.length<2) {
cHEX_g = "0"+cHEX_g
}
while (cHEX_b.length<2) {
cHEX_b = "0"+cHEX_b
}
//
newRGB=cHEX_r+cHEX_g+cHEX_b
document.bgColor=newRGB
//return eval ('document.'+pre+name+suf+'.backgroundColor');
setTimeout('fadebg()',50)
if(tHEX==cHEX){
clearTimeout()
}
}
}	
//-->

