/* AIDS.gov main.js file */
/* Modified by: JH */
/* Date: 2/16/2010 */
/* Latest features: adding pdf download tracking. */

var bookmarkLinks = [{text: "MySpace", className: "myspace", href: "http://www.myspace.com/Modules/PostTo/Pages/?u=[URL]&t=[TITLE]&c=%20"},
					 {text: "Facebook", className: "facebook", href: "http://www.facebook.com/sharer.php?u=[URL]&t=[TITLE]"},
					 {text: "StumbleUpon", className: "stumbleupon", href: "http://www.stumbleupon.com/submit?url=[URL]&title=[TITLE]"},
					 {text: "Technorati", className: "technorati", href: "http://technorati.com/faves?sub=addfavbtn&add=[URL]"},
					 {text: "Reddit", className: "reddit", href: "http://reddit.com/submit?url=[URL]&title=[TITLE]"},
					 {text: "Digg", className: "digg", href: "http://digg.com/submit?url=[URL]&title=[TITLE]&media=News&topic=health&thumbnails=0"},
					 {text: "Del.icio.us", className: "delicious", href: "http://del.icio.us/post?v=4&noui&jump=close&url=[URL]&title=[TITLE]"},
					 {text: "Email to Friend", className: "email", href: "http://www.feedburner.com/fb/a/emailFlare?itemTitle=[TITLE]&uri=[URL]"}];

var pageHREF = encodeURIComponent(window.location.href);
var pageTitle = encodeURIComponent(document.title);
var isIE = jQuery.browser.msie;
var isIE6 = (navigator.appName.indexOf('Microsoft') >= 0) && (parseFloat(navigator.appVersion.substring(navigator.appVersion.indexOf('MSIE')+5)) < 7); 

$(document).ready(function(){
						   
	// font size init
	init_font();
	
	// content read more link
	$("hr#read-more").each( function(){ init_readmore(this); });
	$("div#page-highlights a").click ( function(){ return toggle_readmore(this.href); });
	
						   
	if (!isIE6) $('#global-nav a.top-level:not(.global-'+document.body.id+')')
		.css( {backgroundPosition: "0 0"} )
		.mouseover(function(){
			$(this).animate(
				{backgroundPosition:"(0 -45px)"}, 
				{duration:200})
			})
		.mouseout(function(){
			$(this).animate(
				{backgroundPosition:"(0 0)"}, 
				{duration:200})
	})
	
	if (!isIE6) $('ul.sub-nav > li')
			.css( {backgroundPosition: "0 0"} )
			.hover(function(){
				$(this).animate(
					{backgroundPosition:"(0 -30px)"}, 
					{duration:300}).children("ul").addClass("open").css({display: "none"}).fadeIn("fast");
				}
			,function(){
				$(this).animate(
					{backgroundPosition:"(0 0)"}, 
					{duration:300}).children("ul").removeClass("open").fadeOut("fast", function(){ $(this).css({display: "block"}); });
		})
	else $('ul.sub-nav > li')
			.hover(function(){
				$(this).toggleClass("hover").children("ul").addClass("open").css({display: "none"}).fadeIn("fast");
				}
			,function(){
				$(this).toggleClass("hover").children("ul").removeClass("open").fadeOut("fast", function(){ $(this).css({display: "block"}); });
		})
	$("a.sub-level").addClass("drop").each( function() { $(this).next().css({left: (((findPos(this)[0]-findPos(this.parentNode.parentNode)[0])+this.offsetWidth/2)-$(this).next()[0].offsetWidth/2)}) });	
	
	var currentTask = window.location.href.split("/")[4];
	if ( currentTask != null)
	{
		$("#sub-"+$("body")[0].id+" .sub-level").each( function(){
																
																
																if( this.href.split("/")[4] == currentTask )
																{
																	if (!isIE6)
																	{
																		$(this.parentNode).animate( {backgroundPosition:"(0 -30px)"}, {duration:1});
																	}
																	$(this.parentNode).addClass("current-topic");
																	return;
																}
																})
	}
	
	$("li#print-this a").click( function(){ pageTracker._trackEvent("Print",pageHREF); window.print(); return false; });
	$("li#share-this a").click( function(){ toggle_shareMenu(); clearTimeout(toggleDelay); return false; });
	if ($("li#share-this a")[0]) init_shareMenu();
	
	$('div.content-support div:not(.internal)').click( function(){ window.location="/external-disclaimer.html"; });
	$('div.content-support div.hiv-test,div.content-support div.hiv-test div').unbind();
	
	$("li#email-this a").each( function() { this.href = bookmarkLinks[7].href.replace("[URL]",pageHREF).replace("[TITLE]",pageTitle); });
	
	// form auto clear
	$("input.auto-clear").focus( function(){ if (this.value == this.title) this.value = ""; });
	$("input.auto-clear").blur( function(){ if (this.value == "") this.value = this.title; });
	
	/*ancillary data script
	$("div.ancillary-data").each( function(){
											$(this.getElementsByTagName("h4")[0]).click( function(){ pageTracker._trackEvent("Ancillary Data", this.innerHTML, pageHREF); toggle_ancillary(this); return false;}) 
										   	if (this.getElementsByTagName("h4")[0].className != "open") $("div.ancillary-copy",this).slideToggle(0, function() { $(this).addClass("collapse"); $(this).css({display: "block"})  });
										   });
   */
   
	// home Basics code
	$("div.basics-section").fadeOut(0, function(){$(this).addClass("collapse").css({display:"block"});}).css({left:8});
	$($("div.basics-section")[0]).css({display:"none"}).removeClass("collapse").toggleClass("basics-current-section").fadeIn(0);
	$("ul#basics-nav").each(function() { this.className = $("ul#basics-nav a")[0].rel; });
	$("ul#basics-nav a").mouseover( function() { 	 var whichLink = this.rel
												 		if ( $("ul#basics-nav")[0].className.indexOf(this.rel) < 0 ) {
															$("ul#basics-nav")[0].className = this.rel;
															$("div.basics-current-section").fadeOut(0, function() {$(this).addClass("collapse").css({display:"block"});}).toggleClass("basics-current-section");
															$("div#"+whichLink).css({display:"none"}).removeClass("collapse").fadeIn(250).toggleClass("basics-current-section");
														}
												 		return false;
												   });
   
	// home new media code
	$("#task-newmedia li").hover( function() { $(this.parentNode).addClass(this.id); },
								  function() { $(this.parentNode).removeClass(this.id); } );
	
	// home federal code
	$("map#federal-map area").hover( function() { $("img#links-federal").toggleClass(this.id); },
									 function() { $("img#links-federal").toggleClass(this.id);
									});
	
	// new media tools code
	$("div#toolbox span").click( function() {
										  		if (this.className!="open")
												{
													var toolbox = $("#toolbox")[0];
													
													var x=findPos(toolbox)[0]-findPos($("#wrapper")[0])[0]+9;
													var y=findPos(toolbox)[1]+toolbox.offsetHeight-10;
													$("#wrapper").append("<div id='toolbox-list'></div>");
													$("#toolbox-list").css({top: y, left: x}).append($("#toolbox ul").remove());
												}
												else
												{
													$("#toolbox").append($("#toolbox-list ul").remove());
													$("#toolbox-list").remove();
												}
												$(this).toggleClass("open");
												
											 });
	
	// new media tool index tooltip
	$("dl.tools-list a").hover( function() { $("#wrapper").append('<div class="tool-tip copy-block" id="tooltip-'+this.rel+'">'+$("dd#"+this.rel).html()+'</div>'); $(this).bind("mousemove", function(e) {tool_tip(e, this, "new-media-tool")} ); },
				 				function() { $(this).unbind("mousemove", function(e) {tool_tip(e, this, "new-media-tool")}); $("div#tooltip-"+this.rel).remove();  }
							   );
	
	// hiv-basics  tooltip
	$("dfn").hover( function() { var tipID="tooltip"+Math.round(Math.random()*10000); this.id=tipID.replace("tooltip","trigger");  $("#wrapper").append('<div class="tool-tip copy-block" id='+tipID+'><span>'+$(this).html()+'</span><p>'+this.title+'</p></div>'); $(this).attr("title","").bind("mousemove", function(e) {tool_tip(e, this, "definition")} ); return false; },
				 				function() { $(this).attr("title",$("#"+this.id.replace("trigger","tooltip")+" p").html()).unbind("mousemove", function(e) {tool_tip(e, this, "definition")}); $("#"+this.id.replace("trigger","tooltip")).remove();  }
							   ).buildGlossary();
	
	// hiv/aids basics accordians init
	$("div#hiv-aids-sitemap div.section").each( function() { 
												$("ul.topics ul", this).not($("ul.topics ul", this)[0]).slideUp( "fast" );
												$("a.topic-toggle", this).eq(0).toggleClass( "open" );
											 });
	// hiv/aids basics accordians event handler
	$("div#hiv-aids-sitemap a.topic-toggle").click( function() {
												var selfClick = (this.className.indexOf("open") > 0);
												
												$("a.open", $(this).parent().parent()).toggleClass( "open" );
												$("ul", $(this).parent().parent()).slideUp( "fast" );
															   
												if (!selfClick)
												{
													$(this).toggleClass( "open" );
													$("ul", $(this).parent()).slideDown( "fast" );
												}
												
												return false;
											 });
	
	/* if ($(".paginate-item").length > 3) init_pagination(); */
	
	// content toggle
	$(".toggle-trigger").toggleContent();
	
	// Pacha accordians init
	$("div.pacha-accordion").each( function() { 
												$("ul.topics ul", this).not($("ul.topics ul", this)[0]).slideUp( "fast" );
												$("a.topic-toggle", this).eq(0).toggleClass( "open" );
											 });
	// Pacha accordians event handler
	$("div.pacha-accordion a.topic-toggle").click( function() {
												var selfClick = (this.className.indexOf("open") > 0);
												
												$("a.open", $(this).parent().parent()).toggleClass( "open" );
												$("ul", $(this).parent().parent()).slideUp( "fast" );
															   
												if (!selfClick)
												{
													$(this).toggleClass( "open" );
													$("ul", $(this).parent()).slideDown( "fast" );
												}
												
												return false;
											 });
											 
	
	/* if ($(".paginate-item").length > 3) init_pagination(); */
	
	// faq slide
	$(".slide-toggle").slideContent();
	
	// awareness days content update
	$("div.awareness-day:not(.has-page)").click( function(){ 
										   		$("div.selected-day").toggleClass("selected-day");
										   		$(this).toggleClass("selected-day");

												$("div.upcoming-event").html("<h2>"+$("#"+this.id+" .month").html()+" "+$("#"+this.id+" .day").html()+" "+$("#"+this.id+" h3").html()+"</h2>");
												$("div.upcoming-event").append($("#"+this.id+" div.day-details").html());
												
												var logo = $("#"+this.id+" .logo")[0];
												
												$("div.awareness-intro img.logo").attr({width: logo.width, height: logo.height, alt: logo.alt});
												if (isIE6)
												{
													$("div.awareness-intro img.logo")[0].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + logo.style.filter.split("'")[1] + "',sizingMethod='scale')";
												}
												else
												{
													$("div.awareness-intro img.logo").attr({src: logo.src});
												}
												
												
												window.location = "#event-details";
										    });
	if ($.getQueryParams.showEvent != null) $("#"+$.getQueryParams.showEvent).trigger("click");
	$("div.has-page").click( function(){
											window.location = $(".page-link",this)[0].href;
										});
	
	$(".media-set #blog-posts").paginate({pageLength: 1, setMaxHeight: true});
	$(".media-set #podcasts").paginate({pageLength: 1, setMaxHeight: true});
	$(".newmedia-rightnav #media").paginate({pageLength: 3, setMaxHeight: true});

	var defaultBanner = ( ($.getQueryParams.showBanner) != null && ($("#"+$.getQueryParams.showBanner).length > 0) ) ? $.getQueryParams.showBanner : "news-item-one";
	$("#home-banner").banner({defaultElement: defaultBanner}); //, rotate: 8000

	if (($(".article,.tabbed-page").length > 0))
	{
		var opzioni = {	exact:"whole",
						style_name: "search-highlight",
						style_name_suffix:false,
						highlight: ".copy-block",
						nohighlight: ".embed-code,.sample-code"
					   };
						//debug_referrer: "http://www.google.com/",
						//keys: "new+aids+podcasts+answer",
		jQuery(function(){
			$(document).SearchHighlight(opzioni);
		});
	}
	
	$("a.track-external").click( function() { pageTracker._trackEvent("External Link",this.rel,pageHREF); return true; } );
	
	$("#photo-strip").photoStrip({images:27,
								  photoWidth: 165,
								  uri: "/images/photo-strip-{i}.jpg"
								  });

	$("#vert-strip").photoStrip({images:27,
								  photoWidth: 165,
								  uri: "/images/photo-strip-{i}.jpg",
								  orientation: "vertical"
								  });

	// National HIV/AIDS Strategy code								  
	$(".comment-rotate").commentRotate({rotateSpeed:8000});
	$("#nhas-badge .slide-trigger").click( function() { $("#badge-view").animate({left: -240},200); $("#embed-view").animate({left: 0},200); return false;});
	$("#embed-view .slide-trigger").click( function() { $("#badge-view").animate({left: 0},200); $("#embed-view").animate({left: 240},200); return false;});
	$("#embed-view textarea").focus( function() { this.select(); return false;});
	$("#collage").cycleCollage({rotateSpeed:4000,order:[1,2,4,3],count:9,dims:{w:98,h:88}});
	$("#video-gallery").videoGallery();

	// ias twitter feed pulled from http://ralphwhitbeck.com/2007/11/20/PullingTwitterUpdatesWithJSONAndJQuery.aspx
	String.prototype.linkify = function() {
		return this.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/, function(m) {
    return m.link(m); });}; 
	
	var url = "http://twitter.com/status/user_timeline/aidsgov.json?count=3&callback=?";
	if ($("#twitter-feed").length > 0)
	{
		$.getJSON(url,
				  function(data){ 
				  	$("#twitter-feed")[0].innerHTML="";
				  	$.each(data, function(i, item) { $("#twitter-feed").append("<p>"+item.text.linkify()+"<br /><span>"+relative_time(item.created_at)+"</span></p>");
				  				 });
				  });
	}
	
	$('a').each( function() {
		var isDoc = this.href.match(/\.(?:doc|ppt|pdf|zip|wma|mov|avi|wmv|mp3|mp4)($|\&|\?)/);
		if (isDoc) { 
			try {
				if ( this.hostname == location.host ) {
					$(this).click( function() { pageTracker._trackEvent("Download",this.href);; return true; } );
				}
			}
			catch(e) { return; }
		}
	});
 });

