/*
	Banner Image Ticker
	Kyle Stevenson | New Business Media 2010
*/

$(function(){
	$('.home > ul').css({'height': '0px', 'bottom': '9px', 'border-top': 'none'});
	//$('.home > ul').css('height', '0px');
	$('.homeCopy').css('bottom', '9px');
	
	$('a.no-link').click(function(){
		return false;
	});
});

(function($){
	
	$.fn.bannerTicker = function(settings) {
		// Allow user to overwrite default Settings
		settings = jQuery.extend({
			duration : 5000,
			transition : 800
		}, settings);

		this.each(function() {
			// Setup Banner Ticker
			var $this = $(this);
			var timer_id;

			// Ignore Single Images
			if ($this.find('a').length < 2) return this;

			// Set Timer
			timer_id = setInterval(function(){
				var $active = $this.find('a.active');

				if ($active.length == 0) {
					$active = $this.find('a:last');
				}

				if ($active.next().length > 0) {
					$next = $active.next();

				} else {
					// Stop Timer on Last Item
					clearInterval(timer_id);
					
					ShowTray();
					return false;
				}

				$active.addClass('last-active');

				$next.css({opacity: 0.0})
					.addClass('active')
					.animate({opacity: 1.0}, settings.transition, function(){
						$active.removeClass('active last-active');
					});
			}, settings.duration);
		});

		return this;
	};

})(jQuery);

// Show Tray Function
function ShowTray() {
	
	$('.home > ul').css('border-top', '1px solid #001522');
	
	$('.home > ul').animate({
		bottom: '9px',
		height: '158px'
		}, 625);
	$('.homeCopy').animate({
		bottom: '168px',
		}, 625);
}
