
window.timeout    = 250;
window.closetimer = 0;

window.thismenu   = null;
window.rollmenu   = null;

$naviapp = navigator.appVersion.toLowerCase().split(';');
$naviapp = $naviapp[1];

$browser = $naviapp.indexOf('msie');
$version = $naviapp.replace('msie ','');
$version = parseInt($version);

function setRollOutTimer($caller) {
	$caller.timeout = setTimeout(function () { $caller.rollout(); },20);
}

function setRollInTimer($caller,$menu) {
	$caller.timeout = setTimeout(function () { $caller.rollin($menu); },20);
}

function rollout() {
	clearTimeout(this.timeout);
	$startheight = parseInt(this.style.height);

	if(window.menuSlide && parseInt(this.style.height) < this.rollheight) {
		$newheight = ($startheight + 15);
		if($newheight > this.rollheight) {
			$newheight = this.rollheight;
		}

		this.style.height = $newheight + 'px';
		setRollOutTimer(this);
	}
	else {
		this.style.height = this.rollheight + 'px';
	}
}

function rollin($menu) {
	clearTimeout(this.timeout);
	$startheight = parseInt(this.style.height);

	if(window.menuSlide && parseInt(this.style.height) > 0) {
		$newheight = ($startheight - 15);
		if($newheight < 0) {
			$newheight = 0;
		}

		this.style.height = $newheight + 'px';
		setRollInTimer(this,$menu);
	}
	else {
		$menu.style.visibility = 'hidden';
		$menu.style.left = '0px';
	}
}

function menu_open($id) {
	if(($browser >= 0 && $version > 6) || $browser < 0) {
		menu_no_close();

		$rollover = $id + '_rollover';
		$id = 'submenu_' + $id;

		if(window.thismenu) {
			window.thisroll.rollin(window.thismenu);
		}

		window.thismenu = document.getElementById($id);
		window.thisroll = document.getElementById($rollover);

		if(!window.thisroll.rollheight) {
			window.thisroll.rollheight = window.thisroll.offsetHeight;
		}

		if(window.thismenu) {
			if(window.thisroll.style.height == '') {
				window.thisroll.style.height = '0px';
			}

			window.thisroll.rollout = rollout;
			window.thisroll.rollin  = rollin;

			window.thismenu.style.visibility = 'visible';
			
			$pos = find_pos($id + '_pos')
			window.thismenu.style.left = $pos[0] + 'px';
			window.thismenu.style.top = $pos[1] + 'px';

			window.thisroll.rollout();
		}
	}
}

function menu_set_close() {
	window.closetimer = window.setTimeout(menu_close, window.timeout);
}

function menu_no_close() {
	if(window.closetimer) {
		window.clearTimeout(window.closetimer);
		window.closetimer = null;
	}
}

function menu_close() {
	if(window.thismenu) {
		window.thisroll.rollin(window.thismenu);
	}
}

function find_pos($id) {
	$element = document.getElementById($id);
	$current_left = 0;
	$current_top  = 0;

	if($element) {
		if ($element.offsetParent) {
			$current_left = $element.offsetLeft;
			$current_top  = $element.offsetTop;

			while ($element = $element.offsetParent) {
				$current_left += $element.offsetLeft;
				$current_top  += $element.offsetTop;
			}
		}
	}

	return new Array($current_left - 5,$current_top);
}

// document.onclick = menu_close;