function relative_time(time_value) {
	  var values = time_value.split(" ");
	  time_value = values[1] + " " + values[2] + ", " + values[5] + " " + values[3];
	  var parsed_date = Date.parse(time_value);
	  var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
	  var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);
	  delta = delta + (relative_to.getTimezoneOffset() * 60);
	  
	  var r = '';
	  if (delta < 60) {
	    r = 'a minute ago';
	  } else if(delta < 120) {
	    r = 'couple of minutes ago';
	  } else if(delta < (45*60)) {
	    r = (parseInt(delta / 60)).toString() + ' minutes ago';
	  } else if(delta < (90*60)) {
	    r = 'an hour ago';
	  } else if(delta < (24*60*60)) {
	    r = '' + (parseInt(delta / 3600)).toString() + ' hours ago';
	  } else if(delta < (48*60*60)) {
	    r = '1 day ago';
	  } else {
	    r = (parseInt(delta / 86400)).toString() + ' days ago';
	  }
	  
	  return r;
}

(function($){
  // http://www.jquery.info/spip.php?article50
  $.fn.SearchHighlight = function(options) {
    var ref = options.debug_referrer || document.referrer;
    if(!ref && options.keys==undefined) return this;
    
    SearchHighlight.options = $.extend({exact:"exact",style_name:'hilite',style_name_suffix:true},options);
    if(options.engines) SearchHighlight.engines.unshift(options.engines);  

	var q = options.keys!=undefined?options.keys.toLowerCase().split(/[\s,\+\.]+/):SearchHighlight.decodeURL(ref,SearchHighlight.engines);
    if(q && q.join("")) {
      SearchHighlight.buildNotification(q);
      SearchHighlight.buildReplaceTools(q);
      return this.each(function(){
        var el = this;
        if(el==document) el = $("body")[0];
        SearchHighlight.hiliteElement(el, q); 
      })
    } else return this;
  }    

  var SearchHighlight = {
    options: {},
    regex: [],
    engines: [
    [/^http:\/\/(www\.)?google\./i, /q=([^&]+)/i],                            // Google
    [/^http:\/\/(www\.)?search\.yahoo\./i, /p=([^&]+)/i],                     // Yahoo
    [/^http:\/\/(www\.)?search\.msn\./i, /q=([^&]+)/i],                       // MSN
    [/^http:\/\/(www\.)?search\.live\./i, /query=([^&]+)/i],                  // MSN Live
    [/^http:\/\/(www\.)?search\.aol\./i, /userQuery=([^&]+)/i],               // AOL
    [/^http:\/\/(www\.)?ask\.com/i, /q=([^&]+)/i],                            // Ask.com
    [/^http:\/\/(www\.)?altavista\./i, /q=([^&]+)/i],                         // AltaVista
    [/^http:\/\/(www\.)?feedster\./i, /q=([^&]+)/i],                          // Feedster
    [/^http:\/\/(www\.)?search\.lycos\./i, /q=([^&]+)/i],                     // Lycos
    [/^http:\/\/(www\.)?alltheweb\./i, /q=([^&]+)/i],                         // AllTheWeb
    [/^http:\/\/(www\.)?technorati\.com/i, /([^\?\/]+)(?:\?.*)$/i]           // Technorati
    ],
    subs: {},
    decodeURL: function(URL,reg) {
      URL = decodeURIComponent(URL);
      var query = null;
	  
      $.each(reg,function(i,n){
        if(n[0].test(URL)) {
          var match = URL.match(n[1]);
          if(match) {
            query = match[1].toLowerCase();
            return false;
          }
        }
      })
      
      if (query) {
      query = query.replace(/(\'|")/, '\$1');
      query = query.split(/[\s,\+\.]+/);
      }
      
      return query;
    },
		regexAccent : [
      [/[\xC0-\xC5\u0100-\u0105]/ig,'a'],
      [/[\xC7\u0106-\u010D]/ig,'c'],
      [/[\xC8-\xCB]/ig,'e'],
      [/[\xCC-\xCF]/ig,'i'],
      [/\xD1/ig,'n'],
      [/[\xD2-\xD6\xD8]/ig,'o'],
      [/[\u015A-\u0161]/ig,'s'],
      [/[\u0162-\u0167]/ig,'t'],
      [/[\xD9-\xDC]/ig,'u'],
      [/\xFF/ig,'y'],
      [/[\x91\x92\u2018\u2019]/ig,'\'']
    ],
    matchAccent : /[\x91\x92\xC0-\xC5\xC7-\xCF\xD1-\xD6\xD8-\xDC\xFF\u0100-\u010D\u015A-\u0167\u2018\u2019]/ig,  
		replaceAccent: function(q) {
		  SearchHighlight.matchAccent.lastIndex = 0;
      if(SearchHighlight.matchAccent.test(q)) {
        for(var i=0,l=SearchHighlight.regexAccent.length;i<l;i++)
          q = q.replace(SearchHighlight.regexAccent[i][0],SearchHighlight.regexAccent[i][1]);
      }
      return q;
    },
    escapeRegEx : /((?:\\{2})*)([[\]{}*?|])/g, //the special chars . and + are already gone at this point because they are considered split chars
	buildNotification : function(q) {
		$(document.body).prepend('<div id="search-highlight-info" style="display: none;"><p>It looks like you searched for "' + q.join(", ") + '". Your search terms have been highlighted on the page below. <a href="' + window.location.href + '" id="hide_search_terms">Hide Search Terms</a></div>');
		$("#search-highlight-info").slideDown();
		$("a#hide_search_terms").click( function(){ $('span.search-highlight').removeClass("search-highlight"); $("#search-highlight-info").slideUp(); return false; });;
	},
    buildReplaceTools : function(query) {
        var re = [], regex;
        $.each(query,function(i,n){
            if(n = SearchHighlight.replaceAccent(n).replace(SearchHighlight.escapeRegEx,"$1\\$2"))
              re.push(n);        
        });
        
        regex = re.join("|");
        switch(SearchHighlight.options.exact) {
          case "exact":
            regex = '\\b(?:'+regex+')\\b';
            break;
          case "whole":
            regex = '\\b\\w*('+regex+')\\w*\\b';
            break;
        }    
        SearchHighlight.regex = new RegExp(regex, "gi");
        
        $.each(re,function(i,n){
            SearchHighlight.subs[n] = SearchHighlight.options.style_name+
              (SearchHighlight.options.style_name_suffix?i+1:''); 
        });       
    },
    nosearch: /s(?:cript|tyle)|textarea/i,
    hiliteElement: function(el, query) {
        var opt = SearchHighlight.options, elHighlight, noHighlight;
        elHighlight = opt.highlight?$(opt.highlight):$("body"); 
        if(!elHighlight.length) elHighlight = $("body"); 
        noHighlight = opt.nohighlight?$(opt.nohighlight):$([]);
                
        elHighlight.each(function(){
          SearchHighlight.hiliteTree(this,query,noHighlight);
        });
    },
    hiliteTree : function(el,query,noHighlight) {
        if(noHighlight.index(el)!=-1) return;
        var matchIndex = SearchHighlight.options.exact=="whole"?1:0;
        for(var startIndex=0,endIndex=el.childNodes.length;startIndex<endIndex;startIndex++) {
          var item = el.childNodes[startIndex];
          if ( item.nodeType != 8 ) {//comment node
  				  //text node
            if(item.nodeType==3) {
              var text = item.data, textNoAcc = SearchHighlight.replaceAccent(text);
              var newtext="",match,index=0;
              SearchHighlight.regex.lastIndex = 0;
              while(match = SearchHighlight.regex.exec(textNoAcc)) {
                newtext += text.substr(index,match.index-index)+'<span class="'+
                SearchHighlight.subs[match[matchIndex].toLowerCase()]+'">'+text.substr(match.index,match[0].length)+"</span>";
                index = match.index+match[0].length;
              }
              if(newtext) {
                //add the last part of the text
                newtext += text.substring(index);
                var repl = $.merge([],$("<span>"+newtext+"</span>")[0].childNodes);
                endIndex += repl.length-1;
                startIndex += repl.length-1;
                $(item).before(repl).remove();
              }                
            } else {
              if(item.nodeType==1 && item.nodeName.search(SearchHighlight.nosearch)==-1)
                  SearchHighlight.hiliteTree(item,query,noHighlight);
            }	
          }
        }    
    }
	}
})(jQuery);

// function photo index photo strip
(function($){
	$.fn.photoStrip = function( config ) {

		if (this.length == 0) return;
		
		pictureTemplate = $("li", this).eq(0).clone();
		
		$.fn.photoStrip.stripId = this[0].id;
		$.fn.photoStrip.photoWidth = config.photoWidth;
		$.fn.photoStrip.images = config.images;
		$.fn.photoStrip.orientation = config.orientation;
		$.fn.photoStrip.index = 1;
		
		$.fn.photoStrip.timer = setTimeout( $.fn.photoStrip.animate, 50 );
		
		return this.each(function(i) {
			var $this = $(this);
			
			$imageList = $($("ul",this)[0]);
			switch ( $.fn.photoStrip.orientation ) {
				case "vertical" :
					$imageList.css({height: 160*config.images, top: 0, position: "absolute"});
					break;
				default :
					$imageList.css({width: config.photoWidth*config.images, left: 0, position: "absolute"});
				break;
			}

			$imageList.html("");

			for(var i = 1; i <= config.images; i++)
			{
				$(pictureTemplate).attr({id:"photo-"+i});
				$imageList.append($(pictureTemplate).attr({id:"photo-"+i}).clone());
				
				$("li#photo-"+i+" img").attr({src: config.uri.replace("{i}", i)});
			}
			
			
		});
		
	}
	$.fn.photoStrip.animate = function() {
		switch ( $.fn.photoStrip.orientation ) {
			case "vertical" :
				$("#"+$.fn.photoStrip.stripId+" ul").css({top: parseInt($("#"+$.fn.photoStrip.stripId+" ul").css("top").replace("px",""))-2}); 
		
				if (parseInt($("#"+$.fn.photoStrip.stripId+" ul").eq(0).css("top").replace("px","")) < -170)
				{
					$("#"+$.fn.photoStrip.stripId+" ul").append($("#"+$.fn.photoStrip.stripId+" ul")[0].removeChild($("#"+$.fn.photoStrip.stripId+" ul li")[0]));
					$("#"+$.fn.photoStrip.stripId+" ul").css({top: -2});
				}
				
				$.fn.photoStrip.timer = setTimeout( $.fn.photoStrip.animate, 50 );
				
				break;
			default :
				$("#"+$.fn.photoStrip.stripId+" ul").css({left: parseInt($("#"+$.fn.photoStrip.stripId+" ul").css("left").replace("px",""))-2}); 
		
				if (parseInt($("#"+$.fn.photoStrip.stripId+" ul").eq(0).css("left").replace("px","")) < -$.fn.photoStrip.photoWidth)
				{
					$("#"+$.fn.photoStrip.stripId+" ul").append($("#"+$.fn.photoStrip.stripId+" ul")[0].removeChild($("#"+$.fn.photoStrip.stripId+" ul li")[0]));
					$("#"+$.fn.photoStrip.stripId+" ul").css({left: -2});
				}
				
				$.fn.photoStrip.timer = setTimeout( $.fn.photoStrip.animate, 50 );
				
				break;
		}
	}
})(jQuery);

// function photo index photo strip
(function($){
	$.fn.commentRotate = function( config ) {

		if (this.length == 0) return;
		
		$.fn.commentRotate.config = config;
		$.fn.commentRotate.instances = new Array();
		$.fn.commentRotate.index = 0;
		
		$.fn.commentRotate.timer = setTimeout( $.fn.commentRotate.animate, config.rotateSpeed );
		
		var index = 0;
		return this.each(function(i) {
			
		
			$this = $(this);
			maxHeight = 0;
			
			$.fn.commentRotate.instances[index] = {id: this.id, index: 0, commentList: null};
			
			$commentList = $.fn.commentRotate.instances[index].commentList = $(".quote",this);
			
			for( var i=0; i < $commentList.length; i++ ) {
				maxHeight = ($commentList[i].offsetHeight > maxHeight) ? $commentList[i].offsetHeight : maxHeight;
			}
			if (this.id != "sub-hero") $this.css("height",maxHeight);
			
			$commentList.css({left:0,position:'absolute'}).fadeOut(0);
			$($commentList[0]).fadeIn(0);		
			index++;
		});
		
	}
	$.fn.commentRotate.animate = function() {
		
		$.each( $.fn.commentRotate.instances, function(key, value){

			i = value.index;
	
			$commentList = value.commentList;
			
			$($commentList[i]).fadeOut(750);
	
			value.index = i = (i+1) % $commentList.length;
	
			$($commentList[i]).fadeIn(750);
	
		});
	
		$.fn.commentRotate.timer = setTimeout( $.fn.commentRotate.animate, $.fn.commentRotate.config.rotateSpeed );

	}
})(jQuery);

// rotating 2x2 collage for NHAS interior pages
(function($){
	$.fn.cycleCollage = function( config ) {

		if (this.length == 0) return;
		
		$.fn.cycleCollage.slotIndex = 0;
		$.fn.cycleCollage.count = config.count;
		$.fn.cycleCollage.dims = config.dims;
		$.fn.cycleCollage.rotateSpeed = config.rotateSpeed;
		$.fn.cycleCollage.order = config.order;
		$.fn.cycleCollage.timer = setTimeout( $.fn.cycleCollage.cycle, config.rotateSpeed );
		
		$.fn.cycleCollage.imgIndexRegexp = /\d{1,2}(?=\.)/
		
		pictureTemplate = $(".slot img", this).eq(0).clone();
		pictureURI = $(pictureTemplate).attr("src").replace($.fn.cycleCollage.imgIndexRegexp,"{I}");
		
		return this.each(function(i) {
		
			$this = $(this);

			$(".slot", this).each( function() { $.fn.cycleCollage.initCycle(this) });
			
		});
		
	}
	$.fn.cycleCollage.initSlide = function() { 
												
		$("img", this).wrap("<div></div>");
		$("div", this).css({position:"absolute",width:config.dims.w*$.fn.cycleCollage.count,height:config.dims.h});
		
		slot = parseInt(this.id.split("-")[1]);
		imgIndex = parseInt($("img", this).eq(0).attr("src").match($.fn.cycleCollage.imgIndexRegexp)[0]);
		
		imgBounds = {start: slot*$.fn.cycleCollage.count-(config.count-1), end: slot*$.fn.cycleCollage.count};
	
		for(var i=0; i < config.count-1; i++) {
			imgIndex++;
			
			if (imgIndex > imgBounds.end) imgIndex = imgBounds.start;
			$("div",this).append($(pictureTemplate).clone().attr({src: pictureURI.replace("{I}",imgIndex)}));
		}
	}
	$.fn.cycleCollage.slide = function() {
		idx = ($.fn.cycleCollage.order != null) ? $.fn.cycleCollage.order[$.fn.cycleCollage.slotIndex] : $.fn.cycleCollage.slotIndex+1;
		
		$("#collage #slot-"+idx+" div").animate({left: -$.fn.cycleCollage.dims.w}, 500, function() {
																									$("#collage #slot-"+idx+" div").append( $("#collage #slot-"+idx+" div")[0].removeChild($("#collage #slot-"+idx+" div img")[0]) ).css({left:0});
																									});
	
	 	$.fn.cycleCollage.slotIndex = ($.fn.cycleCollage.slotIndex + 1) % $("#collage .slot").length;
	
		$.fn.cycleCollage.timer = setTimeout( $.fn.cycleCollage.cycle, $.fn.cycleCollage.rotateSpeed );

	}
	$.fn.cycleCollage.initCycle = function(obj) { 
												
		$("img", obj).wrap("<div></div>").css({"z-index":$.fn.cycleCollage.count+1,position:"absolute",top:0,left:0});
		$("div", obj).css({position:"absolute",width:$.fn.cycleCollage.dims.w,height:$.fn.cycleCollage.dims.h});
		
		slot = parseInt(obj.id.split("-")[1]);
		imgIndex = parseInt($("img", obj).eq(0).attr("src").match($.fn.cycleCollage.imgIndexRegexp)[0]);
		
		imgBounds = {start: slot*$.fn.cycleCollage.count-($.fn.cycleCollage.count-1), end: slot*$.fn.cycleCollage.count};
	
		for(var i=0; i < $.fn.cycleCollage.count-1; i++) {
			imgIndex++;
			
			if (imgIndex > imgBounds.end) imgIndex = imgBounds.start;
			$("div",obj).append($(pictureTemplate).clone().css({position:"absolute",top:0,left:0, "z-index":$.fn.cycleCollage.count-i}).attr({src: pictureURI.replace("{I}",imgIndex)}));
		}
	}
	$.fn.cycleCollage.cycle = function() {
		idx = ($.fn.cycleCollage.order != null) ? $.fn.cycleCollage.order[$.fn.cycleCollage.slotIndex] : $.fn.cycleCollage.slotIndex+1;
		
		$("#collage #slot-"+idx+" img").eq(0).fadeOut(750, function() {
																									$("#collage #slot-"+idx+" div").append( $("#collage #slot-"+idx+" div")[0].removeChild($("#collage #slot-"+idx+" div img")[0]) );
																									$("#collage #slot-"+idx+" img").each( function() { $(this).css("z-index",  parseInt($(this).css("z-index"))+1 ) } );
																									$("#collage #slot-"+idx+" img:last").fadeIn(0).css("z-index",1);
																									});
	
	 	$.fn.cycleCollage.slotIndex = ($.fn.cycleCollage.slotIndex + 1) % $("#collage .slot").length;
	
		$.fn.cycleCollage.timer = setTimeout( $.fn.cycleCollage.cycle, $.fn.cycleCollage.rotateSpeed );

	}
})(jQuery);


// function for swapping out blocks of content
(function($){
	$.fn.toggleContent = function() {

		debug(this);
		
		if (this.length == 0) return;
		
		var defaultContent = $.getQueryParams.showTab ? $.getQueryParams.showTab : this[0].rel;
		if ($(".toggle-content[id="+defaultContent+"]").length == 0) defaultContent = this[0].rel;
		
		$(".toggle-content:not(#"+defaultContent+")").addClass("collapse");
		$($(".toggle-trigger[rel="+defaultContent+"]")[0].parentNode).toggleClass("current-trigger");

		return this.each(function(i) {
			var $this = $(this);
			
			$this.hover( function() { $(this.parentNode).toggleClass("hover-trigger") },
						 function() { $(this.parentNode).toggleClass("hover-trigger") });
			
			$this.click( function() {
										pageTracker._trackPageview(window.location.href+"?toggleContent="+this.rel);
		
										if (this.parentNode.className.indexOf("current-trigger")>=0) { return false; }
	
										$("#"+$(".current-trigger a")[0].rel).addClass("collapse");
										
										$("#"+this.rel).removeClass("collapse").hide().fadeIn("fast");
										
										$(".current-trigger").toggleClass("current-trigger");
										$(this).parent().toggleClass("current-trigger");
										
										return false;
									 });
		});
		
		function debug($obj) {
			if (window.console && window.console.log) {
				window.console.log("[toggleContent]");
				$obj.each(function() {window.console.log(this.rel)});
			}
		}
	}
})(jQuery);

// function for swapping out blocks of content
(function($){
	$.fn.buildGlossary = function() {
		
		if (this.length == 0) return;
		
		$("#subject-copy").append("<div class='collapse'><h2>Definitions of terms used on this page:</h2><dl id='page-glossary'></dl></div>");
		$("#interior-page").append("<div class='collapse'><h2>Footnotes on this page:</h2><dl id='page-glossary'></dl></div>");

		return this.each(function(i) {
			$("dl#page-glossary").append("<dt>"+this.innerHTML+"</dt><dd>"+this.title+"</dd>");
		});
	}
})(jQuery);

(function($){
	$.fn.slideContent = function() {
		
		debug(this);
		
		var defaultContent = $.getQueryParams.showContent ? $.getQueryParams.showContent : null;
		if ($(".slider[id="+defaultContent+"]").length == 0) defaultContent = null;
		
		$(".slider:not(#"+defaultContent+")").hide().addClass("collapse").css({display:"block"});
		
		if (defaultContent) 
		{
			$($("a[rel="+defaultContent+"]")[0].parentNode).toggleClass("related-open");
			$("div[id="+defaultContent+"]").toggleClass("slide-open");
			window.location = "#"+defaultContent;
		}
		
		$(".slide-toggle").click( function() {
												var slider = $("#"+this.rel)[0];
												if (slider.className.indexOf("slide-open")>=0)
												{
													$(slider).slideUp("fast",function(){ $(this).addClass("collapse").css({display:"block"}); });
												}
												else
												{
													$(slider).css({display:"none"}).removeClass("collapse").slideDown();
												}
												
												$(this.parentNode).toggleClass("related-open");
												$(slider).toggleClass("slide-open");
												return false;
												
											 });
		
		function debug($obj) {
			if (window.console && window.console.log) {
				$obj.each(function() {window.console.log(this.rel)});
			}
		}
	}
})(jQuery);

(function($){
	$.fn.banner = function(banners) {
		if (this.length <= 0) return;
		
		// set up variables
		$this = $(this[0]);
		var elements = $.fn.banner.elements = $.extend(banners.elements);
		$.fn.banner.rotateSpeed = (banners.rotate != null)?banners.rotate:0;

		if (banners.defaultElement == null)
			var defaultElement = $.fn.banner.defaultElement = $("ul#whats-new-nav a")[0].rel;
		else {
			var defaultElement = $.fn.banner.defaultElement = banners.defaultElement;
			
			if (defaultElement != "news-item-one") {
				banners.rotate = 0;
				$("#whats-new div.news-item:not(.collapse)").hide().addClass("collapse").css({display: "block"});
				$("#"+defaultElement).css({display: "none"}).removeClass("collapse").show();
			}
		}
		
		$("ul#whats-new-nav")[0].className=defaultElement;
		$($("ul#whats-new-nav a[rel="+defaultElement+"]")[0].parentNode).addClass("current-banner");
		
		// add event handler
		$("#whats-new-nav a", $this).click( function() { $.fn.banner.toggle(this); return false; } );
		$("#whats-new-nav a", $this).mousedown( function() { pageTracker._trackEvent( "Home Banner", this.rel ); return true; } );
		
		// start rotate
		if (banners.rotate > 0) $.fn.banner.timeout = setTimeout( $.fn.banner.rotate, $.fn.banner.rotateSpeed );

		function debug($obj) {
			if (window.console && window.console.log) {
				$obj.each(function() {window.console.log(this.id)});
			}
		}
	}
	$.fn.banner.toggle = function(obj) {
		
		clearTimeout($.fn.banner.timeout);
		
		$this = $(obj)[0];
		
		if ($("ul#whats-new-nav")[0].className == $this.rel) return
		
		$("ul#whats-new-nav")[0].className=$this.rel;
		$(".news-item:not(.collapse)").hide().addClass("collapse").css({display: "block"});
		$("#"+$this.rel).css({display: "none"}).removeClass("collapse").fadeIn(1000);
		$(obj.parentNode).css({display: "none"}).css({display: "block"}); //forces IE7 to redraw button to show background
	}
	$.fn.banner.rotate = function() {
		var $nextElement = $("#whats-new-nav .current-banner").toggleClass("current-banner").next()
		if ($nextElement.length == 0) $nextElement = $($("ul#whats-new-nav li")[0]);
		$nextElement.toggleClass("current-banner").children().click();
		$.fn.banner.timeout = setTimeout( $.fn.banner.rotate, $.fn.banner.rotateSpeed );
	}
})(jQuery);

(function($){
	$.fn.paginate = function( paginateOptions ) {
		if (this.length <= 0) return;
		
		var defaults = {
			pageLength: 2,
			setMaxHeight: false
		}
		
		var opts = $.extend(defaults, paginateOptions);
		
		var paginationParent = this[0].parentNode;
		
		if ($(".paginate-item", this[0]).length <= defaults.pageLength)  return;
		
		var paginationItems = $(".paginate-item", this[0]).remove();

		$(paginationParent).removeClass("paginate-no-script");
		
		var page = 1;
		
		var setID = (this[0].id != "") ? this[0].id : "media";
		var pageID = setID+"_page-"+page;
		
		var pageContainer = createNode("div",{id:pageID, className: "pagination-set", style: "left: 0;"});
		$(this[0]).append(pageContainer);
		
		var itemCount = paginationItems.length;
		
		var maxHeight = 0;
		var paginationContain = this[0].offsetWidth;
		
	
		for(var i = 0; i < itemCount; i++)
		{
			$("#"+pageID).append(paginationItems[i]);
			if ((((i+1) % defaults.pageLength) == 0)) {
				maxHeight = (pageContainer.offsetHeight > maxHeight) ? pageContainer.offsetHeight : maxHeight;
				if ((i+1) != itemCount)
				{
					page++;
					pageID = setID+"_page-"+page;
					var pageContainer = createNode("div",{id:pageID, className: "pagination-set"});
					$(pageContainer).css({left: paginationContain*(page-1)});
					$(this[0]).append(pageContainer);
				}
			}
		}
		
		if (page > 1)
		{
		
			$(paginationParent).append('<ul class="paginate-nav"></ul>');
			$paginateNav = $($("ul.paginate-nav", paginationParent)[0]);
			$paginateNav.append('<li><a href="#'+pageID+'" rel="'+pageID+'" class="page-prev">Previous Page</a>');
		
			for(var j=1; j <= page;j++)
			{
				pageID = setID+"_page-"+j;
				$paginateNav.append('<li><a href="#'+pageID+'" rel="'+pageID+'" class="page-trigger">Page '+j+'</a>');
			}
			pageID = setID+"_page-"+2;
			$paginateNav.append('<li><a href="#'+pageID+'" rel="'+pageID+'" class="page-next">Next Page</a>');
			
			if (defaults.setMaxHeight) $(this[0]).css({height: maxHeight});
			
			paginationWidth = 13*page+36;
			$paginateNav.css({left: ((paginationParent.offsetWidth/2)-(paginationWidth/2))});
						
			$($("ul.paginate-nav li", paginationParent)[1]).toggleClass("current-page");
			
			$("a.page-prev", paginationParent).click( function() { clearTimeout($.fn.banner.timeout); $.fn.paginate.setPage( this ); return false; } );
			$("a.page-trigger", paginationParent).click( function() { clearTimeout($.fn.banner.timeout); $.fn.paginate.setPage( this ); return false; } );
			$("a.page-next", paginationParent).click( function() { clearTimeout($.fn.banner.timeout); $.fn.paginate.setPage( this ); return false; } );
		}
	}
	$.fn.paginate.setPage = function( pageLink ) {
		var paginationSet = pageLink.rel.substr(0, pageLink.rel.indexOf("_"));
		if ((pageLink.parentNode.className.indexOf("current-page") >= 0) || ($("#"+paginationSet)[0].className.indexOf("busy")>=0)) return;
		
		$("#"+paginationSet).toggleClass("busy");
		
		var currentIndex = $("li.current-page a", $("#"+paginationSet)[0].parentNode)[0].rel;
		currentIndex = currentIndex.substr(currentIndex.lastIndexOf("-")+1, currentIndex.length);
		var currentPage = paginationSet+"_page-"+currentIndex;
		var targetPage = paginationSet+"_page-"+pageLink.rel.substr(pageLink.rel.lastIndexOf("-")+1, pageLink.rel.length);
		var targetIndex = pageLink.rel.substr(pageLink.rel.lastIndexOf("-")+1, pageLink.rel.length);
		
		$("li.current-page", $("#"+paginationSet)[0].parentNode).toggleClass("current-page");
		$($("a.page-trigger[rel="+targetPage+"]")[0].parentNode).toggleClass("current-page");
		
		switch ( pageLink.className )
		{
			case "page-prev":
				direction = -1;
				break;
			case "page-next":
				direction = 1;
				break;
			default:
				direction = (currentPage > targetPage) ? -1 : 1;
				break;
		}
		
		var containerWidth = $("#"+paginationSet)[0].parentNode.offsetWidth;
		
		$("#"+targetPage).css({left: containerWidth*direction});
		$("#"+targetPage).animate({left: 0}, 200);
		$("#"+currentPage).animate({left: containerWidth*-direction}, 200, "linear", function() { $("#"+paginationSet).toggleClass("busy");} );
		
		var nextIndex = ((targetIndex) % ($("div#"+paginationSet+" div.pagination-set").length))+1;
		var prevIndex = (((targetIndex-1) > 0) ? (targetIndex-1) : $("div#"+paginationSet+" div.pagination-set").length);
		
		$("a.page-next", $("#"+paginationSet)[0].parentNode).attr({href: "#"+paginationSet+"_page-"+nextIndex, rel:paginationSet+"_page-"+nextIndex});
		$("a.page-prev", $("#"+paginationSet)[0].parentNode).attr({href: "#"+paginationSet+"_page-"+prevIndex, rel:paginationSet+"_page-"+prevIndex});
	}
})(jQuery);

/**
 * @author Alexander Farkas
 * 
 * v. 1.02
 */
(function($) {
	$.extend($.fx.step,{
	    backgroundPosition: function(fx) {
			if((fx.elem.className.indexOf("current-topic")>=0)&(fx.end[1]==0)){ return; }
            if (fx.state === 0 && typeof fx.end == 'string') {
                var start = $.curCSS(fx.elem,'backgroundPosition');
                start = toArray(start);
                fx.start = [start[0],start[2]];
                var end = toArray(fx.end);
                fx.end = [end[0],end[2]];
                fx.unit = [end[1],end[3]];
			}
            var nowPosX = [];
            nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
            nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];
            fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];

           function toArray(strg){
               strg = strg.replace(/left|top/g,'0px');
               strg = strg.replace(/right|bottom/g,'100%');
               strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
               var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
               return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
           }
        }
	});
})(jQuery);

