jQuery(function(){		
	var to = {};
	function parsebanners(xml) {
		var bancount = 0;
		var maxbancount = 0;
		
		//Adds banner elements to .promoRotator
		jQuery(xml).find('banner').each(function(idx){
			if ( jQuery(this).find("image").text() !== "") {
				
			jQuery('.promoRotator .img').append('<img class="thumbs i'+bancount+'" src="/'+jQuery(this).find("image").text()+'" rel="'+jQuery(this).find('link').text()+'" />');
			jQuery('.promoRotator .captions').append('<div class="capt cap'+bancount+'"><h4>' + jQuery(this).find('title').text() + '</h4>' + jQuery(this).find("subTitle").text() + '</div>');
			jQuery('.cap'+bancount).css('top',46-(jQuery('.cap'+bancount).height()/2));
			bancount = bancount+1;
			
			
			}

		});
		maxbancount = bancount;
		bancount = 0;
	
		jQuery('.promoRotator .capt, .promoRotator .thumbs').hide();
		jQuery('.promoRotator .i0, .promoRotator .cap0').show();
		jQuery('.promoRotator a').attr('href', jQuery('.promoRotator .i0').attr('rel'));
		
		//Progresses to the next slide.
		function nextSlide() {
			jQuery('.promoRotator .cap'+bancount+', .promoRotator .i'+bancount).fadeOut(500);
			bancount = bancount + 1;
			if (bancount == maxbancount) {
				bancount = 0;	
			}
			jQuery('.promoRotator .cap'+bancount+', .promoRotator .i'+bancount).fadeIn(500);

		}
		
		to = setInterval(nextSlide, 5000); 
	}
	
	//If Promo Rotation spot is on page, load and parse xml
	if (jQuery('.promoRotator').length) {
	  	jQuery.ajax({
                type: "GET",
                url: "promoBannerXML.xml",
                dataType: "xml",
                success: parsebanners
            });

	  }
	  
	  //Checks if #homeHero element exists, 
	  if (jQuery('#homeHero').length) {
		if (heroFile.indexOf('.js') > -1) {
			jQuery('#homeHero .default').hide();
			$.getScript(heroFile, function(data, textStatus){
				jQuery.ajax({
						type: "GET",
						url: "homeheroXML.xml",
						dataType: "xml",
						success: parsehero
					});
			});
			
		} else {
			swfobject.embedSWF(heroFile, "homeHero", heroWidth, heroHeight, "9.0.0","",{},{bgcolor:'#ffffff', wmode:'transparent'});
		}
	}
});

