$(document).ready(function(){
	$("#main .tabs .active").corner("top 6px");
	
	$("#menu div.inner").css('visibility','hidden');
	$("#menu div.inner").css('display','block');
	
	
	
	ltw = 0;
	$("#menu li.top").each(
		function()
		{
			ltw += this.offsetWidth;
		}
	)
	
	tw = new Array;
	$("#menu ul.inner").each(
		function(index)
		{
			tw[index] = 0;
			$('li.inner',this).each(
				function()
				{
					if($.browser.mozilla) tw[index] += 4;
					tw[index] += this.offsetWidth;
				}
			)
			this.style.width = tw[index] + 'px';
		}
	)

	function set_left(index)
	{
		c = $("#menu li.top")[index];
	    x = c.offsetLeft;
	    while (c.offsetParent != null) {
		    c = c.offsetParent;
	    	x += c.offsetLeft;
	    	if (c.tagName == 'BODY') break;
	    }
		return(x);
	}

	$("#menu div.inner").css('display','none');
//	$("#menu div.inner").eq(0).show();
	$("#menu div.inner").css('visibility','visible');
	
	$("#menu .active div.inner").css('display','block');

	$("#menu span.img_span img").each(
		function(index)
		{
			$(this).mousedown(
				function()
				{
					$("#menu div.inner").fadeOut(700);
					$("#menu li.active").removeClass('active');
					
/*					x = set_left(index);
					if(((x + tw[index])>ltw)&&((x +  $("#menu li.top")[index].offsetWidth)> tw[index])) // left offset plus width of hidden element is too long for a window size
					{
						$("#menu div.inner").eq(index).addClass('right');
					}
					else
					{
						$("#menu div.inner").eq(index).removeClass('right');
					}*/
			
					$("#menu li.top").eq(index).addClass('active');
					$("#menu div.inner").eq(index).fadeIn(700);
				}
			)
		}
	)

	$("#login_form_outer_div div.close_div").eq(0).mousedown(
		function()
		{
			$("#login_form_outer_div").eq(0).hide();
			$("#login_over_div").eq(0).hide();
		}
	)
	
	$('.show_form').each(
		function()
		{
			$(this).mousedown(
				function()
				{
					show_login();
					return false;
				}
			)
		}
	)

	$('.metro').each(
		function()
		{
			$('div.selectable div.item',this).each(
				function()
				{
					$(this).mouseover(
						function()
						{
							$('.metro div.selectable div.item').removeClass('over');
							$(this).addClass('over');
						}
					)
				}
			)
		
			$(this).mouseover(
				function()
				{
					$('div.selectable',this).css('display','block');
					
				}
			)
			$(this).mouseout(
				function()
				{
					$('div.selectable',this).css('display','none');
					
				}
			)

			$('div.selectable input[@type="checkbox"]',this).each(
				function()
				{
					$(this).change(
						function()
						{
							set_text(this);
						}
					)
				}
			)
		
			$('div.selectable input[@type="checkbox"]',this).eq(0).each(
				function()
				{
					$(this).click(
						function()
						{
							selectable = this.parentNode.parentNode;
							a = $('input[@type="checkbox"]',selectable);
							if(this.checked)
							{
								for(i=0;i<a.length;i++)
								{
									if(i!=0)
									{
										a[i].checked = 'checked';
									}
								}
							}
							else
							{
								for(i=0;i<a.length;i++)
								{
									if(i!=0)
									{
										a[i].checked = '';
									}
								}
							}
						}
					)
				}
			)
		
		}
	)

	$('div.hor_nav_div div.item').each(
	function()
	{
		$(this).mouseover(
			function()
			{
				$(this).addClass('over');
				
			}
		)
		$(this).mouseout(
			function()
			{
				$(this).removeClass('over');
			}
		)
	}
	)

	// rows effects	

	$("table.chosen tr:nth-child(odd)").addClass("odd");

	$("table.chosen td").each(
	function()
	{
		$(this).mouseover(
		function()
		{
			$(this.parentNode).addClass('over');
		}
		);

		$(this).mouseout(
		function()
		{
			$(this.parentNode).removeClass('over');
		}
		);
		
	}
	);
	
	$('div.sublists div.all a').each(
	function()
	{
		$(this).click(
		function()
		{
			$('div.sublists div.other').slideToggle('slow');
			return false;
		}
		)
	}
	)
	
	check_form();
	window.setTimeout(hovertipInit, 1);
	load();
});

function set_text(node)
{
	selectable = node.parentNode.parentNode;
	text = '';
	a = $('input[@type="checkbox"]',selectable);
	for(i=0;i<a.length;i++)
	{
		if(i!=0)
		{
			if(a[i].checked) text += $(a[i].parentNode).text();
		}
	}
	$('input.a',selectable.parentNode).get(0).value = text;
}

function show_login()
{
	$("#login_form_outer_div").eq(0).css('width',$("#page").get(0).offsetWidth);
//	$("#login_form_outer_div").eq(0).css('height',$("#page").get(0).offsetHeight);
	
	h = $("#header")[0].offsetHeight + $("#menu")[0].offsetHeight + $("#main")[0].offsetHeight + $("#footer")[0].offsetHeight + 55;
	$("#login_over_div")[0].style.height = h + 'px';
	
	$("#login_form_outer_div").eq(0).show();
	$("#login_over_div").eq(0).show();
}

function check_form(name)
{
	$('input[@type="text"].change',name).each(
	function()
	{
		this.val = this.value;
		$(this).focus(
		function()
		{
			if(this.value==this.val)
				this.value = '';
		}
		)
		$(this).blur(
		function()
		{
			if(this.value=='')
				this.value = this.val;
		}
		)
	}
	)
}

/*   function load() {
     if (GBrowserIsCompatible()) {
       var map = new GMap2(document.getElementById("map"));
       map.setCenter(new GLatLng(37.4419, -122.1419), 13);
     }
   }
*/