function tool_tip( evt, trigger, type )
{
	var parentPosition = findPos($("#wrapper")[0]);
	switch( type )
	{
		case "new-media-tool" :
			var toolTip = $("div#tooltip-"+trigger.rel)[0];
			break;
		case "definition" :
			var toolTip = $("#"+trigger.id.replace("trigger","tooltip"))[0];
			break
	}
	
	if (toolTip==undefined) return;
	
	var x = evt.pageX - parentPosition[0];
	var y = evt.pageY - parentPosition[1] - toolTip.offsetHeight - 10;
	
	if (y < getViewportScrollY())
	{
		$(toolTip).addClass("inverse");
		y = evt.pageY + 10;
	}
	else
		$(toolTip).removeClass("inverse");
	
	$(toolTip).css({top: y,left: x});
}

function init_font()
{
	fontSize = parseInt(readCookie("fontSize"));

	if (!isNaN(fontSize))
		set_font(parseInt(fontSize), true)
	else
		set_font("0", true)
		
	$("ul.font-size li").click( function() { incrementor = {"font-increase":1, "font-decrease":-1}; 
										 	 fontSize = parseInt(readCookie("fontSize"));
										 	 fontSize += incrementor[this.className];
											 if (fontSize > 2) fontSize = 2;
											 if (fontSize < 0) fontSize = 0;
											 set_font(fontSize, false); return false; });
}

