
var inits = new Array(); 
function init(){
	setHeight();
	window.onresize = setHeight;
	
	if (de('menu')) menu = new Menu;

/*	var banner = de('banner');
	// Horizontal grey lines
	for (var i=0;i<=100;i+=20){
		var line = newElement('DIV', banner).addClass('h_line');
		line.style.top = (20 + i) +'px';
		}

	// Vertical grey lines
	for (var i=0;i<=90;i+=15){
		var line = newElement('DIV', banner).addClass('v_line');
		line.style.left = (35 + i) +'px';
		}
*/
	for (var i=0;i<inits.length;i++){
		inits[i]();
		}
	}

function setHeight(){
	var doc_height = ie?document.body.clientHeight:window.innerHeight;
	var content_height = (de('content').offsetHeight+de('header').offsetHeight+de('banner').offsetHeight);
	if (content_height > doc_height) doc_height = content_height;
	if (de('menu')) de('menu').style.height = doc_height + 'px';
	var webres_frame = de('webres');
	if (webres_frame && webres_frame.tagName == 'IFRAME'){
		var new_content_height = doc_height - 
					de('header').offsetHeight - 
					de('banner').offsetHeight;
		if (!ie) new_content_height = new_content_height - 2;
		webres_frame.style.height = new_content_height + 'px';
		var doc_width = ie?document.body.clientWidth:window.innerWidth;
		webres_frame.style.width = doc_width - de('menu').offsetWidth + 'px';
		
		}
	}

var menu;

function Menu(){
	function ActivateItem(){
		// We're still executing the last move
		if (menu.moving_items) return false;

		if (menu.current_item && menu.current_item.submenu){
			for (var i=0;i<menu.current_item.submenu.length;i++){
				menu.current_item.submenu[i].style.display = 'none';
				}
			}
		if (!this.submenu) return;
		menu.current_item = this;

		menu.moving_items = new Array();
		/* Rate of movement = distance / 20 - the time constant
		   This may not seem to need to be calced always,
		   but start_pos != offsetTop always (e.g. after already Activating) */
		for (var i=menu.items.length-1;i>=0;i--){
			var c_item = menu.items[i];
			var reverse_i = menu.items.length - 1 - i;

			// Below the item clicked, so we move it down, proportionally
			if (i > this.item_index)
				c_item.end_pos = c_item.start_pos + (20 * reverse_i);
			// The item clicked or above, so we move it up, proportionally
			else 	c_item.end_pos = c_item.start_pos - (20 * i);

			if (c_item.end_pos != c_item.offsetTop)
				menu.moving_items.push(c_item);
			}

		menu.v_line.rate = 0;
		// The v_line needs to be moved
		if (!menu.v_line.offset) menu.v_line.rate = -2;

		if (!menu.moving_items.length){
			// The v_line needs to be restored
			if (menu.v_line.offset) menu.v_line.rate = 2;
			for (var i=0;i<menu.items.length;i++){
				var c_item = menu.items[i];
				c_item.end_pos = c_item.start_pos;
				if (c_item.end_pos != c_item.offsetTop)
					menu.moving_items.push(c_item);
				}
			}
		for (var i=0;i<menu.moving_items.length;i++){
			var c_item = menu.moving_items[i];
			c_item.increment = (c_item.end_pos-c_item.offsetTop)/20
			}

		menu.active_item = this;
		menu.moving_interval = window.setInterval('menu.MoveItems()', 10);

		return false;
		}

	// Should always be called 20 times, with the least of the objects moved 20px
	function MoveItems(){
		var done=0;
		if ((menu.v_line.rate < 0 && menu.v_line.offset < 30) ||
		    (menu.v_line.rate > 0 && menu.v_line.offset > 0)){
			menu.v_line.style.left = menu.v_line.offsetLeft + menu.v_line.rate + 'px';
			menu.v_line.offset -= menu.v_line.rate;
			}

		for (var i=0;i<menu.moving_items.length;i++){
			var c_item = menu.moving_items[i];
			c_item.style.top = c_item.offsetTop + c_item.increment + 'px'; 
			if (c_item.offsetTop == c_item.end_pos){
				done++;
				}
			}

		if (++menu.call_iterations > 21){
			done = 1;
			}

		if (done || !menu.moving_items.length){
			window.clearInterval(menu.moving_interval);
			menu.moving_items = null;
			menu.submenu_iterations = 0;
			if (menu.v_line.offset)
			menu.submenu_interval = window.setInterval('menu.Display_Submenu()', 100);
			}
		}
	this.MoveItems = MoveItems;

	function Display_Submenu(){
		var submenu = menu.current_item.submenu;
		for (var i=0;i<submenu.length;i++){
			if (submenu[i].style.display != 'block'){
				submenu[i].style.top = menu.current_item.offsetTop + 20*(i+1) +'px';
				submenu[i].style.display = 'block';
				shown = 1;
				break;
				}
			}
		if (++menu.submenu_iterations >= submenu.length)
			window.clearInterval(menu.submenu_interval);
		}
	this.Display_Submenu = Display_Submenu;
	
	this.holder = de('menu');

	// Vertical grey lines
	for (var i=-45;i<=45;i+=15){
		var line = newElement('DIV', this.holder).addClass('v_line');
		line.style.left = (line.offsetLeft + i) +'px';
		}

	// Horizontal grey lines
	for (var i=-140;i<=140;i+=20){
		var line = newElement('DIV', this.holder).addClass('h_line');
		line.style.top = (line.offsetTop + i) +'px';
		}

	// Vertical green line
	this.v_line = newElement('DIV', this.holder).addClass('v_line', 'v_green');
	// Used to show that the green_line is to the left
	this.v_line.offset = 0;

	var divs = this.holder.getElementsByTagName('DIV');
	this.items = new Array();
	for (var i=divs.length-1;i>=0;i--){
		if (hasClass(divs[i], 'item') && !hasClass(divs[i], 'sub_item')){
			var c_item = divs[i];
			c_item.start_pos = c_item.offsetTop;
			c_item.style.top = c_item.offsetTop + 'px';
			c_item.style.marginTop = 0;
			c_item.style.position = 'absolute';
			if (c_item.getAttribute('activate')) window.activate_item = c_item;
			this.items.push(c_item);
			c_item.onclick = ActivateItem;
			// Horizontal green lines, must move with the cross
			newElement('DIV', c_item).addClass('h_green');
			var next_item = sibling_ofTag(c_item, 'DIV');
			if (next_item.className == 'submenu'){
				c_item.submenu = new Array();
				var s = 0;
				for (var si=next_item.firstChild;si;si=si.nextSibling){
					if (si.className && hasClass(si, 'sub_item'))
						c_item.submenu[s++] = si;
					}
				}
			}
		}

	this.items.reverse();
	for (var i in this.items) this.items[i].item_index = i;

	if (window.activate_item) window.inits.push(function(){window.activate_item.onclick()});

	return this;
	}
 
