

/**
 * The version of this javascript file (see _shared.php)
 */
var javascript_version = 14;


/**
 * Used for keeping key/value data in memory.
 *
 * By keeping data in key/value pairs, we keep the javascript files uncluttered.
 * Unfortunately dumping the debug info is a freaking pain!
 *
 * @see _get()
 * @see _set()
 */
var data_store = [];



function main()
{
	// ===============================================
	// CONFIG SECTION
	
	_set('debug', true);
	
	_set('closed_width', 16);
	_set('open_width',  340);

	_set('closed_height', 20);
	_set('open_height', 200);

	_set('size_step', 20);
	
	_set('slow_loop_speed', 200);
	_set('fast_loop_speed',  10);


	// This formula forces it to always be like 4 seconds
	_set('open_cycles', 4000 / _get('slow_loop_speed'));

	// CONFIG SECTION
	// ===============================================

	_set('compat.css', false);
	_set('compat.w3c', false);
	_set('compat.nn4', false);
	_set('compat.ie4', false);
	_set('compat.ie6', false);
	
	if (document.body && document.body.style)          { _set('compat.css', true); }
	if (_get('compat.css') && document.getElementById) { _set('compat.w3c', true); }
	if (document.layers)                               { _set('compat.nn4', true); }
	if (_get('compat.css') && document.all)            { _set('compat.ie4', true); }
	if (document.compatMode && (document.compatMode.indexOf("CSS1") >= 0))
	                                                   { _set('compat.ie6', true); }
	
	var options_outer = get_element_by_id('options_outer');
	_set('options_outer', options_outer);
	

	if (javascript_version != php_javascript_version)
	{
		options_outer.innerHTML = '<small>Your cached scripts or styles (for this site) are outdated. Please refresh this page.  (<a href="cache.php">Huh?</a>)</small>';
		return;
	}
	

	options_outer.innerHTML = '<div id="options_box"><\/div>';
	
	var options_box = get_element_by_id('options_box');
	_set('options_box', options_box);
	
	options_box.innerHTML = '<a href="#" onclick="horizontal_toggle();"><img class="options_image" src="images/h_arrow.png" alt="&lt;-&gt;" title="Click to open/close this box." /><\/a>';
	
	options_box.style.width = _get('closed_width') + 'px';
	options_box.style.height = _get('closed_height') + 'px';
	
	_set('current_width', _get('closed_width'));
	_set('target_width', _get('closed_width'));
	
	_set('current_height', _get('closed_height'));
	_set('target_height', _get('closed_height'));
	
	
	var m = document.getElementById('linkmap');
	
	var a = document.createElement('area');
	a.setAttribute('shape', 'rect');
	a.setAttribute('coords', '4,36,84,51');
	a.setAttribute('href', 'http://www.debian.org/doc/');
	a.setAttribute('alt', 'Debian documentation');
	m.appendChild(a);
	
	var a = document.createElement('area');
	a.setAttribute('shape', 'rect');
	a.setAttribute('coords', '88,36,168,51');
	a.setAttribute('href', 'http://trac.lighttpd.net/trac/wiki/Docs');
	a.setAttribute('alt', 'Lighttpd documentation');
	m.appendChild(a);
	
	var a = document.createElement('area');
	a.setAttribute('shape', 'rect');
	a.setAttribute('coords', '172,36,252,51');
	a.setAttribute('href', 'http://dev.mysql.com/doc/');
	a.setAttribute('alt', 'MySQL documentation');
	m.appendChild(a);
	
	var a = document.createElement('area');
	a.setAttribute('shape', 'rect');
	a.setAttribute('coords', '256,36,336,51');
	a.setAttribute('href', 'http://www.php.net/manual/en/');
	a.setAttribute('alt', 'PHP Documentation');
	m.appendChild(a);
	
	var a = document.createElement('area');
	a.setAttribute('shape', 'rect');
	a.setAttribute('coords', '4,55,84,70');
	a.setAttribute('href', 'http://www.w3.org/TR/REC-html40/');
	a.setAttribute('alt', 'HTML 4.01 Specification');
	m.appendChild(a);
	
	var a = document.createElement('area');
	a.setAttribute('shape', 'rect');
	a.setAttribute('coords', '88,55,168,70');
	a.setAttribute('href', 'http://www.w3.org/TR/REC-CSS2/');
	a.setAttribute('alt', 'CSS2 Specification');
	m.appendChild(a);
	
	var a = document.createElement('area');
	a.setAttribute('shape', 'rect');
	a.setAttribute('coords', '172,55,252,70');
	a.setAttribute('href', 'http://www.mozilla.org/docs/end-user/');
	a.setAttribute('alt', 'Firefox documentation');
	m.appendChild(a);
	
	var a = document.createElement('area');
	a.setAttribute('shape', 'rect');
	a.setAttribute('coords', '256,55,336,70');
	a.setAttribute('href', 'http://en.wikipedia.org/wiki/Help:Contents');
	a.setAttribute('alt', 'WikiPedia documentation');
	m.appendChild(a);
	
	
		
	
	
	_set('open_counter', 0);
	setTimeout('loop()', _get('slow_loop_speed'));
}


