(function($) {
		/******************************************************************
		 *     START: foreign currency - fx- rates update
		 *	takes 
		 * <a class="dyna-MATCHING-ID-RSS-rate" href="location of non-js rates page">View rates here</a>
		 *      and replaces it with live rate
		 */

		var processForeignCurrencyRates = function(xml) {
				$("td[class^='dyna-fx']").each(function() {
				   htmlClsName = $(this).attr('class');
				   countryText = $(this).find("a").text();
				   clsNameArray = htmlClsName.split(" ");
				   className = "";
				   
				   $.each(clsNameArray, function(index,value) {
				   	singleClass = value;
				   	if (singleClass.indexOf("dyna") != -1) {
				   		className = singleClass;
				   	}
				   })
				   xmlClsName =  className.replace("dyna-","");
				   xmlNode = $(xml).find("[id='"+xmlClsName.toUpperCase() +"']");
				   country= xmlNode.find("country").text();
				   label = xmlNode.find("label").text();
				   ttbuy = xmlNode.find("ttbuy").text();
				   chequebuy = xmlNode.find("chequebuy").text();
				   notebuy = xmlNode.find("notebuy").text();
				   ttsell = xmlNode.find("ttsell").text();
				   notesell= xmlNode.find("notesell").text();
				 
				   	newHtml = "<td>&nbsp;" + country;
				   	newHtml = newHtml + "</td><td>&nbsp;" + ttbuy; 
				   	newHtml = newHtml + "</td><td>&nbsp;" + chequebuy; 
				   	newHtml = newHtml + "</td><td>&nbsp;" + notebuy; 
				   	newHtml = newHtml + "</td><td>&nbsp;" + ttsell; 
				   	newHtml = newHtml + "</td><td>&nbsp;" + notesell; 
					newHtml = newHtml +  "</td>";
				   	$("td[class='"+htmlClsName+"']").replaceWith(newHtml);
				 

				})
				
				
				
				$("span[class='dyna-fx-date']").each(function() {
					date = $(xml).find("effectivedate").text();					
				 	$("span[class='dyna-fx-date']").replaceWith(date);
				}) 

		}
		
		formatFx = function (value) {
							return ((value == "") ? "&nbsp;" : value);
				}
		/* Set up to run when rates are retrieved */
		$.BNZ.feeds.foreignCurrencyRates.registerCallback(processForeignCurrencyRates, $('empty'));
		/**
		 *                                      END:foreign currency - fx- rates update
		 ******************************************************************/
	
})(jQuery);

