﻿/*	JavaScript Source File
	for Lottery Post (http://www.lotterypost.com)
	Author: Todd Northrop
	E-mail: webmaster (at) lotterypost (dot) com
	Copyright (c) 1999-2011. All Rights Reserved.
	Reproduction in whole or in part in any form or medium without express written permission of the Author is prohibited.
	Lottery Post and the Lottery Post logo are trademarks of Todd Northrop, and may not be used without express written permission.
------------------------------------------------------*/

var jQT = new $.jQTouch({
	icon: "/apple-touch-icon.png",
	startupScreen: "/images/Mobile-Loading-Screen.png",
	statusBar: "black",
	cacheGetRequests: false,
	slideSelector: "body > * > ul li a,.optionButton a:not([target~=_replace])"
});

$(function () {
	
	$("a[target~=_replace]").tap(function (evt) {
		var $trigger = $(evt.target).addClass("active"),
			$bucket = $("<div />");
					
		$bucket.load($trigger.attr("href"), function (response, status, xhr) {

			if (status === "error") {
				$trigger.removeClass("active")
				alert("There was a problem loading the content. Please try again.");
			}
			else {
				$trigger.replaceWith($bucket);
			}
		});
					
		return false;
	});

	function mobileAdSetAll($ads) {

		if ($ads.length) {

			$ads.each(function () {
				$(this).html(mobileAdHtml(this));
			});
		}
	}
	
	function mobileAdHtml(el) {

		if (el.className.indexOf("mobileAd320x50") >= 0) {
			return '<div style="text-align:center"><div style="display:inline-block;width:320px;height:50px"><iframe src="/i/mobilead-google-320x50-1.asp" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" topmargin="0" leftmargin="0" allowtransparency="true" style="background:transparent;width:320px;height:50px"></iframe></div></div>';
		}

		return "";
	}
	
	$("body > *").live("pageAnimationEnd", function (evt, info) {
		var $ad = $(".mobileAd", this);

		if ($ad.length) {
		
			if (info.direction === "in") {
				window.setTimeout($.wired(null, mobileAdSetAll, $ad.filter(":visible")), 20);
			}
			else {
				$ad.empty();
			}
		}
	});

	mobileAdSetAll($("#home .mobileAd:visible"));
});

