sP.Registry  = [];
sP.aniLen    = 250; // animation's millisecond length
sP.hideDelay = 0;   // ignore me

ua   = navigator.userAgent.toLowerCase();
ie6  = (ua.indexOf("msie") && document.all && ua.indexOf("netscape") == -1);
nnf  = (ua.indexOf("netscape")  != -1 && ua.indexOf("gecko") != -1);
nni  = (ua.indexOf("netscape")  != -1 && ua.indexOf("msie") != -1);
nn6  = (ua.indexOf("netscape")  != -1);
gek  = (ua.indexOf("gecko")     != -1);
ff1  = (ua.indexOf("firefox")   != -1);
opr  = (ua.indexOf("opera")     != -1);
mac  = (ua.indexOf("mac")       != -1);
web  = (ua.indexOf("webtv")     != -1);
saf  = (ua.indexOf("safari")    != -1);
kon  = (ua.indexOf("konqueror") != -1);
nn4  = (document.layers);

function panelAlt(n){ if(n) sP.showPanel('panel' + n); }

function resetPanels(){
	var reg = sP.Registry;
	for(panel in reg){
		left  = sP.Registry[panel].left;
		width = sP.Registry[panel].width;
		if(left < 0){
			if(gek){
				left = parseInt(window.innerWidth / 2) + left;
				if(document.body.scrollHeight > document.body.clientHeight){
					// the retard has scroll bars
					left = left - 10;
				}
			} else {
				left = parseInt(document.body.clientWidth / 2) + left;
			}
		} else {
			if(gek){
				left = parseInt(window.innerWidth / 2) + left - width;
				if(document.body.scrollHeight > document.body.clientHeight){
					// the retard has scroll bars
					left = left - 10;
				}
			} else {
				left = parseInt(document.body.clientWidth / 2) + left - width;
			}
		}
		document.getElementById(sP.Registry[panel].id + 'Container').style.left = left;
	}
}

function sP(id, dir, left, top, width, height){
	this.ie = document.all ? 1 : 0;
	this.dom = document.getElementById ? 1 : 0;
	
	if(this.ie || this.dom){
		this.id = id;
		this.left = left;
		this.width = width;
		this.dir = dir;
		this.orientation = dir == "left" || dir == "right" ? "h" : "v";
		this.dirType = dir == "right" || dir == "down" ? "-" : "+";
		this.dim = this.orientation == "h" ? width : height;
		this.hideTimer = false;
		this.aniTimer = false;
		this.open = false;
		this.vis  = 0;
		this.startTime = 0;
		this.gRef = "sP_" + id;
		
		eval(this.gRef+"=this");
		sP.Registry[id] = this;
		
		if(left < 0){
			if(gek){
				left = parseInt(window.innerWidth / 2) + left;
				if(document.body.scrollHeight > document.body.clientHeight){
					// the retard has scroll bars
					left = left - 10;
				}
			} else {
				left = parseInt(document.body.clientWidth / 2) + left;
			}
		} else {
			if(gek){
				left = parseInt(window.innerWidth / 2) + left - width;
				if(document.body.scrollHeight > document.body.clientHeight){
					// the retard has scroll bars
					left = left - 10;
				}
			} else {
				left = parseInt(document.body.clientWidth / 2) + left - width;
			}
		}
		//alert(left)
		var d = document;
		var strCSS = '<style type="text/css">';
		strCSS += '#' + this.id + 'Container { visibility:hidden; '
		strCSS += 'left:' + left + 'px; '
		strCSS += 'top:' + top + 'px; '
		strCSS += 'overflow:hidden; z-index:10000; }'
		strCSS += '#' + this.id + 'Container, #' + this.id + 'Content { position:absolute; '
		strCSS += 'width:' + width + 'px; '
		strCSS += 'height:' + height + 'px; '
		strCSS += 'clip:rect(0 ' + width + ' ' + height + ' 0); '
		strCSS += '}'
		strCSS += '</style>'
		d.write(strCSS)
		this.load();
	}
}

sP.prototype.load = function(){
	var d = document
	var lyrId1 = this.id + "Container"
	var lyrId2 = this.id + "Content"
	var obj1 = this.dom ? d.getElementById(lyrId1) : d.all[lyrId1];
	
	if(obj1){
		var obj2 = this.ie ? d.all[lyrId2] : d.getElementById(lyrId2);
	}
	
	var temp;
	if(!obj1 || !obj2){
		window.setTimeout(this.gRef + ".load()", 100);
	} else {
		this.container = obj1
		this.panel = obj2
		this.style = this.panel.style
		this.homePos = eval("0" + this.dirType + this.dim)
		this.outPos = 0
		this.accelConst = (this.outPos - this.homePos) / sP.aniLen / sP.aniLen 
		//set initial state
		this.endSlide()
	}
}

sP.showPanel = function(id){
	var reg = sP.Registry
	var obj = sP.Registry[id]
	if(obj.vis){
		sP.hidePanel(id);
		obj.vis = 0;
	} else {
		if(obj.container){
			obj.over = true
			if (obj.hideTimer) { reg[id].hideTimer = window.clearTimeout(reg[id].hideTimer) }
			if (!obj.open && !obj.aniTimer) reg[id].startSlide(true)
			obj.vis = 1;
		}
	}
}

sP.hidePanel = function(id){
	var obj = sP.Registry[id]
	if(obj.container){
		if (obj.hideTimer) window.clearTimeout(obj.hideTimer)
		obj.hideTimer = window.setTimeout("sP.hide('" + id + "')", sP.hideDelay);
	}
}

sP.hide = function(id){
	var obj = sP.Registry[id]
	obj.over = false
	if (obj.hideTimer) window.clearTimeout(obj.hideTimer)
	obj.hideTimer = 0
	if (obj.open && !obj.aniTimer) obj.startSlide(false)
}

sP.prototype.startSlide = function(open) {
	this[open ? "onactivate" : "ondeactivate"]()
	this.open = open
	if (open) this.setVisibility(true)
	this.startTime = (new Date()).getTime() 
	this.aniTimer = window.setInterval(this.gRef + ".slide()", 10);
}

sP.prototype.slide = function() {
	var elapsed = (new Date()).getTime() - this.startTime
	if (elapsed > sP.aniLen) this.endSlide()
	else {
		var d = Math.round(Math.pow(sP.aniLen-elapsed, 2) * this.accelConst)
		if (this.open && this.dirType == "-") d = -d
		else if (this.open && this.dirType == "+") d = -d
		else if (!this.open && this.dirType == "-") d = -this.dim + d
		else d = this.dim + d
		this.moveTo(d)
	}
}

sP.prototype.endSlide = function() {
	this.aniTimer = window.clearTimeout(this.aniTimer)
	this.moveTo(this.open ? this.outPos : this.homePos)
	if (!this.open) this.setVisibility(false)
	if ((this.open && !this.over) || (!this.open && this.over)) {
		this.startSlide(this.over)
	}
}

sP.prototype.setVisibility = function(bShow) { 
	var s = this.container.style
	s.visibility = bShow ? "visible" : "hidden"
}

sP.prototype.moveTo = function(p) { 
	this.style[this.orientation == "h" ? "left" : "top"] = p + "px";
}

sP.prototype.getPos = function(c) {
	return parseInt(this.style[c])
}

sP.prototype.onactivate = function() { }

sP.prototype.ondeactivate = function() { }

document.onmousemove = resetPanels;