var pageNum;
var TimeOut;
$(document).ready(function(){					
	var flashvars = {
		pageNum: pageNum
	};
	
	var params = {
	  swliveconnect : "true",
	  allowscriptaccess : "always",
	  wmode: "transparent"
	};
	
	var attributes = {
		id: "flashNav",
		name: "flashNav"
	};	
	
	//700 x 600
	//http://svc.qa.ny.pch.com/lottocontestwebservice/main.swf	
	swfobject.embedSWF( mediaBasePath + "packages/" + packageId + "/assets/lto_shl_mainNav.swf" , "flashNav", "866", "51", "10.0.0", "assets/expressInstall.swf", flashvars, params, attributes);	
	//launch game on load
	if(getURLValue("gm")) fLaunchGame(getURLValue("gm"));
});

var exitURL;
function fEndGame(){
	flb_Hide(true)
	w=950;
	h=600;
	newwindow=window.open(exitURL,"nextwin","scrollbars=yes,toolbar=no,directories=no,menubar=no,resizable=yes,status=no,width="+w+",height="+h+"");
	newwindow.window.focus();
	//refresh hack -added for 5671 per Mark
    document.location = document.location.protocol+'//'+document.location.host+document.location.pathname;
}


function fLaunchPlayedToday(){	
	$(".flashWrap").hide();
	$("#playedToday").show();	
	bOverrideNavAway=true;
	return false;
}

function fLaunchCoreg(){
       $(".flashWrap, #lbGame .adType2").hide();
       $("#coreg").show();
       //window.setTimeout(fLaunchCoreg,3333);
       return false;
}


function fCoregContinue(){
	$("#coregSplash").hide();
	var randomnumber=Math.floor(Math.random()*11)
	coregURL = "CoregRedirect.aspx?junk="+randomnumber;
	document.getElementById("coregFrame").src = coregURL;
	$("#coregFrame").show();	
}

function fCoregEntry(){
	$("#coregFrame").hide();	
	$("#coregConfirm").show();
	TimeOut = window.setTimeout(fCoregDone,5555);
}

function fCoregDone(){
	$("#coreg").hide();	
	$(".flashWrap, #lbGame .adType2").show();
	window.clearTimeout(TimeOut);
	fLaunchInstant(0);
	
}



function testMe(){
    fLaunchCoreg();
	
}

function callFGamePlayed(){
	fLaunchPlayedToday();
}

var countdownInterval;

function loadAd(url, countdown) {

	//alert(countdown);
	//sample ad calls
//	var adsurl = "http://ad.doubleclick.net/adi/" + ADS_SiteSection + "/" + ADS_Path + ";page=" + ADS_PageName + ";pos=9;tile=9;sz=300x250;ord=" + ADS_Rand + "?";
//    var iframeurl = ProxyUrl + '?useFilter=true&url=' + escape(adsurl);
    
	var now = new Date();
	
	url = url + "ord=" + now.getTime();
	
	var str = '<iframe src="'+url+'" name="ad_300x250" id="ad_300x250" width="300" height="250" scrolling="no" frameborder="0" ></iframe>'
	
	//strTot = '<script src="' + url + '">' + '</script' + '>';
	
	//ad_300x250.document.write(strTot);
	//ad_300x250.document.close();
	$('#adpanel').html(str);
	$('#adpanel_wrapper').show();
	
	$('#flashcontent_wrapper').css("left", -1000);
		
	$('#countdown').html(countdown);
	
	fRefreshAds();
	countdownInterval = setInterval("decCountdown()", 1000);
	
}

function decCountdown() {
	i = parseInt($('#countdown').html());
	
	if(i==0) {
		clearInterval(countdownInterval);
	}
	
	$('#countdown').html((i-1));
}

function unloadAd() {
	$('#adpanel_wrapper').hide();
	$('#flashcontent_wrapper').css("left", 0);
}


