// JavaScript Document
$(function() {

	/*CALENDAR*/
	$("a#foxydiary, a.fbdiary").colorbox({width:"999px", height:"750px", iframe:true, opacity: "0.5"});
	
	
	/* YOU TUBE LIGHTBOX*/
	$("a.youtube_lightbox").colorbox({iframe:true, innerWidth:640, innerHeight:385});
	
	/* You pdf lightbox */
	$("#pdf-popup").colorbox({iframe:true, innerWidth:750, innerHeight:520});
	
	/* username in login box */
	var alias = $.cookie("Alias");
	if (alias != undefined) $('#username').attr('value',alias);
	$('#username, #password').click(function() {
		$(this).select().css('text-transform','none');	   
	});
	
	/*POPUP BEHAVIOURS*/
	$("a.popup").click(function(e) { 
		e.preventDefault();
		var $this = $(this);
		var properties;
		
		/*MEGA GUARANTEED JACKPOT*/
		if ($this.attr("id")=="megaguaranteed") 
		{
			properties = "toolbar=0,location=0,left=0,top=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=860,height=800";
			
		}
		
		window.open($this.attr("href"),"",properties); 
	});
	
	/*CONTACT FORM*/
	$(".send-contact-email").livequery(function(){
		$(".send-contact-email").click(function(e) {
			e.preventDefault();
			var $this = $(this);
			//var type;
			var type = $this.attr("id").replace(/^send-/,'');
			//console.log(type);
			var selectval = $("#"+type+"-team .field_subject").fieldValue();
			//console.log(selectval[0]);
			$("#email-feedback").load("/pop/help/sendemail.php",
				{
					type: type,
					name : $("#"+type+"-team .field_name").val(),
					email: $("#"+type+"-team .field_email").val(),
					email_confirm: $("#"+type+"-team .field_email_confirm").val(),
					alias: $("#"+type+"-team .field_alias").val(),
					querytype: selectval[0],
					query: $("#"+type+"-team .field_message").val(),
					refer: $("#"+type+"-team .refer").val(),
					sitename: $("#"+type+"-team .sitename").val()
				}
			);
			$("#email-forms").empty();
		});
	});
	
});
/* Timed Content 
---------------------------*/

function getTime()
{
var d = new Date();
var weekday=new Array(7);
weekday[0]="Sunday";
weekday[1]="Monday";
weekday[2]="Tuesday";
weekday[3]="Wednesday";
weekday[4]="Thursday";
weekday[5]="Friday";
weekday[6]="Saturday";
return weekday[d.getDay()];
}

function timed(dir,div,override,includepath,playerClass,url)
{
	var urlmatch, path;
	
 	urlmatch = url.search("main.php");
	//if (urlmatch==1) path= '/include/timed/';	//there is a match
	//else 
	path = '/include/timed/';
	/*if (jQuery.browser.mozilla) console.log("ajax call: "+path+"timed_function.php?day="+today+"&dir="+dir+"&includepath="+includepath+"&playerClass="+playerClass);*/
	//alert(dir);
	var today;
	if (override=="")today = getTime();
	else today = override;
	
	$(div).load(path+"timed_function.php?day="+today+"&dir="+dir+"&includepath="+includepath+"&playerClass="+playerClass);
	
}


/* Display Calendar Picker
-----------------------------------*/
	function formSubmitIntercept(sender, event){
		if (event && event.keyCode == 13) {
		datePickerClosed(sender);
		return false;
		}
	}
	function datePickerClosed(dateField){
		(valDate(dateField));
		go(dateField.attributes["formAction"].value,false);			
	} 
	function GameDetail(gameID){
			document.mainForm.gameID.value = gameID;
			go('MYGAMEDETAIL', false, 'mygamesdetail.php');
	}



/* Launch Game to specific tabs
-----------------------------------*/
function launchGame(iRoom,loc,tab,dl) {
        var bGameOpen = false;
        //debugger
        loc = "/skin/play.php";
        if(dl) loc += "?tab=" + tab + "&DL=" + dl + "&cachebuster=" + (Math.random()+'');
        else   loc += "?tab=" + tab + "&cache=" + (Math.random()+'');

        // check if game window already open
        try
        {
          var oTest = playWin.document;
          if (oTest != null)	bGameOpen = true;
                }
        catch(ee)
                {
                bGameOpen = false;
                }

        if (!bGameOpen)
                {
                        h=(screen.height*.9)-54
                        w=(screen.width*.9)

                        if (navigator.appName.indexOf("Microsoft") != -1)
                        {
                                playWin = window.open(loc, "playWin", "height="+h+",width="+w+",top=1,left=1,resizable");
                        }
                        else
                        {
                                playWin = window.open(loc, "playWin", "height="+screen.height-2+",width="+screen.width-2+",screenY=1,screenX=1,resizable");
                }
                playWin.focus();
        }
  else
        {
                playWin.focus();
        }
}