function loop()
{
	// enable in this method to speed up the next loop
	var fast_loop = false;
	var target_width = _get('target_width');


	if (_get('current_width') < target_width)
	{
		var options_box = _get('options_box');
		var new_width = _get('current_width') + _get('size_step');
		
		if (new_width >= target_width)
		{
			new_width = target_width;
			options_box.innerHTML = '<a href="#" onclick="horizontal_toggle();"><img class="options_image" src="images/h_arrow.png" alt="&lt;-&gt;" title="Click to open/close this box." /><\/a>&nbsp;&nbsp;JavaScript engine is <a href="cache.php">enabled</a> and functioning.';
		}
		else
		{
			fast_loop = true;
		}
		
		_set('current_width', new_width);
		options_box.style.width = new_width + 'px';
	}
	else if (_get('current_width') > target_width)
	{
		var options_box = _get('options_box');
		var new_width = _get('current_width') - _get('size_step');
		
		if (new_width <= target_width)
		{
			new_width = target_width;
		}
		else
		{
			fast_loop = true;
		}
		
		_set('current_width', new_width);
		options_box.style.width = new_width + 'px';
		
		
	}
	else
	{
		if (_get('current_width') == _get('closed_width'))
		{
			// Do nothing for now
		}
		else
		{
			_set('open_counter', _get('open_counter') + 1);
			if (_get('open_counter') >= _get('open_cycles'))
			{
				_set('target_width', _get('closed_width'));
				_set('open_counter', 0);
			}
		}
	}



	// Last two lines
	if (fast_loop)
	{
		setTimeout('loop()', _get('fast_loop_speed'));
	}
	else
	{
		fast_loop = false;
		setTimeout('loop()', _get('slow_loop_speed'));
	}
}




function horizontal_open()
{
	_set('target_width', _get('open_width'));
}

function horizontal_close()
{
	_set('target_width', _get('closed_width'));
	
	var options_box = _get('options_box');
	options_box.innerHTML = '<a href="#" onclick="horizontal_toggle();"><img class="options_image" src="images/h_arrow.png" alt="&lt;-&gt;" title="Click to open/close this box." /><\/a>';
}


function horizontal_toggle()
{
	if (_get('current_width') == _get('closed_width'))
	{
		horizontal_open();
	}
	else
	{
		horizontal_close();
	}
}


























