var JS_PATH = "/js/";

/********************************************************************************

	Misc. User Agent setup and debug functions

********************************************************************************/
//	use( string )includes ancilliary thing class files that aren't loaded by default:
//	thing.clip, thing.mouse, thing.sequence, thing.slide, thing.unroll, thing.write
function use( what ){
	what = what.toLowerCase();
	if( ! usedFiles[what] )
		document.write( '<script type="text/javascript" src="' + JS_PATH + what + '.js"></script>\n' );
	usedFiles[ what ] = true;
}
var usedFiles = new Array();

window.origInit = window.init;
if( window.origInit == null ) window.origInit = function(){}
init = function( fcn ){
	// alert( 'in init: fcn is ' + fcn );
	if( ! window.initFunctions )
		window.initFunctions = new Array();
	if( typeof(fcn) == "string")
		window.initFunctions[ window.initFunctions.length ] = fcn;
	else{
		origInit();
		for( var i=0; i<window.initFunctions.length; i++ ){
			// alert( 'eval(' + window.initFunctions[i] + ')' );
			eval(window.initFunctions[i]);
		}
	}
}
onload=init

function puke( it, showValues, showEmpty ){
	var s = '';
	for( var i in it ){
		if( typeof(it[i]) != 'function' )
			if( showEmpty || it[i] ){
				s += '\n' + i + ' ';
				if( showValues ) s += it[i];
			}
	}
	alert(s);
}

function Is(){
	var appName = navigator.appName;
	var version = navigator.appVersion;
	
	this.ns = ( appName == "Netscape" );
	this.ns4 = this.ns && version.indexOf("4.")!=-1;
	this.ns5 = this.ns && version.indexOf("5.")==0;
	this.ns6 = ( this.ns5 || (this.ns && version.indexOf("6.")!=-1) );

	this.ie = ( appName == "Microsoft Internet Explorer" );
	this.ie4 = this.ie && version.indexOf("MSIE 4.")!=-1;
	this.ie5 = this.ie && version.indexOf("MSIE 5.")!=-1;
	this.ie6 = this.ie && version.indexOf("MSIE 6.")!=-1;
	
	var userAgent = navigator.userAgent.toLowerCase()
	this.mac = ( userAgent.indexOf( "mac" ) != -1 )
	this.win = ( userAgent.indexOf( "windows" ) != -1 )
	this.linux = ( userAgent.indexOf( "linux" ) != -1 )
}
Is.prototype.toString = function(){
	var s = ''
	for( var i in this ){
		s += i + ': ' + this[i] + '\n'
	}
	return s;
}
var is = new Is();

//resize fix for netscape 4
function resize(){
		if ( scrW != window.innerWidth || scrH != window.innerHeight )
			location.reload()
}
if ( is.ns4 ){
	var scrW = window.innerWidth;
	var scrH = window.innerHeight;
	onresize=resize;
}

/********************************************************************************

	Point Objects

********************************************************************************/
function Point( /* x,y or p */ ){
	if( Point.isPoint(arguments[0]) ){
		this.x = arguments[0].x;
		this.y = arguments[0].y;
	}
	else{
		this.x = arguments[0];
		this.y = arguments[1];
	}
}
Point.isPoint = function(what){
	return ( what.constructor == Point );
}
Point.prototype.getArgs = function( /* [[x,y]] or [[p]] */ ){
	return new Point( arguments[0][0], arguments[0][1] )
}

Point.prototype.add = function( /* x,y or p */ ){
	var that = this.getArgs( arguments )
	return new Point( this.x + that.x, this.y + that.y );
}
Point.prototype.sub = function( /* x,y or p */ ){
	var that = this.getArgs( arguments )
	return new Point( this.x - that.x, this.y - that.y );
}
Point.prototype.mult = function( mult ){
	return new Point( mult * this.x, mult * this.y);
}
Point.prototype.perp = function(){
	return new Point( - this.y, this.x )
}
Point.prototype.distTo = function( /* x,y or p */ ){
	var that = this.getArgs( arguments )
	var dx = this.x - that.x;
	var dy = this.y - that.y;
	if( dx == 0 ) return Math.abs(dy);
	if( dy == 0 ) return Math.abs(dx);
	return Math.sqrt( dx*dx + dy*dy );
}
Point.prototype.size = function(){
	var p = new Point(0,0);
	return this.distTo( p )
}
Point.prototype.toString = function(){
	return '(' + this.x + ', ' + this.y + ')';
}
Point.prototype.isInRect = function( t, r, b, l ){
	return ( this.y > t && this.x < r && this.y < b && this.x > l );
}

