(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery) 

$(function ()
{
    $("header section form#search input.submit").mouseover(function(){
        $(this).attr("src", "/public/jogo.cz/images/header/search/ok-btn-hover.png")
    });   
    
    $("header section form#search input.submit").mouseout(function(){
        $(this).attr("src", "/public/jogo.cz/images/header/search/ok-btn.png")
    });  
    
    $.preLoadImages(
     '/public/jogo.cz/images/header/search/ok-btn-hover.png',
     '/public/jogo.cz/images/left/white-link-brown.png',
     '/public/jogo.cz/images/left/ladder/btn-white.png',
     '/public/jogo.cz/images/left/white-link-green.png'
    ); 

});

function gamesTopPlayed(object, ul)
{
  $('.timers a').removeClass('active');
  $(object).addClass('active');
  $('.ladder').addClass('hidden');
  $('.ladder.' + ul).removeClass('hidden');
}

Cufon.replace('#left h3', {
       textShadow: '#333 1px 1px'
});

Cufon.replace('#left .ladder li .number', {
        textShadow: '#333 1px 1px'
});

Cufon.replace('footer h2', {
        textShadow: '#333 1px 1px'
});

$(document).ready(function() {
    $(document).on("mouseenter", "div.videoblock", function() {
        var gameVideoParams = this.id.split('-');
        var gameVideoUrl = '/data/' + location.hostname + '/videos/' + gameVideoParams[1] + '.swf';

        if($("div.gamevideo", this).length == 0)
        {
            if($("div.picWrapper img", this).length > 0)
            {
                $("<div class='gamevideo'></div>").insertAfter($("div.picWrapper img", this));
            }
            else
            {
                $("<div class='gamevideo'></div>").insertAfter($("img", this)); 
            }
            $("div.gamevideo", this).flash({
                swf: gameVideoUrl,
                width: gameVideoParams[2],
                height: gameVideoParams[3],
                wmode: 'transparent'
            });
        }
        else
        {
            $("div.gamevideo", this).flash({
                swf: gameVideoUrl,
                width: gameVideoParams[2],
                height: gameVideoParams[3],
                wmode: 'transparent'
            });
        }
    }).on("mouseleave", "div.videoblock", function() {
        if($("div.gamevideo", this).length > 0)
        { 
            $("div.gamevideo object", this).remove();
        }
        else if($("img.nopic", this).length > 0)
        {
            $("img.nopic", this).remove();
        }
    });
});  
