cur_mnu = null;
cur_img = null;

	
function check_hover_div(mEvent) {
	// Internet Explorer
	if (mEvent.srcElement)
		showPopup(mEvent, 'linkPopup', mEvent.srcElement);

	// Netscape and Firefox
	else if (mEvent.target)
		showPopup(mEvent, 'linkPopup', mEvent.target);
}

function getPopupObject(myId) {
	if (document.getElementById(myId)) {
		return document.getElementById(myId);
	} else {
		return window.document[myId]; 
	}     
}	

function check_menu_id() {
	if(!ton_menu)
		close_menu();
	setTimeout('check_menu_id()', 2000);
}

ton_menu = false;
function showPopup(myEvent, id, myElement) {
	if(myElement.nodeName == 'IMG')
		myElement = myElement.parentNode;
		
	if(
		(myElement.id == null && myElement.id.indexOf('menu') < 0) || 
		(myElement.className != null &&  myElement.className.indexOf('menu') < 0)
	)			
		ton_menu = false;
	else
		ton_menu = true;
	
	//document.getElementById('debug_area').innerHTML = myElement.nodeName + '\n id=' + myElement.id + '\n am=' + active_menu;
}

Event.observe(window, 'load', function() {	
	setTimeout('check_menu_id()', 2000);
	var IE = document.all ? true : false;	
	
	if (!IE) {
		document.captureEvents(Event.MOUSEMOVE);
		document.onmousemove = check_hover_div;
	} else 
		document.onmousemove = function() { check_hover_div(event); }	

	//document.body.onmousemove = function() { check_hover_div(event); }
});

function swap_image(ptr, image) {
	ptr.src = image;
}

shade_amount = 500;

function shade_div_down(obj, div_height) {
	var box_height = obj.offsetHeight;

	if(box_height < div_height - shade_amount) {
		obj.style.height = (box_height + shade_amount) + 'px';

		setTimeout(function () { shade_div_down(obj, div_height); }, 1);
	} else
		obj.style.height = div_height + 'px';
}

active_menu 	= false;
active_sub_menu = false;

function close_active_menu(id, m) {
	if(m != false) {
		menu_outer = document.getElementById(id + '_outer');
		menu_inner = document.getElementById(id + '_inner');
		
		if(!menu_outer || !menu_inner)
			return;

		menu_outer.style.display = 'none';
		menu_inner.style.display = 'none';
	}
}

function set_position(obj, x, y) {
	obj.style.left 	= x + 'px';
	obj.style.top 	= y + 'px';
}

function show_sub_menu(id) {
    close_active_menu('sub_' + active_sub_menu, active_sub_menu);	

 	menu_inner 	= document.getElementById('sub_' + id + '_inner');
	menu_outer 	= document.getElementById('sub_' + id + '_outer');

	if(!menu_inner) {
		active_sub_menu = false;
		return;
	}

	active_sub_menu = id;	

	parent_inner_id = document.getElementById('menu_' + id + '_link');
	pos 			= find_pos(parent_inner_id);
	//pos 			= $(parent_inner_id).getCumulativeOffset();

	menu_outer.style.display = '';
	menu_inner.style.display = '';
	
	target_height 		= get_height(menu_inner);
	target_width		= get_width(menu_inner) + 5;
	
	menu_inner.style.height = '1px';
	menu_outer.style.height = '1px';
	
	if(pos[0] + target_width > 780)
		target_width = target_width * -1;

	// position the item
	set_position(menu_outer, pos[0] + target_width - offset_left, pos[1] - offset_top);
	set_position(menu_inner, pos[0] + target_width - offset_left, pos[1] - offset_top);

	// height of each
	shade_div_down(menu_outer, target_height);
	shade_div_down(menu_inner, target_height);
}

function show_menu(ptr, id) {
  	close_menu();
	
	//hide_select();

	active_menu = id;
	
	menu_inner = document.getElementById(id + '_inner');
	menu_outer = document.getElementById(id + '_outer');
	
	if(!menu_outer || !menu_inner)
		return;	

	menu_outer.style.display = '';
	menu_inner.style.display = '';

	pos = find_pos(ptr);

	target_height = get_height(menu_inner);
	target_width  = get_width(menu_inner);
	
	//offset = -126; //-1;

	menu_inner.style.height = '1px';
	menu_outer.style.height = '1px';

	// position them
	//set_position(menu_outer, pos[0] + offset, pos[1] + 122);
	//set_position(menu_inner, pos[0] + offset, pos[1] + 122);
	
	set_position(menu_outer, pos[0] - offset_left, pos[1] - offset_top + 122);
	set_position(menu_inner, pos[0] - offset_left, pos[1] - offset_top + 122)	

	// height of each
	shade_div_down(menu_outer, target_height);
	shade_div_down(menu_inner, target_height);
}

function close_menu() {
	if(cur_mnu)
		swap_image(cur_mnu, cur_img);

	if(active_menu)
		close_active_menu(active_menu, active_menu);
		
	if(active_sub_menu)
		close_active_menu('sub_' + active_sub_menu, active_sub_menu);
	
	unhide_select();
}

function get_height(obj) {
	xPos = obj.offsetHeight;

	return xPos;
}

function get_width(obj) {
	xPos = obj.offsetWidth;

	return xPos;
}

function find_pos(obj) {
	//return $(obj).cumulativeOffset();
	
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop 	= obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop 	+= obj.offsetTop
		}
	}

	return [curleft,curtop];
}

function hide_select() {
	for (j=0; j<document.forms.length; j++) {
		var theForm = document.forms[j]
		for(i=0; i<theForm.elements.length; i++){
			if(theForm.elements[i].type == "select-one") {
				theForm.elements[i].style.visibility = "hidden";
			}
		}
	}
}

function unhide_select() {
	var theObj = document.getElementsByTagName("select");
	for(j=0; j<theObj.length; j++)
		theObj[j].style.visibility = "visible";
}

function menu_out(i) {}