$(document).ready(function() {
viewp();
if(viewportheight > 744){
    var fhiegt = viewportheight - 704;
}else{
    fhiegt = 100;
}

$('#logoCycle').removeClass('hide');
$('#logoCycle').cycle();

//email field
$('#email').focus(function(){

       if($(this).val() == 'Enter your e-mail'){
            $(this).val('');
       }
   
}).blur(function(){

       if($(this).val() == ''){
            $(this).val('Enter your e-mail')
       }

});

$('#bsubmit').click(function(){

        var exp = /.+@.+\..+/;
        var emval = $('#email').val();
        
        var par = $(this).parent('form')
        
        $('#loader').remove();
        par.append('<span id="loader"><img src="public/images/loader_circle.gif" />&nbsp;Processing request...</span>');

        if(emval.match(exp)){

        $.ajax({
                    type: "POST",
                    url: "home/subscribe_alert/",
                    data: {
                        email: emval
                    },

                    dataType: "json",

                    success: function (R) {

                       if(R.valid){

                            $('#loader').css('color', '#396419').text(R.msg);
                            $('#loader').fadeOut(5000);

                       }else{
                            $('#loader').css('color', '#C94E1B').text(R.msg);

                            //setTimeout($('#loader').fadeOut(1000));
                            $('#loader').fadeOut(5000);
                       }

                    }

                });

           
        }else{

           $('#loader').css('color', '#C94E1B').text('Invalid E-mail address!');
           $('#loader').fadeOut(5000);

        }
        
        return false;
});

$('#sic-box-close').click(function(){
        $('#sic-container').hide();
        $('#sic-content').children('p').html('START WINNING');
        $('#sic-form').show();
        $('#sic-client-list').html('<option value="0">Select Client</option>');
        $('#sic-game-logo').attr('src', 'public/images/games/logo/loading-game-logo.png');
        $('#goclient').attr('href', '#');
        return false;
});

$(window).resize(function(){
    
  // window.location.reload(true);

   viewp();

    $('#logoCycle').css({'width': '100%'});


    $('.slide').each(function(){
        $(this).css({'width': '100%'});
    });
//   $('.slide').each(function(){
//       alert(viewportwidth);
//    $(this).css({'width': viewportwidth});
//    });
   $('#logoCycle').css({'width': viewportwidth});

   var fbm = $("#sic-box");
   var toph = viewportheight/2;
   var topf = toph - 160;

   fbm.animate({'top' : topf});

});

$('#sic-client-list').change(function(){

    $('#goclient').attr('href', $(this).val());
    
});

$('#footer').css({
    'height' : fhiegt+'px'
});

$('#footer2').css({
    'height' : fhiegt+'px'
});

$('#flashwrap2').css({
    'height' : fhiegt+'px'
});

$('#gamelist').change(function(){
    viewp();
    var fbm = $("#sic-box");
    var toph = viewportheight/2;
    var topf = toph - 160;
    var options;
    var n = $(this).val();

    $('#sic-content').children('h4').text('PICK A CLIENT');

                $.ajax({
                    type: "POST",
                    url: "home/choose_game/",
                    data: {
                        gamecode: n
                    },

                    dataType: "json",

                    success: function (R) {

                        fbm.css({'top' : topf});

                        $('#sic-game-logo').attr('src', R.img);

                        var j = R.option;

                            $.each(j, function(){

                               var option = new Option(this.optionName, this.optionValue);

                               var list = $('#sic-client-list')[0];

                                if ($.browser.msie) {
                                    list.add(option);
                                }

                                else {

                                    list.add(option, null);

                                }

                            });

                        $('#sic-client-list').html(options);

                        $('#sic-container').show();

                    },

                    complete: function () {

                        $('.scrLoader').fadeOut('slow')

                    }

                });

    return false;
});

$('#clientlist').change(function(){
    viewp();
    var fbm = $("#sic-box");
    var toph = viewportheight/2;
    var topf = toph - 160;

    var n = $(this).val();

                $.ajax({
                    type: "POST",
                    url: "home/choose_client/",
                    data: {
                        casinocode: n
                    },

                    dataType: "json",

                    success: function (R) {

                        fbm.css({'top' : topf});

                        $('#sic-form').hide();

                        $('#sic-game-logo').attr('src', R.img);

                        $('#sic-content').children('h4').text(R.name).show();

                        $('#sic-content').children('p').html('<a target="_blank" href="'+R.dlUrl+'">Download</a><a target="_blank" href="'+R.wbUrl+'">Visit Site</a>');

                        $('#sic-container').show();

                    },

                    complete: function () {

                        $('.scrLoader').fadeOut('slow')

                    }

                });

    return false;
});

//header animation
//$('#animation img.light').fadeTo('fast',0).show();



}); //end document.ready


//end of document on load

$(function(){

  var _totalJackpot = $('#wajJackpot').val();

  var _startsum = Math.round((_totalJackpot * 0.99999)*100)/100;

  var _offset = _totalJackpot - _startsum;

  wajticker(_startsum, _totalJackpot);
  
});


function wajticker(_jstart, _jtotal){

    if(_jstart < _jtotal){

        var jstarts = _jstart + 0.12;

    }else{

        jstarts = Math.round((_jtotal * 0.99999)*100)/100;

    }
    var displayVal = addCommas(Math.abs(Math.round(_jstart*100)/100));

    $('#jtick').text('$'+ displayVal);
    $('#jtickshade').text('$'+ displayVal);

    setTimeout('wajticker('+ jstarts +','+ _jtotal +');', 69);
}

function viewp(){
         // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight

         if (typeof window.innerWidth != 'undefined')
         {
              viewportwidth = window.innerWidth,
              viewportheight = window.innerHeight
         }

        // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

         else if (typeof document.documentElement != 'undefined'
             && typeof document.documentElement.clientWidth !=
             'undefined' && document.documentElement.clientWidth != 0)
         {
               viewportwidth = document.documentElement.clientWidth,
               viewportheight = document.documentElement.clientHeight
         }

         // older versions of IE

         else
         {
               viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
               viewportheight = document.getElementsByTagName('body')[0].clientHeight
         }

    }

function addCommas(nStr)
    {
            nStr += '';
            x = nStr.split('.');
            x1 = x[0];
            x2 = x.length > 1 ? '.' + x[1] : '';
            var rgx = /(\d+)(\d{3})/;
            while (rgx.test(x1)) {
                    x1 = x1.replace(rgx, '$1' + ',' + '$2');
            }
            return x1 + x2;
    }

//function wajSpectrum()
//    {
//            $('#stripspectrum')
//                .animate( { backgroundColor: 'pink' }, 2000)
//                .animate( { backgroundColor: 'purple' }, 2000)
//                .animate( { backgroundColor: 'green' }, 2000)
//                .animate( { backgroundColor: 'blue' }, 2000);
//
//                setTimeout('wajSpectrum();', 7200);
//}
