/**************************************************************/
/*	 			 MAKE ADDITIONAL FUNCTIONS AFTER LINE 100	 				  */
/**************************************************************/

documentReadyListeners = new Array();

/**
 * Keeps an array of all registered document ready listeners. This
 * are invoked when the page is loaded by full page load or AJAX
 */
function documentReady(fnName){
	documentReadyListeners.push(fnName);
}

/**
 * Invokes all registered document ready listeners
 */
function invokeDocumentReadyListeners(firesifr){
	for(i=0; i<documentReadyListeners.length; i++)
	{
		eval(documentReadyListeners[i] + "()");
	}	
}

/**
 * Define the global document ready handler
 */
jQuery(document).ready(function(){
    invokeDocumentReadyListeners(false);
});

function splitValue(value, token, index){
    var arr = value.split(token);
    return arr[index];
}

String.prototype.stripSpaces = function( ){ return this.replace( /\s/g, "" ); };

function whiteSpace(value){
    value = value.replace(/^\s*|\s*$/g, '');
    return value;
}

function removeSpaces(string) {
 return string.split(' ').join('');
}

function getParam(name){
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var result = regex.exec(window.location.href);
    if (result == null) 
        return "";
    else 
        return result[1];
}

function splitValue(value, token, index)
{
	 var arr = value.split(token);
 	 return arr[index];
} 

function vj_popup(url, width, height)
{
	 var params = 'width='+ width;
	 params += ', height='+ height;
	 params += ',menubar=yes';
	 params += ',toolbar=yes';
	 params += ',resizable=yes';
	 window.open(url,"", params);
}

function addCarousel(id, movieLocation, width, height, alt)
{
	var flashvars = {};
	var params = { };
	var attributes = {};
	
	flashvars.xmlpath = escape(jQuery("[id$='"+id+"']").attr("class"));
	flashvars.holdfor = "5";
	params.wmode = "opaque";
	
	var myMovie = movieLocation;
	var expressInstall = "/javascript/swfobject/expressInstall.swf";
	
	swfobject.embedSWF(myMovie, alt, width, height, "9.0.0", expressInstall, flashvars, params, attributes);
}

documentReady("attachPopupCode");
function attachPopupCode()
{
	jQuery(".shareLink").click( function() {
		vj_popup(jQuery(this).attr("href"), 400, 300);
		return false;
	}); 
}

/**************************************************************/
/*				      	  	EDIT BELOW THIS LINE										*/
/**************************************************************/