function fLaunchGame(inGameNum){

/*
so.addParam("allowScriptAccess", "always");
so.addVariable("themePath", "themes/theme1/");

//change path to webservice here
so.addVariable("servVar", "http://svc.qa.ny.pch.com/lottocontestwebservice/LottoContestService.asmx?WSDL");				
so.write("flashcontent");
*/
	
	var flashvars = {
		themePath: mediaBasePath + "Microsites/PCHLotto/GameExperience/themes/theme1/",
		servVar: lottoContestWebSvcURL + '?WSDL',
		gameKey: "XI798=skin1:XK589=skin4:XI808=skin2:XK590=skin11",
		gameStartID: inGameNum,
		appCode: "LOTTOGAME",
		strtGameId: inGameNum,
		strtGame: 0,
		coverFlowOn: "0",
		clickAd: "http://ad.doubleclick.net/adi/pch.pchlotto/flash;s1=flash;url=flash;kw=;pch=ad;pos=box;dcopt=ist;sz=300x250;tile=1;",
		scratch:"testMe()"  
	};
	
	var params = {
	  swliveconnect : "true",
	  allowscriptaccess : "always",
	  wmode: "transparent"
	};
	
	$("#adFrame3").attr({src: " AdFrame1.aspx " });
    $("#adFrame2").attr({src: " AdFrame2.aspx" });       

	var attributes = {
		id: "flashGame",
		name: "flashGame"
	};	
	
	//700 x 600
	//http://svc.qa.ny.pch.com/lottocontestwebservice/main.swf	
	swfobject.embedSWF( mediaBasePath + "Microsites/PCHLotto/GameExperience/main.swf", "flashGame", "700", "600", "10.0.0", "assets/expressInstall.swf", flashvars, params, attributes);	

	flb_Show("#lbGame")
	return false;
}

function fLaunchGameRdr(inGameNum){
	document.location = "Home.aspx?gm="+inGameNum;
	return false;
}

function fLaunchRegister(){
	flb_Show("#lbRegister");
	populateRegistrationLightBox();
	return false;
}

function fLaunchSignIn(){
	flb_Show("#lbSingIn");	
	return false;	
}

function fLaunchRegThanks(){
	flb_Show("#lbRegConfirm");
	//RemovePchUserInfoCookie();
	return false;
}

function fLaunchForgotPassword(){
	flb_Show("#lbForgotPassword");
}

function fLaunchPasswordSent(){	
	flb_Show("#lbPasswordSent");
}

function fLaunchNotSignedIn(){	
	flb_Show("#lbNotSignedIn");
}

function fLaunchDidIWin(){	
	flb_Show("#lbDidIWin");
	return false;
}

function fRedirect(inNum){
	switch(parseInt(inNum)){
		case 1:
			document.location = "Home.aspx"
			break;
		case 2:
			document.location = "Drawings.aspx"
			break;			
		case 3:
			document.location = "WinnersSpotlight.aspx"
			break;			
		case 4:
			document.location = "ByTheNumbers.aspx"
			break;			
		case 5:
		     CheckLoggedIn();
			//document.location = "MyAccount.aspx"
			break;						
		default:
			alert("Page Number Error: " + inNum);
			break;
	}

}

function changeHeight(inObj, inHeight){
	$(inObj).css({height: inHeight})	
}

function fDrawDate(inMonth,inDate,inYear)
{
    var today = new Date(); 
    var SelectedDate = new Date(inYear, inMonth-1, inDate,0,0,0);
    var CurrentDate = new Date(today.getFullYear(),today.getMonth(),today.getDate(), 0, 0, 0);
           
    //Selected date always should be less than current date
    if(SelectedDate >= CurrentDate)
    {
        alert("There are no drawing results for the date you selected. Please choose another date.");
    }
    else
    {
        var sdt = new Date(SelectedDate.getFullYear(),SelectedDate.getMonth(),SelectedDate.getDate(), 0, 0, 0);
        var edt = new Date(SelectedDate.getFullYear(),SelectedDate.getMonth(),SelectedDate.getDate(), 23, 59, 59);
        ByDateDrawingHTML(formateDate(sdt), formateDate(edt),"DrawingDate");
    }
}

function getURLValue(v){
	q = document.location.search.substring(1);
	if (q=="") return q;
	pairs = q.split("&");
	for (i=0; i<pairs.length; i++){
		if (pairs[i].split("=")[0].toLowerCase() == v.toLowerCase()) return unescape(pairs[i].split("=")[1]);
	}
	return "";
}

var arrNumsTemp=[];
var lastNum="00";

function fByTheNumbers(){	


	if(!arrNumsTemp.length){
		//reset
		for(var iA=0;iA<arrNums.length;iA++){
			if(arrNums[iA]!=lastNum)arrNumsTemp.push(arrNums[iA]);
		}
	}
	
	var iRand = Math.floor(Math.random()*arrNumsTemp.length);		

	
	var newNum=arrNumsTemp[iRand]
	//$("#byNumWrap").addClass("num"+lastNum)

	if(newNum<10) newNum="0"+newNum;

	
	var strImageLoc = $("#byNumWrap").css("background-image").replace(lastNum,newNum);
	
	$("#byNumWrap").css({backgroundImage: strImageLoc})
	
	lastNum=newNum

	arrNumsTemp.splice(iRand,1);
	return false;
}

function fRefreshAds(){
	$("#adFrame2").attr({src: $("#adFrame2").attr("src") });
	$("#adFrame3").attr({src: $("#adFrame3").attr("src") });
	return false;
}
