/*************************************************
  javascript tools i've collected from various 
  places.  fun to use and i didn't have to take 
  the time to write them myself. 
*************************************************/

// 1k DHTML API
d=document;l=(d.layers)?1:0;op=navigator.userAgent.toLowerCase().indexOf('opera')!=-1;
function gE(e,f){if(l){f=(f)?f:self;var V=f.document.layers;if(V[e])return V[e];for(var W=0;W<V.length;)t=gE(e,V[W++]);return t;}if(d.all)return d.all[e];return d.getElementById(e);}
function sE(e){if(l)e.visibility='show';else e.style.visibility='visible';}
function hE(e){if(l)e.visibility='hide';else e.style.visibility='hidden';}
function sZ(e,z){if(l)e.zIndex=z;else e.style.zIndex=z;}
function sX(e,x){if(l)e.left=x;else if(op)e.style.pixelLeft=x;else e.style.left=x;}
function sY(e,y){if(l)e.top=y;else if(op)e.style.pixelTop=y;else e.style.top=y;}
function sW(e,w){if(l)e.clip.width=w;else if(op)e.style.pixelWidth=w;else e.style.width=w;}
function sH(e,h){if(l)e.clip.height=h;else if(op)e.style.pixelHeight=h;else e.style.height=h;}
function sC(e,t,r,b,x){if(l){X=e.clip;X.top=t;X.right=r;X.bottom=b;X.left=x;}else e.style.clip='rect('+t+' '+r+' '+b+' '+x+')';}
function wH(e,h){if(l){Y=e.document;Y.write(h);Y.close();}if(e.innerHTML)e.innerHTML=h;}


// 1k SLIDE EXT
// originally from tim morgan (http://timmorgan.info/dhtml/1k/extensions/slide.html)
// heavily modified by me to incorporate a port of robert penner's easing equations.
// aside from fancy easing in and out, it also makes it time based instead of processor
// based so it will drop frames on slower machines. -- 08/18/2003
// sample use: slide([element],[target left value],[target top value],0,[desired travel time],[easing function],[function on complete])
function slide(e,x,y,tStartTime,tTotalDuration,EaseEq,funcCall,xStartValue,yStartValue){
	var num;
	if(typeof e!='object'){num=e;e=slide.all[num];e.sliding=true;}
	else{if(e.sliding)return}
	if(!parseInt(xStartValue))xStartValue=parseInt(e.left||e.style.left||e.style.pixelLeft);
	if(!parseInt(yStartValue))yStartValue=parseInt(e.top||e.style.top||e.style.pixelTop);
	if(!tStartTime)tStartTime=new Date().getTime();
	if(EaseEq=='')EaseEq='linearTween';
	tCurrentTime=new Date().getTime();
	deltaTime=tCurrentTime-tStartTime;
	if(deltaTime>=tTotalDuration){
	  xLoc=x;
	  yLoc=y;
	}else{
	  eval('xLoc='+EaseEq+'('+deltaTime+','+xStartValue+','+(x-xStartValue)+','+tTotalDuration+')');
	  eval('yLoc='+EaseEq+'('+deltaTime+','+yStartValue+','+(y-yStartValue)+','+tTotalDuration+')');
	}
	sX(e,px(xLoc));
	sY(e,px(yLoc));
	if(num==null){num=slide.all.length;slide.all[num]=e;}
	if(xLoc!=x||yLoc!=y)setTimeout('slide('+num+','+x+','+y+','+tStartTime+','+tTotalDuration+',"'+EaseEq+'","'+funcCall+'",'+xStartValue+','+yStartValue+')', 30);
	else{
		e.sliding=false;
		if(funcCall!='')eval(funcCall);
	}
};
slide.all=[];
function sign(x,y){return(x<y)?1:-1};
function px(n){return n+(!l&&!op?'px':0)};

/**
 * Easing equations originally taken from robertpenner.com
 * 
 * // reference-like translation of values
 * t = current time/frame (zero based - getTimer()-starttime)
 * b = start value (constant)
 * c = value to travel, not final destination (constant)
 * d = duration (constant)
 * 
 */     
