/* ------------------------------------------------------------
 * PROJECT        : Phoenix Rising
 * FILENAME       : jqload.js
 * ------------------------------------------------------------
 * LAST UPDATED   : 05 Jan 2010
 * ------------------------------------------------------------
 * AUTHOR(S)      : Kevin Scholl    (http://www.ksscholl.com/)
 * ------------------------------------------------------------
 * NOTE(S)        : 
 * ------------------------------------------------------------ */
 
$(document).ready(function(){
													 
	// close open popups on window unload
//  $(window).unload(function(){
//		closePopWin(POPWIN);
//		});
	
	// remove bottom margin on last child element(s)
  $(""
		+ "div:last-child,"
		+ "fieldset:last-child,"
		+ "form:last-child,"
		+ "img:last-child,"
		+ "li:last-child,"
		+ "ol:last-child,"
		+ "p:last-child,"
		+ "table:last-child,"
		+ "ul:last-child"
		+ "").css("margin-bottom","0");

	// display Contact icon if Javascript is enabled
	$("#iconnav").append("<a "
		+ "href=\"#\" id=\"displayContact\"><img src=\"/images/icon_contact.gif\" "
		+ "alt=\"Contact\" title=\"Contact\" width=\"24\" height=\"24\" /></a>");

	// toggle display of Contact form and information
	$("#divContact").hide();
	$("#displayContact").click(function () {
		$("#divContact").is(":visible") ? $("#divContact").slideUp(500) : $("#divContact").slideDown(1500);
		return false;
		});

	// display subnavs if Javascript is enabled
	$("p.subnav").show();
	// hide more info if Javascript is enabled 
	$("p.moreInfo").hide();
	
	// section initialization
	$("div.portfolioBlock, div.meanderingsBlock, div.dvdBlock, div.downloadsBlock, div.quicklinksBlock, div.resourcesBlock").hide();
	$("div.archiveBlock").hide();
	$("div#portfolioWeb, div#meanderingsRecent, div#dvdNowShowing, div#downloadsBrowsers, div#quicklinksAffiliates, div#resourcesInsights").show();
	$("div#archive2010").show();
	
	// add icon to externally-directing links
	var cssExtLink = {
		'background' : 'transparent url(/images/bg_ext_link.gif) right center no-repeat',
		'padding-right' : '16px'
		}
	$("a[href^='http://']").not(":has('img')").css(cssExtLink);
	
	// form field styling
	$("input, select, textarea").not(".actionBtn").css({
	  "border"     : "1px solid #666",
		"background" : "#333"
		})	
	// initialize contact form fields
	$("input:file, input:password, input:text, select, textarea").not("[readonly]").toggleActive({
		focusBG   : "#332",
		focusFG   : "#CCC",
		blurBG    : "#333",
		blurFG    : "#999",
		toggleVal :  true
		});	
	
	});

/* ------------------------------------------------------------
 * JQUERY PLUGINS
 * ------------------------------------------------------------ */

// toggle default value and coloring on form field focus/blur
// usage: $("#elementID").toggleActive(settings);
jQuery.fn.toggleActive = function(settings) {
	settings = jQuery.extend({
		focusBG   : "#F6F6F6",
		focusFG   : "#000",
		blurBG    : "#FFF",
		blurFG    : "#333",
		toggleVal :  false
		}, settings);
	this.each(function() {
		$(this)
		  .css("border","1px solid #666")
			.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;
					}
				});
		if ($(this).is("select"))
		  $(this).css("padding","1px")
		});
	};

/* ------------------------------------------------------------
 * FUNCTIONS
 * ------------------------------------------------------------ */

function showSection(sectionClass,sectionID) {
	if ($("div#" + sectionID).is(":not(:visible)")) {
		$("div." + sectionClass).hide();	
		$("div#" + sectionID).fadeIn(1000);
		}
	else
	  $("div#" + sectionID).fadeOut(500);
	}