function set_font( fontIndex, pageLoad )
{
	
	
	fontSizes = ["font-small", "font-medium", "font-large"];
	
	// clear old font size
	fontSize = parseInt(readCookie("fontSize"));
	if ((fontSize != null) && !pageLoad) $("body").toggleClass(fontSizes[fontSize]);
	
	//set new font size
	$("body").addClass(fontSizes[fontIndex]);
	
	//store size in a cookie
	createCookie("fontSize", fontIndex, 365);
	
	// recalculate stuff with fixed heights based on fontsize
	if (!pageLoad) 
	{
		$("hr#read-more").each( function(){ init_readmore(this, true); });
		$("#media").each( function(){ 
								   		var pages=$(".pagination-set",this);
										if (pages.length == 0) return;
										var maxHeight = 0;
										for (var i=0; i < pages.length; i++)
										{
												if (pages[i].offsetHeight > maxHeight) maxHeight = pages[i].offsetHeight;
										}
										
										$("#media").css({height: maxHeight});
									});
		pageTracker._trackEvent("Font Size",fontSizes[fontSize]);
	}
}

/*
CONTENT READ MORE LINK
*/
var READ_MORE = "View Full Page";
var READ_LESS = "Collapse";

function init_readmore(page_break, fontChange)
{
	var READ_MORE_HEIGHT_STYLE = "read-more-height";
	// grab read-more-height css rule
	var stylesheet = document.styleSheets[0];
	var styles = stylesheet.cssRules ? stylesheet.cssRules: stylesheet.rules
	var endTop;
	for (var i = 0; i<styles.length; i++)
	{
		if (styles[i].selectorText.toLowerCase() == "."+READ_MORE_HEIGHT_STYLE)
		{
			var heightStyle = styles[i];
			break;
		}
	}
	
	copyBlockID = ($("#subject-copy").length > 0) ? "subject-copy" : "interior-page";

	var copyOffsetTop = $("#"+copyBlockID)[0].offsetTop;
	var pagebreak_x = $(page_break).next()[0].offsetTop-copyOffsetTop;
	heightStyle.style.height = pagebreak_x+"px";
	
	if (fontChange)
	{
		$("#"+copyBlockID+"-end").css("top",((($("#"+copyBlockID+"-end a")[0].className=="less")?$("#"+copyBlockID)[0].offsetHeight+copyOffsetTop:pagebreak_x+copyOffsetTop)))
		return;
	}
	
	var content_block = page_break.parentNode;
	
	if (window.location.href.indexOf("#") >= 0)
	{
		var last_child = $(content_block).children()[$(content_block).children().length-1];
		var x = last_child.offsetTop + last_child.offsetHeight;
		
		$("#"+copyBlockID+"-end").css("top",$("#"+copyBlockID)[0].offsetHeight+copyOffsetTop).append(createNode("a", {id:"link-readmore", className:"less", href: "#"+copyBlockID+"-end"}, READ_LESS));
	}
	else
	{
		
		$(content_block).addClass(READ_MORE_HEIGHT_STYLE);
		(copyBlockID != "interior-page") ? endTop = pagebreak_x+20 : endTop = pagebreak_x+copyOffsetTop-10;
		$("#"+copyBlockID+"-end").css("top",endTop).append(createNode("a", {id:"link-readmore", className:"more", href: "#"+copyBlockID+"-end"}, READ_MORE));
	}
	
	$("#"+copyBlockID+"-end").removeClass("full-page").addClass("partial-page");
	$("#link-readmore").click( function(){ return toggle_readmore(); } );
	
	$("#body").toggleClass("read-more-page");
}