function reload_visibility()
{
	var img = get_element_by_id("visibility_image");
	
	var f_x1 = get_element_by_id("x1");
	var f_x2 = get_element_by_id("x2");
	var f_y1 = get_element_by_id("y1");
	var f_y2 = get_element_by_id("y2");
	
	var f_a1 = get_element_by_id("a1");
	var f_a2 = get_element_by_id("a2");
	var f_d1 = get_element_by_id("d1");
	var f_d2 = get_element_by_id("d2");
	var f_v1 = get_element_by_id("v1");
	var f_v2 = get_element_by_id("v2");
	
	f_x1 = f_x1.value;
	f_y1 = f_y1.value;
	f_x2 = f_x2.value;
	f_y2 = f_y2.value;
	f_a1 = f_a1.value;
	f_a2 = f_a2.value;
	f_d1 = f_d1.value;
	f_d2 = f_d2.value;
	f_v1 = f_v1.value;
	f_v2 = f_v2.value;
	

	// Sanity Checking For All

	if ((Math.round(f_x1) != f_x1) || (Math.round(f_x2) != f_x2) || (Math.round(f_y1) != f_y1) || (Math.round(f_y2) != f_y2))
	{
		alert("Please use only whole numbers between -9 and 9 for coordinate positions.");
		return false;
	}
	
	if ((f_x1 == f_x2) && (f_y1 == f_y2))
	{
		alert("Objects cannot exist in the same place at the same time.");
		return false;
	}
	
	if ((Math.round(f_a1) != f_a1) || (Math.round(f_a2) != f_a2) || (Math.round(f_v1) != f_v1) || (Math.round(f_v2) != f_v2))
	{
		alert("Please use only whole numbers between 0 and 359 for angles.");
		return false;
	}
	
	if ((Math.round(f_d1) != f_d1) || (Math.round(f_d2) != f_d2))
	{
		alert("Please use only whole numbers between 0 and 9 for viewing distance.");
		return false;
	}
	
	if ((f_x1 < -9) || (f_x1 > 9) || (f_x2 < -9) || (f_x2 > 9) || (f_y1 < -9) || (f_y1 > 9) || (f_y2 < -9) || (f_y2 > 9))
	{
		alert("Please use only whole numbers between -9 and 9 for coordinate positions.");
		return false;
	}

	if ((f_a1 < 0) || (f_a1 > 359) || (f_a2 < 0) || (f_a2 > 359) || (f_v1 < 0) || (f_v1 > 359) || (f_v2 < 0) || (f_v2 > 359))
	{
		alert("Please use only whole numbers between 0 and 359 for angles.");
		return false;
	}
	
	if ((f_d1 < 0) || (f_d1 > 9) || (f_d2 < 0) || (f_d2 > 359))
	{
		alert("Please use only whole numbers between 0 and 9 for viewing distance.");
		return false;
	}
	
	img.src = "image.visibility.php?x1=" + f_x1 + "&y1=" + f_y1 + "&x2=" + f_x2 + "&y2=" + f_y2 + "&a1=" + f_a1 + "&a2=" + f_a2 + "&d1=" + f_d1 + "&d2=" + f_d2 + "&v1=" + f_v1 + "&v2=" + f_v2;


	return false;
}


























function get_element_by_id(vID)
{
	// Copy the object.  We *may* manipulate the_object, which
	// *may* cause problems in the if/typeof since the value is
	// unchanged.  I don't know this for sure, but oh well.
	
	if (typeof vID == 'string')
	{
		if (_get('compat.w3c'))
		{
			return document.getElementById(vID);
		}
		else if (_get('compat.ie4'))
		{
			return document.all(vID);
		}
		else if (_get('compat.nn4'))
		{
			return _seek_layer(document, vID);
		}
	}
	
	return vID;
}




function _get(vKey)
{
	if (!data_store instanceof Array)
	{
		return null;
	}
	
	if (typeof data_store[vKey] == 'undefined')
	{
		return null;
	}
	
	return data_store[vKey];
}

function _set(vKey, vVal)
{
	if (!data_store instanceof Array)
	{
		return null;
	}
	
	data_store[vKey] = vVal;
}



function _dump()
{
	document.write('<pre>');
	for (vKey in data_store)
	{
		document.write(vKey + " = " + data_store[vKey] + '<br />');
	}
	document.write('</pre>');
}







function _get_inside_window_width()
{
	if (document.body && document.body.clientWidth)
	{
		return document.body.clientWidth;
	}
	else if (window.innerWidth)
	{
		return window.innerWidth;
	}
	else if (_get('compat.ie6'))
	{
		return document.body.parentElement.clientWidth;
	}

	return 0;
}


function _get_inside_window_height()
{
	if (document.body && document.body.clientHeight)
	{
		return document.body.clientHeight;
	}
	else if (window.innerHeight)
	{
		return window.innerHeight;
	}
	else if (_get('compat.ie6'))
	{
		return document.body.parentElement.clientHeight;
	}
	

	return 0;
}


function center_object(object_or_string)
{
	var the_object = get_element_by_id(object_or_string);
	
	var scrollX = 0, scrollY = 0;
	
	if (document.body && typeof document.body.scrollTop != "undefined")
	{
		scrollX += document.body.scrollLeft;
		scrollY += document.body.scrollTop;
		
		if (document.body.parentNode && typeof document.body.parentNode.scrollTop != "undefined")
		{
			scrollX += document.body.parentNode.scrollLeft;
			scrollY += document.body.parentNode.scrollTop;
		}
	}
	else if (typeof window.pageXOffset != "undefined")
	{
		scrollX += window.pageXOffset;
		scrollY += window.pageYOffset;
	}
	
	var x = Math.round((_get_inside_window_width()  / 2) - (_get_object_width(the_object)  / 2)) + scrollX;
	var y = Math.round((_get_inside_window_height() / 2) - (_get_object_height(the_object) / 2)) + scrollY;

	move_object(the_object, x, y);
}