function linearTween(t, b, c, d){return c*t/d + b};
function easeInQuad(t, b, c, d){t /= d;return c*t*t + b;}
function easeOutQuad(t, b, c, d){t /= d;return -c * t*(t-2) + b;}
function easeInOutQuad(t, b, c, d){t /= d/2;if (t < 1) return c/2*t*t + b;t--;return -c/2 * (t*(t-2) - 1) + b;}
function easeInCubic(t, b, c, d){t /= d;return c*t*t*t + b;}
function easeOutCubic(t, b, c, d) {	t /= d;	t--;return c*(t*t*t + 1) + b;}
function easeInOutCubic (t, b, c, d) {t /= d/2;	if (t < 1) return c/2*t*t*t + b;	t -= 2;	return c/2*(t*t*t + 2) + b;}
function easeInQuart (t, b, c, d) {	t /= d;	return c*t*t*t*t + b;}
function easeOutQuart (t, b, c, d) {	t /= d;	t--;	return -c * (t*t*t*t - 1) + b;}
function easeInOutQuart (t, b, c, d) {	t /= d/2;	if (t < 1) return c/2*t*t*t*t + b;	t -= 2;	return -c/2 * (t*t*t*t - 2) + b;}
function easeInQuint (t, b, c, d) {	t /= d;	return c*t*t*t*t*t + b;}
function easeOutQuint (t, b, c, d) {	t /= d;	t--;	return c*(t*t*t*t*t + 1) + b;}
function easeInOutQuint (t, b, c, d) {	t /= d/2;	if (t < 1) return c/2*t*t*t*t*t + b;	t -= 2;	return c/2*(t*t*t*t*t + 2) + b;}
function easeInSine (t, b, c, d) {return -c * Math.cos(t/d * Math.PI/2) + c + b;}
function easeOutSine (t, b, c, d) {	return c * Math.sin(t/d * Math.PI/2) + b;}
function easeInOutSine (t, b, c, d) {	return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;}
function easeInExpo (t, b, c, d) {	var flip = 1;	if (c < 0) {		flip *= -1;		c *= -1;	}	return flip * (Math.exp(Math.log(c)/d * t)) + b;}
function easeOutExpo (t, b, c, d) {	var flip = 1;	if (c < 0) {		flip *= -1;		c *= -1;	}	return flip * (-Math.exp(-Math.log(c)/d * (t-d)) + c + 1) + b;}
function easeInOutExpo (t, b, c, d) {	var flip = 1;	if (c < 0) {		flip *= -1;		c *= -1;	}	if (t < d/2) return flip * (Math.exp(2*Math.log(c/2)/d * t)) + b;	return flip * (-Math.exp(-2*Math.log(c/2)/d * (t-d)) + c + 1) + b;}
function easeInCirc (t, b, c, d) {	t /= d;	return -c * (Math.sqrt(1 - t*t) - 1) + b;}
function easeOutCirc (t, b, c, d) {	t /= d;	t--;	return c * Math.sqrt(1 - t*t) + b;}
function easeInOutCirc (t, b, c, d) {	t /= d/2;	if (t < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;	t -= 2;	return c/2 * (Math.sqrt(1 - t*t) + 1) + b;}




/*****************************************************
* ypSlideOutMenu
* 3/04/2001
*
* a nice little script to create exclusive, slide-out
* menus for ns4, ns6, mozilla, opera, ie4, ie5 on 
* mac and win32. I've got no linux or unix to test on but 
* it should(?) work... 
*
* Revised:
* - 08/29/2002 : added .hideAll()
*
* Revised:
* - 08/15/2003 : added StartFunction, EndFunction
*
* --youngpup--
*****************************************************/
ypSlideOutMenu.Registry = []
ypSlideOutMenu.aniLen = 150
ypSlideOutMenu.hideDelay = 500
ypSlideOutMenu.minCPUResolution = 10
// constructor
function ypSlideOutMenu(id, dir, left, top, width, height, StartFunction, EndFunction)
{
this.ie = document.all ? 1 : 0
this.ns4 = document.layers ? 1 : 0
this.dom = document.getElementById ? 1 : 0
if (this.ie || this.ns4 || this.dom) {
this.id = id
this.dir = dir
this.StartFunction = StartFunction
this.EndFunction = EndFunction
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.over = false
this.startTime = 0
this.gRef = "ypSlideOutMenu_"+id
eval(this.gRef+"=this")
ypSlideOutMenu.Registry[id] = this
// commented the following line out because it's defined above.
//  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()
}
}
ypSlideOutMenu.prototype.load = function() {
var d = document
var lyrId1 = this.id + "Container"
var lyrId2 = this.id + "Content"
var obj1 = this.dom ? d.getElementById(lyrId1) : this.ie ? d.all[lyrId1] : d.layers[lyrId1]
if (obj1) var obj2 = this.ns4 ? obj1.layers[lyrId2] : this.ie ? d.all[lyrId2] : d.getElementById(lyrId2)
var temp
if (!obj1 || !obj2) window.setTimeout(this.gRef + ".load()", 100)
else {
this.container = obj1
this.menu = obj2
this.style = this.ns4 ? this.menu : this.menu.style
this.homePos = eval("0" + this.dirType + this.dim)
this.outPos = 0
this.accelConst = (this.outPos - this.homePos) / ypSlideOutMenu.aniLen / ypSlideOutMenu.aniLen 
// set event handlers.
if (this.ns4) this.menu.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT);
this.menu.onmouseover = new Function("ypSlideOutMenu.showMenu('" + this.id + "')")
this.menu.onmouseout = new Function("ypSlideOutMenu.hideMenu('" + this.id + "')")
//set initial state
this.endSlide()
}
}
ypSlideOutMenu.showMenu = function(id)
{
var reg = ypSlideOutMenu.Registry
var obj = ypSlideOutMenu.Registry[id]
if (obj.container) {
obj.over = true
for (menu in reg) if (id != menu) ypSlideOutMenu.hide(menu)
if (obj.hideTimer) { reg[id].hideTimer = window.clearTimeout(reg[id].hideTimer) }
if (!obj.open && !obj.aniTimer) reg[id].startSlide(true)
}
}
ypSlideOutMenu.hideMenu = function(id)
{
var obj = ypSlideOutMenu.Registry[id]
if (obj.container) {
if (obj.hideTimer) window.clearTimeout(obj.hideTimer)
obj.hideTimer = window.setTimeout("ypSlideOutMenu.hide('" + id + "')", ypSlideOutMenu.hideDelay);
}
}
ypSlideOutMenu.hideAll = function()
{
var reg = ypSlideOutMenu.Registry
for (menu in reg) {
ypSlideOutMenu.hide(menu);
if (menu.hideTimer) window.clearTimeout(menu.hideTimer);
}
}
ypSlideOutMenu.hide = function(id)
{
var obj = ypSlideOutMenu.Registry[id]
obj.over = false
if (obj.hideTimer) window.clearTimeout(obj.hideTimer)
obj.hideTimer = 0
if (obj.open && !obj.aniTimer) obj.startSlide(false)
}
ypSlideOutMenu.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()", ypSlideOutMenu.minCPUResolution)
}
ypSlideOutMenu.prototype.slide = function() {
var elapsed = (new Date()).getTime() - this.startTime
if (elapsed > ypSlideOutMenu.aniLen) this.endSlide()
else {
var d = Math.round(Math.pow(ypSlideOutMenu.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)
}
}
ypSlideOutMenu.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)
}
if (this.open) eval(this.StartFunction)
}
ypSlideOutMenu.prototype.setVisibility = function(bShow) { 
var s = this.ns4 ? this.container : this.container.style
s.visibility = bShow ? "visible" : "hidden"
}
ypSlideOutMenu.prototype.moveTo = function(p) { 
this.style[this.orientation == "h" ? "left" : "top"] = this.ns4 ? p : p + "px"
}
ypSlideOutMenu.prototype.getPos = function(c) {
return parseInt(this.style[c])
}
ypSlideOutMenu.prototype.onactivate = function() { }
ypSlideOutMenu.prototype.ondeactivate = function() {
  eval(this.EndFunction)
}