function toggle_readmore( anchorHREF )
{
	var copyBlockID = ($("#subject-copy").length > 0) ? "subject-copy" : "interior-page";

	var READ_MORE_HEIGHT_STYLE = "read-more-height";

	var content_block = $("#"+copyBlockID+"-end").prev()[0];
	
	var toggle_link = $("#link-readmore")[0];
	
	if (toggle_link.className == "more")
	{
		$(content_block).removeClass(READ_MORE_HEIGHT_STYLE);
		
		var last_offset = ($("dfn",content_block).length > 0) ? 2 : 1;
		var last_child = $(content_block).children()[$(content_block).children().length-last_offset];
		var x = last_child.offsetTop + last_child.offsetHeight;
		if(copyBlockID == "interior-page") x+=10;
		if (anchorHREF != null)
		{
			$("#"+copyBlockID+"-end").css({top:x});
			window.location = anchorHREF;
		}
		else
			$("#"+copyBlockID+"-end").css({top:x});
		
		toggle_link.className = "less";
		toggle_link.innerHTML = READ_LESS;
		
		// IE silliness
		$("#page-highlights").hide().show();
		
		return false;
	}
	else if ((anchorHREF == null) && (toggle_link.className == "less"))
	{
		window.location = "#"+copyBlockID;
		var page_break = $("hr#read-more")[0];
		var content_block = page_break.parentNode;
		
		var x = $(page_break).next()[0].offsetTop; 
		if(copyBlockID == "interior-page") x-=10;
		
		$(content_block).addClass(READ_MORE_HEIGHT_STYLE);;
		$("#"+copyBlockID+"-end").css({top:x});
		
		toggle_link.className = "more";
		toggle_link.innerHTML = READ_MORE;
		
		return false;
	}
	else if ((anchorHREF != null) && (toggle_link.className == "less")) return true;

}

