var selectedGameGuid = null;
var gameHref = null;

var popup = null;

/*
WHEN DOCUMENT IS READY
*/
$(document).ready(function () {
    /**
    * IS BKGCOOKIE SET ?
    */
    findCasinoBkgCookie();




    /*
    SLIDESHOW
    */
    if ($('#slideshow').length != 0) {
        $('#slideshow').cycle({
            fx: 'scrollHorz',
            speed: 800,
            timeout: 5000,
            next: '#slideshow-container .next',
            prev: '#slideshow-container .prev'
        });
    }


    /*
    HEADER ROULETTE GAMES SLIDESHOW
    */
    if ($('#headerRouletteList').length != 0) {
        headerRouletteGamesSlide();

        /*
        ON HEADER GAME CLICK
        */
        $('#headerRouletteList .headerGame a').click(function (e) {
            //e.preventDefault();
        });
    }
    /*
    HEADER POKER GAMES SLIDESHOW
    */
    if ($('#headerPokerList').length != 0) {
        headerPokerGamesSlide();

        /*
        ON HEADER GAME CLICK
        */
        $('#headerPokerList .headerGame a').click(function (e) {
            //e.preventDefault();
        });
    }
    /*
    HEADER BLACKJACK GAMES SLIDESHOW
    */
    if ($('#headerBJList').length != 0) {
        headerBJGamesSlide();

        /*
        ON HEADER GAME CLICK
        */
        $('#headerBJList .headerGame a').click(function (e) {
            //e.preventDefault();
        });
    }
    /*
    HEADER SLOT GAMES SLIDESHOW
    */
    if ($('#headerSlotList').length != 0) {
        headerBJGamesSlide();

        /*
        ON HEADER GAME CLICK
        */
        $('#headerSlotList .headerGame a').click(function (e) {
            //e.preventDefault();
        });
    }









    /*
    */
    if ($('#resumeGamesBox').length != 0) {
        $('#resumeGamesBoxBkg').css({
            opacity: '0'
        });
    }



});

















/**
 * GETURLPARAMS FUNCTION
 * @return array
 */
function getUrlParams(url)
{
	var paramsString = url.substr(url.indexOf('?') + 1);
	
	var tempParamsArray = new Array;
	tempParamsArray = paramsString.split('&');
	
	var paramsArray = new Array;
	for(var i = 0; i < tempParamsArray.length; i++)
	{
		var param = tempParamsArray[i].split('=');
		
		paramsArray[param[0]] = param[1];
	}
	
	return paramsArray;
} //end getUrlParams method



/**
 * LAUNCH GAME
 */
function selectGame(index)
{
	ASPxPageControlMain.SetActiveTabIndex(index);
} // end selectGame method




function launchRoulette(gameId) {
    ASPxCallbackRegisterGame.PerformCallback(gameId);
}








/**
 * ENABLE OR DISABLE ANIMATED BACKGROUND
 */
function updateBackgroundAnimation(e)
{
	if(ASPxCheckBoxBackgroundAnimation.GetChecked())
	{
		disableBackground();
	}
	else
	{
		enableBackground();
	}
} // end updateBackgroundAnimation method

function enableBackground() {
	$('#globalBackground object').css({
		display: 'block'
	});

    var expDate = new Date();
    // unset cookie => date is yesterday
    expDate.setTime(expDate.getTime() - (1 * 24 * 3600 * 1000));

    document.cookie = "casinoAnimatedBackground=disabled;expires=" + expDate.toGMTString() + ";path=/";
}

function disableBackground() {
	$('#globalBackground object').css({
		display: 'none'
	});

    var expDate = new Date();
    // 2 weeks valid cookie
    expDate.setTime(expDate.getTime() + (14 * 24 * 3600 * 1000));

    document.cookie = "casinoAnimatedBackground=disabled;expires=" + expDate.toGMTString() + ";path=/";

    $('#animatedBkgDiv span').removeClass('dxWeb_edtCheckBoxUnchecked_BlackGlass');
    $('#animatedBkgDiv span').addClass('dxWeb_edtCheckBoxChecked_BlackGlass');
}


function findCasinoBkgCookie() {
    var cookie = document.cookie.search("casinoAnimatedBackground");
    if (cookie >= 0) {
        disableBackground();
    }
    else {
        enableBackground();
    }
} // end findCircusBkgCookie method








/**
 * CLOSE POPUP OR LIGHTBOX
 */
function closeGame() {

    refreshAllCredits();

    if (popup) {
        popup.close();
    }

    if($('#gameBoxBkg').length != 0)
    {
        $('#gameBoxBkg').remove();
    }
} // end closeGame method



function refreshAllCredits() {
    // Nothing to do in unsecured zone except avoid JS undefined function
}





/*
 * called from popupgame when server cannot be reached
 */
function serverUnreachable() {
    // do something
}