var inits = new Array();
var ie = (navigator.userAgent.toLowerCase().indexOf('msie')!=-1)?1:0;
var safari = (navigator.userAgent.toLowerCase().indexOf('safari')!=-1)?1:0;

// Set up all prototypes the same way.
window.prototypes = new Object();
function addPrototype(name, applyTo){
	if (!applyTo) applyTo = 'ALL';
	else applyTo = applyTo.toUpperCase();
	if (!window.prototypes[applyTo]) window.prototypes[applyTo] = new Object();
	window.prototypes[applyTo][name] = window[name+'_prototype'];
	}

function make_bindable(obj){
	if (obj._bindings) return;
	obj.set = _setter;
	obj.add = _array_add;
	obj._bindings = new Object;
	}
function _setter(props){
	for (var prop in props){
		this[prop] = props[prop];
		if (this._bindings[prop]){
			for (var i=0;i<this._bindings[prop].length;i++){
				var bind_to = this._bindings[prop][i];
				bind_to.SetValue(prop, props[prop]);
				}
			}
		}
	}
function _array_add(arrs){
	for (var arr in arrs){
		var add_item = arrs[arr];
		this[arr].push(add_item);
		if (this._bindings[arr]){
			for (var i=0;i<this._bindings[arr].length;i++){
				var bind_to = this._bindings[arr][i];
				bind_to.NewItem({object:add_item});
				}
			}
		}
	}
