FedWeb = function(){
	var Dom = YAHOO.util.Dom;
	var Event = YAHOO.util.Event;
	var $ = function(id) {
	      return document.getElementById(id);
	} ;
	var $T = function(tagName) {
	      return document.getElementsByTagName(tagName);
	} ;
	//Put all the configuration here
    var config = {
     	dropdownID:'dropdown',
			ghosttabs:'ghosttabs',
      tabviewID:'tabview',
      visibleClass:'show',
      historyFieldID:'history-field',
      historyIframeID:'history-iframe',
      popupID:'popup',
      navigationID:'nav',
      visibleClass:'show',
      noLinkImage:'no_link_image',
      readMoreId:'pi_readMore',
    	readMoreIdSelected:'pi_readMoreSelected',
    	readLessId:'pi_readLess',
    	readMoreText:'pi_readMoreText',
		  ngurl:'/sitelib/RichmondFedOrg/cf/newsgator.cfm'
    };

	function isdefined(object,variable) {
		return (typeof((window)[variable]) != 'undefined');
	}

	function debug(s) {
		// turn off this function completely for now. there is a bug somewhere - RJA 2/5/09
		return;

		// if this is production, don't do anything
		if(document.location.toString().match(/richmondfed\.org/g) != null) { return; }

		// if firebug is enabled, use that for debugging
		var fbug = isdefined(window,'console');

		if(typeof s == 'object') {
			// if firebug is enabled, use that. otherwise, use the function below to display the object properites
			(fbug) ? console.dir(s) : dir(s);

			return;
		}

		// if firebug is enabled, use that. otherwise, show an alert with the message
		(fbug) ? console.log(s) : alert(s);

		function dir(obj) {
			var r = '';

			var p;

			for(p in obj) {
				r = r + '\n' + p.toString();
				try {
					if(p.value != '') {
						r = r + '=' + p.value;
					}
				} catch(e) {}
			}

			alert(r);
		}

	}

	function initialize() {
		try {
			resize();
		} catch(e) {
			debug(e);
		}

		try {
			createTabsWithHistory();
		} catch(e) {
			debug(e);
		}

		try {
			populateFeed();
		} catch(e) {
			debug(e);
		}

		try {
			addDropShadows();
		} catch(e) {
			debug(e);
		}

		try {
			createDropDownMenu();
		} catch(e) {
			debug(e);
		}

		try {
			alternateRow();
		} catch(e) {
			debug(e);
		}

		try {
			doPopups();
		} catch(e) {
			debug(e);
		}
		
		try {
			fileLinks();
		} catch(e) {
			debug(e);
		}

		try {
			doToggle();
		} catch(e) {
			debug(e);
		}

		try {
			fixDisplayIssues();
		} catch(e) {
			debug(e);
		}
		try {
			createNewsGatorWidget();
		} catch(e) {
			debug(e);
		}
		try {
			createHomepageChartsWidget();
		} catch(e) {
			debug(e);
		}		
		try {
			createBlueLines();
		} catch(e) {
			debug(e);
		}
		try {
			trackContactUsLinks();
		} catch(e) {
			debug(e);
		}

		try {
			init();
		} catch(e) {
			debug(e);
		}
			//alert('done');
    }
	
	function trackContactUsLinks() {
		var as = YAHOO.util.Selector.query('.pi_contact_group a',$('pi_right_column_contact_us'));
		
		if(as) {
			for(var i=0,j=as.length;i<j;i++) {
				YAHOO.util.Event.on(as[i], 'click', function() { dcsMultiTrack('WT.z_contact','1','WT.dl','6'); });
			}
		}
	}

//    function init(){
//    var obj = $("pi_tagline");
//    if (window.location.href.indexOf("banking/payments_services")<0) {
//           obj.style.display="none";
//        } else {
//            obj.style.display="block";
//        }
//   };
    
	function toggleTabs(state) {
		var tabs = $(config.tabviewID);
		var ghost = $(config.ghosttabs);



		if(tabs) {
			tabs.style.display = state;
		
			if (state == 'block') {
			    ghost.style.display="none";
			}
/*
			var tabnav = YAHOO.util.Selector.query('ul',tabs);
			
			if(tabnav) {
				tabnav[0].style.display = state;
			}
*/
		}
	}
	
    function resize(){
    	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
		 var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
		 if (ieversion>=6 || ieversion>=5)
		  {
		  	YAHOO.util.Event.addListener(window, 'resize', calcWidth);
		  }
		}
    };

	function addDropShadows() {
		function addBorder(e) {
			var cbox = YAHOO.util.Dom.get(e);

			if(!cbox) { return; }

			var spanx1 = document.createElement('span');
			var spanx1a = document.createElement('span');
			var spanx2 = document.createElement('span');
			var spanx2a = document.createElement('span');

			var elemspanx1a = spanx1.appendChild(spanx1a);
			var elemspanx2a = spanx2.appendChild(spanx2a);

			var fc = YAHOO.util.Dom.getFirstChild(cbox);

			YAHOO.util.Dom.insertBefore(spanx2,fc);

			YAHOO.util.Dom.insertBefore(spanx1,spanx2);

			YAHOO.util.Dom.addClass(spanx1,'x1');
			YAHOO.util.Dom.addClass(spanx1a,'x1a');
			YAHOO.util.Dom.addClass(spanx2,'x2');
			YAHOO.util.Dom.addClass(spanx2a,'x2a');

			YAHOO.util.Dom.addClass(cbox,'cc_clearFix');

			return;
		}

		if($('pi_right_column_ng_box')) {
			// add the generic box class to the newsgator box on the right
			YAHOO.util.Dom.addClass('pi_right_column_ng_box','pi_generic_box');;
		}

		if(YAHOO.env.ua.gecko > 0 || (YAHOO.env.ua.ie >= 7)) {
			addBorder('pi_right_column_ng_box');
			
			addBorder('pi_home_right_our_latest_news');
			addBorder('pi_home_right_careers');
			addBorder('pi_home_right_ekiosk');
			addBorder('pi_home_right_pi_ng_box');
			addBorder('pi_left_content_our_recent_work');
			addBorder('pi_left_content_fact_of_the_day');
			//addBorder('pi_left_content_top_topic');
			addBorder('pi_right_content_our_focus');
			addBorder('pi_right_content_economic_indicators');
			addBorder('pi_home_left_pi_home_interactive');
			addBorder('pi_right_column_ekiosk');
			addBorder('pi_right_column_contact_us');
			//addBorder('pi_left_content_top_topics');
			addBorder('pi_home_right_our_top_story');

			var promoboxes = YAHOO.util.Selector.query('div.promo_box');

			for(var i=0,l=promoboxes.length;i < l;i++) {
				var current = promoboxes[i];

				addBorder(current.id);
			}

		}

		return;
	}

	function fixDisplayIssues() {
		var tabs = YAHOO.util.Selector.query('div.yui-content > div',$(config.tabviewID));

		// if there are tabs, loop over them
		if(tabs.length != 0) {
			for(var i=0,t=tabs.length;i < t; i++) {
				// get the last thumb container and remove the bottom border from it
				var block = YAHOO.util.Selector.query('div.pi_item_thumb_container:last-child',tabs[i]);

				if(block.length == 1) {
					// TODO: probably should apply a class here instead of setting the property directly
					block[0].style.borderBottom = '0';
				}

				// get the last td and th of each row and remove the right border
				var td = YAHOO.util.Selector.query('table tr td:last-child, table tr th:last-child',tabs[i]);

				if(td.length != 0) {
					for(var c=0,d=td.length;c < d;c++) {
						// TODO: probably should apply a class here instead of setting the property directly
						td[c].style.borderRight = '0';
					}
				}

				// get the last tr of each row and remove the bottom border
				var tr = YAHOO.util.Selector.query('table tr:last-child',tabs[i]);

				if(tr.length != 0) {
					for(var c=0,d=tr.length;c < d;c++) {
						// TODO: probably should apply a class here instead of setting the property directly
						tr[c].style.borderBottom = '0';
					}
				}

				// get the last tr of each row and remove the bottom border
				var tbl = YAHOO.util.Selector.query('table:last-child',tabs[i]);

				if(tbl.length == 1) {
					// TODO: probably should apply a class here instead of setting the property directly
					tbl[0].style.borderBottom = '0';
				}
			}
		}
	};

	function createDropDownMenu(){
      YAHOO.util.Event.onContentReady(config.dropdownID, function () {

                /*
                     Instantiate a MenuBar:  The first argument passed to the
                     constructor is the id of the element in the page
                     representing the MenuBar; the second is an object literal
                     of configuration properties.
                */

                var oMenuBar = new YAHOO.widget.MenuBar(config.dropdownID, {
                                                            autosubmenudisplay: true,
                                                            hidedelay: 750,
                                                            lazyload: true });

                /*
                     Call the "render" method with no arguments since the
                     markup for this MenuBar instance is already exists in
                     the page.
                */
				
                oMenuBar.render();
                oMenuBar.show();
				
				// this is a hack to fix a menu alignment bug in IE7
				oMenuBar.subscribe("show", function () {
					if (YAHOO.env.ua.ie === 7 && this.parent) {
						this.align();
						this.align();
					}
				});
		});
    };


    function createTabView(){
        YAHOO.util.Event.onContentReady(config.tabviewID, function () {
    	 	var tabView = new YAHOO.widget.TabView(config.tabviewID);
    	  });
    };
    function createTabsWithHistory(){
		    // The initially selected tab will be chosen in the following order:
		    //
		    // URL fragment identifier (it will be there if the user previously
		    // bookmarked the application in a specific state)
		    //
		    //         or
		    //
		    // "tab0" (default)

			if(!$(config.tabviewID)) { return; }

			var bookmarkedTabViewState = YAHOO.util.History.getBookmarkedState("tabview");
		    var initialTabViewState = bookmarkedTabViewState || "tab0";

		    var tabView;

		    // Register our TabView module. Module registration MUST
		    // take place before calling YAHOO.util.History.initialize.
		    YAHOO.util.History.register("tabview", initialTabViewState, function (state) {
		        // This is called after calling YAHOO.util.History.navigate, or after the user
		        // has trigerred the back/forward button. We cannot discrminate between
		        // these two situations.

		        // "state" can be "tab0", "tab1" or "tab2".
		        // Select the right tab:
		        tabView.set("activeIndex", state.substr(3));
		    });

		    function handleTabViewActiveTabChange (e) {

				var newState, currentState;

		        newState = "tab" + this.getTabIndex(e.newValue);
				
				var mylink = this.getElementsByTagName('a');				

		        try {
		           var xUrl = this.getElementsByTagName('a')[this.getTabIndex(e.newValue)].href;
		           
				   if (xUrl.indexOf('#')<0)
		           {
		           	window.location=xUrl;
		           	return;
		           }
		            currentState = YAHOO.util.History.getCurrentState("tabview");
		            // The following test is crucial. Otherwise, we end up circling forever.
		            // Indeed, YAHOO.util.History.navigate will call the module onStateChange
		            // callback, which will call tabView.set, which will call this handler
		            // and it keeps going from here...
		            if (newState != currentState) {
		                YAHOO.util.History.navigate("tabview", newState);
		            }
		           xUrl = xUrl.substring(0,xUrl.indexOf('#'));

		           var locationUrl= window.location.href;
		           locationUrl = locationUrl.substring(0,locationUrl.indexOf('#'));

		         //  alert(xUrl);
		        //   alert(locationUrl);

		           divId = getIdFromUrl(this.getElementsByTagName('a')[this.getTabIndex(e.newValue)].href ,"#");

				   if(xUrl != locationUrl && locationUrl.length>0)
				   {
				   		callAJAX(xUrl, divId);
				   }

				   
		        } catch (e) {
		            tabView.set("activeIndex", newState.substr(3));

		        }
		    }
			function callAJAX(xUrl,divId){
				var callback = {
				success: function(o) {
							document.getElementById(divId).innerHTML =  o.responseText;
				},
				failure: function(o) {
							alert("Request to get tab content failed."); //FAILURE
					}
				}
				var transaction = YAHOO.util.Connect.asyncRequest('GET', xUrl, callback, null);
				return false;
			}
			function getIdFromUrl(aUrl,indexString){

				return aUrl.substring(aUrl.indexOf(indexString)+1,aUrl.length);
			}
		    function initTabView () {
		        // Instantiate the TabView control...
		        tabView = new YAHOO.widget.TabView("tabview");
		        tabView.addListener("activeTabChange", handleTabViewActiveTabChange);
		    }

		    // Use the Browser History Manager onReady method to instantiate the TabView widget.
		    YAHOO.util.History.onReady(function () {
		        var currentState;

		        initTabView();

		        // This is the tricky part... The onLoad event is fired when the user
		        // comes back to the page using the back button. In this case, the
		        // actual tab that needs to be selected corresponds to the last tab
		        // selected before leaving the page, and not the initially selected tab.
		        // This can be retrieved using getCurrentState:
		        currentState = YAHOO.util.History.getCurrentState("tabview");
		        tabView.set("activeIndex", currentState.substr(3));
				toggleTabs('block');
		    });

		    // Initialize the browser history management library.
		    try {
		        YAHOO.util.History.initialize("history-field", "history-iframe");
		    } catch (e) {
		        // The only exception that gets thrown here is when the browser is
		        // not supported (Opera, or not A-grade) Degrade gracefully.
		        initTabView();
			toggleTabs('block');
		    }
    };
    function reset(){
        // do stuff
    };

	//populate feeds
	function populateFeed(){
	  var feeds = YAHOO.util.Dom.getElementsByClassName('utility_feed');	
	  for (var i=0; i < feeds.length; i++) {
		  var feedurl = feeds[i].getAttribute('cc:feedurl');
		  var numberOfItems = feeds[i].getAttribute('cc:numberOfItemsToReturn');
		  getExternalFeed(feedurl, numberOfItems, feeds[i]);
	  }
	}


	function getExternalFeed(feedurl, numberOfItems, currentItem){
		var url = '/sitelib/RichmondFedOrg/cf/feedGetter.cfm?feedurl=' + feedurl + '&numberOfItemsToDisplay=' + numberOfItems;
		YAHOO.util.Connect.asyncRequest('GET',url, {
			success: function(obj) {

				currentItem.innerHTML = obj.responseText;
				
				// get feed links created by the feed getter script
				var feedLinks = YAHOO.util.Dom.getElementsByClassName('externalFeedLink');
				
				// loop over them and add the standard external link image
				for(var b=0,k=feedLinks.length; b < k; b++) {
					addOffsiteLinkImage(feedLinks[b]);
				}
				
		},
			failure: function(obj) {
				debug('Feed Getter request failed.\n\nURL=' + url);
			},
			timeout: 5000
		});
	};



    // do popups
	function doPopups(){
		  var links = YAHOO.util.Dom.getElementsByClassName(config.popupID, 'a');
		  for (var i=0; i < links.length; i++) {
		      links[i].onclick = function() {
		        window.open(this.href);
		        return false;
		      }
		  }
	};
	function popup(URL)
	 {
			var _window = window.open (URL,  'popup','width=668,height=700,directories=no,location=no,menubar=no,scrollbars=yes,status=yes,toolbar=no,resizable=no');
	 	 //_window.moveTo(0,0);
	 	 	_window.focus();
	 };
	function handleClick (e) {
		 	YAHOO.util.Event.preventDefault(e);
	        popup(this.href);
	 };

	function flashPopup(URL)
	 {
			var _window = window.open (URL,  'popup','width=734,height=750,directories=no,location=no,menubar=no,scrollbars=0,status=yes,toolbar=no,resizable=yes');
	 	 //_window.moveTo(0,0);
	 	 	_window.focus();
	 };
	function handleFlashClick (e) {
		 	YAHOO.util.Event.preventDefault(e);
	        flashPopup(this.href);
	 };
	 
	 function addOffsiteLinkImage(linkNode) {
		var extImg = document.createElement('img');
		var locationHost = location.host.toLowerCase();

		extImg.src = 'http://www.richmondfed.org/images/icons/offsite_link.gif';					
		YAHOO.util.Dom.addClass(extImg, "extLink");
		YAHOO.util.Dom.insertAfter(extImg,linkNode);
	 };
	 
	function fileLinks() {
	    var fileLink;
	    var aLinks=$T('a');
		// This filter will take care of http and https
		var aExtLinks = YAHOO.util.Selector.filter(aLinks,'a[href^=http]');
		for(var i=0;i<aExtLinks.length;i++) {
			var items = aExtLinks[i].getElementsByTagName('img');
			if(aExtLinks[i].className.indexOf(config.noLinkImage)<0)
	  		{
				if(items.length==0){
					aExtLinks[i].setAttribute('target', '_blank');
				}
			}
			var extPdfLinks = aExtLinks[i].href;
			if(extPdfLinks.toString().match("pdf$")!="pdf" && items.length==0){
				addOffsiteLinkImage(aExtLinks[i]);
			}
		}

		//for fixed width popups
	    var aPopupLinks = YAHOO.util.Selector.filter(aLinks,'a[href^=/soundingssix]');
	    if(aPopupLinks.toString().length >0){
			YAHOO.util.Event.on(aPopupLinks, 'click', handleClick);
		}
		//flashvideo/
		var aVideoLinks = YAHOO.util.Selector.filter(aLinks,'a[href^=/flashvideo]');
	    if(aVideoLinks.toString().length >0){
			YAHOO.util.Event.on(aVideoLinks, 'click', handleFlashClick);
		}
		var aContactLinks = YAHOO.util.Selector.filter(aLinks,'a[href^=/contact_us]');
		if(aContactLinks.toString().length >0){
			YAHOO.util.Event.on(aContactLinks, 'click', handleClick);
		}
		///slideshow
		var aSlideshowLinks = YAHOO.util.Selector.filter(aLinks,'a[href^=/slideshow]');
		if(aSlideshowLinks.toString().length >0){
			YAHOO.util.Event.on(aSlideshowLinks, 'click', handleClick);
		}
 	/*
		var aZipLinks = YAHOO.util.Selector.filter(aLinks,'a[href$=zip]');
		if(aZipLinks.toString().length >0){
			for(var i=0;i<aZipLinks.length;i++) {
		  		if(aZipLinks[i].className.indexOf(config.noLinkImage)<0)
		  		{

						aZipLinks[i].setAttribute('target', '_blank');
					    aZipLinks[i].className = 'zipLink';

				}
			}
		}
		var aDocLinks = YAHOO.util.Selector.filter(aLinks,'a[href$=doc]');
		if(aDocLinks.toString().length >0){
			for(var i=0;i<aDocLinks.length;i++) {
		  		if(aDocLinks[i].className.indexOf(config.noLinkImage)<0)
		  		{

						aDocLinks[i].setAttribute('target', '_blank');
					    aDocLinks[i].className = 'docLink';

				}
			}
		}*/

		// the filter is broken and will return named anchor links (local page links) that don't end in pdf
		// such as http://e1web801/publications/research/special_reports/treasury_fed_accord/bios/eccles.cfm#2
		var aPdfLinks = YAHOO.util.Selector.filter(aLinks,'a[href*=pdf]');
		//debug.log(aPdfLinks);
		if(aPdfLinks.toString().length >0){
			for(var i=0;i<aPdfLinks.length;i++) {
				// must add the check for the .pdf here to fix filter bug from above
		  		if(aPdfLinks[i].className.indexOf(config.noLinkImage)<0 && aPdfLinks[i].href.indexOf('.pdf') != -1)
		  		{
		  			//debug.log(aPdfLinks[i].href.indexOf('.pdf'));
					//aPdfLinks[i].setAttribute('target', '_blank');
					//aPdfLinks[i].setAttribute('title', 'this is a test');
					// don't do this this way. use the YAHOO Event system instead of setting an onmouseover attribute
					//aPdfLinks[i].setAttribute('onmouseover', 'getPdfFileSize()');

					var items = aPdfLinks[i].getElementsByTagName('img');
	    			if(items.length==0){
						var extImg = document.createElement('img');
						extImg.src = 'http://www.richmondfed.org/images/icons/pdf_link.gif';
						extImg.alt = 'PDF';
						YAHOO.util.Dom.addClass(extImg, "pdfLink");
						YAHOO.util.Dom.insertAfter(extImg,aPdfLinks[i]);
						aPdfLinks[i].setAttribute('target', '_blank');

					}

				}
			}
		}
	};