/*
ANICILLARY DATA ACCORDIAN
*/
function toggle_ancillary( ancillary )
{
	if (ancillary.className.indexOf("open") < 0 ){
		$("div#"+ancillary.parentNode.parentNode.id+" h4.open").each( function(){ $(this).toggleClass("open");
														  $(this).next().slideToggle(100, function(){ $(this).addClass("collapse").css({display: "block"}) });
													   });
		
		$(ancillary).toggleClass("open");
		$(ancillary).next().removeClass("collapse").css({display: "none"}).slideToggle(100);
	}
	else
	{
		$(ancillary).toggleClass("open");
		$(ancillary).next().slideToggle(100, function() { $(this).addClass("collapse"); $(this).css({display: "block"})  });
	}
}

/*
SHARE THIS PAGE
*/

var bookmarkLinks = [{text: "MySpace", className: "myspace", href: "http://www.myspace.com/Modules/PostTo/Pages/?u=[URL]&t=[TITLE]&c=%20", smallShare: true},
					 {text: "Facebook", className: "facebook", href: "http://www.facebook.com/sharer.php?u=[URL]&t=[TITLE]", smallShare: true},
					 {text: "StumbleUpon", className: "stumbleupon", href: "http://www.stumbleupon.com/submit?url=[URL]&title=[TITLE]", smallShare: false},
					 {text: "Technorati", className: "technorati", href: "http://technorati.com/faves?sub=addfavbtn&add=[URL]", smallShare: false},
					 {text: "Reddit", className: "reddit", href: "http://reddit.com/submit?url=[URL]&title=[TITLE]", smallShare: false},
					 {text: "Digg", className: "digg", href: "http://digg.com/submit?url=[URL]&title=[TITLE]&media=News&topic=health&thumbnails=0", smallShare: true},
					 {text: "Del.icio.us", className: "delicious", href: "http://del.icio.us/post?v=4&noui&jump=close&url=[URL]&title=[TITLE]", smallShare: true},
					 {text: "Email to Friend", className: "email", href: "http://www.feedburner.com/fb/a/emailFlare?itemTitle=[TITLE]&uri=[URL]", smallShare: false}];

function createListItem(bookmark, bookmarkList)
{
	if ($("li.smallShare")[0] && !bookmark.smallShare) return;
	var URL = bookmark.href;
	URL = URL.replace("[URL]",pageHREF);
	URL = URL.replace("[TITLE]",pageTitle);
	var listItem = createNode("li");
	var bookmarkLink = createNode("a", {href: URL, className: bookmark.className}, bookmark.text);
	$(bookmarkLink).click( function(e) { pageTracker._trackEvent("Share This Page",this.className,pageHREF); }); 
	listItem.appendChild(bookmarkLink);
	bookmarkList.appendChild(listItem);
}

function init_shareMenu()
{
	smallShare = ($("li.smallShare")[0] != null);
	// generate main ul
	var shareList = createNode("ul", {id: "share_page"});
	
	$.each(bookmarkLinks, function(i, bookmark) { createListItem(bookmark, shareList) } );
	
	// create what's this link
	if (!smallShare)
	{
		var whatsThis = createNode("li", {className: "whatsThis"}, "What's This?");
		shareList.appendChild(whatsThis);
		
		$(whatsThis).click( function(e) { pageTracker._trackEvent("Share This Page","What is This"); toggle_whatsThis("show"); }); 
	}
	// div that encompasses then entire menu
	var containClass = (smallShare) ? "hidden smallShare" : "hidden fullShare";
	var shareContain = createNode("div", {id: "shareContain", className: containClass});
	shareContain.appendChild(shareList);
	
	// dropshadow
	if (!smallShare) var dropShadow = createNode("div", {id: "dropShadow", className: "hidden"}," ");
	
	$('body').append(shareContain);
	if (!smallShare) $('body').append(dropShadow);

	positionMenu(shareContain, shareContain.offsetTop,  shareContain.offsetLeft)

	// attach mouseout and over events for delayed hide of menu
	$("#shareContain").mouseleave(function(e) { toggleDelay=setTimeout(toggle_shareMenu,1000); });
	$("#shareContain").mouseenter(function(e) { clearTimeout(toggleDelay); });
	
	$("#share-this").mouseleave(function(e) { if (this.className.indexOf("shareThis_on") >= 0) toggleDelay=setTimeout(toggle_shareMenu,750); });
	$("#share-this").mouseenter(function(e) { clearTimeout(toggleDelay); });
	
	$(".whatsThis").mouseenter(function(e) { $(this).toggleClass("hover"); });
	$(".whatsThis").mouseleave(function(e) { $(this).toggleClass("hover"); });
}

