var timer = new Array();
var delay = 400;

var original_class = 'nav';
var highlight_class = 'nav_hover';
function dropDown(id,action,options,links,orig,cntr) {
	if(action=='clear') {
		var all_fields = document.getElementById('all_fields').value;
		var all_fields = all_fields.split(",");
		for(var i=0;i<all_fields.length;i++) {
			if(all_fields[i]!=id) {
				if(document.getElementById(all_fields[i])) {
					document.getElementById('menu_'+all_fields[i]).className = original_class;
					document.getElementById(all_fields[i]).style.display = 'none';
				}
			}
		}
	}
	if(action=='show') {
		document.getElementById('menu_'+id).className = highlight_class;
		if(!document.getElementById(id)) {
			var options = options.split("#");
			var links = links.split("#");
            var newdiv = document.createElement('div');
			newdiv.setAttribute('id', id);
			newdiv.style.position = 'absolute';
			newdiv.style.width = '182px';
			newdiv.style.display = 'none';
			newdiv.style.borderLeft = '1px solid #c9c9c9';
			newdiv.style.borderRight = '1px solid #c9c9c9';
			newdiv.style.borderBottom = '1px solid #c9c9c9';
			newdiv.style.textAlign = 'left';
			var html = '';
			var styleadd = '';
			for(var i = 0;i<options.length;i++) {
                styleadd = '';
				if(i==(options.length - 1)) styleadd = 'style="border-bottom:0px;" ';
				html += '<a '+styleadd+'onMouseOver="dropDown(\''+id+'\',\'clear\',\'\',\'\',\'\',\''+cntr+'\');" onMouseOut="dropDown(\''+id+'\',\'set\',\'\',\'\',\'\',\''+cntr+'\');" class="dropdown" href="'+links[i]+'">&nbsp;'+options[i]+'</a>';
			}
			newdiv.innerHTML = html;
			document.body.appendChild(newdiv);
		}
		var all_fields = document.getElementById('all_fields').value;
		var all_fields = all_fields.split(",");
		for(var i=0;i<all_fields.length;i++) {
			if(all_fields[i]!=id) {
				if(document.getElementById(all_fields[i])) {
					document.getElementById('menu_'+all_fields[i]).className = original_class;
					document.getElementById(all_fields[i]).style.display = 'none';
				}
			}
		}
		var target = document.getElementById(id);
		var top = parseInt(orig.offsetHeight);
		var curleft = curtop = 0;
		if(orig.offsetParent) {
			do {
				curleft += orig.offsetLeft;
				curtop += orig.offsetTop;
			} while (orig = orig.offsetParent);
		}
		var top = top + curtop + 7;
		var top = top+'px';
		var left = curleft - 1;
		var left = left+'px';
		target.style.display = 'block';
        target.style.top = top;
        target.style.left = left;
		window.clearTimeout(timer[cntr]);
	}
	if(action=='clear') {
		window.clearTimeout(timer[cntr]);
	}
	if(action=='set') {
		timer[cntr] = window.setTimeout("dropDown('"+id+"','hide','','','','"+cntr+"');", delay);
	}
	if(action=='hide') {
		var target = document.getElementById(id);
	    target.style.display = 'none';
		document.getElementById('menu_'+id).className = original_class;
	}
}

function link_swap(objID,dir,xPos) {
	if(dir=='over') document.getElementById(objID).style.backgroundImage = 'url(images/links_hover.gif)';
	if(dir=='out') document.getElementById(objID).style.backgroundImage = 'url(images/links.gif)';
}
function scroller_setup() {
	var height = 0;
	if(document.getElementById('scroller_box')) height = document.getElementById('scroller_box').offsetHeight;
	if(height>288) {
		document.getElementById('dnarrow').style.visibility = 'visible';
	}
}
window.onload=function() { scroller_setup(); };

function scroll_div() {
	var dir = document.getElementById('imgmove').value;
	topval = parseInt(document.getElementById('scroller_box').style.top);
	var height = document.getElementById('scroller_box').offsetHeight;
	var bottomMax = 0 - (height - 288);
	if(dir=='U') scrollUp(topval);
	if(dir=='D') scrollDown(bottomMax,topval);
    if(topval==0) document.getElementById('uparrow').style.visibility = 'hidden';
	if(topval==bottomMax) document.getElementById('dnarrow').style.visibility = 'hidden';
    if(topval<0) document.getElementById('uparrow').style.visibility = 'visible';
	if(topval>bottomMax) document.getElementById('dnarrow').style.visibility = 'visible';
}
function scrollUp(topval) {
	var new_height = topval + 1;
	if(new_height>0) new_height = 0;
    document.getElementById('scroller_box').style.top = new_height+'px';
	setTimeout("scroll_div()",1);
}
function scrollDown(bottomMax,topval) {
	var new_height = topval - 1;
	if(new_height<bottomMax) new_height = bottomMax;
    document.getElementById('scroller_box').style.top = new_height+'px';
	setTimeout("scroll_div()",1);
}