/*
	function getPdfFileSize() {
		alert('test get pdf file size');
	};
*/
    function emptyElement(element) {
	  while (element.hasChildNodes()) {
	    element.removeChild(element.lastChild);
	  }
	};
    function setCookie(){
		/*YAHOO.util.Event.on("yui-cookie-btn2", "click", function(){
		var newValue = "fedweb" + Math.round(Math.random() * Math.PI * 100000);
		YAHOO.util.Cookie.set("example", newValue);
		});*/
    };
    function getCookie(){
    	/*
    	YAHOO.util.Event.on("yui-cookie-btn1", "click", function(){
		    var value = YAHOO.util.Cookie.get("example");
		    alert(value);
		    YAHOO.log("Cookie 'example' has a value of '" + value + "'");
		});
	*/

    };
    function doToggle(){
    	var createHideFlag=false;

    	if($('pi_readMoreText')){
    		createShowElement();
    	}
    	var module = new YAHOO.widget.Module(config.readMoreText,{
                                     visible: false,
                                     monitorresize: true,
                                     effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.25}
                                     });

		module.render() ;
    	function createHideElement(){
    		var elId=config.readLessId;
    		if(createHideFlag){
				var a = document.createElement('a');
	            a.id = elId;
	            a.href = '#';
	            a.innerHTML ='Hide';
	            YAHOO.util.Dom.addClass(a, elId);
	            YAHOO.util.Dom.insertAfter(a,config.readMoreText);
	            YAHOO.util.Event.addListener(a,
	            							'click',
	            							function(e){
												YAHOO.util.Event.preventDefault(e);
												module.hide();
												YAHOO.util.Event.removeListener("click",elId);
												a.removeChild(a.childNodes.item(0));
												createHideFlag=true;
											},
											module,
											true);
			}

    	};
    	function createShowElement(){
    		var elId=config.readMoreId;
    		var elIdSelected=config.readMoreIdSelected;
    		createHideFlag=true;
			var a = document.createElement('a');
            a.id = elId;
            a.href = '#';
            a.innerHTML ='Show';
            YAHOO.util.Dom.addClass(a, elId);
            YAHOO.util.Dom.insertBefore(a,config.readMoreText);
            YAHOO.util.Event.addListener(a,
            							'click',
            							function(e){
											YAHOO.util.Event.preventDefault(e);
											module.show();
											createHideElement();
											if (createHideFlag==true){
												createHideFlag=false;
											}
											YAHOO.util.Dom.replaceClass(a, elIdSelected);
										},
										module,
										true);

    	}

    };

	function calcWidth() {
		//alert(document.body.clientWidth);
		//alert( document.body.clientWidth+"BBB");
		document.getElementById('pi_body_holder').style.width = document.body.clientWidth < 1000 ? '795px' : '100%';
	};

	function alternateRow(){
		var tables = $T("table");
		if(tables){
			for ( var t = 0; t < tables.length; t++ ) {
			  var rows = tables[t].getElementsByTagName("tr");
			  for ( var i = 1; i < rows.length; i += 2 )
			    YAHOO.util.Dom.addClass( rows[i], "odd" );
			}
		}
	};
	
	//create the newsgator widget, the html should have the following element
	//<div id="pi_news_gator_tgt" title="_5th District News - Maryland^_5th District News - North Carolina^_5th District News - South Carolina^_5th District News - Virginia^_5th District News - Washington D.C.^_5th District News - West Virginia"></div>
	function createNewsGatorWidget() {
		var showWidget=$('pi_news_gator_tgt');

		if(!showWidget) { return; } 

		if(!showWidget.title.length) {
			alert("Please correct the missing district information for the news widget element on the page. ");

			return;
		}

		if(showWidget){
			//var aDistricts=['_5th District News - Maryland','_5th District News - North Carolina','_5th District News - South Carolina','_5th District News - Virginia','_5th District News - Washington D.C.','_5th District News - West Virginia'];
			var panels = showWidget.title.split("^");

			var ngAccordion;

			var panelHolder = [];

			var panelCount = panels.length;

			showWidget.title = '';

			createAccordion(panels);
		}

		function createAccordion(panels){
			try {
				ngAccordion = new YAHOO.widget.AccordionView('ng_widget_accordion', {id: 'ng_widget_accordion', collapsible: false, expandable: false, width: '100%', animate: true, animationSpeed: '0.2'});

				ngAccordion.appendTo(showWidget);

				for (var i = 0,len=panels.length; i < len; i++) {
					var panelLabel=panels[i];
					
					var buzzFullName = panels[i];

					panelLabel=panelLabel.substring(panelLabel.indexOf("-")+1,panelLabel.length);

					//var econtent = '<div id="p' + i + '" class="ng_article_container">Loading ...</div>';

					//ngAccordion.addPanel({label: panelLabel, content: (econtent)});

					var url = "http://" + location.host + config.ngurl + '?id=' + encodeURIComponent(panels[i]);

					YAHOO.util.Connect.asyncRequest('GET',url, {
						//callback to fire when the script is successfully loaded:
						success: function(obj) {
							try {
								callback(YAHOO.lang.JSON.parse(obj.responseText),this.argument);
							} catch(e) {
								callback(null,this.argument,'This service is temporarily unavailable. Please check back later.');
							}
						},

						//callback to fire if the script does not successfully load:
						failure: function(o) {
							debug('NewsGator request failed.\n\nURL=' + url);
						},

						timeout: 5000,

						argument: [i,panelLabel,buzzFullName]
					});
				}
			} catch(e) { }

		};

		function showError(msg) {

		}

		function callback(jsonData,args,err) {
			var containerNumber = args[0];
			var panelLabel = args[1];
			var buzzFullName = args[2];

			var content = '<div id="p' + containerNumber + '" class="ng_article_container" cc:ngBuzzFullName="' + buzzFullName + '">';

			if(jsonData != null) {
				content = content + '<ol class="ng_ol_container" SEQNUM="' + containerNumber + '">';

				for (var i = 0, len = jsonData.length; i < len; ++i) {
					var current = jsonData[i];

					content = content + '<li><span class="ng_post_title"><a cc:ngBuzzFullName="' + buzzFullName + '" cc:ngPostId="' + current.postid + '" target="_blank" href=' + current.url + '> ' + unescape(current.title) + '</a><img class="extLink" src="/images/icons/offsite_link.gif"/></span>';
					content = content + '<span class="ng_feedInfo">' + current.feed + '</span>';
					content = content + '<span class="ng_pubDate">' + current.date + '</span></li>';
				}

				content = content + "</ol>";
			} else {
				content = content + '<p>' + err + '</p>';
			}

			content = content + "</div>";

			try {
				panelHolder[containerNumber] = {label: panelLabel, content: (content)};

				panelCount--;

				if(!panelCount) {
					//debug.dir(panelHolder);
					ngAccordion.addPanels(panelHolder);

					ngAccordion.openPanel(0);
					
					// track a hit to the main 'master' widget
					trackNewsGatorLoad(showWidget);
					
					// track a hit to the first 'subordinate' widget
					trackNewsGatorLoad(YAHOO.util.Dom.get('p0'));
					
					ngAccordion.addListener('panelOpen',trackNewsGatorAccordionClick);

					YAHOO.util.Event.on(YAHOO.util.Selector.query('a',YAHOO.util.Dom.get('pi_news_gator_tgt')), 'click', trackNewsGatorClick); 
				}
			} catch(e) { console.dir(e); }
		};
		
		function trackNewsGatorAccordionClick(el) {
			try {
				var clickedElement = YAHOO.util.Dom.get('p' + el.index);
				
				trackNewsGatorLoad(clickedElement);
			} catch(e) { }
		}
		
		var ngtrackerpath = '/sitelib/RichmondFedOrg/cf/newsgatorTracker.cfm?';
			
		function trackNewsGatorLoad(el) {
			var buzzname = el.getAttribute('cc:ngBuzzFullName');
			var masterbuzzname = '_5th District News - Master';
			
			var ngtrackerurl = 'http://' + location.host + ngtrackerpath;
			
			ngtrackerurl = ngtrackerurl + 'eventName=view';
			ngtrackerurl = ngtrackerurl + '&orgCode=frbr';

			// if there is a buzzname, this is a 'subordinate' widget so send the current buzzname and the master buzzname
			if(buzzname) {
				ngtrackerurl = ngtrackerurl + '&buzzId=' + encodeURIComponent(buzzname);
				ngtrackerurl = ngtrackerurl + '&mid=' + encodeURIComponent(masterbuzzname);
			// otherwise, just send the master buzzname buzzid
			} else {
				ngtrackerurl = ngtrackerurl + '&buzzId=' + encodeURIComponent(masterbuzzname);
			}
			
			//master = '_5th District News'
			
			//console.log(ngtrackerurl);
			
			makeAjaxRequest(ngtrackerurl);
		}

		function trackNewsGatorClick(el) {
			var clickedElement = YAHOO.util.Event.getTarget(el);
			
			var ngtrackerurl = 'http://' + location.host + ngtrackerpath;

			//YAHOO.util.Event.preventDefault(el);
			
			//console.dir(clickedElement);
			
			var postid = clickedElement.getAttribute('cc:ngPostId');
			
			if(!postid) { return; }
			
			var buzzname = clickedElement.getAttribute('cc:ngBuzzFullName');
			
			if(!buzzname) { return; }
			
			//console.log(buzzname);
			//console.log(postid);
			
			ngtrackerurl = ngtrackerurl + 'eventName=click';
			ngtrackerurl = ngtrackerurl + '&orgCode=frbr';
			ngtrackerurl = ngtrackerurl + '&pid=' + encodeURIComponent(postid);
			ngtrackerurl = ngtrackerurl + '&buzzId=' + encodeURIComponent(buzzname);
			
			//console.log(url);
			
			makeAjaxRequest(ngtrackerurl);
		}

		function makeAjaxRequest(url) {
			YAHOO.util.Connect.asyncRequest('GET',url, {
				//callback to fire when the script is successfully loaded:
				success: function(obj) {
					reqCallback(obj);
				},
	
				//callback to fire if the script does not successfully load:
				failure: function(o) {
					reqCallback(obj);
				},
	
				timeout: 5000
			});
		}
		
		function reqCallback() {
			// do something productive
		}
	}

	// Add the Blue lines to certain elements
	// Look for a specific thumbnail container on the page
	// Look one or two of the next elements for tabs oe tables

	function testForRuleToAdd(container) {
	    var tab = YAHOO.util.Selector.query('#tabview',container);
	    var table = YAHOO.util.Selector.query('table',container);
	    var thumbnail = YAHOO.util.Selector.query('.pi_thumb',container);

	    return ((tab.length+table.length+thumbnail.length)==0);
        }

	function createBlueLines() {

	    var div = YAHOO.util.Selector.query('#pi_center_column div[class^=pi_item_thumb_container]');

        if (div.length > 0) {
            // have a thumbnail container
            var addHR;
            var parentDiv = div[0].parentNode;
            addHR = (parentDiv.className != "pi_tabcontent");
            if (addHR) {    // if we are ina tab, don't even batehr t check for blue lines
                var nextSib = parentDiv.nextSibling;
                if (!(nextSib)) {
                    // sometimes there is not an outter container, just look at the next sibling
                    nextSib = div[0].nextSibling;
                }
                if (nextSib) {
                    // if there is a sibling to examine
                    if (nextSib.nodeName != "DIV") {
                        nextSib = nextSib.nextSibling;
                    }
                    if (nextSib) {
                        addHR = testForRuleToAdd(nextSib);
                        }
    
                    if (nextSib) {
                        if (addHR) {
                            // did not find a any tabs or tables, look one level deeper
                            if (nextSib.nextSibling) {
                                nextSib = nextSib.nextSibling;
                                if (nextSib.nodeName != "DIV") {
                                    nextSib = nextSib.nextSibling;
                                    }                        
                                if (nextSib) {
                                    addHR = testForRuleToAdd(nextSib);
                                    }
                                }
                            }
                        }
                    }
                }
            if (addHR) {
                // no tab or table near by, insert a <hr> emelemnt (with blue_line class)
        		var hr = document.createElement('hr');
        		YAHOO.util.Dom.addClass(hr,"blue_line");
        		YAHOO.util.Dom.insertAfter(hr,div[0]);
        	    }
    	    }
	    }
