window.onload = initializeJS;

//Initialize events that have to occur after the window has loaded.
function initializeJS() {

	//Search Text-Box onFocus event
    $('#nav_search').example('Search Site');

	//Search Text-Box onKeyPress event to capture "Enter" key
	document.getElementById("nav_search").onkeypress = function(e) {
		if( window.event )
			key=window.event.keyCode;
		else if (e) key = e.which;
		else return true;
		if(key==13) 
			searchSite(this.value);
	}

	//Search Button onClick Event
	document.getElementById("search_button").onclick = function () {
		searchSite(document.getElementById("nav_search").value);
	}
	if ($('#widget1').html() != null && $('#widget1').html().length > 0)
		$('#widget1').show();
	if ($('#widget2').html() != null && $('#widget2').html().length > 0)
		$('#widget2').show();

	AddCorners();

	InitializeScrollPane();

	$('#navigation a, #city_maps a, #rp_links a, #characters a, #quick_links a').each(function() {
	    if ($.browser.msie) {
	        $(this).mouseover(function() {
	            $(this).css({ 'background-color': '#c09b69', 'color': '#FFF', 'font-weight': 'bold' });
	        });
	        $(this).mouseout(function() {
	            $(this).css({ 'background-color': 'transparent', 'color': '#000', 'font-weight': 'normal' });
	        });
	    }
	});
	$('.nav_title, .nav_sub_title').each(function() {
	    if ($.browser.msie) {
	        $(this).mouseover(function() {
	            $(this).css({ 'background-color': '#c09b69', 'color': '#FFF' });
	        });
	        $(this).mouseout(function() {
	            $(this).css({ 'background-color': 'transparent', 'color': '#000' });
	        });
	    }
	});
}

function InitializeScrollPane() {
    //$('#sub_contents').jScrollPane({ showArrows: true });
}

function linkmail(address, domain, ext) {
    window.location = "mailto:" + address + "@" + domain + "." + ext;
}

//Search Site in google
function searchSite(str) {
	window.open("http://www.google.com/search?q=" + str + "&sitesearch=tsosmud.org", "SiteSearch");
}

function nav_show(id) {
	if( id != "navigation")
	    $('#navigation_links').hide("fast");
	if( id != "city_maps" )
	    $('#city_maps_links').hide("fast");
	if( id != "rp_links" )
	    $('#rp_links_links').hide("fast");
	if (id != "characters" && id != "ctl00_side_nav_CharacterBios") {
	    $('#characters_links').hide("fast");
	    $('#ctl00_side_nav_CharacterBios_links').hide("fast");
	}
	if( id != "quick_links" )
	    $('#quick_links_links').hide("fast");
	if (id != "ctl00_side_nav_admin")
	    $('#ctl00_side_nav_admin_links').hide("fast");

	$('#' + id + "_links").show("fast", InitializeScrollPane);
}

function AddCorners()
{
	$('.content').each(function(i) {
		var top_left = document.createElement("img");
		var top_right = document.createElement("img");
		var bottom_left = document.createElement("img");
		var bottom_right = document.createElement("img");

		top_left.src = "/_IMAGES/top_left_corner.png";
		top_right.src = "/_IMAGES/top_right_corner.png";
		bottom_left.src = "/_IMAGES/bottom_left_corner.png";
		bottom_right.src = "/_IMAGES/bottom_right_corner.png";

		top_left.className = 'content_corner top left';
		top_right.className = 'content_corner top right';
		bottom_left.className = 'content_corner bottom left';
		bottom_right.className = 'content_corner bottom right';

		top_left.alt = "Top Left Corner";
		top_right.alt = "Top Right Corner";
		bottom_left.alt = "Bottom Left Corner";
		bottom_right.alt = "Bottom Right Corner";
		
		$(this).append(top_left);
		$(this).append(top_right);
		$(this).append(bottom_left);
		$(this).append(bottom_right);
	});
}