function Rect( t, r, b, l ){
	this.t = t; 
	this.r = r;
	this.b = b;
	this.l = l;
}
Rect.prototype.toString = function(){
	return "(" + this.t + ", " + this.r + ", " + this.b + ", " + this.l + ")";
}


/********************************************************************************

	Thing Class

	Initialization
		Thing.init()                  -- looks through document & gets all divs ending in "Div"
	                                     adds that to the Thing.all array without the "Div"
	Member Variables
		myThing.name                   -- "myThing"
		myThing.id                     -- "myThingDiv"
		myThing.div                    -- the actual html object
		myThing.style                  -- the style of the object
		myThing.position               -- a Point with the thing's position
		myThing.size                   -- a Point with the thing's size

********************************************************************************/
init( "Thing.init()" );

function Thing( div ){
	this.id = div.id;
	this.name = div.id.replace(/Div/, "");

	this.div = div;
	this.style = ( is.ns4 ) ? this.div : this.div.style;

	this.position = this.getPosition();
	this.size = this.getSize();
}

Thing.add = function( div ){
	var name = div.id.slice(0, -3);
	if( div.id == name + "Div" ){
		Thing.all[ name ] = new Thing( div );
		eval( name + " = Thing.all." + name );
	}
}
Thing.all = new Array();
Thing.init = function( doc ){
	this.isLoaded = true;
	if( document.layers ){
		if( doc == null ) doc = document;
		for( var i=0; i<doc.layers.length; i++ ){
			Thing.add( doc.layers[i] );
			Thing.init( doc.layers[i].document );
		}
		return true;
	} 
	
	var allD = false;
	if( is.ie4 ) allD = document.all.tags("DIV")
	else if( is.ie5 || is.ie6 ) allD = document.getElementsByTagName("DIV");
	else if( is.ns6 ) allD = document.getElementsByTagName("DIV");
	
	if( allD ){
		for( var i=0; i<allD.length; i++ )
			Thing.add( allD[i] );
		return true;
	}
	return false;
}

/********************************************************************************

	Style Initialization

		Point      myThing.getPosition();   -- set this.position and return it
		Point      myThing.getSize();       -- set this.size and return it
		
********************************************************************************/
if( is.ns4 ) 
	Thing.prototype.getPosition = function(){
		this.position = new Point(
			parseInt(this.style.left),
			parseInt(this.style.top)
		);
		return this.position;
	}
else
	Thing.prototype.getPosition = function(){
		this.position = new Point(
			parseInt(this.div.offsetLeft),
			parseInt(this.div.offsetTop)
		);
		return this.position;
	}
	
if( is.ns4 )
	Thing.prototype.getSize = function(){
		this.size = new Point(
			this.div.document.width,
			this.div.document.height 
		);
		return this.size;
	}
else if( is.ie4 )
	Thing.prototype.getSize = function(){
		this.size = new Point(
			parseInt( this.div.scrollWidth ), 
			parseInt( this.div.scrollHeight )
		);
		return this.size;
	}
else
	Thing.prototype.getSize = function(){
		this.size = new Point(
			parseInt(this.div.offsetWidth),
			parseInt(this.div.offsetHeight)
		);
		this.style.offsetWidth = this.size.x;
		this.style.offsetHeight = this.size.y;
		return this.size;
	}

/********************************************************************************

	Position Manipulation
	
		myThing.setPosition()          -- updates the html object to match the position
		                                  called by moveTo, moveBy, etc
		myThing.moveTo(p)              -- move to point
		myThing.moveTo(x,y)            -- move to specified location
		myThing.moveBy(p)              -- move by point values
		myThing.moveBy(x,y)            -- move by specified increments

********************************************************************************/
	Thing.prototype.setPosition = function(){
		this.style.left = this.position.x;
		this.style.top = this.position.y;
	}
	Thing.prototype.moveTo = function( /*x,y or p*/ ){
		this.position = new Point( arguments[0], arguments[1] )
		this.setPosition();
	}
	Thing.prototype.moveBy = function( /*x,y or p*/ ){
		this.position = this.position.add( arguments[0], arguments[1] )
		this.setPosition();
	}

/********************************************************************************

	Visibility Manipulation
	
		myThing.show()                 -- show the div
		myThing.hide()                 -- hide the div
		myThing.isVisible()            -- return true if visible, false if not
		myThing.toggle()               -- hide if visible, show if not
		
********************************************************************************/

	Thing.prototype.show = function(){
		this.style.visibility = "visible";
	}
	Thing.prototype.hide = function(){
		this.style.visibility = "hidden";
	}
	Thing.prototype.isVisible = function(){
		return ( this.style.visibility.indexOf("d") == -1 );
	}
	Thing.prototype.toggle = function(){
		return ( this.isVisible() ) ? this.hide() : this.show();
	}
	
