// myoung 3/11/09
var nowDateLE = new Date();

function showDayOfWeekLinkExchange(dateObject) {
	var dayOfWeek = "";
	var dayNumber = dateObject.getDay();
		switch(dayNumber) {
		case 0:
			dayOfWeek="Sunday";
		  break;    
		case 1:
			dayOfWeek="Monday";
		  break;
		case 2:
			dayOfWeek="Tuesday";
		  break;
		case 3:
			dayOfWeek="Wednesday";
		  break;
		case 4:
			dayOfWeek="Thursday";
		  break;
		case 5:
			dayOfWeek="Friday";
		  break;
		case 6:
			dayOfWeek="Saturday";
		  break;
		}
	return dayOfWeek;
}


function LinkExchangeController() {
	this.date1html = "";
	this.feedItemArray = new Array();
	this.currentDate = new Date();
	this.day1FeedArray = new Array();
	this.date1 = new Date();
	
	this.addFeedItem = function(feedItem) {
		this.feedItemArray.push(new linkExItem(feedItem));
	}
	
	this.sortFeedItems = function() {
		var completeArrays = 0;
		var currentArray = 0;
		var currentDateOffset = 0;

		var date1set = false;
		
		var tempArray = new Array();
		
		// Empty out future posts from the main array
		for (var i=0; i<this.feedItemArray.length; i++) {
			if (this.feedItemArray[i].publishDate < this.currentDate) {
				tempArray.push(this.feedItemArray[i]);
			}
		}
		this.feedItemArray = tempArray;

		while (completeArrays < 1) {
			for (var i=0; i<this.feedItemArray.length; i++) {
				var checkDate = new Date();
				checkDate.setDate(checkDate.getDate() - currentDateOffset);
				if (this.feedItemArray[i].publishDate.getDate() == checkDate.getDate()) {
					if (!date1set) {
						date1 = checkDate;
						date1set = true;
						completeArrays++;
					}
				}
			}
			currentDateOffset++;
		}
		
		for (var i=0; i<this.feedItemArray.length; i++) {
			if ((this.feedItemArray[i].publishDate.getDate() == date1.getDate()) && (this.feedItemArray[i].publishDate.getMonth() == date1.getMonth()) && (this.feedItemArray[i].publishDate.getYear() == date1.getYear())) {
				this.day1FeedArray.push(this.feedItemArray[i]);
			}
		}
	}
	
	this.populateFeedDivs = function() {
		this.date1html += '<div class="date">' + showDayOfWeekLinkExchange(date1) + '</div>';

		for (var i=0; i<this.day1FeedArray.length; i++) {
			this.date1html += '<div><span class="dailyFeedContentType">' + this.day1FeedArray[i].category + '</span>: <a target="_blank" class="dailyFeedTitle" href="' + this.day1FeedArray[i].headlineUrl + '">' + this.day1FeedArray[i].headline + '</a> (' + this.day1FeedArray[i].source + ')</div>';
		}
		
		$j("#otherFunnyWebLinks").html(this.date1html);
	}
}

function linkExItem(initObj) {
	this.publishDate = new Date(initObj.publishDate);
	this.headline = initObj.headline;
	this.headlineUrl = initObj.headlineUrl;
	this.source = initObj.source;
	this.category = initObj.category;
}