function toggle_whatsThis(display)
{
	var width=400;
	var height=250;
	var borderWidth=6
	
	var top=(($(window).height()/2) - (height/2)) + $(window).scrollTop();
	var left=($(document).width()/2) - (width/2);
	
	if (this.transBorder == undefined)
	{
	
		this.transBorder = createNode("div",{id: "transBorder"});
		this.whatsThisContain = createNode("div",{id: "whatsThisContain"});
		this.closeWhatsThis = createNode("span",{id: "closeWhatsThis"}, "Close");

		$(this.transBorder).css({ width: (width+borderWidth*2),
									   height: (height+borderWidth*2),
									   top: (top - borderWidth),
									   left: (left - borderWidth)
									 });
		$(this.transBorder).hide();
		
		$(this.whatsThisContain).css({ width: width,
										  	height: height,
											top: top,
											left: left
										  });
		$(this.whatsThisContain).hide();
		
		$("body").prepend(transBorder);
		$("body").prepend(whatsThisContain);
		$("div#whatsThisContain")[0].innerHTML='<iframe height="'+ (height-20) +'" frameborder="0" width="'+ width +'" scrolling="auto" id="whatsThisFrame" src="/whats-this.html" border="0"/>';
		$("div#whatsThisContain").prepend(this.closeWhatsThis);
		
		$("iframe#whatsThisFrame")[0].setAttribute("border","0");
		$("iframe#whatsThisFrame")[0].setAttribute("frameborder","0");
		
		$("closeWhatsThis").click(function(e) { toggle_whatsThis("hide")  });
	}
	
	if (display == "show")
	{
		$("#transBorder").show();
		$("#whatsThisContain").show();
		
		$(window).bind("scroll", function(e) { toggle_whatsThis("reposition")  });
		$(window).bind("resize", function(e) { toggle_whatsThis("reposition")  });
		$(document).bind("mousedown", function(e) { toggle_whatsThis("hide")  });
	}
	else if (display == "hide")
	{
		$("#transBorder").hide();
		$("#whatsThisContain").hide();
		
		$(window).unbind();
		$(window).unbind();
		$(document).unbind();
	}
	else
	{
		$(this.transBorder).css({top: (top - borderWidth),
								  left: (left - borderWidth)
								});
		$(this.whatsThisContain).css({ top: top,
								  left: left
								});
	}
}

function switchClass(obj,class1,class2) {
	if (obj.className == class1) obj.className = class2
	else obj.className = class1
}

var toggleDelay;
function toggle_shareMenu() {
	smallShare = ($("li.smallShare")[0] != null);
	
	var shareThis = $("#share-this")[0];
	
	var shareContain = $("#shareContain")[0];
	var dropShadow = $("#dropShadow");

	if (smallShare)
	{
		positionMenu(shareContain,findPos(shareThis)[1]+5,findPos(shareThis)[0] - 560);
	}
	else
		positionMenu(shareContain,shareThis.offsetHeight+findPos(shareThis)[1]+5,findPos(shareThis)[0]);

	$(shareContain).toggleClass("hidden");
	$(dropShadow).toggleClass("hidden");

	$(shareThis).toggleClass("shareThis_on");
}

function positionMenu(shareContain, y, x) {
	$(shareContain).css({	top: y,
							left: x,
							visibility: "hidden",
							display: "block"
							});

	var width, height, top, left;
	width = shareContain.offsetWidth - 6;
	height = shareContain.offsetHeight - 6;
	
	top = y + 5;
	left = x + 7;
	
	$("#dropShadow").css({	top: top,
							left: left,
							width: width,
							height: height
							});
	$(shareContain).css({
							visibility: "visible",
							display: ""
							});
}

/*
UTILITY FUNCTIONS
*/

(function($) {
	jQuery.fn.backgroundPosition = function() {
		var p = $(this).css('background-position');
		if(typeof(p) === 'undefined') 
			return $(this).css('background-position-x') + ' ' + $(this).css('background-position-y');
		else return p;
	};
})(jQuery);

function createNode(type, attributeList, text)
{
	var node = document.createElement(type);
	
	if ((type) && (typeof type == "string"))
	{
	
		if ((attributeList) && (typeof attributeList == "object"))
		{
			
			$.each( attributeList, function(key, value){
				if (key == "className") 
					node.className = value;
				else
					node.setAttribute(key,value);
			});
		}
		if ((text) && (typeof text == "string"))
		{
			var txt = document.createTextNode(text);
			node.appendChild(txt);
		}
	}
	return node;
}

jQuery.getQueryParams = (function() {
		
		var source = window.location.href;
		
		if (source.indexOf("?")<0) return {};
		
		var query = source.split("?")[1];
		var queryPairs=query.split("&");
		
		var queryParams = {};
		
		for(i=0; i < queryPairs.length; i++)
		{
			pairSplit = queryPairs[i].split("=");
			queryParams[pairSplit[0]] = pairSplit[1];
		}
		
		return queryParams;
})();


// code from http://www.quirksmode.org/js/findpos.html
// QuirksMode.org is the personal site of Peter-Paul Koch
function findPos(obj)
{
	var curleft = curtop = 0;
	if (obj.offsetParent) {
	curleft = obj.offsetLeft
	curtop = obj.offsetTop
	while (obj = obj.offsetParent) {
	curleft += obj.offsetLeft
	curtop += obj.offsetTop
}
}
return [curleft,curtop];
}

