function loadGames(){
$('.temp-cat-ad').remove();
$('.holder').html('

');
sort = $('#arrGamesCat option:selected').val();
$('.holder').load('/ajax/games/?sort='+sort+'&page='+pageNumber+'&loc='+loc+'&cat='+dbword+'&type='+currentpage+'&sid='+sid, function() {
urlHash = 'sort='+sort;
location.hash = urlHash;
$('.pageNav a').attr('href', function(i, attr){
if(attr.indexOf("#sort=") > 0){
return attr.substr(0, attr.length - 1)+sort;
}
else{
return attr+'#'+urlHash;
}
});
var gameSort = sort;
});
}
function aboutThisGame(p, i){
var popUp = p+'|'+i;
}
$(function(){
if(location.hash.substr(0,6) == '#sort='){
urlSort = location.hash.replace('#sort=', '');
if(urlSort != gameSort){
$('#arrGamesCat').val(urlSort);
loadGames();
}
}
$('#arrGamesCat').change(function(){
loadGames();
});
// registering country drop down
$("#cdd").click(function(){
$("#cdb").show();
$("#cdd").hide();
$("#cdu").show();
});
$("#cdu").click(function(){
$("#cdb").hide();
$("#cdd").show();
$("#cdu").hide();
});
$('.announce-head .close').click(function(){
$('#announce').slideUp();
$('#contentbox').addClass('nopenguin');
});
var gsb = $("form[name='subscribe'] input");
gsb.focus(function(){ clearInput(this); });
gsb.keypress(function(event){ if(EnterPressed(event)){ searchgame(); return false; } });
// partner click
$("a.partner").click(function(){ out($(this).attr("rel")); });
// making category box titles clickable
$(".cats li.more a").each(function(i,e){
var href = this.href;
$(this).parents("ul:first").parents("li:first").children(".head").css({"cursor":"pointer"}).click(function(){ document.location = href }).hover(function(){ window.status = href; },function(){ window.status = ""; });
});
$('.new .screen').each(function(){
var newSpan = $("").addClass("newPic").appendTo($(this));
newSpan.click(function(){document.location.href = $(this).parent().find('a').attr('href')})
});
});
$(document).ready(function(){
window.___gcfg = {lang: loc};
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/plusone.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
// Search field "fix"
$('#searchbutton').click(function(){
window.location = '/'+searchWord+'/'+$('#searchinput').attr('value');
});
$('#gamesearch').submit(function(){
window.location = '/'+searchWord+'/'+$(this).find('#searchinput').attr('value');
return false;
});
if(typeof skyScraperPlaced != 'undefined' && skyScraperPlaced != false){
$('#'+skyScraperPlaced+'-skyscraper').css('display', 'block');
}
textWidthFix('.game-column h2, .more-games-block h2, .more-games-block h2, .game-footer a, #game-sidebar .scroller-header');
if(currentpage == 'game'){
$('#outer-skyscraper').css('top', '420px');
}
if (window.PIE) {
$('#p-message, #p-message-content').each(function() {
PIE.attach(this);
});
}
penguinAnimation();
//showSidebarScraper();
$("#easter-egg").click(function() {
var s = document.createElement('script');s.type='text/javascript';document.body.appendChild(s);s.src='http://erkie.github.com/asteroids.min.js';void(0);
});
});
function getTopPos () {
if ($('#sidebar-scraper').length) return $('#sidebar-scraper').offset().top
}
function showSidebarScraper() {
if ($('#sidebar-scraper').length && $('#game-sidebar').length) {
$('#sidebar-scraper').css({'display': 'block'});
$('#game-sidebar').css({'display': 'none'});
// var offset = $('#sidebar-scraper').offset().top;
$('#outer-skyscraper').addClass('move-to-sidebar').css({'position':'absolute', 'top': getTopPos()});
skyScraperPlaced = 'sidebar';
// $('#content').addClass('sidebar-scrapper-on');
// console.log(getTopPos());
}
}
function outerSkyscraper(){
if(screen.width > 1199){
if(currentpage != 'game'){
GA_googleFillSlotWithSize("ca-pub-5936100259797777", skyScraperSlotname, 160, 600);
}
else {
GA_googleFillSlot(skyScraperSlotname);
}
$('body').addClass('ad-left');
skyScraperPlaced = 'outer';
}
}
function innerSkyscraper(){
if(screen.width < 1200 && gameRows * 200 - $('#cat-left-nav').height() > 600){
GA_googleFillSlotWithSize("ca-pub-5936100259797777", skyScraperSlotname, 160, 600);
skyScraperPlaced = 'inner';
}
}
function narrowResSkyscraper(){
if(screen.width < 1200){
GA_googleFillSlot(skyScraperSlotname);
skyScraperPlaced = 'sidebar';
$('#game-sidebar').addClass('sidebar-scraper-show');
}
}
function gameSkyscraperFallback(){
GA_googleFillSlot('160x600_fr_game');
}
function sitewideSkyscraperFallback(){
GA_googleFillSlotWithSize("ca-pub-5936100259797777", '160x600_fr', 160, 600);
}
function gameLeaderboardFallback(){
GA_googleFillSlot("game_728x90_fr");
}
function textWidthFix (item) {
$(item).each(function(){
//console.info($(this));
var maxW = $(this).innerWidth();
var actualW = this.scrollWidth;
// console.log(maxW + " " + actualW);
if(maxW < actualW) {
var text = $(this).text();
removeLetters = parseInt((actualW - maxW )/ (actualW / text.length)) + 5;
$(this).text(text.substring(0, text.length - removeLetters ) + '...');
}
});
}
function penguinAnimation() {
if ($('#penguin').length) {
var $announc = $('#p-announcement'),
announceH = $announc.outerHeight(true),
announceW = $announc.outerWidth(true),
duration = 600;
$('#p-link a').click(function() {
$('#p-content').animate({ 'marginBottom': '-6px', 'paddingBottom': '71px' }, duration);
$('#p-message').animate({ 'marginRight': '247px' }, duration);
$('#p-ico').animate({ 'bottom': '8px' }, duration);
$('#p-message-content').animate({ 'width': announceW, 'height': announceH }, duration);
$('#p-link').fadeOut(duration);
$('#p-announcement').css({'display': 'none', 'visibility': 'visible'}).fadeIn(duration, function() {
$('#p-close').css({'visibility': 'visible'})
if(skyScraperPlaced == 'sidebar') {
$('#outer-skyscraper').css({'position':'absolute', 'top': getTopPos()});
}
});
return false;
});
$('#p-close').click(function() {
$('#penguin').animate({'height': 0}, duration, function() {
$(this).empty();
if(skyScraperPlaced == 'sidebar') {
$('#outer-skyscraper').css({'position':'absolute', 'top': getTopPos()});
}
});
return false;
});
}
}