Current File : /data/web/virtuals/215191/virtual/www/domains/jogosde2.com/js/functions.js
var cur_page = 1;

// remap jQuery to $
(function($){})(window.jQuery);

/* trigger when page is ready */
$(document).ready(function (){

  $('#logo').mouseover(function() {
    $('#logo_in').stop().fadeIn(400);
  });

  $('#logo_in').mouseout(function() {
    $('#logo_in').stop().fadeOut(400);
  });

  // scroll body to 0px on click
  $('a#top').click(function () {
  	$('body,html').animate({
  		scrollTop: 0
  	}, 800);
  	return false;
  });

$(".game").mouseenter(function() {

var id = $(this).attr('id');
id = id.replace('game_id_', '');

$("#game_embed_"+id).show().html('<embed src="https://www.jogosde2.com/games/nahled/'+ id +'.swf"  height="100" width="273" wmode="transparent" loop="false"><div class="shadow"></div>');
}).mouseleave(function() {

var id = $(this).attr('id');
id = id.replace('game_id_', '');

$("#game_embed_"+id).hide().html('');
});

$(".game_smaller").mouseenter(function() {

var id = $(this).attr('id');
id = id.replace('game_id_', '');

$("#game_embed_"+id).show().html('<embed src="https://www.jogosde2.com/games/nahled/'+ id +'_small.swf"  height="100" width="273" wmode="transparent" loop="false"><div class="shadow"></div>');
}).mouseleave(function() {

var id = $(this).attr('id');
id = id.replace('game_id_', '');

$("#game_embed_"+id).hide().html('');
});

$(".podobne_game").mouseenter(function() {

var id = $(this).attr('id');
id = id.replace('game_id_', '');

$("#game_embed_"+id).show().html('<embed src="https://www.jogosde2.com/games/nahled/'+ id +'_small.swf"  height="100" width="273" wmode="transparent" loop="false"><div class="shadow"></div>');
}).mouseleave(function() {

var id = $(this).attr('id');
id = id.replace('game_id_', '');

$("#game_embed_"+id).hide().html('');
});

$(".game_small").mouseenter(function() {

var id = $(this).attr('id');
id = id.replace('game_id_', '');

$("#game_embed_"+id).show().html('<embed src="https://www.jogosde2.com/games/nahled/'+ id +'_small.swf"  height="100" width="273" wmode="transparent" loop="false"><div class="shadow"></div>');
}).mouseleave(function() {

var id = $(this).attr('id');
id = id.replace('game_id_', '');

$("#game_embed_"+id).hide().html('');
});

$("#games_new_feed_button").click(function() {

  $.ajax({
    type: "POST",
    url: "https://www.jogosde2.com/ajax/feed_games.php",
    cache: false,
    data: { "start": games_feed_start, "count": games_feed_count, "cat": is_cat },
    dataType: "json"
  }).done(function( json ) {

$("#games_new_feed").append(json.html);
$("#games_new_feed_"+ games_feed_start).fadeIn(1000);


$( document ).on( "mouseenter", ".game", function() {
var id = $(this).attr('id');
id = id.replace('game_id_', '');

$("#game_embed_"+id).show().html('<embed src="https://www.jogosde2.com/games/nahled/'+ id +'.swf"  height="100" width="273" wmode="transparent" loop="false"><div class="shadow"></div>');
}).on( "mouseleave", ".game", function() {
var id = $(this).attr('id');
id = id.replace('game_id_', '');

$("#game_embed_"+id).hide().html('');
});

if (json.last == 1) {
$("#games_new_feed_button").fadeOut();
$("#games_new_feed_button_all").fadeOut();
}

games_feed_start=games_feed_start+games_feed_count;

  });

return false;
});

$("#games_new_feed_button_all").click(function() {

  $.ajax({
    type: "POST",
    url: "https://www.jogosde2.com/ajax/feed_games.php",
    cache: false,
    data: { "start": games_feed_start, "count": 100000, "cat": is_cat },
    dataType: "json"
  }).done(function( json ) {

$("#games_new_feed").append(json.html);
$("#games_new_feed_"+ games_feed_start).fadeIn(1000);


$( document ).on( "mouseenter", ".game", function() {
var id = $(this).attr('id');
id = id.replace('game_id_', '');

$("#game_embed_"+id).show().html('<embed src="https://www.jogosde2.com/games/nahled/'+ id +'.swf"  height="100" width="273" wmode="transparent" loop="false"><div class="shadow"></div>');
}).on( "mouseleave", ".game", function() {
var id = $(this).attr('id');
id = id.replace('game_id_', '');

$("#game_embed_"+id).hide().html('');
});

if (json.last == 1) {
$("#games_new_feed_button").fadeOut();
$("#games_new_feed_button_all").fadeOut();
}

games_feed_start=games_feed_start+games_feed_count;

  });

return false;
});

$('a.rozbalit').click(function () {
  if ($('a.rozbalit div').hasClass("flop")) {
  $('a.rozbalit div').removeClass("flop");
  $('a.rozbalit span').text("Mostrar categorias de jogos");
  } else {
  $('a.rozbalit div').addClass("flop");
  $('a.rozbalit span').text("Ocultar categorias de jogos");
  }
  $('#menu').stop().slideToggle();
  return false;
});

$("#search").click(function() {

if($('#search_input').val() != "") {

    cur_page = 1;
    $('#web_darkshadow').fadeIn();
    $('.searchbox').fadeIn();
    feedSearchBox(cur_page,$('#search_input').val());

    $('#web_darkshadow').click(function () {
      $('#web_darkshadow').fadeOut();
      $('.searchbox .box_cont').fadeOut();
      $('.searchbox').fadeOut();
      return false;
    });
}

return false;

});

});


