$(document).ready
(
	function()
	{
		// remove focus rectangles from buttons and tabs
		$("a.button, a.tab").click
		(
			function()
			{
				this.blur();
			}
		);
		// initialize login button
		$("a#login").click
		(
			function()
			{
				// is login form hidden?
				//if($("div#loginView").is(":hidden"))
				if($("#loginView").is(":hidden"))
				{
					// fix for stupid IE7
					//$("div#loginView").css("filter", "alpha(opacity=100)");
					// yep, let's show it
					//$("div#loginView").fadeIn("fast");
					$("div#loginView").fadeIn("fast");
					// and turn the button on
					$(this).addClass("onState");
				}
				else
				{
					// nope, let's hide it
					$("div#loginView").fadeOut("fast");
					// and turn the button off
					$(this).removeClass("onState");
				}
			}
		);
		$("a#login2").click
		(
			function()
			{
				// is login form hidden?
				if($("div#loginView").is(":hidden"))
				{
					// fix for stupid IE7
					//$("div#loginView").css("filter", "alpha(opacity=100)");
					// yep, let's show it
					$("div#loginView").fadeIn("fast");
					// and turn the button on
					$(this).addClass("onState");
					/*$( "#dialog:ui-dialog" ).dialog( "destroy" );*/
				}
				else if (! $( "#dialog-box" ).is(":hidden")){
					//do nothing
				}else{
					// nope, let's hide it
					$("div#loginView").fadeOut("fast");
					// and turn the button off
					$(this).removeClass("onState");
				}
			}
		);
		// set up dropdown tabs
		$("div.dropdown").each
		(
			function()
			{
				// add dropdown glyph
				$(this).children("div.tabMain").append("<div class=\"dropdownGlyph\"></div>");
			}
		);
		// handle clicks on tabs
		$("div.dropdown div.tabLeft, div.dropdown div.tabMain, div.dropdown div.tabRight, div.dropdown div.dropdownGlyph").click
		(
			function()
			{
				// is dropdown hidden?
				if($(this).siblings("div.dropdownContent").is(":hidden"))
				{
					// hide any other dropdowns that are open
					$("div.dropdownContent").fadeOut("fast");
					$("div.dropdown").removeClass("onState");
					// fix for stupid IE7
					$(this).siblings("div.dropdownContent").css("filter", "alpha(opacity=100)");
					// yep, let's show it
					$(this).siblings("div.dropdownContent").fadeIn("fast");
					// and turn the button on
					$(this).addClass("onState");
				}
				else
				{
					// nope, let's hide it
					$(this).siblings("div.dropdownContent").fadeOut("fast");
					// and turn the button off
					$(this).removeClass("onState");
				}
			}
		);
		// set up tab links
		$("div.tab").click
		(
			function()
			{
				// if this tab isn't a dropdown
				if(!$(this).hasClass("dropdown"))
				{
					// navigate to link defined in rel attribute
					self.location.href = $(this).attr("rel");
				}
			}
		);
		// set up links that open in new tab
		$("a.newWindow").click
		(
			function()
			{
				// open link in new tab
				window.open(this.href);
				// stop current tab from loading link
				return false;
			}
		);
	}
);