/*
	//create the google widget, the html should have the following element
	//<div id="pi_map" title="create_map"></div>
	function createMap() {
		var showWidget=$('pi_map');

		if(!showWidget) { return; } 

		if(!showWidget.title.length) {
			alert("Please correct the missing information for the map widget element on the page. ");

			return;
		}

		if(showWidget){
			
			//var panels = showWidget.title.split("^");

			//var ngAccordion;

			//var panelHolder = [];

			//var panelCount = panels.length;

			showWidget.title = '';

			createMapDisplay();
		}

		function createMapDisplay(){
			try {

					var url = "http://" + location.host + config.ngurl + '?id=' + encodeURIComponent(panels[i]);

					YAHOO.util.Connect.asyncRequest('GET',url, {
						//callback to fire when the script is successfully loaded:
						success: function(obj) {
							try {
								callback(YAHOO.lang.JSON.parse(obj.responseText),this.argument);
							} catch(e) {
								callback(null,this.argument,'This service is temporarily unavailable. Please check back later.');
							}
						},

						//callback to fire if the script does not successfully load:
						failure: function(o) {
							debug('createMap request failed.\n\nURL=' + url);
						},

						timeout: 5000,

						//argument: [i,panelLabel,buzzFullName]
					});
			} catch(e) { }

		};

		function showError(msg) {

		}

		function callback(jsonData,args,err) {
			var containerNumber = args[0];
			var panelLabel = args[1];
			var buzzFullName = args[2];

			var content = '<div id="p' + containerNumber + '" class="ng_article_container" cc:ngBuzzFullName="' + buzzFullName + '">';

			if(jsonData != null) {
				content = content + '<ol class="ng_ol_container" SEQNUM="' + containerNumber + '">';

				for (var i = 0, len = jsonData.length; i < len; ++i) {
					var current = jsonData[i];

					content = content + '<li><span class="ng_post_title"><a cc:ngBuzzFullName="' + buzzFullName + '" cc:ngPostId="' + current.postid + '" target="_blank" href=' + current.url + '> ' + unescape(current.title) + '</a><img class="extLink" src="/images/icons/offsite_link.gif"/></span>';
					content = content + '<span class="ng_feedInfo">' + current.feed + '</span>';
					content = content + '<span class="ng_pubDate">' + current.date + '</span></li>';
				}

				content = content + "</ol>";
			} else {
				content = content + '<p>' + err + '</p>';
			}

			content = content + "</div>";

			try {
				panelHolder[containerNumber] = {label: panelLabel, content: (content)};

				panelCount--;

				if(!panelCount) {
					//debug.dir(panelHolder);
					ngAccordion.addPanels(panelHolder);

					ngAccordion.openPanel(0);
					
					// track a hit to the main 'master' widget
					trackNewsGatorLoad(showWidget);
					
					// track a hit to the first 'subordinate' widget
					trackNewsGatorLoad(YAHOO.util.Dom.get('p0'));
					
					ngAccordion.addListener('panelOpen',trackNewsGatorAccordionClick);

					YAHOO.util.Event.on(YAHOO.util.Selector.query('a',YAHOO.util.Dom.get('pi_news_gator_tgt')), 'click', trackNewsGatorClick); 
				}
			} catch(e) { console.dir(e); }
		};
		

		

		function makeAjaxRequest(url) {
			YAHOO.util.Connect.asyncRequest('GET',url, {
				//callback to fire when the script is successfully loaded:
				success: function(obj) {
					reqCallback(obj);
				},
	
				//callback to fire if the script does not successfully load:
				failure: function(o) {
					reqCallback(obj);
				},
	
				timeout: 5000
			});
		}
		
		function reqCallback() {
			// do something productive
		}
	} // end create map
*/

    //Run the functions now.

	YAHOO.util.Event.onDOMReady(initialize);

}();

		/************************************************************************************/
		/* FUNCTION   : toggleChart                                                         */
		/* PROGRAMMER : Michael Hooper                                                      */
		/* PARAMETERS : state - show=display the chart; hide=hide the chart (default)       */
		/* DESCRIPTION: This function will either hide or display the ecomonic indicators   */
		/* chart on the home page.                                                          */
		/* RETURN     : n/a                                                                 */
		/************************************************************************************/
		function toggleChart(state) 
		{
			// get chart element by ID
			var chart = document.getElementById('pi_homepage_charts_tgt');
			
			// get ghost element by ID
			var ghost = document.getElementById('ghost_economic_indicators');

			if (chart && ghost) 
			{
				if (state == 'show') 
				{
					chart.style.display = "block"; // show
					ghost.style.display = "none";	 // hide
				} // show chart image and hide ghost image
				else
				{
					chart.style.display = "none";  // hide
					ghost.style.display = "block"; // show
				} // show ghost image and hide chart image
			} // chart and ghost element exist
		} // toggleChart
	  /************************************************************************************/

