﻿$(document).ready(function () {
    /**
    *	CENTER FOOTER
    */
    var footerWidth = 0;
    $('#footer ul li').each(function () {
        footerWidth += $(this).outerWidth();
    });

    $('#footer ul').css({
        width: footerWidth + 5 + 'px'
    });


    /**
    * FEATURED GAMES SLIDESHOW
    */
    if ($('#featuredGames').length != 0) {
        $('#featuredGamesListBox .featuredGameBox:first-child').css({
            marginLeft: '192px'
        });

        featuredGamesSlide();
    }


    /**
    * Scrollable header games lists
    * Scroll bar style found in css (background color)
    */
    $('.headerGameContainer').each(function () {
        $(this).jScrollPane({
            autoReinitialise: true
        });
    });


    /**
    *
    */
    //    if ($('#sub_form1 .register-form-status').length > 0) {
    //        console.log('hoh');
    //    }

    //    $('#sub_form1 .register-form-status').each(function () {
    //        console.log($(this));
    //    });



    /**
    * POP
    */
    $('.activatePopupLinkBox p a').click(function (e) {
        var ieUrl = "http://windows.microsoft.com/fr-BE/Windows7/Internet-Explorer-Pop-up-Blocker-frequently-asked-questions";
        var chromeUrl = "http://www.google.com/support/chrome/bin/answer.py?hl=fr&answer=95472";
        var safariUrl = ""
        var firefoxUrl = "http://support.mozilla.com/fr/kb/Controler%20les%20fenetres%20popup";
        var operaUrl = "";

        if ($.browser.safari) {
            if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1) {
                
                $(this).attr('href', chromeUrl);

            }
            else {

                $(this).attr('href', safariUrl);

            }
        }
        else if ($.browser.opera) {

            $(this).attr('href', operaUrl);

        }
        else if ($.browser.mozilla) {

            $(this).attr('href', firefoxUrl);
        }
        else if ($.browser.msie) {

            $(this).attr('href', ieUrl);

        }

    });


});





/**
*  IS FLASH UP TO DATE
*/
function testFlashVersion() {
    var flashUpToData = isFlashUpToDate(10, 3);
    if (!flashUpToData) {

        var noFlashBoxContent =
        '<div class="noFlashShadowBox"></div>' +
        '<div class="noFlashBox">' +
            '<p>' +
                'Votre lecteur Flash n\'est pas à jour. Pour pouvoir profiter plainement des services proposés par Circus nous vous invitons à télécharger la dernière version du lecteur Flash' +
            '</p>' +
            '<p>' +
                '<a href=\'http://www.adobe.com/go/getflashplayer\' target=\'_blank\'><img src=\'http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif\' alt=\'Get Adobe Flash player\' /></a>' +
            '</p>' +
        '</div>';



        $('body').append(noFlashBoxContent);

        if ($('.noFlashShadowBox').length > 0) {
            var noFlashBoxWidth = $('.noFlashBox').width();
            var noFlashBoxHeight = $('.noFlashBox').height();

            var screenWidth = $(window).width();
            var screenHeight = $(window).height();

            $('.noFlashBox').css({
                top: (screenHeight / 2) - (noFlashBoxHeight / 2),
                left: (screenWidth / 2) - (noFlashBoxWidth / 2)
            });
        }
    }


    $('.noFlashBox a').bind('click', function (e) {
        $('.noFlashShadowBox').remove();
        $('.noFlashBox').remove();
    });
}







/**
* FEATUREDGAMESSLIDE FUNCTION
*/
function featuredGamesSlide() {
    var gamesArray = $('#featuredGamesList .featuredGameBox');

    var gamesCount = gamesArray.length;

    var gameWidth = $(gamesArray[0]).outerWidth();

    //ON LEFT ARROW CLICK
    $('#featuredGamesLeftArrow').click(function (e) {
        e.preventDefault();

        if ((!$('#featuredGamesLeftArrow').hasClass('stopAnime')) || (!$('#featuredGamesRightArrow').hasClass('stopAnime'))) {
            $('#featuredGamesLeftArrow').addClass('stopAnime');
            $('#featuredGamesRightArrow').addClass('stopAnime');

            var gameClone = $(gamesArray[gamesCount - 1]).clone(true).prependTo('#featuredGamesList');

            $(gamesArray).each(function () {

                //
                // webkit (chrome & safari) bug fix DO NOT REMOVE
                //
                if ($.browser.safari) {
                    console.log($(this).attr('style'));
                }
                //
                // webkit (chrome & safari) bug fix DO NOT REMOVE
                //

                $(this).removeAttr('style');

            });

            $(gameClone).animate({ marginLeft: gameWidth + 'px' }, 1000, function () {

                gamesArray = $('#featuredGamesList .featuredGameBox');
                gamesCount = gamesArray.length;

                $(gamesArray[gamesCount - 1]).remove();

                gamesArray = $('#featuredGamesList .featuredGameBox');
                gamesCount = gamesArray.length;

                $('#featuredGamesLeftArrow').removeClass('stopAnime');
                $('#featuredGamesRightArrow').removeClass('stopAnime');

            });

        }

    });







    //ON RIGHT ARROW CLICK
    $('#featuredGamesRightArrow').click(function (e) {
        e.preventDefault();

        if ((!$('#featuredGamesRightArrow').hasClass('stopAnime')) || (!$('#featuredGamesLeftArrow').hasClass('stopAnime'))) {
            $('#featuredGamesRightArrow').addClass('stopAnime');
            $('#featuredGamesLeftArrow').addClass('stopAnime');

            var gameClone = $(gamesArray[0]).clone(true).appendTo('#featuredGamesList');
            $(gameClone).removeAttr('style');

            $(gamesArray[0]).animate({ marginLeft: 0 + 'px' }, 1000, function () {

                $(gamesArray[0]).remove();

                gamesArray = $('#featuredGamesList .featuredGameBox');
                gamesCount = gamesArray.length;

                $(gamesArray[0]).css({
                    marginLeft: '192px'
                });

                $('#featuredGamesRightArrow').removeClass('stopAnime');
                $('#featuredGamesLeftArrow').removeClass('stopAnime');
            });

        }
    });
} // end featuredGamesSlide method
