/* ------------------------------------------------------------
 * PROJECT        : The Wargmaer
 * FILENAME       : jqload.js
 * ------------------------------------------------------------
 * DATE CREATED   : 28 Jan 2008
 * LAST UPDATED   : 13 Feb 2008
 * ------------------------------------------------------------
 * AUTHOR(S)      : Kevin Scholl (http://www.ksscholl.com/)
 * ------------------------------------------------------------ */
 
/* ------------------------------------------------------------
 * BASIC DECLARATIONS
 * ------------------------------------------------------------ */

$(document).ready(function(){

  $(""
		+ "div:last-child,"
		+ "ol:last-child,"
		+ "p:last-child,"
		+ "ul:last-child,"
		+ "").css("margin-bottom","0");

  // set search field actions
	$("#txtSiteSearch").toggleActive({
		toggleVal :  true
	  });

  // display the PRINT PAGE and EMAIL PAGE links
	$("#pageInfo p.actions")
	  .prepend("<a href=\"#\" class=\"linkPrint\" onclick=\"window.print(); return false;\">Print</a> | ")
	  .prepend("<a href=\"#\" class=\"linkEmail\" onclick=\"emailPage(); return false;\">Email</a> | ");
	
	// activate the navigation system
	$("#mainNav li a").toggleNavigation();
	
	// article listing
	$("div.articleListing:nth-child(even)").css("background","#E1E3DD");
	$("div#articleSearch fieldset ol li.advancedOptions").css("display","none");

  // article header
	$("div.articleHeader").css("min-height",$("div.articleHeader img.boxart").height());
	
	// home page news and article screen cap listing
	$("div.newsItem:nth-child(4n)").css("margin-right","0");
	$("div.newsRow, div.screenCapRow").append("<div class=\"cleaner\"><!-- --></div>");
	
	// establish width of screen cap row
	$("div.screenCapRow").css("width",($("div.screenCapRow div.screenCap").length * 220) + "px")

	// position radio buttons and checkboxes
	$("input[type='radio']").addClass("radioBtn");
	$("input[type='checkbox']").addClass("checkBox");

	});

/* ------------------------------------------------------------
 * FUNCTIONS
 * ------------------------------------------------------------ */

function emailPage() {
  $("#pageURL").attr("value",window.location);
	// alert($("#pageURL").val());
  $("#frmEmailPage").submit();
	}

/* ------------------------------------------------------------
 * JQUERY PLUGINS
 * ------------------------------------------------------------ */

var CURRNAV = "";

jQuery.fn.toggleNavigation = function() {
	this.each(function() {
		$(this)
	  .click(function() {
			var activeNav = $(this).attr("id");
			if (CURRNAV == "") {
				$("#" + activeNav).addClass("navon");
				$("#s" + activeNav).slideDown(250);
				CURRNAV = activeNav;
				}
			else if (CURRNAV == activeNav) {
				$("#s" + CURRNAV).slideUp(250, function(){
					$("#" + CURRNAV).removeClass("navon");
					CURRNAV = "";
				  });
				}
			else {
				$("#s" + CURRNAV).slideUp(250, function(){
					$("#" + CURRNAV).removeClass("navon");
					$("#" + activeNav).addClass("navon");
					$("#s" + activeNav).slideDown(250);
					CURRNAV = activeNav;
				  });
				}
  		return false;
			})
		});
	}

// toggle default value and coloring on form field focus/blur
// usage: $("#elementID").toggleActive(settings);
jQuery.fn.toggleActive = function(settings) {
	settings = jQuery.extend({
		focusBG   : "#222",
		focusFG   : "#CCC",
		blurBG    : "#444",
		blurFG    : "#999",
		toggleVal :  false
		}, settings);
	this.each(function() {
		$(this)
			.focus(function() {
				$(this).css({ backgroundColor: settings.focusBG, color: settings.focusFG });
				if (settings.toggleVal == true && this.value == this.defaultValue && this.value != "http://") {
					this.value = "";
					}
				})
			.blur(function() {
				$(this).css({ backgroundColor: settings.blurBG, color: settings.blurFG });
				if (settings.toggleVal == true && this.value == "") {
					this.value = this.defaultValue;
					}
				});
		});
	};