//createhome page chart element
//<div id="pi_homepage_charts_tgt" title="Chart 1 Title~Chart Description 1~chartfile1.png^title="Chart 2 Title~Chart Description 2~chartfile2.png^...etc
function createHomepageChartsWidget() {

    var showWidget=document.getElementById('pi_homepage_charts_tgt');

    if(!showWidget) { return; }

    if(!showWidget.title.length) {
        alert("Please correct the missing information for the charts widget element on the page. ");
        return;
    }

    if(showWidget){
        //var panels=['_Chart 1 Title - chart1.jpg^_Chart 2 Title - chart2.jpg^_Chart 3 Title - chart3.jpg^_Chart 4 Title - chart4.jpg'];
        var panels = showWidget.title.split("^");   // chart title and source image name
        var chartsAccordion;                        // the widget (when created)
        var panelHolder = [];                       // stuff in the widget
        var panelCount = panels.length;             // how may widget will we have
        var content =  '<div><ul class="ng_ol_container" SEQNUM="' + i + '">';
        showWidget.title = '';

        // create the widget
        //chartsAccordion = new YAHOO.widget.AccordionView('charts_widget', {id: 'ng_widget_accordion', collapsible: false, expandable: false, width: '100%', animate: true, animationSpeed: '0.2'});
        chartsAccordion = new YAHOO.widget.AccordionView('charts_widget', {id: 'yui-gen0', collapsible: false, expandable: false, width: '100%', animate: true, animationSpeed: '0.2'});

        //  loop over the items
        for (var i = 0; i<panels.length; i++) {
            var panel=panels[i].split("~");
            var panelLabel=panel[0];
            var panelAltText=panel[0];
            var panelLink=panel[1];
            var theLinks=panelLink.split("@");
            var panelImage=panel[2];;

            content = content + '<ul class="ng_ol_container" SEQNUM="' + i + '">';
            content = content + '<div id="p' + i + '" class="ng_post_title">';
            content = content + "<li><img src=/images/graphs/"+panelImage+" alt='"+panelAltText+"'></li>";
            content = content + "</div>";
            
            
			content=content +  "<div id='graph_moreInfo'><hr /><p>For more information:</p><div class='graph_links'><li><a href="+theLinks[0]+">"+theLinks[1]+"</a></li><li><a href="+theLinks[2]+">"+theLinks[3]+"</a></li></div><br />";
			
            panelHolder[i] = {label: panelAltText, content: (content)};
            content="";

        }
		
		chartsAccordion.on('afterPanelOpen', function(nIndex){  

			var theName = arguments[0].panel.getElementsByTagName('a')[0].innerHTML;
			var i = theName.indexOf("<");
			theName = theName.substring(0,i);
			theName=theName.replace(/[^a-z0-9]/ig,"");
			//alert(theName);
			dcsMultiTrack("DCSext.HPchart",theName);
			
		});

        //content = content + "</ul></div>";
        chartsAccordion.addPanels(panelHolder);
        
        // open the first panel
        chartsAccordion.openPanel(0);
        
        // put on the page
        chartsAccordion.appendTo(showWidget);
        
        // display chart
        toggleChart('show');
    }
}