function reset_bindings(obj){
	for (var binding in obj._bindings){
		for (var i=0;i<obj._bindings[binding].length;i++){
			var bind_to = obj._bindings[binding][i];
			if (typeof obj[binding] == 'object'){
				while (bind_to.items.length){
					bind_to.items[0].Delete();
					}
				}
			else {
				bind_to.value = '';
				}
			}
		}
	}
function set_bindings(obj){
	for (var binding in obj._bindings){
		for (var i=0;i<obj._bindings[binding].length;i++){
			var bind_to = obj._bindings[binding][i];
			if (typeof obj[binding] == 'object')
				for (var i=0;i<obj[binding].length;i++)
					bind_to.NewItem({object:obj[binding][i]});
			else bind_to.value = obj[binding];
			}
		}
	}
function update_binders(){
	for (var bind_prop in this.binding){
		var bind_to = this.binding[bind_prop];
		bind_to[bind_prop] = this.value;
		}
	}

function de(o, dment){
	var obj;
	if (!dment) dment = document;
	if (obj = dment.getElementById(o)){
		return obj;
		}

	return false;
	}

function next_element(obj,i){
	if (! i ) i = 0;
	var c = 0;
	var next_node;
	while ( next_node = obj.nextSibling ){
		if ( next_node.nodeType == 1 ){
			if ( c == i ) return next_node;
			if ( c++ > i ) break;
			}
		obj = obj.nextSibling;
		}
	return false;
	}

function child_ofTag(obj){
        for (var i=obj.firstChild;i;i=i.nextSibling){
                if (i.tagName)
                  for (var a=1;a<arguments.length;a++) if (i.tagName == arguments[a]) return i;
                }
        return false;
        }

function sibling_ofTag(obj){
        for (var i=obj.nextSibling;i;i=i.nextSibling){
                if (i.tagName)
                  for (var a=1;a<arguments.length;a++) if (i.tagName == arguments[a]) return i;
                }
        return false;
        }

function child_ofClass(obj, cName){
	if ( obj.nodeType == 3 ) return false;
	if (hasClass(obj, cName)) return obj;
	for (var i=obj.firstChild;i;i=i.nextSibling){
		if ( i.nodeType == 3) continue;
		var t = child_ofClass(i, cName);
		if (t) return t;
		}
	return false;
	}

function hasClass(obj, cName){
	if (obj.className.match("\\b"+cName+"\\b")) return 1;
	return false;
	}

function newElement(tag, parent){
	if (!parent) parent = document.body;
	var element = document.createElement(tag);
	if (parent != -1) parent.appendChild(element);
	var tags = ['ALL', tag.toUpperCase()];
	for (i in tags){
		for (j in window.prototypes[tags[i]]){
			element[j] = window.prototypes[tags[i]][j];
			}
		}
	return element;
	}
function newText(text, parent){
	var t_o = document.createTextNode(text);
	parent.appendChild(t_o);
	return t_o;
	}
function addClass_prototype(){
	for (var i=0;i<arguments.length;i++) this.className += (i<arguments.length?' ':'')+arguments[i];
	return this;
	}
addPrototype('addClass');

function removeClass_prototype(){
	for (var i=0;i<arguments.length;i++){
        	if (this.className == arguments[i]) this.className = '';
        	else this.className = this.className.replace(' '+arguments[i], '');
		}
	return this;
	}
addPrototype('removeClass');

function setStyle_prototype(selector, value){
	if (value == 'center') this.setCenter(selector);
	else this.style[selector] = value;
	if (safari
	 && (selector == 'width' || selector == 'height')
	 && (value.match(/px/))){
		var prop = selector == 'width'?'offsetWidth':'offsetHeight';
		var int_value = parseInt(value);
		if (int_value != this[prop] && int_value){
			var new_value = (int_value - (this[prop]-int_value)) + 'px';
			this.style[selector] = new_value;
			}
		}

	}
addPrototype('setStyle');

function pixelLeft_prototype(to_element){
	var o = this;
	var i = o.offsetLeft;
	while ((o=o.parentNode)&&(o!=to_element)) if (o.offsetLeft) i += o.offsetLeft;
	return i;
	}
addPrototype('pixelLeft', 'DIV');

function pixelTop_prototype(to_element){
	var o = this;
	var i = o.offsetTop;
	while ((o=o.parentNode)&&(o!=to_element)) if (o.offsetTop) i += o.offsetTop;
	return i;
	}
