// JavaScript Document

// requires JQuery Libraries

	// reads the XML feed and builds the announces into an unordered list
	// requires variable 'feedurl' to be set
	
	function build_announce(){
	
		// get the feed
		$.get(feedurl, function(data){
			// what to do with the feed
			var doc = data;
			var rootnode = doc.getElementsByTagName('banners');
			if( rootnode.length > 0 ){
				var announces = rootnode[0].getElementsByTagName('banner');
				if( announces.length == 0 ){
					// there are no announces
					return false;
				} else {
					// we've got some announces, now let's process them
					// create an element for them to sit in
					$("<div id=\"announcebox\"></div>").prependTo("#headerBottom");
					$("<ul id=\"announceslideshow\"></ul>").appendTo("#announcebox");
					for (var j=0; j < announces.length; j++) {
						announce = announces[j];
						imagesrc = getXMLValue(announce, 'flatImageSource');
						//duration = getXMLValue(announce, 'slideDuration');
						//transition = getXMLValue(announce, 'slideTransition');
						globallink = getXMLValue(announce, 'globalLink');
						alttext = getXMLValue(announce,'flatImageAltText');
						//alert(alttext);
if (globallink == '') {
						$("#announceslideshow").append("<li><img src=\""+imagesrc+"\" alt=\""+ alttext + "\" /></li>");
} else {
						$("#announceslideshow").append("<li><a href=\""+ globallink + "\" title=\""+ alttext + "\"><img src=\""+imagesrc+"\" alt=\""+ alttext + "\" /></a></li>");
}
						
					}
					// call the fade
					$('#announceslideshow').innerfade({
						speed: 'slow',
						timeout: '7000',
						type: 'sequence',
						containerheight: '250px'
					}); 
				}
					
			}
		
		});
	
	}
	
	// initialises the fade
	$(document).ready( function(){
			build_announce();
	} );
	
	// gets the contents of a named tag
	function getXMLValue(xml, tagname){
		nodes = xml.getElementsByTagName(tagname);
		return nodes[0].firstChild.nodeValue;
	}
