// Used to download the casino, and then redirect to the beginner's room, download casino.
function gotoDefaultCasinoDownload()
{
    gaCasinoDownload();
    setCasinoDownloadedCookie();
    var rStatus = $.cookie('rStatus');
    if(rStatus == null || rStatus == 1) {
        var popupUrl = '/t/customer/registrationpopup.aspx?submit=downloadForm';
        SB.base.deferWindowCommand(popupUrl, 'popup', false);
    } else {
        document.downloadForm.submit();
    }
}

// Sets a Cookie: used whilst nagging
function setCasinoCookie(c_name, value, expiredays)
{
	var exdate = new Date()
	exdate.setDate(exdate.getDate() + expiredays)
	document.cookie = c_name + "=" + escape(value) + ";path=/" + ((expiredays==null) ? "" : ";expires=" + exdate.toGMTString())
}

// Gets a Cookie: used whilst nagging
function getCookie(c_name)
{
	if (document.cookie.length > 0)
	{
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start != -1)
		{ 
			c_start = c_start + c_name.length + 1; 
			c_end = document.cookie.indexOf(";", c_start);
			if (c_end == -1)
				c_end = document.cookie.length
			return unescape(document.cookie.substring(c_start, c_end));
		}
	}
	return "";
}

// This is the cookie set when the customer has downloaded the casino
function setCasinoDownloadedCookie()
{
	setCasinoCookie('casino', 'y', 3650);
}

// Nags the customer incessantly in an attempt to harass them into downloading the casino
function nag()
{
	var nagged = getCookie('casino');
	if (nagged == "")
	{
		var attributes = "width=360,height=220,resizable=no,scrollbars=no,status=no,location=no,toolbar=no";
		popUp("/t/casino/pop-up/download-question.aspx", "DownloadCasino", attributes);
	}
}

// Confirms the customer wants to download the casino from the "nag" popup
function confirmCasinoDownload()
{
    dcsMultiTrack('DCS.dcsuri', '/CasinoDownload/PlayNowButton/DownloadNow', 'WT.ti', 'Button:Casino Download - Download Now', 'WT.cg_n', 'Casino', 'WT.cg_s', 'Download Casino', 'WT.si_n', 'Casino', 'WT.si_p', 'Download', 'WT.ac', 'Casino Download - PlayNowButton');
    gaCasinoDownload();
	document.downloadForm.submit();
	setCasinoDownloadedCookie();
}

function delayCasinoDownload()
{
	dcsMultiTrack('DCSext.gaming', 'No Download', 'DCSext.refusecasinodownload', '1', 'DCSext.creative', 'Not Now Button');
	window.close();
}

// Called from the "please don't tell me about this any more" button
function rejectCasinoDownload()
{
	setCasinoDownloadedCookie();
	window.close();
}

// Shows or hides the game previews
function showPreview(isShown,divId)
{
	if(document.layers)
	{	
		if (isShown)
		{
			document.layers[divId].visibility = "show";
			document.layers[divId].display = "";
		}
		else
		{
			document.layers[divId].visibility = "hide";
			document.layers[divId].display ="none";		
		}		
	} 
	else if(document.getElementById) 
	{
		if (isShown)
		{
			document.getElementById(divId).style.visibility = "visible";
			document.getElementById(divId).style.display = "";
		}
		else
		{
			document.getElementById(divId).style.visibility = "hidden";
			document.getElementById(divId).style.display = "none";
		}
	} 
	else 
	{
		if (document.all(divId).style.visibility == "visible")
		{
			document.all(divId).style.visibility = "visible";
			document.all(divId).style.display = "";
		}
		else
		{
			document.all(divId).style.visibility = "hidden";
			document.all(divId).style.display = "none";
		}
	}
}

// Jackpot Banner Rotation
var b_delay  = 3600; //retardo entre divs
var b_timer=0;
var b_active; 
var b_banner = 0;
function b_init(){        
	var t;
	while (true)
	{
		t = document.getElementById("banner_"+b_banner);
		if (!t)
			break;
		b_banner++;
	}
	b_active=b_banner-1;
	b_show(b_active);    
	hb_counter();        
}

function hb_counter()
{            
	b_hide(b_active);            
	b_active = (b_banner+(b_active+1))%b_banner;
	b_show(b_active);        
	b_timer = window.setTimeout("hb_counter()",b_delay);
}

function b_show(t) 
{
    var theBanner = document.getElementById("banner_" + t);
    if (theBanner != null)
    {
        theBanner.style.display = "";
	}
}

function b_hide(t) 
{
    var theBanner = document.getElementById("banner_" + t);
    if (theBanner != null)
    {
        theBanner.style.display = "none";
    }
}

function b_stop(){    
	clearTimeout(b_timer);
	b_timer=0;
}

function b_move(w){
	b_hide(b_active);
	b_active = w?(b_banner+b_active+1)%b_banner:(b_banner+b_active-1)%b_banner;
	b_show(b_active);
	if (!b_timer)
		b_timer = window.setTimeout("hb_counter()",b_delay);            
}