// Position an object at a specific pixel coordinate
function move_object(object_or_string, x, y)
{
	var the_object = get_object(object_or_string);
	
	if (the_object)
	{
		if (_get('compat.css'))
		{
			the_object.left = x + units;
			the_object.top  = y + units;
		}
		else if (_get('compat.nn4'))
		{
			the_object.moveTo(x, y);
		}
	}
}

















function _get_object_left(object_or_string)
{
	var elem = get_element_by_id(object_or_string);
	var result = 0;
	
	if (document.defaultView)
	{
		var style = document.defaultView;
		var cssDecl = style.getComputedStyle(elem, "");
		result = cssDecl.getPropertyValue("left");		
	}
	else if (elem.currentStyle)
	{
		result = elem.currentStyle.left;
	}
	else if (elem.style)
	{
		result = elem.style.left;
	}
	else if (_get('compat.nn4'))
	{
		result = elem.left;
	}
	
	return parseInt(result);
}


function _get_object_top(object_or_string)
{
	var elem = get_element_by_id(object_or_string);
	var result = 0;
	
	if (document.defaultView)
	{
		var style = document.defaultView;
		var cssDecl = style.getComputedStyle(elem, "");
		result = cssDecl.getPropertyValue("top");		
	}
	else if (elem.currentStyle)
	{
		result = elem.currentStyle.top;
	}
	else if (elem.style)
	{
		result = elem.style.top;
	}
	else if (_get('compat.nn4'))
	{
		result = elem.top;
	}
	
	return parseInt(result);
}


function _get_object_width(object_or_string)
{
	var elem = get_element_by_id(object_or_string);
	var result = 0;
	
	if (elem.offsetWidth)
	{
		result = elem.offsetWidth;
	}
	else if (elem.clip && elem.clip.width)
	{
		result = elem.clip.width;
	}
	else if (elem.style && elem.style.pixelWidth)
	{
		result = elem.style.pixelWidth;
	}
	
	return parseInt(result);	
}


function _get_object_height(object_or_string)
{
	var elem = get_element_by_id(object_or_string);
	var result = 0;
	
	if (elem.offsetHeight)
	{
		result = elem.offsetHeight;
	}
	else if (elem.clip && elem.clip.height)
	{
		result = elem.clip.height;
	}
	else if (elem.style && elem.style.pixelHeight)
	{
		result = elem.style.pixelHeight;
	}
	
	return parseInt(result);	
}


function _debug(msg)
{
	if (null == msg) { return _get('debug'); }
	if (false == _get('debug')) { return false; }

	var p = document.createElement('p');
	p.className = 'debug';
	p.innerHTML = msg;

	document.body.appendChild(p);
	return true;
}








































// eMail Obfuscator Script 2.1 by Tim Williams - freeware
function print_email(message, linkword)
{
	coded = "k1rjw@djkuxltc.x1p";
	
	cipher = "aZbYcXdWeVfUgThSiRjQkPlOmNnMoLpKqJrIsHtGuFvEwDxCyBzA1234567890"; shift=coded.length; link="";
	for (i=0; i<coded.length; i++){
		if (cipher.indexOf(coded.charAt(i))==-1){
			ltr=coded.charAt(i); link+=(ltr);
		}else{
			ltr = (cipher.indexOf(coded.charAt(i))-shift+cipher.length) % cipher.length; link+=(cipher.charAt(ltr));
		}
   	}
		
	document.write("<p>" + message + " <a href='mailto:"+link+"'>"+linkword+"<\/a>.<\/p>");
}




function print_download_table(link, label, note, onclick)
{
	document.write('<table class="sub_table"><tr>' + 
		'<td align="center" valign="middle" width="42" height="42"><img width="32" height="32" src="images/download.gif" alt="Download" title="Download" /></td>' +
		'<td valign="middle">' + 
		'<a href="' + link + '" onclick="' + onclick + '" title="' + label + '">' + label + "</a><br />" + 
		"<small>" + note + "</small></td></tr></table>"
	);

}
