var OrderPage =
{
	ViewModeChangeField: null,
	AdCount: 0,
	FavoritesCount: 0,
	UpdateFavoritesCount: function()
	{
		$.ajax
		(
			{
				type: "POST",
				contentType: "application/json; charset=utf-8",
				url: Global.VirtualRoot + "/AjaxJSON.asmx/GetCheckedPhotoCount",
				data: JSON.stringify
				(
					{
						checkedSessionId: OrderPage.CheckedSessionId,
						eventId: OrderPage.EventId,
						subEventOnly: OrderPage.SubEventOnly
					}
				),
				beforeSend: function(x)
				{
					if (x && x.overrideMimeType)
						x.overrideMimeType("application/json;charset=utf-8");
				},
				success: function(data)
				{
					OrderPage.FavoritesCount = data.d;
				
					$(".thumbgrid-selectedcount").text(OrderPage.FavoritesCount);
				},
				error: function(req, status)
				{
					//debugger;
				},
				dataType: "json"
			}
		);
	},
	HasFavorites: function()
	{
		if (slideState == 1) // we're already in view favs mode
			return true;
		
		var hasFavs = false;
		
		for (var i = 0; i < Slideshow.Photos.length; i++)
		{
			var photo = Slideshow.Photos[i];
			
			if (!photo || !photo.Checked)
				continue;
			
			hasFavs = true;
			break;
		}

		if (!hasFavs)
			alert(L10n.OrderPage_aspx_js.noFavorites);
		
		return hasFavs;
	},
	DisplayAd: function()
	{
		//$("#" + adContainerId).attr("src", "ViewAd.aspx?e=" + eventIdy + "&s=" + adSize + "&ts=" + new Date().getTime());
		OrderPage.AdCount++;
	},
	SetViewModeChange: function()
	{
		$(OrderPage.ViewModeChangeField).val("1");
	},
	OnDocumentReady: function()
	{
		OrderPage.DisplayAd();

		$.timer
		(
			30000,
			function (timer)
			{
				if (OrderPage.AdCount < 5)
					OrderPage.DisplayAd();
			}
		);

		$("input[type='hidden']").each
		(
			function(i)
			{
				if (this.id.indexOf("HiddenViewModeChange") != -1)
					OrderPage.ViewModeChangeField = this;
			}
		);

		$("#DivSlideshowFavorites").click
		(
			function()
			{
				$.timer
				(
					100,
					function (timer)
					{
						OrderPage.UpdateFavoritesCount();
						timer.stop();
					}
				);
			}
		);

		OrderPage.UpdateFavoritesCount();
	}
};

$(document).ready(OrderPage.OnDocumentReady);

