﻿var sSearchDefault = "Search...";
var sUserNameDefault = "Username";
var sPasswordDefault = "Password";
var timer;
var curItem;
var sOrigMapSrc;

function init () {
	
	// Searchbox behaviour
	$(".txtSearch, .txtUserName").bind("focus", onFormFocus);
	$(".txtSearch, .txtUserName").bind("blur", onFormBlur);
	
	// Set up leftmenu mouseovers
	$("ul.left-nav .hasSubNav").bind("mouseover", onLeftNavMouseOver );
	$("ul.left-nav .hasSubNav").bind("mouseout", onLeftNavMouseOut );
	
	// Set up coloring of alt rows
	$(".setAltNodes > *:odd").addClass("alt");
}

function onLeftNavMouseOver() {
	clearTimeout(timer);
	$(".left-nav ul").css("display", "none");
	$("ul", this).css( { display:"block", top:$(this).position().top + "px" } );
	$(this).children("a").addClass("leftNavItemOver");
}

function onLeftNavMouseOut() {
	//timer = setTimeout("hideIt()", 200);
	curItem = this;
	hideIt();
}

function hideIt() {
	$("ul", curItem).css("display", "none");
	$(curItem).children("a").removeClass("leftNavItemOver");
}

function onFormFocus() {
	if ($(this).hasClass("txtSearch") && this.value == sSearchDefault) {
		this.value = "";
		$(".txtSearch").css( { fontStyle:"normal", color:"#000000" } );
	}
	else if ($(this).hasClass("txtUserName") && this.value == sUserNameDefault) {
		this.value = "";
	}
//	else if ($(this).hasClass("txtPassword") && this.value == sPasswordDefault) {
//		this.value = "";
//	}
}

function onFormBlur() {
	if (this.value == "") {
		if ($(this).hasClass("txtSearch")) {
			this.value = sSearchDefault;
			$(".txtSearch").css( { fontStyle:"italic", color:"#666666" } );
		}
		else if ($(this).hasClass("txtUserName")) {
			this.value = sUserNameDefault;
		}
//		else if ($(this).hasClass("txtPassword")) {
//			this.value = sPasswordDefault;
//		}
	}
}

function preloadImages() {
  for(var i = 0; i<arguments.length; i++) {
    var img = new Image();
    img.src = arguments[i];
  }
}

function showMap(sImg) {
	if (!sOrigMapSrc && sImg)
		sOrigMapSrc = $(".world-map").attr("src");
	if (!sImg)
		sImg = sOrigMapSrc;
	$(".world-map").attr("src", sImg);
}

$(document).bind("ready", init);