addPrototype('pixelTop', 'DIV');

function setCenter_prototype(dir){
	var offset, length;
	var parent = document.body;
	if (this.parent) parent = this.parent.content || this.parent;
	if (dir == 'left'){
		offset = this.clientWidth/2;
		length = parent.clientWidth/2;
		}
	else {
		offset = (this.clientHeight)/2;
		length = ((parent.clientHeight||window.innerHeight)-(parent==document.body?30:0))/2;
		}
	this.style[dir] = Math.floor(length - offset) + 'px';
	}
addPrototype('setCenter');

var dragee;
var current_action;
function startDrag(e){
	e = get_event(e);
	if (current_action && current_action != 'dragging') return;
	var win = this.win || this;
	if (win.maximized) return;
	current_action = 'dragging';
	if (win.win_object) win.win_object.setActive();
	else dragee = win;

	dragee.offset_x = e.clientX - dragee.offsetLeft;
	dragee.offset_y = e.clientY - dragee.offsetTop;

	document.onmousemove = doDrag;
	document.onmouseup = endDrag;
	}
function endDrag(){
	current_action = null;
	document.onmousemove = null;
	document.onmouseup = null;
	}
function doDrag(e){
	e = get_event(e);

	dragee.style.left = e.clientX - dragee.offset_x + 'px';
	if (e.clientY > 0 && (!taskbar || e.clientY < taskbar.bar.offsetTop)) 
		dragee.style.top = e.clientY - dragee.offset_y + 'px';
	}
function makeDragable_prototype(){
	var drag_bar = this.drag_bar = this.titlebar || this;
	drag_bar.win = this;
	drag_bar.onmousedown = startDrag;
	}
addPrototype('makeDragable', 'DIV');

var resize_side;
function startResize(e){
	e = get_event(e);
	if (current_action && current_action != 'resizing') return;
	this.parentNode.win_object.setActive();
	if (match = this.className.match(/(\w*)_border/)){
		dragee.right_offset = (this.pixelLeft()+this.clientWidth)- e.clientX; 
		dragee.bottom_offset = (this.pixelTop()+this.clientHeight)- e.clientY;
		current_action = 'resizing';
		document.onmousemove = window['resize_'+match[1]];;
		document.onmouseup = endResize;
		}
	}
function endResize(){
	document.onmousemove = null;
	document.onmouseup = null;
	current_action = null;
	}
function resize_right(e){
	e = get_event(e);
	var new_width = (e.clientX+dragee.right_offset)-dragee.offsetLeft;
	if (new_width < 200) return;
	dragee.style.width = new_width + 'px';
	if (dragee.content_holder){
	  	dragee.content_holder.reset();
		}
	}
function resize_bottom(e){
	e = get_event(e);
	var new_height = (e.clientY+dragee.bottom_offset)-dragee.offsetTop;
	if (new_height < 75) return;
	dragee.style.height = new_height + 'px';
	if (dragee.content_holder){
	  	dragee.content_holder.reset();
		}
	}
function resize_corner(e){
	resize_bottom(e);
	resize_right(e);
	}
function makeResizable_prototype(){
	newElement('DIV', win).addClass('right_border').onmousedown = startResize;
	newElement('DIV', win).addClass('bottom_border').onmousedown = startResize;
	newElement('DIV', win).addClass('corner_border').onmousedown = startResize;
	if (this.content)
		this.content.onmousedown = function(){ this.win.win_object.setActive() };
	}
addPrototype('makeResizable', 'DIV');

function mouseoutClass(e){
	get_event(e);
	this.removeClass(this.hover_class);
	}
function mouseoverClass(e){
	get_event(e);
	this.addClass(this.hover_class);
	}
function mousedownClass(e){
	get_event(e);
	this.addClass(this.depress_class);
	}
function button_clicked(e){
	get_event(e);
	this.removeClass(this.depress_class);
	this.button_action();
	}
function makeButton_prototype(class_name, button_action){
	this.win = this.parentNode.parentNode;
	this.addClass(class_name, 'button');
	this.hover_class = 'button_hover';
	this.depress_class = 'button_depress';
	this.button_action = button_action;
	newElement('DIV', this);
	this.onmouseover = mouseoverClass;
	this.onmouseout = mouseoutClass;
	this.onmousedown = mousedownClass;
	this.onmouseup = button_clicked;
	}
