// * *
// * gzlib.js version 0.2
// * by eric@groundzero.com
// *
// * if you are thinking about changing this file please stop and ask eric
// * first. page-specific scripts should go in a seperate file. thanks
// *


// * *
// * constants
// *

var ROLL_OVER_ON = "_on";
var ROLL_OVER_OFF = "";

var FRAMELENGTH = 10;
var FRAMERATE = 42;

var GRAVITY = .00442368;

// Earth = .027648
// Moon = .00442368

// * *
// * system functions
// *

var unnamed_object_count = 0;
var pid_count = 0;
var process_table = new Array();

var hear_resize = new Array();
var hear_resize_count = 0;
var hear_scroll = new Array();
var hear_scroll_count = 0;

var listening = false;

var event_listener_table = new Array();

var is_msie;
var scroll_string;

var eventListenerTable = new Array();


function respond(e){
	var actions;
	
	actions = this.event_listener_table[e.type];
	
	for(i=0; i<actions.length; i++){
		eval(actions[i]);
	}
}

function addResponse(event, process_string){
	
	process_string = process_string.toString().replace("this", this.id);
	

	if(!this.event_listener_table[event]){
		this.event_listener_table[event] = new Array();
		
		this.event_listener_table[event][0] = process_string;
	
		if(this.addEventListener){
			this.addEventListener(event, respond, false);
		}
		else if(this.attachEvent){
			this.attachEvent("on" + event, function(){if(window.event.srcElement){window.event.srcElement.respond(window.event);}else{window.respond(window.event);}});
		}
		else {
			eval("this.on" + event + " = function(){if(window.event.srcElement){window.event.srcElement.respond(window.event);}else{window.respond(window.event);}}");
		}
	}
	else{
		this.event_listener_table[event][this.event_listener_table[event].length] = process_string;
	}
	
}

function gzlibInitialize(){
	var all_tags;

	all_tags = document.getElementsByTagName("*");
	
	if(navigator.userAgent.indexOf("MSIE") != -1){
		is_msie = true;
	}
	
	if(document.documentElement && document.documentElement.scrollTop){
		scroll_string = "document.documentElement.scroll";
	}
	else {
		scroll_string = "document.body.scroll";
	}
	
	for(i=0; i<all_tags.length; i++){
		if(all_tags[i].id){
			if(!eval("window." + all_tags[i].id)){
				eval(all_tags[i].id + " = all_tags[i]");
			}
						
			all_tags[i].event_listener_table = new Array();
			all_tags[i].addResponse = addResponse;
			all_tags[i].respond = respond;
			
			all_tags[i].getApparentStyle = getApparentStyle;
			all_tags[i].getStyle = getStyle;
			all_tags[i].setStyle = setStyle;
			
			all_tags[i].moveTo = moveTo;
			all_tags[i].moveToScreenFloor = moveToScreenFloor;
			
			all_tags[i].show = show;
			all_tags[i].hide = hide;
			
			all_tags[i].setRoll = setRoll;
			all_tags[i].rollOn = rollOn;
			all_tags[i].rollOff = rollOff;
			
			all_tags[i].changeTextSize = changeTextSize;
			all_tags[i].changeTextSize_core = changeTextSize_core;
			
			if(all_tags[i].id.indexOf("rollover") != -1){
				all_tags[i].setRoll();
				all_tags[i].addResponse("mouseover", "this.rollOn()");
				all_tags[i].addResponse("mouseout", "this.rollOff()");	
			}
			
			if(all_tags[i].id.indexOf("rollclass") != -1){
				all_tags[i].addResponse("mouseover", "this.className='" + all_tags[i].className + ROLL_OVER_ON + "'");
				all_tags[i].addResponse("mouseout", "this.className='" + all_tags[i].className + ROLL_OVER_OFF + "'");	
			}
			
			if(all_tags[i].id.indexOf("text") != -1){
				for(var j in all_tags[i].parentNode.event_listener_table){
					all_tags[i].addResponse(j,all_tags[i].parentNode.event_listener_table[j]);
				}
			}
			
			if(is_msie && (all_tags[i].getApparentStyle("position") == "fixed")){
				var x, y;

				x = all_tags[i].offsetLeft;		
				y = all_tags[i].offsetTop;		

				all_tags[i].setStyle("position", "absolute");
				
				all_tags[i].fixed_x = x;
				all_tags[i].fixed_y = y;
				all_tags[i].moveTo(x,y);
				
				//addResponse("scroll", all_tags[i].id + ".moveTo(" + all_tags[i].id + ".fixed_x," + all_tags[i].id + ".fixed_y)");
			}
		}
	}
}