/* The following functions to create, read, and delete cookies
 is courtesy Peter-Paul Koch, http://www.quirksmode.org/js/cookies.html */
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function deleteCookie(cookie_name){
	var cookie_date = new Date ( );  // current date & time
	  cookie_date.setTime ( cookie_date.getTime() - 1 );
	  document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function scrollToMedia() {
	var scrollDestination = findPos($("h1")[0])[1];
	window.scroll(0,scrollDestination);
}

function scrollToSearch() {
	var scrollDestination = findPos($("h1")[0])[1] +345;
	window.scroll(0,scrollDestination);
}

function getViewportScrollY() {
  var scrollY = 0;
  if( document.documentElement && document.documentElement.scrollTop ) {
    scrollY = document.documentElement.scrollTop;
  }
  else if( document.body && document.body.scrollTop ) {
    scrollY = document.body.scrollTop;
  }
  else if( window.pageYOffset ) {
    scrollY = window.pageYOffset;
  }
  else if( window.scrollY ) {
    scrollY = window.scrollY;
  }
  return scrollY;
}

function pipes(obj)
{
	if (typeof($)=="undefined") return;
	
	var MAX_ITEMS = 10,
		DESC_LENGTH = 150,
	    max = (obj.count < MAX_ITEMS) ? obj.count : MAX_ITEMS,
	    template = $(".feed-item").remove().removeAttr("style"),
	    node;
	    THUMB_SRC = {"AIDS.gov":		{"src":"/images/icon-aidsgov.gif"},
	    			 "CDC.gov": 		{"src":"/images/icon-cdcgov.gif"},
					 "NIH.gov": 		{"src":"/images/icon-nihgov.gif"},
	    			 "AIDS.gov Blog":	{"src":"/images/icon-aidsgov-blog.gif"}};
	    
	$("#news-feed p.noscript").remove();
	for ( var i = 0; i < max; i++) {
		node = $(template).clone();
		$('img',node).attr({"alt":obj.value.items[i].author,"src":THUMB_SRC[obj.value.items[i].author].src});
		$('.title',node).html(obj.value.items[i].title).attr("href",obj.value.items[i].link);
		$('.source',node).html(obj.value.items[i].author);
		$('.date',node).html(obj.value.items[i]["y:published"].month+"."+obj.value.items[i]["y:published"].day+"."+obj.value.items[i]["y:published"].year);
		$('.description',node).html(trimDesc(obj.value.items[i].description,DESC_LENGTH));
		$('#news-feed .feed-list').append(node);
	}
	$("#news-feed .feed-item:odd").addClass("odd");
	$("#news-feed .feed-item").hover( function() {$(this).addClass("hover")},function() {$(this).removeClass("hover")});
	$("#news-feed .feed-item").click( function() { window.location = $('.title',this).attr("href"); });
}

function nhasPipes(obj)
{
	if (typeof($)=="undefined") return;
	
	var MAX_ITEMS = 1,
		DESC_LENGTH = 250,
	    max = (obj.count < MAX_ITEMS) ? obj.count : MAX_ITEMS,
	    template = $(".feed-item").remove().removeAttr("style"),
	    node;
	    
	$("#nhas-feed p.noscript").remove();
	for ( var i = 0; i < max; i++) {
		node = $(template).clone();
		$('.date',node).html(formatDate(obj.value.items[i]["y:published"]));
		$('.title a',node).html(obj.value.items[i].title).attr("href",obj.value.items[i].link);
		$('.description',node).html(trimDesc(obj.value.items[i].description,DESC_LENGTH));
		$('#nhas-feed').append(node);
	}
}

function formatDate(d) {
	var dString = "",
		mArray = ["January","February","March","April","May","June","July","August","September","October","November","December"];
	dString+=mArray[d.month-1];
	dString+=" "+d.day;
	dString+=", "+d.year;
	return dString;
}

function trimDesc(str,l) {
	// var stripHtml = new RegExp(\<.*?>\);
	str=str.replace(/<.*?>/g,"");
	if (str.length <= l) return str;
	var t = str.substr(0,l);
	t = t.substr(0,t.lastIndexOf(" ")) + "...";
	return t;
}

(function($){
	$.fn.dropDown = function() {
		if (this.length <= 0) return;
		$("li.drop-menu", this).hover(function() {
								$.fn.dropDown.clearMenu();
								clearTimeout($.fn.dropDown.clearTimer);
							 	$(this).addClass("hover");
							 },
							 function() {
							 	$.fn.dropDown.clearTimer=setTimeout($.fn.dropDown.clearMenu, 500);
							 });
	};
	$.fn.dropDown.clearMenu = function() { $("#main-nav li.hover").removeClass("hover"); };
})(jQuery);


(function($){
	$.fn.videoGallery = function() {
		$.fn.videoGallery.videoData = {"koh-stein":{d:{swf:"http://www.youtube-nocookie.com/v/KYdhXGUhR50&amp;hl=en_US&amp;fs=1&amp;rel=0&amp;hd=1",
										  w:425,
										  h:264},
										fv:null,
										param:null
										},
						 "koh-strategy-update":{d:{swf:"http://www.youtube-nocookie.com/v/5DqXFAuPlcI&amp;hl=en_US&amp;fs=1&amp;rel=0&amp;hd=1",
						 				  w:425,
						 				  h:264},
										fv:null,
										param:null
										},
						 "koh-chau-update":{d:{swf:"http://www.youtube-nocookie.com/v/BoMKZST9k9E&amp;hl=en_US&amp;fs=1&amp;rel=0&amp;hd=1",
						 				  w:425,
						 				  h:264},
										fv:null,
										param:null
										},
						 "koh-wilson-iac":{d:{swf:"http://www.youtube-nocookie.com/v/gXEUWJ7axXA&amp;hl=en_US&amp;fs=1&amp;rel=0&amp;hd=1",
						 				  w:425,
						 				  h:264},
										fv:null,
										param:null
										},										
						 "koh-gayle-iac":{d:{swf:"http://www.youtube-nocookie.com/v/Hfex3-wU56A&amp;hl=en_US&amp;fs=1&amp;rel=0&amp;hd=1",
						 				  w:425,
						 				  h:264},
										fv:null,
										param:null
										},										
						 "valdiserri-dieffenbach":{d:{swf:"http://www.youtube-nocookie.com/v/KHlfihqiXtE&amp;hl=en_US&amp;fs=1&amp;rel=0&amp;hd=1",
						 				  w:425,
						 				  h:264},
										fv:null,
										param:null
										},										
						 "valdiserri-hofmann":{d:{swf:"http://www.youtube-nocookie.com/v/ldhRn68E2PA&amp;hl=en_US&amp;fs=1&amp;rel=0&amp;hd=1",
						 				  w:425,
						 				  h:264},
										fv:null,
										param:null
										},										
						 "valdiserri-brooks":{d:{swf:"http://www.youtube-nocookie.com/v/JNUh5_emGoI&amp;hl=en_US&amp;fs=1&amp;rel=0&amp;hd=1",
						 				  w:425,
						 				  h:264},
										fv:null,
										param:null
										},										
						 "valdiserri-fenton":{d:{swf:"http://www.youtube-nocookie.com/v/Liyjz5pJh6Y&amp;hl=en_US&amp;fs=1&amp;rel=0&amp;hd=1",
						 				  w:425,
						 				  h:264},
										fv:null,
										param:null
										},										
						 "valdiserri-goosy":{d:{swf:"http://www.youtube-nocookie.com/v/cjFFbuGUGQQ&amp;hl=en_US&amp;fs=1&amp;rel=0&amp;hd=1",
						 				  w:425,
						 				  h:264},
										fv:null,
										param:null
										},
						 "nhas-one-year":{d:{swf:"http://www.youtube-nocookie.com/v/57vbfb8AL4M&amp;hl=en_US&amp;fs=1&amp;rel=0&amp;hd=1",
						 				  w:425,
						 				  h:264},
										fv:null,
										param:null
										},
						"nhas-implementing":{d:{swf:"http://www.youtube-nocookie.com/v/HtwEAHwSRKs&amp;hl=en_US&amp;fs=1&amp;rel=0&amp;hd=1",
						 				  w:425,
						 				  h:264},
										fv:null,
										param:null
										},
						"nhas-wh-wad-event":{d:{swf:"http://www.youtube-nocookie.com/v/60uUA0uGOkc&amp;hl=en_US&amp;fs=1&amp;rel=0&amp;hd=1",
						 				  w:425,
						 				  h:264},
										fv:null,
										param:null
										},
						"nhas-latino-community":{d:{swf:"http://www.youtube-nocookie.com/v/dL1qxtKObsY&amp;hl=en_US&amp;fs=1&amp;rel=0&amp;hd=1",
						 				  w:425,
						 				  h:264},
										fv:null,
										param:null
										},
		
						"strategy-psa":{d:{swf:"http://a.vimeocdn.com/p/flash/moogaloop/5.1.31/moogaloop.swf?v=1.0.0",
						 				  w:425,
						 				  h:264},
										fv:null,
										param:"server=vimeo.com&amp;player_server=player.vimeo.com&amp;cdn_server=a.vimeocdn.com&amp;embed_location=http%3A%2F%2Fvimeo.com%2F20822335&amp;force_embed=0&amp;force_info=0&amp;moogaloop_type=moogaloop_local&amp;js_api=1&amp;js_getConfig=player26155754_1972790070.getConfig&amp;js_setConfig=player26155754_1972790070.setConfig&amp;clip_id=26155754&amp;fullscreen=1&amp;js_onLoad=player26155754_1972790070.player.moogaloopLoaded&amp;js_onThumbLoaded=player26155754_1972790070.player.moogaloopThumbLoaded"
										},
						"nhas-womens-day":{d:{swf:"http://a.vimeocdn.com/p/flash/moogaloop/5.1.31/moogaloop.swf?v=1.0.0&amp;",
						 				  w:425,
						 				  h:264},
										fv:null,
										param:"server=vimeo.com&amp;player_server=player.vimeo.com&amp;cdn_server=a.vimeocdn.com&amp;embed_location=&amp;force_embed=0&amp;force_info=0&amp;moogaloop_type=moogaloop_local&amp;js_api=1&amp;js_getConfig=player20822335_632221596.getConfig&amp;js_setConfig=player20822335_632221596.setConfig&amp;clip_id=20822335&amp;fullscreen=1&amp;js_onLoad=player20822335_632221596.player.moogaloopLoaded&amp;js_onThumbLoaded=player20822335_632221596.player.moogaloopThumbLoaded"
										},
						"nhas-white-house-release":{d:{swf:"http://www.whitehouse.gov/sites/all/modules/swftools/shared/flash_media_player/player5x1.swf",
						 				  w:425,
						 				  h:264},
										fv:null,
										param:"config=http://www.whitehouse.gov/xml/video/14570/config.xml&amp;path_to_plugins=http://www.whitehouse.gov/sites/default/modules/wh_multimedia/wh_jwplayer/plugins&amp;path_to_player=http://www.whitehouse.gov/sites/all/modules/swftools/shared/flash_media_player/player5x1.swf"
										},
						  "defaults":{d:null,
						       fv:null,
						       param:{allowFullScreen:true, allowscriptaccess: true, wmode:"transparent"}
						        }
						 };
						 				 
	
		if (this.length <= 0) return;
		
		$("li", this).click( function() { return $.fn.videoGallery.setActive(this); } ).eq(0).addClass("current");
			
		/*$("li", this).click(function() {  $('#video-gallery').focus();$('#video-gallery').select(); });		*/
		$("li", this).click(function() {  $('#video-gallery').focus();});
		
		
	};
	$.fn.videoGallery.setActive = function(item) { 
		$("#video-nav li.current").removeClass("current");
		$(item).addClass("current");
		
		var video = $("a", item).eq(0).attr("rel");
		
		$("#video")[0].innerHTML="<div id='placeholder'></div>";
		
		var param = ($.fn.videoGallery.videoData[video].param == null) ? $.fn.videoGallery.videoData.defaults.param : $.fn.videoGallery.videoData[video].param;
		var fVars = ($.fn.videoGallery.videoData[video].fv == null) ? $.fn.videoGallery.videoData.defaults.fv : $.fn.videoGallery.videoData[video].fv;
		
		swfobject.embedSWF($.fn.videoGallery.videoData[video].d.swf, "placeholder", $.fn.videoGallery.videoData[video].d.w, $.fn.videoGallery.videoData[video].d.h, "9.0.0","expressInstall.swf", fVars, param, null);
		
		return false;
	};
})(jQuery);

pageTracker = new PageTracker();
function PageTracker() {};
PageTracker.prototype._trackPageview = function(){ return false; };

(function($) {  // self executing function that extends jQuery with a new function, intronate (called above)
	$.fn.intronate = function(options) {
		return this.each(function() {   // loop through each element found (in this case, just the one #intro-nav)		
		$("a", this).click( function(e) { $.fn.intronate.toggle(e,this); return false; } ); // for each a in this (this is #intro-nav) on click, do that code
	});
};
$.fn.intronate.toggle = function(e,obj) {  // extend intronate with a helper function
	if (obj.className.indexOf('selected') > -1)   // if this link is already active, do something
		{
			return false;
		}
		else
		{
			var animateIn = $("#"+obj.href.split("#")[1]);  // use rel as the id of the div to show and get it
			$('.selected').removeClass('selected');  // remove 'selected' from the currently selected link
			$(obj).addClass('selected');  // add class selected to newly clicked link
		}
	var animateOut = $('#goal-descriptions .current');  // fetch the currently active div
	animateOut.animate({opacity: 0}, 10, function() { animateOut.addClass('collapse')}).removeClass('current');  // jQuery animate, with function call once animation is done
	animateIn.css({'opacity':0}).removeClass('collapse').addClass('current').animate({'opacity': 1}, 400);  // jQuery animate, other stuff
	return false;
}
})(jQuery);
