$(document).ready(function(){

	// _blank replacement
	externalLinks();
	
	// preload images
	$.preloadImages("/images/btn_business_opp_o.png", "/images/btn_right-for-me_o.png", "/images/btn_choose-future_o.png", "/images/btn_learn-more_o.png" , "/images/btn_60-day_o.jpg", "/images/btn_apply-now_o.jpg", "/images/btn_assess-skills_o.jpg");

	// image (button) rollover functionality
	PEPS.rollover.init();
});
// -- end DOM ready events -- //


// email information; hide from spam bots
var mailserver = "";

function getEmail (incommingAddress)
{
	var address = incommingAddress + "@" +  mailserver;
	document.write('<a href="mailto:'+address+'?Subject=Information request from "' + 'rel="next"' + 'title="Email us directly.">' +address+ '</a>');
}


// replacement for _blank target. use: "rel="external" on links to activate
function externalLinks() 
{ 
	if (!document.getElementsByTagName)
	{
		return;
	}
	var anchors = document.getElementsByTagName("a"); 
	
	for (var i=0; i<anchors.length; i++)
	{ 
		var anchor = anchors[i]; 
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
		{
			anchor.target = "_blank";
		}
	}
}


// preload images that need to be available asap
jQuery.preloadImages = function()
{
  for(var i = 0; i < arguments.length; i++)
  {
    jQuery('<img>').attr("src", arguments[i]);
  }
}


// image (button) rollover functionality
PEPS = {};

PEPS.rollover =
{
   init: function()
   {
      this.preload();
     
      $(".ro").hover(
         function () { $(this).attr( 'src', PEPS.rollover.newimage($(this).attr('src')) ); },
         function () { $(this).attr( 'src', PEPS.rollover.oldimage($(this).attr('src')) ); }
      );
   },

   preload: function()
   {
      $(window).bind('load', function() {
         $('.ro').each( function( key, elm ) { $('<img>').attr( 'src', PEPS.rollover.newimage( $(this).attr('src') ) ); });
      });
   },
   
   newimage: function( src )
   {
      return src.substring( 0, src.search(/(\.[a-z]+)$/) ) + '_o' + src.match(/(\.[a-z]+)$/)[0];
   },

   oldimage: function( src )
   {
      return src.replace(/_o\./, '.');
   }
};