var navTime, ie6 = navigator.appVersion.match(/MSIE (5.5|6)/) && document.uniqueID ? true : false;

var preloadImgs = function (imgs) {
	var i = imgs.length;
	while (i-- > 0) {
		(new Image()).src = '/images/' + imgs[i];
	}
};

var initNav = function () {
	var subs = document.getElementById('nav').getElementsByTagName('UL');
	var i = subs.length;
	while (i-- > 0) {
		var opener = document.createElement('A');
		opener.href = 'javascript:void();';
		opener.style.position = 'absolute';
		if (window.opera) {
			opener.style.left = '136px';
		}
		opener.style.margin = '-2px 0 0 -124px';
		opener.onclick = function () {
			var subs = document.getElementById('nav').getElementsByTagName('UL');
			var i = subs.length;
			var ul = this.nextSibling;
			while (i-- > 0) {
				if (subs[i] != ul) {
					if (subs[i].className == 'nav-opened') {
						subs[i].previousSibling.firstChild.src = '/images/common/nav_closed.gif';
						subs[i].className = 'nav-closed';
					}
				}
			}
			if (ul.className == 'nav-opened') {
				this.firstChild.src = '/images/common/nav_closed.gif';
				ul.className = 'nav-closed';
			} else {
				this.firstChild.src = '/images/common/nav_opened.gif';
				ul.className = 'nav-opened';
			}
			this.blur();
			return false;
		};
		opener.innerHTML = '<img src="/images/common/nav_' + (subs[i].className && subs[i].className.indexOf('nav-opened') != -1 ? 'opened' : 'closed') + '.gif" width="9" height="9" alt="" style="vertical-align: bottom" />';
		subs[i].parentNode.insertBefore(opener, subs[i]);
		opener.parentNode.style.position = 'relative';
	}
};

var openFull = function (image, width, height) {
	width  += 18;
	height += 18;
	var left = screen.width / 2 - width / 2;
	var top  = screen.height / 2 - height / 2;
	window.open('/display.php?' + image, '_blank', 'status=no,dependent=yes,modal=yes,height=' + height + ',width=' + width + ',left=' + left + ',top=' + top);
	return false;
};

window.onload = function () {
	preloadImgs(['common/nav_opened.gif']);
	initNav();
};
