/*
 * When an event is nearly full, or full, or waitlisted, we may wish to do something. (Currently, for example,
 * we want to:
 * 		1) put dots on schedules providing a visual cue of whether something is nearly full or full, and
 *		2) provide registrants with a warning that an event they're registering in is full
 *
 * JP, July 2010
 */
function reactToFullness(reactionFunction) {

	var NEARLY_FULL_SLOT_REMAINING_COUNT = 2;  // So if 1 or 2 slots were left in a given event, it would be considered 'nearly full'.
	
	$.getJSON	("http://www.boards2bits.com/fcwebservices/registrationservices.asmx/GetAllStatusCodesByCutoff?callback=?&format=json", 
				{"slotsLeftToBeConsideredNearlyFull": NEARLY_FULL_SLOT_REMAINING_COUNT}, 
				function (data) {	

					$.each(data.d, reactionFunction);
				}
	); 

}


/*
 * This is used to place the dots on the schedule that
 * indicate whether an event is nearly full (yellow dot)
 * or full/waitlisted (red dot).
 */
function doDots(i, item) {

	var splitEntry = item.split(":");
	var slot = splitEntry[0];
	var status = splitEntry[1];
	
	var target = "td.eventCellData:contains(" + slot + ")";
	$(target).css('background-position', 'center');
	$(target).css('background-repeat', 'no-repeat');
	if (status === "F") {
		$(target).css('background-image', 'url(/images/circle-red.png)');
	} else {
		$(target).css('background-image', 'url(/images/circle-yellow.png)');
	}

}


/*
 * This is used to warn users that they're registering in an event that is full.
 * 
 * This is called in Traffik's /js/registration.js script in CheckEvents().
 *
 * JP, July 2010
 */
function doWaitlistWarnings(i, item) {

	var splitEntry = item.split(":");
	var slot = splitEntry[0];
	var status = splitEntry[1];
	
	var target = "span:contains(" + slot + ")";

	if (status === "F") {
		var waitlistPosition = parseInt(splitEntry[2]) + 1;
		var message = "<span class='full-warning'>	&rArr;  This event is full. You will be put on its waitlist in position " + waitlistPosition + ".</span>";
		$(target).append(message);
		$('span.full-warning').css("color", "red");
	} 

}
 


function displayAuctionSlotsUsedInfoInCarousel() {

	$.getJSON("http://www.boards2bits.com/fcwebservices/auctionservices.asmx/GetNumberSlotsUsed?callback=?&format=json", 
			function (data) { 
				var slotsUsed = data.d; 
				$('.num-slots-used').html(slotsUsed); 
			} 
	);
}

function displayAuctionSlotsAvailableInfoInCarousel() {

	$.getJSON("http://www.boards2bits.com/fcwebservices/auctionservices.asmx/GetNumberSlotsLeft?callback=?&format=json", 
			function (data) { 
				var slotsLeft = data.d; 
				$('.slots-left').html(slotsLeft); 
			} 
	);
}

function displayAuctionSellerInfoInCarousel() {
	$.getJSON("http://www.boards2bits.com/fcwebservices/auctionservices.asmx/GetNumberUniqueSellers?callback=?&format=json", 
		function (data) { 
			$('.num-sellers').html(data.d); 
		}
	);
}

function displayTotalNumberFallConRegistrantsInCarousel() {
	$.getJSON("http://www.boards2bits.com/fcwebservices/registrationservices.asmx/GetTotalNumberRegistrants?callback=?&format=json", 
		function (data) { 
			$('.num-registrants').html(data.d + 3); 
		}
	);
}

function displayNumberFullEventsInCarousel() {
	$.getJSON("http://www.boards2bits.com/fcwebservices/registrationservices.asmx/GetNumberFullSlots?callback=?&format=json", 
		function (data) { 
			$.getJSON("http://www.boards2bits.com/fcwebservices/registrationservices.asmx/GetNumberWaitlistedSlots?callback=?&format=json",
				function (nfdata) {
					var totalUsers = data.d + nfdata.d;
					$('.num-full-events').html(totalUsers);
				}
			);
		}
	);
}

function displayNumberNearlyFullEventsInCarousel() {
	var NUMBER_EMPTY_SPACES_LEFT_TO_BE_CONSIDERED_NEARLY_FULL = 2;

	$.getJSON("http://www.boards2bits.com/fcwebservices/registrationservices.asmx/GetNumberNearlyFullSlotsByCutoff?callback=?&format=json", 
		{ slotsLeftToBeConsideredNearlyFull: NUMBER_EMPTY_SPACES_LEFT_TO_BE_CONSIDERED_NEARLY_FULL }, 
		function (data) { 
			$('.num-nearfull-events').html(data.d); 
		}
	);	
}

/*
function displayDailyNumbersInCarousel() {
	$.getJSON("http://www.boards2bits.com/fcwebservices/registrationservices.asmx/GetNumberPasses?callback=?&format=json", 
		function (data) { 
			var numEarlyBirdWeekendPasses = data.d[0];
			var numRegularWeekendPasses = data.d[1];
			var numWeekendPasses = numEarlyBirdWeekendPasses + numRegularWeekendPasses;
			var numFridayPasses = data.d[2];
			var numSaturdayPasses = data.d[3];
			var numSundayPasses = data.d[4];
			var numFamilyPasses = data.d[5];
			$('.num-Friday-registrants').html(numWeekendPasses + numFridayPasses); 
			$('.num-Saturday-registrants').html(numWeekendPasses + numSaturdayPasses); 
			$('.num-Sunday-registrants').html(numWeekendPasses +numSundayPasses); 
		}
	);
}
*/


function displayFrontPageCarousel() {
	displayAuctionSlotsUsedInfoInCarousel();
	displayAuctionSlotsAvailableInfoInCarousel();
	displayAuctionSellerInfoInCarousel();
	displayTotalNumberFallConRegistrantsInCarousel();
	displayNumberFullEventsInCarousel();
	displayNumberNearlyFullEventsInCarousel();
}


function displayAuctionPageCarousel() {
	displayAuctionSlotsUsedInfoInCarousel();
	displayAuctionSlotsAvailableInfoInCarousel();
	displayAuctionSellerInfoInCarousel();
}

function setCarousel() {
	$(".carousel").jCarouselLite(
		{  
			vertical: true,  
			visible: 1,  
			auto:1,  
			speed:2200,  
			mouseWheel: true
		}	
	);  
}

function setCountdownTimer() {
	var austDay = new Date("October 14, 2011 17:00:00");			
	$('#defaultCountdown').countdown({until: austDay, format: 'ODHMS'});
}

function highlightNewGames() {
	var target = "td:contains(*)";
	var starredGames = $(target);
	starredGames.each(function(i) {
		$(this).css("background-color", "#eecc00");
	});
}