function getApparentStyle(property, include_units){
	var rval;
	
	if(!property){
		property = "";
	}
	else{
		property = "." + property;
	}
	
	if(this.currentStyle){
		rval = eval("this.currentStyle" + property);
	}
	else {
		rval = eval("document.defaultView.getComputedStyle(this,\"\")" + property);
	}
	
	if(!include_units && parseInt(rval.charAt(0)) >= 0){
		rval = parseInt(rval);
	}
	
	return rval;
}

function getStyle(property, include_units){
	var rval;
	
	if(!property){
		rval = this.style;
	}
	else{
		rval = eval("this.style." + property);
		
		if(!include_units && parseInt(rval.charAt(0))>=0){
			rval = parseInt(rval);
		}	
	}
	
	return rval;
}

function setStyle(property, value){
	if(property == "left" && this.fixed_x != null){
		this.fixed_x = value;
		value = eval(scroll_string + "Left") + this.fixed_x;		
	}
	else if(property == "top" && this.fixed_y != null){
		this.fixed_y = value;
		value = eval(scroll_string + "Top") + this.fixed_y;		
	}
	
	if(value) eval("this.style." + property + " = '" + value + "'");
}

function moveTo(x, y){
	this.setStyle("left", x);
	this.setStyle("top", y);
}

function moveToScreenFloor(){
	var fix;
	
	if(navigator.appName == "Microsoft Internet Explorer" && navigator.platform == "Win32"){
		fix = 4;	
	}
	else{
		fix = 0;
	}
	
	if(window.innerHeight){
		this.setStyle("top", window.innerHeight - this.getApparentStyle("height") - fix);
	}
	else {
		this.setStyle("top", document.body.offsetHeight - this.getApparentStyle("height") - fix);
	}
}

function hide(){
	this.setStyle("visibility", "hidden");
}

function show(){
	this.setStyle("visibility", "visible");
}

function setRoll(){
	var src_length, file_suffix_location;
	
	this.old_src = this.src;
	
	src_length = this.src.length;
	file_suffix_location = this.src.lastIndexOf(".");
	this.new_src = this.src.substring(0,file_suffix_location)
		+ ROLL_OVER_ON
		+ this.src.substring(file_suffix_location, src_length);
}

function rollOn(){
	this.src = this.new_src;
}

function rollOff(){
	this.src = this.old_src;
}

function changeTextSize_core(object, increment){
	var original_font_size, original_line_height, original_style;

	for(i=0; i<object.childNodes.length; i++){
		this.changeTextSize_core(object.childNodes[i], increment);
	}

	if(object.style){
		
		if(object.currentStyle){
			original_style = this.currentStyle;
		}
		else {
			original_style = document.defaultView.getComputedStyle(this,"");
		}
		
		var new_font_size;
		
		new_font_size = original_style.fontSize + increment;
	
		object.style.lineHeight = new_font_size * original_style.lineHeight / original_style.fontSize 
		object.style.fontSize = new_font_size;
	}
}

function changeTextSize(increment){
	var all_children, font_sizes, line_heights;
	
	all_children = this.getElementsByTagName("*");
	font_sizes = new Array();
	line_heights = new Array();
	
	for(i=0; i<all_children.length; i++){
		var original_style;
		
		if(all_children[i].currentStyle){
			original_style = all_children[i].currentStyle;
		}
		else {
			original_style = document.defaultView.getComputedStyle(all_children[i],"");
		}
		
		font_sizes[i] = original_style.fontSize;
		line_heights[i] = original_style.lineHeight;
	
	}
	
	for(i=0; i<all_children.length; i++){
		
		
		if(!font_sizes[i]) continue;	
		
		var new_font_size, lh_ratio;
		
		new_font_size = parseInt(font_sizes[i]) + increment;
	
		li_ratio = parseInt(line_heights[i]) / parseInt(font_sizes[i])
	
		all_children[i].style.lineHeight = Math.round(new_font_size * li_ratio) + "px";
	
		all_children[i].style.fontSize = new_font_size+"px";
	}
}