/********************************************************************************

	Miscellaneous Manipulation
	
		myThing.setBackground( color ) -- set the bgcolor to "color"		

		myThing.getZindex()            -- get the zIndex
		myThing.setZindex( n )         -- set the zIndex to n

********************************************************************************/
if ( is.ns4 )
	Thing.prototype.setBackground = function( color ){
		this.div.document.bgColor=color;
	}
else
	Thing.prototype.setBackground = function( color ){
		this.style.backgroundColor = color;
	}
	
	Thing.prototype.setZindex = function( n ){
		this.style.zIndex = n;
	}

/********************************************************************************	
 	Image Flip usage : 
 		Change OFF_SUFFIX and ON_SUFFIX to match image names.
 		
 		For each image which is to be flipped, document.onload should call
 			flip.myFlipName = new Flip( myImageName, myImageSource )
 		To turn image on, call 
 			flip.myFlipName.on()
 		To turn image off, call
 			flip.myFlipName.off()
********************************************************************************/
init( "Flip.init()" )
var IMAGE_OFF_SUFFIX = "_off.gif"
var IMAGE_ON_SUFFIX = "_on.gif"

var flip = new Array();
function Flip( imgName, imgSrc, doc ){
	this.docImg = getDocImg(imgName, doc);
	if( this.docImg ){
		this.imgOff = new Image( this.docImg.width, this.docImg.height )
		this.imgOffsrc = this.imgOff.src = this.docImg.src;
		
		this.imgOn = new Image ( this.docImg.width, this.docImg.height )
		this.imgOnsrc = this.imgOn.src = ( imgSrc != null ) ? imgSrc : this.docImg.src.replace( IMAGE_OFF_SUFFIX, IMAGE_ON_SUFFIX )	}
	else{
		this.imgOff = this.imgOn = new Image();
		this.imgOffSrc = this.imgOnSrc = '';
	}
}

Flip.prototype.on = function(force){
	if( force ){
		this.imgOn.src = "";
		this.docImg.src = this.imgOnsrc;
	}
	else if( this.imgOn.src ){
			this.docImg.src = this.imgOn.src;
	}
	if ( this.status )
		window.status = this.status;
	return true;
}

Flip.prototype.off = function(force){
	if( force ){
		this.imgOff.src = "";
		this.docImg.src = this.imgOffsrc;
	}
	else if( this.imgOff.src ){
		this.docImg.src = this.imgOff.src;
	}
	window.status = "";
	return true;
}
Flip.prototype.killFlip = function( newSrc ){
	var fixedImgSrc
	if ( newSrc == "on" )
		fixedImgSrc = this.imgOn.src
	else if ( newSrc == "off" )
		fixedImgSrc = this.imgOff.src
	else
		fixedImgSrc = newSrc
	this.imgOff.src = this.imgOn.src = this.docImg.src = fixedImgSrc;
}
Flip.prototype.resurect = function(){
	this.imgOff.src = this.imgOffsrc;
	this.imgOn.src = this.imgOnsrc;
	this.docImg.src = this.imgOffsrc;
}
function getDocImg(name, d){
	d = ( d == null ) ? document : d; //set d to be the document if empty
	var img = d.images[name];
	if (img) return img; //found it
	
	if ( ! document.layers ) return null; //in ie, we die here
	
	for ( var i=0; i < d.layers.length; i++ ) 
		if ( d.layers[i].id ){
			img = getDocImg( name, d.layers[i].document )  //recursive call
				if (img) return img; //found it
		}
	return null; //did not find it
}
function mouseover(name){
	if (flip[name])
		flip[name].on()
}
function mouseout(name){
	if (flip[name])
		flip[name].off()
}
Flip.init = function( d ){
	if( d == null ) d = document;
	for ( var i = 0; i < d.images.length; i++ ){
		var src = d.images[i].src
		if ( d.images[i].name ){
			if ( src.indexOf( IMAGE_OFF_SUFFIX ) != -1 ){
				flip[ d.images[i].name ] = new Flip( d.images[i].name, null, d )
			}
		}
	}
	if ( !document.layers ) return;
	for ( var i=0; i < d.layers.length; i++ ) 
		Flip.init( d.layers[i].document )  //recursive call
}