/* optional triggers

$(window).load(function() {
	
});

$(window).resize(function() {
	
});

*/

function like(type,gameid) {

$("#game_the_like").removeClass("active");
$("#game_the_dislike").removeClass("active");

if (type==1) {
$("#game_the_like").addClass("active");
} else {
$("#game_the_dislike").addClass("active");
}

  $.ajax({
    type: "POST",
    url: "https://www.jogosde2.com/ajax/like.php",
    cache: false,
    data: { "gameid": gameid, "vote": type },
    dataType: "json"
  }).done(function( json ) {
    if (type==1) {
    $("#game_the_dislike").attr("title","Este jogo não agrada "+json.dislike+" pessoas.");
    $("#game_the_like").attr("title","Este jogo agrada você e "+json.like+" outras pessoas.");
    } else {
    $("#game_the_like").attr("title","Este jogo agrada "+json.like+" pessoas.");
    $("#game_the_dislike").attr("title","Este jogo não agrada você e "+json.dislike+" outras pessoas.");
    }

  });

}

function add_fav(game) {
if ($("#star_shake_"+game).hasClass("active")) {
$("#star_shake_"+game).removeClass("active");
} else {
$("#star_shake_"+game).addClass("active").effect("shake",{direction:"up",distance:4});
popup_small('oblibene.php');
}
}

function podobne_games(page) {
$("#podobne_games_control_0").removeClass("active");
$("#podobne_games_control_1").removeClass("active");
$("#podobne_games_control_2").removeClass("active");
$("#podobne_games_control_3").removeClass("active");
$("#podobne_games_control_4").removeClass("active");

$("#podobne_games_control_"+page).addClass("active");
$("#podobne_games_controller").stop().animate({ "margin-left": "-"+ (864*page) +"px" }, 1000 );
}

function znamkuj(number) {
  $.ajax({
    type: "POST",
    url: "https://www.jogosde2.com/ajax/znamkovani.php",
    cache: false,
    data: { "number": number }
  }).done(function( html ) {
    if (html==1) {
    popup("znamkovani.php");
    } else {
    popup("znamkovani_bad.php");
    }

  });
}

function popup(file) {
  $.ajax({
    url: "https://www.jogosde2.com/popup/" + file,
    cache: false
  }).done(function( html ) {
    $('#popup').fadeOut(function() {
    $('#popup_small').fadeOut(function() {
    $('#popup').html( html ).css("margin-top", "-"+parseInt(parseInt($('#popup').css("height"))/2)+"px").fadeIn();
    $('#web_shadow').fadeIn();

    $('#popup_top a.close').click(function () {
      $('#web_shadow').fadeOut();
      $('#popup').fadeOut();
      return false;
    });

    $('#web_shadow').click(function () {
      $('#web_shadow').fadeOut();
      $('#popup').fadeOut();
      return false;
    });

});
});

  });
}