/**************************************************
 * dom-drag.js
 * 09.25.2001
 * www.youngpup.net
 **************************************************
 * 10.28.2001 - fixed minor bug where events
 * sometimes fired off the handle, not the root.
 **************************************************/

var Drag = {

	obj : null,

	init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
	{
		o.onmousedown	= Drag.start;

		o.hmode			= bSwapHorzRef ? false : true ;
		o.vmode			= bSwapVertRef ? false : true ;

		o.root = oRoot && oRoot != null ? oRoot : o ;

		if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
		if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";
		if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
		if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";

		o.minX	= typeof minX != 'undefined' ? minX : null;
		o.minY	= typeof minY != 'undefined' ? minY : null;
		o.maxX	= typeof maxX != 'undefined' ? maxX : null;
		o.maxY	= typeof maxY != 'undefined' ? maxY : null;

		o.xMapper = fXMapper ? fXMapper : null;
		o.yMapper = fYMapper ? fYMapper : null;

		o.root.onDragStart	= new Function();
		o.root.onDragEnd	= new Function();
		o.root.onDrag		= new Function();
	},

	start : function(e)
	{
		var o = Drag.obj = this;
		e = Drag.fixE(e);
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		o.root.onDragStart(x, y);

		o.lastMouseX	= e.clientX;
		o.lastMouseY	= e.clientY;

		if (o.hmode) {
			if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
			if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
		} else {
			if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
			if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
		}

		if (o.vmode) {
			if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
			if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
		} else {
			if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
			if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
		}

		document.onmousemove	= Drag.drag;
		document.onmouseup		= Drag.end;

		return false;
	},

	drag : function(e)
	{
		e = Drag.fixE(e);
		var o = Drag.obj;

		var ey	= e.clientY;
		var ex	= e.clientX;
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		var nx, ny;

		if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
		if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
		if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
		if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);

		nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
		ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));

		if (o.xMapper)		nx = o.xMapper(y)
		else if (o.yMapper)	ny = o.yMapper(x)

		Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
		Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
		Drag.obj.lastMouseX	= ex;
		Drag.obj.lastMouseY	= ey;

		Drag.obj.root.onDrag(nx, ny);
		return false;
	},

	end : function()
	{
		document.onmousemove = null;
		document.onmouseup   = null;
		Drag.obj.root.onDragEnd(	parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), 
									parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
		Drag.obj = null;
	},

	fixE : function(e)
	{
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	}
};