addPrototype('makeButton');

function get_event(e){
	if (!e) e = window.event;
	if (!e) return;
        if (e.stopPropagation) e.stopPropagation();
        else e.cancelBubble = true;
	return e;
	}
function two_d(i){
	return i < 10 ? '0'+i : i;
	}

var req_objs = [];
var req_obj;
function server(url, args_array, debug){
	// Find a free request_obj
	req_obj = null;
	for (i in req_objs){
		if (req_objs[i].readyState != 4) continue;
		req_obj = req_objs[i];
		break;
		}
	if (!req_obj){
		req_obj = createXMLHttpRequest();
		//req_objs.push(req_obj);
		}

	if (! url.match(/\?/)) url += '?';
	else url += '&';
	if (!args_array) args_array = new Array();

	url = url.replace(/\+/g, '%2B');
	url = url.replace(/#/g, '%23');
	//url = '/' + url;
	if (debug) prompt('', url);

	req_obj.onreadystatechange = server_response;
	req_obj.open('POST', url, true);
	req_obj.send( obj2JSON(args_array) );
	}

function server_response(){
	if (req_obj.readyState != 4) return;
	try {
		eval(req_obj.responseText);
		}
	catch (e){
		alert('There was an error in the server response.\nSee red window.');
		var err = newElement('DIV');
		with (err.style){
			position= 'absolute';
			left= '5%';
			top= '5%';
			width ='90%';
			height ='90%';
			backgroundColor='white';
			border='5px solid red';
			zIndex = '999';
			}
		err.innerHTML = req_obj.responseText;
		}
	}

function createXMLHttpRequest(){
        try { return new ActiveZObject ("Msxml2.XMLHTTP"); } catch (e) {}
        try { return new ActiveXObject ("Microsoft.XMLHTTP"); } catch (e) {}
        try { return new XMLHttpRequest (); } catch (e) {};
        alert ("XMLHttpRequest not supported");
        return null;
        }

(function () {
    var m = {
            '\b': '\\b',
            '\t': '\\t',
            '\n': '\\n',
            '\f': '\\f',
            '\r': '\\r',
            '"' : '\\"',
            '\\': '\\\\'
        },
        s = {
            array: function (x) {
                var a = ['['], b, f, i, l = x.length, v;
                for (i = 0; i < l; i += 1) {
                    v = x[i];
                    f = s[typeof v];
                    if (f) {
                        v = f(v);
                        if (typeof v == 'string') {
                            if (b) {
                                a[a.length] = ',';
                            }
                            a[a.length] = v;
                            b = true;
                        }
                    }
                }
                a[a.length] = ']';
                return a.join('');
            },
            'boolean': function (x) {
                return String(x);
            },
            'null': function (x) {
                return "null";
            },
            number: function (x) {
                return isFinite(x) ? String(x) : 'null';
            },
            object: function (x) {
                if (x) {
                    if (x instanceof Array) {
                        return s.array(x);
                    }
                    var a = ['{'], b, f, i, v;
                    for (i in x) {
                        v = x[i];
                        f = s[typeof v];
                        if (f) {
                            v = f(v);
                            if (typeof v == 'string') {
                                if (b) {
                                    a[a.length] = ',';
                                }
                                a.push(s.string(i), ':', v);
                                b = true;
                            }
                        }
                    }
                    a[a.length] = '}';
                    return a.join('');
                }
                return 'null';
            },
            string: function (x) {
                if (/["\\\x00-\x1f]/.test(x)) {
                    x = x.replace(/([\x00-\x1f\\"])/g, function(a, b) {
                        var c = m[b];
                        if (c) {
                            return c;
                        }
                        c = b.charCodeAt();
                        return '\\u00' +
                            Math.floor(c / 16).toString(16) +
                            (c % 16).toString(16);
                    });
                }
                return '"' + x + '"';
            }
        };

    window.obj2JSON = function(obj){
        return s.object(obj);
    };

    window.array2JSON = function(obj){
        return s.array(obj);
    };
})();

String.prototype.parseJSON = function () {
    try {
        return (/^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/.test(this)) &&
            eval('(' + this + ')');
    } catch (e) {
        return false;
    }
};



  