function iconnav_Over(iconnav) {
var fielname = "";

	fielname = document.getElementById("iconnav_"+iconnav).src;
	fielname = fielname.substr(0,fielname.indexOf(".png"))+"Over.png"
	document.getElementById("iconnav_"+iconnav).src=fielname;

	fielname = document.getElementById("iconnav_Text").src;
	fielname = fielname.substr(0,fielname.indexOf("icontext_"))+"icontext_"+iconnav+".png"
	document.getElementById("iconnav_Text").src=fielname;
}

function iconnav_Out(iconnav) {
var fielname = "";

	fielname = document.getElementById("iconnav_"+iconnav).src;
	fielname = fielname.substr(0,fielname.indexOf("Over.png"))+".png";
	document.getElementById("iconnav_"+iconnav).src=fielname;

	fielname = document.getElementById("iconnav_Text").src;
	fielname = fielname.substr(0,fielname.indexOf("icontext_"))+"icontext_blank.png";
	document.getElementById("iconnav_Text").src=fielname;
}

function iconnav_Over1(iconnav,path) {
var fielname = "";

	//fielname = document.getElementById("iconnav_"+iconnav).src;
	//fielname = fielname.substr(0,fielname.indexOf(".png"))+"Over.png"
	document.getElementById("iconnav_"+iconnav).src=path+"images/topiconnav/iconnav_"+iconnav+"Over.png";

	//fielname = document.getElementById("iconnav_Text").src;
	//fielname = fielname.substr(0,fielname.indexOf("icontext_"))+"icontext_"+iconnav+".png"
	document.getElementById("iconnav_Text").src=path+"images/topiconnav/icontext_"+iconnav+".png";
}

function iconnav_Out1(iconnav,path) {
var fielname = "";

	//fielname = document.getElementById("iconnav_"+iconnav).src;
	//fielname = fielname.substr(0,fielname.indexOf("Over.png"))+".png";
	document.getElementById("iconnav_"+iconnav).src=path+"images/topiconnav/iconnav_"+iconnav+".png";

	//fielname = document.getElementById("iconnav_Text").src;
	//fielname = fielname.substr(0,fielname.indexOf("icontext_"))+"icontext_blank.png";
	document.getElementById("iconnav_Text").src=path+"images/topiconnav/icontext_blank"+".png";
}