/* Curfon fonts declarations 
---------------------------------*/
Cufon.DOM.ready(function() {
  Cufon.replace(".page-header span", {fontFamily: "Marketing Script"});    
	Cufon.replace("#section-header, .inner-content h2, .sub-header, .inner-content h3, #foxysynopsis h2", {fontFamily: "VAGRounded"});
	Cufon.replace("#loginfrm label, .label-name, #loginfrm a, .playermsg, #bottom-edge p, #today-message h2, #today-message h3, .newsletterlinks, #uf-today-message h3, #other-button", {fontFamily: "VAGRounded"});
	Cufon.replace(".input-row label, #forgotlink, #registerlink, #morelink, #display-subnav p, #member-subnav p", {fontFamily: "VAGRounded"});
	Cufon.replace("#navbar li a",{hover:true , fontFamily: "VAGRounded"});
});

/* jquery call to libraries functions
----------------------------------------*/

$(document).ready(function ()
{
	
	var $atozlinks = $(".content-section");
	var $archivenews = $("#newsletterpg .content-section ");
	$archivenews.hide();
    // atozlinks.hide().filter(":first").show();
     $(".intro-links a").click(function (e) {
     	  e.preventDefault();
        $atozlinks.hide();
        $atozlinks.filter(this.hash).show();
        $(".intro-links a").removeClass("selected");
        $(this).addClass("selected");
      return false;
   }).filter(":first").click();
   
   $(".newsletterlinks a").click(function (e) {
   	e.preventDefault();
   	$archivenews.hide();
        $atozlinks.filter(this.hash).show();
        $(".newsletterlinks a").removeClass("selected");
        $(this).addClass("selected");
        $archivenews.insertAfter($(this));
   	 return false;
   }).filter(".content-section:first").click();	
   
       
   // set page-headers
   $(".page-header > span").css("padding-top","38px");
   $("#section-header > span").css("padding-top","0");
   
   $(".facebook-refer").click(function(e) {
        e.preventDefault();
    });
	
   //style tables
   $(".tbl_content tr > td:first-child").addClass("first");
   $(".tbl_content tr  td:last-child").addClass("last");
   $("<div class=bottomtbl><!-- --></div>").insertAfter($(".tbl_content"));
   showhideNav();
   popupDiv();
  
});
function showhideNav(){
	$("#display-subnav").hide();
		
	$("#morelink").click(function(){
		$("#display-subnav").slideToggle("slow"); 
		$(this).toggleClass("active").css("visibility","hidden");
		return false; 
	});
  
	 $("#closelink").click(function(){
		 $("#display-subnav").slideToggle("slow");
		 $(this).toggleClass("active");
		 $("#morelink").css("visibility","visible");
		 return false;
	  });
}

function popupDiv(){
 $(".showdiv").hide();
 $("#button").click(function(){
    $(".showdiv").show();
    return false;
 });

 $("#btnCancel").click(function(){
    $(".showdiv").hide();
    return false;
 });

}

/* Check Balance */
function checkBal(){
    var bal, answer;
    bal = document.getElementById("playerBal").value.replace(/,/,"");
    if(parseInt(bal)>=30){
	answer = confirm("You still have withdrawable funds left in your account.\nClick OK to launch the cashier and withdraw the funds \nClick CANCEL to continue with the self exclusion.");
	if(answer){
          goCashierForm();
	  document.getElementById("playerBal").value = 0;
   	  return;
	}
    }
   go('selfexclude',false,'members.php');
}

/* Open new window functions - LEGACY FUNCTIONS NOT SURE IF IN USE STILL
------------------------------------------------------------------------ */
function newWindow(theURL,winName,features) { //v2.0 replaces name 'MM_openBrWindow'
  window.open(theURL,winName,features);
}

function playRoom(iRoomID){
   playWin = window.open("/skin/play.php?room=" + iRoomID, "playWin", "height="+screen.height-2+",width="+screen.width-2+",screenY=1,screenX=1,resizable");
}
	
function advent(){
		var $i = window.open('/skin/promotions/advent/advent_calendar.html',"advent","toolbar=0,top=0,left=0,location=0,directories=0,status=1,menubar=0,scrollbars=0,resizable=0,width=770,height=585");
}
	
function howtoplay(){
	window.open('/skin/howtoplay.php',"game","toolbar=0,location=0,left=0,top=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,width=720,height=520"); 
}

function expand() {
	styleObj = document.getElementById('playertop').style;
  styleObj.display = 'inline';
}

function megajackpots(){
		window.open('/skin/games/coverall/guaranteed-schedule.php',"guaranteeds","toolbar=0,location=0,left=0,top=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=820,height=800"); 
}

function megajackpots_ball(){
window.open('/skin/games/coverall/guaranteed-schedule-ball.php',"guaranteeds","toolbar=0,location=0,left=0,top=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=820,height=750"); 
}