﻿/// <reference path="jquery.intellisense.js"/>

/****************
 INITIALISATION  
****************/

$(document).ready(function() {
	var listingMaxHeight = 0;
	var listingWidth = 324;
	var listingAnimationDuration = 500;
	var pageNavAllowedHeight = 70;
	var currentPage = 1;
	var numPages = 0;

	$(".Listing").each(function() {
		numPages++;
		$(this).css("position", "absolute");
		if (numPages > 1) {
			//$(this).css("display", "none");
			$(this).css("left", listingWidth + "px");
		}
		if ($(this).innerHeight() > listingMaxHeight) listingMaxHeight = $(this).innerHeight();
	});

	// Initialise navigation
	if ($(".PageNavList").length > 0) {
		listingMaxHeight += pageNavAllowedHeight;
		if (currentPage == 1) DisableNav($(".NavPrevious"));
		if (currentPage == numPages) DisableNav($(".NavNext"));
		$(".PageNavList").css({ position: "absolute", bottom: "0px", right: "0px" });
	}


	$(".ListHolder").css("height", listingMaxHeight);
	// Set height for content holder to accommodate for navigation
	$("#ContentHolder").css("height", listingMaxHeight);

	$('.NavPrevious').click(function() {
		if (currentPage > 1) {
			// $("#ListingPage" + currentPage).hide();
			$("#ListingPage" + currentPage).animate({ left: listingWidth + 'px' }, listingAnimationDuration);
			// $("#ListingPage" + (currentPage - 1)).show();
			$("#ListingPage" + (currentPage - 1)).animate({ left: '0px' }, listingAnimationDuration);
			currentPage--;
		}
		if (currentPage == 1) DisableNav($(".NavPrevious"));
		EnableNav($(".NavNext"));
	});

	$('.NavNext').click(function() {
		if (currentPage < numPages) {
			// $("#ListingPage" + currentPage).hide();
			$("#ListingPage" + currentPage).animate({ left: '-' + listingWidth + 'px' }, listingAnimationDuration);
			// $("#ListingPage" + (currentPage + 1)).show();
			$("#ListingPage" + (currentPage + 1)).animate({ left: '0px' }, listingAnimationDuration);
			currentPage++;
		}
		if (currentPage == numPages) DisableNav($(".NavNext"));
		EnableNav($(".NavPrevious"));
	});
});

function DisableNav(el) {
	$(el).addClass("Disabled");
	$(el).css("cursor", "default");
}

function EnableNav(el) {
	$(el).removeClass("Disabled");
	$(el).css("cursor", "pointer");
}
