var jTicker = {
	tickerInterval: null,
	hotTopics: null,
	tickerStack: new Array(),
	uList: null,
	tickerHeight: null,

	fillTickerStack: function(arr){
		$(arr).each(function(){
			jTicker.tickerStack.push(this);
		});
	},

	buildListItem: function(item){
		var
			listItem = $('<li>');
			
		$(item).each(function(){
			var
				span = $("<span>"),
				anchor = $('<a>');
				
			$(span).text(this.type + ':');
			$(anchor).attr("href", this.url).text(this.linkDisplay);
			$(listItem).append(span).append(anchor);
		});
		
		return listItem;
	},

	tick: function(){
		var
			item,
			firstLi = $(jTicker.uList).find("li"),
			newLi;
			
		if(jTicker.tickerStack.length > 0){
			item = jTicker.tickerStack.shift().info;
			newLi = jTicker.buildListItem(item);
			$(jTicker.uList).append(newLi);
			$(jTicker.uList).find('li').animate({ "top" : "-=" + jTicker.tickerHeight + "px"}, "slow", function(){
				firstLi.remove();
				$(newLi).css('top', '0');
			});
			setTimeout("jTicker.tick()", jTicker.tickerInterval);
		}
		else{
			jTicker.fillTickerStack(jTicker.hotTopics);
			jTicker.tick();
		}
	},

	init: function(){
		var
			listItem = $('<li>'),
			item,
			newLi;
		
		jTicker.uList = $("#hot-topics ul");
		jTicker.tickerHeight = $("#hot-topics").height();
		jTicker.fillTickerStack(jTicker.hotTopics);
		item = jTicker.tickerStack.shift().info;
		newLi = jTicker.buildListItem(item);
		$(jTicker.uList).append(newLi);
		setTimeout("jTicker.tick()", jTicker.tickerInterval);
	}
};

var headerSwap = {
	images: null,
	imagesDir: "http://prod.static.steelers.clubs.nfl.com/assets/images/header-swap/",

	setImage: function(){
		var
			randomIndex = Math.floor(Math.random() * headerSwap.images.length),
			imagePath = headerSwap.imagesDir + headerSwap.images[randomIndex];

		$('#header-swap').css("background", "url(" + imagePath + ") no-repeat top left");
	}
};

var proshopSwap = {
	images: null,
	imagesDir: "http://prod.static.steelers.clubs.nfl.com/assets/images/proshop-swap/",
	imagesUrl: "",

	setImage: function(){
		var
			randomIndex = Math.floor(Math.random() * proshopSwap.images.length),
			imagePick = proshopSwap.images[randomIndex],
			imageElements = imagePick.split(' '),
			imagePath = proshopSwap.imagesDir + imageElements[0],
			imageUrl = proshopSwap.imagesUrl + imageElements[1];

		$('#proshop-swap').css("background", "url(" + imagePath + ") no-repeat top left");
		$('#proshop-swap a').attr("href", imageUrl);
	}
};