function popup_small(file) {
  $.ajax({
    url: "https://www.jogosde2.com/popup/" + file,
    cache: false
  }).done(function( html ) {
    $('#web_shadow').fadeIn();
    $('#popup_small').html( html ).css("margin-top", "-"+parseInt(parseInt($('#popup_small').css("height"))/2)+"px").fadeIn();

    $('#popup_small_top a.close').click(function () {
      $('#web_shadow').fadeOut();
      $('#popup_small').fadeOut();
      return false;
    });

    $('#web_shadow').click(function () {
      $('#web_shadow').fadeOut();
      $('#popup_small').fadeOut();
      return false;
    });

  });
}

function feedSearchBox(page,search) {

  $.ajax({
    type: "GET",
    url: "https://www.jogosde2.com/ajax/searchbox.php",
    cache: false,
    data: { "page": page, "search": search },
    dataType: "json"
  }).done(function( html ) {

$(".searchbox .box_cont").fadeOut( "slow", function() {

    if (html.count == 0 && html.count_cat == 0) {
    $(".searchbox .box_cont").html('<div class="search_notfound">Este jogo não foi encontrado.</div>');
    } else {

var games = "";

if (html.count_cat > 0) {

$(".searchbox .box_top .nadpis").text("CATEGORIA");

games += '<div class="search_cats">';

html.data_cats.forEach(function(entry) {

  $.ajax({
    type: "GET",
    url: "https://www.jogosde2.com/ajax/searchbox_games_count.php",
    cache: false,
    async: false,
    data: { "id": entry.id }
  }).done(function( cat_games_count ) {

games += '<a href="https://www.jogosde2.com/'+ entry.seo_url +'" class="search_cat"><span class="stitek"></span><span class="nazev">'+ entry.popis +' ('+ cat_games_count +')</span></a>';

  });
});

games += '<div class="clear"></div>';
games += '</div>';

if (html.count > 0) {
games += '<div class="search_sub"><div class="nadpis">JOGOS ONLINE GRÁTIS</div></div>';
}

} else {
$(".searchbox .box_top .nadpis").text("JOGOS ONLINE GRÁTIS");
}

html.data.forEach(function(entry) {
games += '<div class="search_game" id="game_id_search_'+ entry.id +'"><a href="https://www.jogosde2.com/'+ entry.seo_url +'"><div class="game_embed" id="game_embed_search_'+ entry.id +'"></div></a><a href="https://www.jogosde2.com/'+ entry.seo_url +'" class="nahled"><img src="https://www.jogosde2.com/games/img/'+ entry.id +'_small.jpg" alt="'+ entry.nazev +'"></a><div class="hodnoceni hodnoceni'+ makeHodnoceni(entry.hodnoceni) +'"><span>'+ entry.hodnoceni +'%</span></div><a href="https://www.jogosde2.com/'+ entry.seo_url +'" class="nadpis">'+ entry.nazev +'</a><div class="clear"></div></div>';
});


    $(".searchbox .box_cont").html(games + '<div class="search_bottom">Número de jogos encontrados: <b>'+ html.count +'</b></div><a href="#" class="search_bottom_nav_right" title="Próxima página"></a><a href="#" class="search_bottom_nav_left" title="Página anterior"></a><div class="clear"></div>');

$(".search_game").mouseenter(function() {

var id = $(this).attr('id');
id = id.replace('game_id_search_', '');

$("#game_embed_search_"+id).show().html('<embed src="https://www.jogosde2.com/games/nahled/'+ id +'_small.swf"  height="100" width="273" wmode="transparent" loop="false"><div class="shadow"></div>');
}).mouseleave(function() {

var id = $(this).attr('id');
id = id.replace('game_id_search_', '');

$("#game_embed_search_"+id).hide().html('');
});

if (html.count > 3) {

if ((cur_page * 3) < html.count) {
$(".search_bottom_nav_right").addClass("active2");
}

if (cur_page > 1) {
$(".search_bottom_nav_left").addClass("active2");
}

}

    }
$(".searchbox .box_cont").fadeIn();

$("a.search_bottom_nav_right.active2").click(function() {
cur_page++;
feedSearchBox(cur_page,$('#search_input').val());
return false;
});

$("a.search_bottom_nav_left.active2").click(function() {
cur_page--;
feedSearchBox(cur_page,$('#search_input').val());
return false;
});

});

  });

}

function validateEmail(email) {
    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    return re.test(email);
}

function makeHodnoceni(hodnoceni) {
if (hodnoceni > 89) {
return 3;
} else if (hodnoceni > 79) {
return 2;
} else {
return 1;
}
}