var so=new SWFObject("/_/swf/tiny_games.swf","tiny_games_swf","300","215","8");so.addParam("menu","false");so.write("tiny_games");var loader;var game=getFlashObj('flashgame');var gameHidden=false;var flashborder=$('.flashborder:eq(0)');var orgwidth=flashborder.width();var orgheight=flashborder.height();if(orgwidth<450)
{flashborder.width(450);}
if(orgheight<400)
{flashborder.height(400);}
function getFlashObj(movie){if(window.document[movie]){return window.document[movie];}
if(navigator.appName.indexOf("Microsoft Internet")==-1){if(document.embeds&&document.embeds[movie]){return document.embeds[movie];}}else{return document.getElementById(movie);}}
loader=window.setInterval("checkLoading()",1000);function checkLoading()
{var percent=game.PercentLoaded();if(percent>=0&&percent<100)
{$('#flashalert span.percent').html(" ("+percent+"%).");if(!gameHidden)
{gameHidden=true;$(game).css('visibility','hidden');}}
else
{gameHidden=false;$('#flashalert p.info').html("Game is loaded.");$('#flashalert input[type=button]').val("Play it!");window.clearInterval(loader);window.setTimeout("sendGamePlayedInfo()",15000);showStars();}}
function sendGamePlayedInfo()
{$.ajax({type:"GET",url:"/game/gamePlayed/"+gameId});}
$('#flashalert input[type=button]').click(function(){$('#flashalert').hide();flashborder.height(orgheight);flashborder.width(orgwidth);$(game).css('visibility','visible');});var commentPageLoading=1;var commentCache=new Array();$(document).ready(function()
{$('img.empty_star').css('opacity','0.3');$('#comment_pagination a').click(function(){if($(this).parent().attr('class')=='active')
{return false;}
var old=$('#comment_pagination li.active');old.find('a').html(commentPageLoading);old.removeClass('active');$(this).parent().addClass('active');commentPageLoading=$(this).html();$(this).html('<img src="/_/img/loaders/comments.gif" alt="'+commentPageLoading+'" />');if(commentCache[commentPageLoading]!==undefined)
{readJsonComments(commentCache[commentPageLoading]);$('#comment_pagination li.active a').html(commentPageLoading);}
else
{$.ajax({type:"POST",dataType:"json",url:"/game/ajaxComments/"+gameId+"/"+((commentPageLoading-1)*4),success:function(msg){commentCache[commentPageLoading]=msg;readJsonComments(msg);$('#comment_pagination li.active a').html(commentPageLoading);},error:function(){},complete:function(){}});}
return false;});});function readJsonComments(json)
{$.each(json,function(i,item){var comment=item.comment;var date=item.date;var id=item.id;var login=item.login;var country=item.country;var points=item.points;var stars=item.stars;var avatar=item.avatar;var commobj=$('#comments div.comment:eq('+i+')');commobj.fadeTo("slow",0.1,function(){$(this).find('div.avatar').html("<a href='/profile/"+login+"'><img src='"+avatar+"' alt='"+login+"' /></a>");$(this).find('P.text').html(comment);$(this).find('P.login').html("<a href='/profile/"+login+"'>"+login+"</a> "+country+" "+points);$(this).find('div.date').html(date);star_title="no vote";if(stars>0)
{star_title=stars+"/6";}
$(this).find('div.vote img').css('opacity','0.3').attr('title',star_title);$(this).find('div.vote img:lt('+stars+')').css('opacity','1').attr('title',star_title);$(this).fadeTo("slow",1);});});if(json.length<4)
{$('#comments div.comment:gt('+(json.length-1)+')').fadeTo("slow",0);}}
var preview_showing;var preview_div;var preview_pos;$(document).ready(function()
{preview_div=$('div.game_preview');var reaction;$('#prev_bttn').mouseenter(function(){preview_showing=prevGame;});$('#next_bttn').mouseenter(function(){preview_showing=nextGame;});$('#rand_bttn').mouseenter(function(){preview_showing=randGame;});$('a.preview_bttn').mouseenter(function(){preview_pos=($(this).parent().position().left+5)+"px";reaction=window.setInterval("showPreview()",800);}).mouseleave(function(){window.clearInterval(reaction);preview_div.slideUp('slow');});});function showPreview()
{var id=preview_showing[0];var name=preview_showing[1];preview_div.find('p').html(name);preview_div.find('img').attr('alt','Play '+name).attr('src','/_/img/thumbs/'+id+'-0.jpg');preview_div.stop(true,true);preview_div.css('left',preview_pos);preview_div.slideDown('slow');}
$(document).ready(function(){checkVote();$('#vote_stars span img').mouseenter(function(){if(voted===false)
{var stars=$(this).prevAll().andSelf();stars.attr('src','/_/img/star_full.png');$('#rating div.top').html('vote ('+stars.length+'/6)');}}).mouseleave(function(){if(voted===false)
{$(this).siblings().andSelf().attr('src','/_/img/star_empty.png');$('#rating div.top').html('vote');}}).click(function(){voted=$(this).prevAll().andSelf().length;$.ajax({type:"GET",dataType:"text",url:"/game/vote/"+gameId+"/"+voted,beforeSend:function(){$('#rating div.top').html('sending vote...');},success:function(msg){if(msg=='ok')
{$('#rating div.top').html('you have voted '+voted+'/6');checkVote();}
else
{$('#rating div.top').html('invalid data');voted=false;}},error:function(){$('#rating div.top').html('connection failure');voted=false;}});});$('#favourites').mouseenter(function(){$('#favourites div.top').css('min-width',$('#favourites div.top').width()+"px");$('#favourites div.top').html((fav)?"del from":"add to");}).mouseleave(function(){$('#favourites div.top').html('favourites');}).click(function(){$.ajax({type:"GET",dataType:"text",url:"/game/favourites/"+(fav?"del":"add")+"/"+gameId,beforeSend:function(){$('#favourites div.top').html('sending...');},success:function(msg){if(msg=='ok')
{$('#favourites div.top').html('favourites');fav=!fav;checkFav();}
else
{$('#favourites div.top').html('invalid data');}},error:function(){$('#favourites div.top').html('connection failure');}});});$('#broken_link').mouseenter(function(){if(broken==false)
{$('#broken_link div.top').css('min-width',$('#broken_link div.top').width()+"px");$('#broken_link div.top').html("report");}}).mouseleave(function(){$('#broken_link div.top').html('broken link');}).click(function(){if(broken==false)
{broken=true;$.ajax({type:"GET",dataType:"text",url:"/game/reportBrokenLink/"+gameId,beforeSend:function(){$('#broken_link div.top').html('sending...');},success:function(msg){if(msg=='ok')
{$('#broken_link div.top').html('broken link');$('#broken_link div.bottom').html('thanks!');$('#broken_link').css('cursor','default');}
else
{$('#broken_link div.top').html('invalid data');broken=false;}},error:function(){$('#broken_link div.top').html('connection problem');broken=false;}});}});});function showStars()
{$('div.stats img.loader').remove();showStar(0);}
function showStar(star)
{$('#vote_stars img:eq('+star+')').fadeIn('slow',function(){var star=$(this).prevAll().andSelf().length;if(star<6)
{showStar(star);}});}
function checkVote()
{if(voted)
{showStars();$('#vote_stars span img').attr('src','/_/img/star_empty.png');$('#vote_stars span img:lt('+voted+')').attr('src','/_/img/star_full.png');$('#rating').css('cursor','default');}}
function checkFav()
{if(fav)
{$('#favourites div.bottom img').attr('src','/_/img/delete.png');}
else
{$('#favourites div.bottom img').attr('src','/_/img/add.png');}}