/**
 * Site Specific Functions Go Here:
 */
	// <![CDATA[
	jQuery(document).ready(function(){
	
	  jQuery(".btn1").hoverIntent(
		function() {
			jQuery(this).addClass("hover");
			jQuery(this).find(".portal-1").slideDown();
		},
		function() {
			jQuery(this).removeClass("hover");
			jQuery(this).find(".portal-1").slideUp();
		}
	  );
	  
	  jQuery(".btn2").hoverIntent(
		function() {
			jQuery(this).addClass("hover");
			jQuery(this).find(".portal-2").slideDown();
		},
		function() {
			jQuery(this).removeClass("hover");
			jQuery(this).find(".portal-2").slideUp();
		}
	  );
	  
	  /* adjusting position in single image gallery */
    jQuery("div.gallery .primary .image-container .image-content a img").each(function(e) {
        var boxWidth = jQuery(this).closest("li").width();
        var boxHeight = jQuery(this).closest("li").height();
        var imgWidth = jQuery(this).attr("width");
        var imgHeight = jQuery(this).attr("height");
        var topMarginNeeded = ((boxHeight - imgHeight) / 2) - 5;
        var leftMarginNeeded = ((boxWidth - imgWidth) / 2) - 5;
        jQuery(this).closest("li").find("div.image-container").css("margin-left", leftMarginNeeded).css("margin-top", topMarginNeeded);
    }); 
	  /*
	  jQuery("#.btn1").hoverIntent(
		function() {jQuery(this).closest("portal-1").addClass("hover");},
		function() {jQuery(this).closest("portal-1").removeClass("hover");}
	  );

	  jQuery("#.btn2").hoverIntent(
		function() {jQuery(this).closest("portal-2").addClass("hover");},
		function() {jQuery(this).closest("portal-2").removeClass("hover");}
	  );
	  */

	/* displaying/hiding main navigation drop downs on hover and focus */
		jQuery("#navlist > li").hoverIntent(
			function() {
				jQuery(this).addClass("hover");
				jQuery(this).find(".drop-down").slideDown();
			},
			function() {
				jQuery(this).removeClass("hover");
				jQuery(this).find(".drop-down").slideUp();
			}
		);
		jQuery("#navlist > li > .drop-down").hoverIntent(
			function() {jQuery(this).closest("li").addClass("hover");},
			function() {jQuery(this).closest("li").removeClass("hover");}
		);
		/* focus - for keyboard only users */
			jQuery("#navlist > li > a").focus(
				function() {
					jQuery("#navlist > li .drop-down").hide();
					jQuery("#navlist > li").removeClass("hover");
					jQuery(this).closest("li").addClass("hover");
					jQuery(this).closest("li").find(".drop-down").slideDown();
				});
			jQuery("#navlist > li > ul li a").focus(
				function() {jQuery(this).closest("li").addClass("hover");},
				function() {jQuery(this).closest("li").removeClass("hover");}
			);


	    $('#feature-home').cycle({
		  fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		  pager:  '#pager',
		  speed:  5000,
		  pause:  1,
		  pagerAnchorBuilder: function(index, el) {
			return '<a href="#" class="pagerNav"></a>'; // whatever markup you want
		  }
		});
		
		$("span.disclaimer a.open").click(function () { 
		  $("#disclaimer-details").slideDown(); 
		});
		
		$("#disclaimer-details p.close").click(function () { 
		  $("#disclaimer-details").slideUp(); 
		});
		
		
		$("#OptOut").change(function(){
		  if(this.value == 'Mail')
			{$("#Mail").slideDown();}
			else
			{$("#Mail").slideUp();}
		  });
		  
		$("#opt-in").click(function() {
		    $("#emailOptOut").val(($("#opt-in:checked").length > 0) ? 1 : 0);
		     	    
		});
		
		$('#Mail').hide();
		
		jQuery("#subnav-left li").hoverIntent(
		function() {
			jQuery(this).addClass("hover");
		},
		function() {
			jQuery(this).removeClass("hover");
		}
	  );



  });


  $(document).ready(function() {
      $('a.movieOverlay').attr('rel', '#overlay');
      $('a.movieOverlay').overlay({ onClose: movieOverlayClose });
      $('a.movieOverlay').click(function(e) {
          e.preventDefault();
          movieOverlayClose();
          var t = setTimeout("movieOverlayLoad('" + $(this).attr('href') + "')", 500);
      });
  });

  function movieOverlayLoad(url) {
      var flashVarsVid = { url: url, autoPlay: "true", showSpinner: "true", controls: "scrub,time,duration,volume,fullscreen", colorTheme: "#259DD4", framing: "touchinside" };
      var paramsVid = { menu: 'false', allowFullScreen: "true", allowScriptAccess: "sameDomain", bgColor: "#FFFFFF" };
      var attributesVid = { id: 'movieOverlayPlayer', name: 'movieOverlayPlayer' };
      swfobject.embedSWF('/swf/videoplayer/videoplayer.swf', 'contentWrap', '640', '360', '9.0.28', false, flashVarsVid, paramsVid, attributesVid);
      trackEventClick(siteArea, "Video Overlay", window.location.pathname);
  }

  function movieOverlayClose() {
      $('#overlay object').replaceWith('<div id="contentWrap"></div>');
  }
	
	// ]]>

/*Cufon Replace*/


