function initialize () {
	if (!document.info) { return; }

	if (document.info.menu) {
		var menu = document.info.menu.value.split(',');
		for (var i=0; i<menu.length; i++) {
			var obj = document.getElementById(sprintf('img-%s', menu[i]));
			if (!obj) { continue; }
			obj.onmouseover = mouseOver;
			obj.onmouseout = mouseOut;
		}
	}

	if (document.info.submenu) {
		var submenu = document.info.submenu.value.split(',');
		for (var i=0; i<submenu.length; i++) {
			var obj = document.getElementById(sprintf('box-%s', submenu[i]));
			if (!obj) { continue; }
			obj.onmouseover = mouseOver;
			obj.onmouseout = mouseOut;
			obj.onmouseup = mouseUp;
		}
	}
}

//-------------------------------------------------------//
// MOUSE FUNCTIONS                                       //
//-------------------------------------------------------//

function mouseOver (e) {
	var event = getEvent(e);
	var target = getTarget(event);

	if (target && target.id && target.className) {
		if (target.className.indexOf('-on') != target.className.length - 3) {
			target.className = target.className + '-on';
		}

		// highlight arrow if it exists
		if (target.id.indexOf('img-') == 0) {
			var arrow = document.getElementById(sprintf('arrow-%s', target.id.substr(4)));
			if (arrow) { arrow.className = arrow.className + '-on'; }
		}
	}
}

function mouseOut (e) {
	var event = getEvent(e);
	var target = getTarget(event);

	if (target && target.id && target.className) {
		if (target.className.indexOf('-on') == target.className.length - 3) {
			target.className = target.className.substr(0, target.className.length - 3);
		}

		// dim arrow if it exists
		if (target.id.indexOf('img-') == 0) {
			var arrow = document.getElementById(sprintf('arrow-%s', target.id.substr(4)));
			if (arrow) { arrow.className = arrow.className.substr(0, arrow.className.length - 3); }
		}
	}
}

function mouseUp (e) {
	var event = getEvent(e);
	var target = getTarget(event);

	if (target && target.id && target.className) {
		if (target.className.indexOf('menuitem') == 0 && target.childNodes[0]) {
			var link = target.childNodes[0].getAttribute('href');
			if (link) { location.href = link; }
		}
	}
}

//-------------------------------------------------------//
// BASE FUNCTIONS                                        //
//-------------------------------------------------------//

function sprintf () {
	var format = arguments[0];
	var pattern = /%(s|d)/;
	var match = format.search(pattern);
	var count = 1;
	while (match >= 0) {
		var key = format.substr(match, 2);
		var value = arguments[count];
		if (key == '%d') { value = parseInt(value); }
		else if (key == '%s') { value = value.toString(); }
		format = format.substr(0, match) + value + format.substr(match+2);
		match = format.search(pattern);
		count++;
	}
	return format;
}

function removeChildren (obj) {
	while (obj.firstChild) { obj.removeChild(obj.firstChild); }
}

function getEvent (e) {
	return (typeof e == 'undefined') ? window.event : e;
}

function getTarget (e) {
	return e.target ? e.target : e.srcElement;
}

//-------------------------------------------------------//
// LISTING FUNCTIONS                                     //
//-------------------------------------------------------//

function positionStatus () {
	var IE = (navigator.appName == 'Microsoft Internet Explorer');
	var start_y = 367 + (IE ? 15 : 0);
	var offset_y = 241 + (IE ? 13 : 0);
	var screen_w = parseInt(IE ? document.body.clientWidth : window.innerWidth);

	for (var i=1; i<30; i++) {
		var status = document.getElementById('status'+i);
		if (status) {
			if (IE) { status.style.left = (screen_w / 2) - 365; }
			status.style.top = start_y + (i-1) * offset_y;
			status.style.display = '';
		}
	}
}

function positionStatusListing () {
	var IE = (navigator.appName == 'Microsoft Internet Explorer');
	var screen_w = parseInt(IE ? document.body.clientWidth : window.innerWidth);
	var status = document.getElementById('status');
	if (!status) { return; }
	if (IE) {
		status.style.left = (screen_w / 2) - 365;
		status.style.top = 368;
	}
	else {
		status.style.top = 361;
	}
	status.style.display = '';
}
