/* BROOKS & DUNN */
/* Paged Banners Function
----------------------------------------------------------------------------- */


	function bannersFeed(unit, selector) {

		var banners = '<ul class="banners">';
		$unit = unit;
		$selector = selector;

		$unit.find('banner').each(function() {

			if ($(this).find('status').text() == "Publish") {

				var url = $(this).children('url').text();
				var image = $(this).children('image').text();
				var caption = $(this).children('description').text();

				if (url == "" || url == "http://") {

					banners += '<li><img src="' + image + '" alt="' + caption + '" /></li>';

				}

				else {

					banners += '<li><a href="' + url + '"><img src="' + image + '" alt="' + caption + '" /></a></li>';

				}

			}

		});

		banners += '</ul>';

		if ($(banners).children().length > 0) {

			$(banners).appendTo($selector);

		} else {

			$selector.parent().remove();
		
		}

	}

	function banners() {
 
		$.get('/feeds/banners', function(data) {

			// Load banners
			$(data).find('unit').each(function() {

				// Page Exemptions
				if (page == "index") {

					var exemptions = true;

				} else {

					var exemptions = false;

				}

				// Featured Banners
				if ($(this).find('name').text() == "featured_banners") {

					bannersFeed($(this), $('div.ad.featured.banners'));

				}

			});

			if ($('div.ad.featured.banners ul.banners li').length > 0) {

				$('div.ad.featured.banners ul.banners').after('<div class="pager"><div>').cycle({
	
					fade: true,
					speed: 400,
					timeout: 9000,
					pager: 'div.pager div'
	
				});
	
				$('div.ad div.pager div').each(function() {
	
					$(this).css('float', 'left');
					$(this).css('width', $(this).width() + 'px');
					$(this).css('float', 'none');
					$(this).children('a:last-child').addClass('last');
	
				});
			
			} else {
			
				tabs('removeEmptyTabs');
			
			}
			
		});

	}