﻿String.prototype.trim=function(){
return this.replace(/^[\s]+|[\s]+$/g,"");
};
(function(){
if(typeof Session=="undefined"){
this.Session={};
}
Session.write=function(_1,_2,_3){
if(_3){
var _4=new Date();
_4.setTime(_4.getTime()+(_3*24*60*60*1000));
var _5="; expires="+_4.toGMTString();
}else{
var _5="";
}
document.cookie=_1+"="+_2+_5+"; path=/; domain=catinaboxgames.com";
};
Session.read=function(_6){
var _7=_6+"=";
var ca=document.cookie.split(";");
for(var i=0;i<ca.length;++i){
var c=ca[i].trim();
if(c.indexOf(_7)==0){
return c.substring(_7.length,c.length);
}
}
return null;
};
Session.erase=function(_b){
this.write(_b,"",-1);
};
})();
(function(){
if(typeof Engine=="undefined"){
this.Engine={running:false,currentPath:"",processes:{},commands:[],styleCache:{},imageCache:{},dataCache:{},methodCache:{},engines:{},firstTime:true,processId:0,pathImages:"http://images.catinaboxgames.com/w2/",pathMobile:"http://m.catinaboxgames.com/",pathServer:"http://w2.catinaboxgames.com/",assetsPrecached:false,assetsPrecachedDelegate:null,animateQueue:[],animateRunning:false,wallpaperCache:{},wallpaperCurrId:"",wallpaperCurrVal:0,naviInit:false,naviPushed:false,naviStack:[],naviXhr:null,naviDispatched:false,naviQueue:[],modals:{},modalOr:"middle",modalOx:0,modalOy:0};
}
Engine.loadWallpaper=function(_c){
var _d=new Image();
_d.onload=function(){
Engine.animateBegin("Engine.loadWallpaper["+_c+"]",function(){
$(_d).xalpha(0);
$("#wallpaper").append(_d);
$(window).resize();
$(_d).xfade(0,1,200,function(){
$("#wallpaper").find("img:first").remove();
Engine.animateEnd();
});
});
};
_d.src=Engine.pathImages+_c;
};
Engine.windowResize=function(){
var w=$(window).width();
var h=$(window).height();
$("#win").css("left",Math.max(-20,(w-940)/2)+"px");
$("#win-centre").height(Math.max(h-102,500));
$("#modal").height($("#win-centre").height());
$("#modal-win").css("top",($("#modal").height()-$("#modal-win").height())/2);
$("#sidebar").height($("#win-centre").height()-10);
var img=$("#wallpaper > img");
var fw,fh;
if(w*1/h>1.3333){
fw=Math.max(w,1024)+64;
fh=fw/1.3333;
}else{
fh=(Math.max(h,684)+64);
fw=fh*1.3333;
}
img.width(fw).height(fh).css("left",Math.max(w>940?(w-fw)/2:(940-fw)/2)+"px").css("top",(h>582?(h-fh)/2:(582-fh)/2)+"px");
$("#wallpaper").width(w).height(h);
};
Engine.nextProcessId=function(){
return ++Engine.processId;
};
Engine.stripUri=function(str){
return str.indexOf(Engine.pathServer)==0?str.replace(Engine.pathServer,""):str;
};
Engine.stripLeadingText=function(id){
var c=$(id)[0].firstChild;
if(c&&c.nodeName=="#text"){
c.parentNode.removeChild(c);
}
};
Engine.getCurrentPath=function(){
return window.location.hash.replace(/^.*#/,"");
};
Engine.registerProcess=function(_16,id){
if(id){
Engine.processes[id]=_16;
}else{
Engine.processes[Engine.nextProcessId()]=_16;
}
};
Engine.animateBegin=function(id,_19){
if(Engine.animateRunning){
Engine.animateQueue.push({id:id,delegate:_19});
}else{
Engine.animateRunning=true;
Engine.registerProcess(window.setTimeout(_19,100));
}
};
Engine.animateEnd=function(){
if(Engine.animateQueue.length>0){
var _1a=Engine.animateQueue.shift();
Engine.registerProcess(window.setTimeout(_1a.delegate,100));
}else{
Engine.animateRunning=false;
}
};
Engine.cacheImages=function(_1b,_1c,_1d){
if(Engine.imageCache[_1b]){
_1c(_1b,Engine.imageCache[_1b].images);
return;
}
if(_1d.length==0){
_1c(_1b,_1d);
return;
}
var obj={id:_1b,counter:_1d.length,images:[]};
Engine.imageCache[_1b]=obj;
obj["callback"]=function(){
_1c(_1b,obj.images);
};
for(var i=0;i<_1d.length;++i){
var img=new Image();
obj.images.push(img);
for(var a in _1d[i]){
if(a!="src"){
img[a]=_1d[i][a];
}
}
img.onload=function(){
obj.counter-=1;
if(obj.counter<=0){
obj.callback();
}
};
img.onerror=function(){
obj.counter-=1;
if(obj.counter<=0){
obj.callback();
}
};
img.src=_1d[i].src;
}
};
Engine.loadBanner=function(_22){
var img=new Image();
img.onload=function(){
$("#win-head").css("background","transparent url("+_22+") no-repeat");
};
img.src=Engine.pathServer+_22;
};
Engine.showModal=function(_24,_25,_26,_27){
Engine.hideYouTube();
$("#modal-icon").attr("src",Engine.pathImages+"icon-"+_24+".png");
$("#modal-title").empty().append(_25);
$("#modal-message").empty().append(_26);
$("#modal").show();
$("#modal-link").unbind("click").click(function(){
Engine.hideModal();
if(_27){
_27();
}
});
$(window).resize();
$("#load-status").hide();
};
Engine.hideModal=function(){
$("#modal").hide();
Engine.showYouTube();
};
Engine.hideYouTube=function(){
$("div.youtube").each(function(){
var o1=$(this).find("object");
var o2=$("<div class=\"youtube-placeholder\">YouTube</div>");
o2.width(o1.width()-4).height(o1.height()-4);
var obj=$(this);
window.setTimeout(function(){
obj.empty().append(o2);
},0);
});
};
Engine.showYouTube=function(){
$("div.youtube").each(function(){
if($(this).find("object").size()>0){
return;
}
var id=$(this).attr("id");
if(Engine.dataCache[id+"-show"]){
var obj=$(this);
window.setTimeout(function(){
obj.html(Engine.dataCache[id+"-show"]);
},0);
}else{
var a=id.split(".");
var m=a[1];
var w=a[2];
var h=a[3];
var o="";
if($.browser.mozilla){
var e="<embed src=\"http://www.youtube.com/v/"+m+"&amp;hl=en&amp;fs=1&amp;rel=0&amp;hd=1&amp;showinfo=0\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"never\" allowfullscreen=\"true\" width=\""+w+"\" height=\""+h+"\"></embed>";
o="<object width=\""+w+"\" height=\""+h+"\">"+e+"</object>";
}else{
o="<object width=\""+w+"\" height=\""+h+"\" type=\"application/x-shockwave-flash\"><param name=\"movie\" value=\"http://www.youtube.com/v/"+m+"&amp;hl=en&amp;fs=1&amp;rel=0&amp;hd=1&amp;showinfo=0\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowscriptaccess\" value=\"never\"></param></object>";
}
$(this).html(o);
Engine.dataCache[id+"-show"]=o;
}
});
};
Engine.loadScript=function(_33,_34){
Engine.registerProcess(window.setTimeout(function(){
$.ajax({async:false,type:"GET",url:_33,success:function(_35,_36){
if(_34){
Engine.registerProcess(window.setTimeout(_34,0));
}
},cache:false,dataType:"script"});
},0));
};
Engine.abortProcessActivity=function(){
if(Engine.naviXhr){
Engine.naviXhr.abort();
Engine.naviXhr=null;
}
delete Engine.naviQueue;
Engine.naviQueue=[];
delete Engine.animateQueue;
Engine.animateQueue=[];
Engine.animateRunning=false;
delete Engine.commands;
Engine.commands=[];
for(var i in Engine.processes){
window.clearTimeout(Engine.processes[i]);
}
delete Engine.processes;
Engine.processes={};
Engine.hideModal();
};
Engine.navi=function(_38){
if(!Engine.naviInit){
Engine.naviInit=true;
return;
}
if(!Engine.naviPushed){
if(Engine.naviStack.length==0){
return;
}
Engine.naviStack.pop();
Engine.abortProcessActivity();
Engine.dispatch({path:_38,saveHistory:false});
}
Session.erase("redirect");
Session.write("redirect",_38);
Engine.naviPushed=false;
};
Engine.go=function(_39){
_39=_39[0]=="/"?_39.substr(1):_39;
Engine.naviStack.push(_39);
Engine.naviPushed=true;
$.historyLoad(_39);
};
Engine.query=function(_3a,_3b){
Engine.dispatch({path:_3a,saveHistory:false,immediateDispatch:false,callback:_3b});
};
Engine.queryCallback=function(_3c){
if(_3c){
$("#content").empty().html(_3c.trim());
Engine.rebindContent();
}
};
Engine.dispatch=function(_3d){
var _3e="";
var _3f=null;
var _40="GET";
var _41=null;
var _42=true;
var _43=true;
var _44=null;
var _45=null;
if(typeof _3d=="string"){
_3e=_3d;
}else{
if(typeof _3d=="object"){
_3e=_3d.path;
_3f=_3d.callback;
_40=_3d.method||"GET";
_41=_3d.data;
_43=_3d.immediateDispatch==true;
_42=_3d.saveHistory==true;
_44=_3d.onComplete;
_45=_3d.onError;
}else{
alert("Invalid data type \""+typeof (_3d)+"\" encountered when dispatching.");
return;
}
}
_3e=_3e[0]=="/"?_3e.substr(1):_3e;
if(_43){
Engine.naviDispatched=true;
Engine.abortProcessActivity();
}else{
if(Engine.naviDispatched){
Engine.naviQueue.push(_3d);
return;
}
}
Engine.hideModal();
$("#load-status").show();
Engine.naviXhr=$.ajax({url:"/query/"+_3e,type:_40,cache:false,dataType:"html",timeout:8000,data:_41,complete:function(xhr,_47){
Engine.naviXhr=null;
$("#load-status").hide();
if(Engine.firstTime){
window.setTimeout(function(){
$("#win").show();
$(window).resize();
},0);
Engine.firstTime=false;
}
if(_44){
Engine.registerProcess(window.setTimeout(_44,0));
}
Engine.naviDispatched=false;
if(Engine.naviQueue.length>0){
var _48=Engine.naviQueue.shift();
Engine.registerProcess(window.setTimeout(function(){
Engine.dispatch(_48);
},0));
}
},success:function(_49,_4a){
if(_49.length==0){
var _4b=Engine.naviXhr.getResponseHeader("Err-code");
var _4c=Engine.naviXhr.getResponseHeader("Err-title");
var _4d=Engine.naviXhr.getResponseHeader("Err-message");
if(_4b){
Engine.showModal("warning","Error "+_4b+": "+_4c,_4d,_45);
}else{
Engine.showModal("warning","Error 404: Not Found","The document you requested cannot be found. Please check the URI and try again.",_45);
}
return;
}
if(_42){
Engine.naviStack.push(_3e);
Engine.naviPushed=true;
$.historyLoad(_3e);
}
if(_3f){
Engine.registerProcess(window.setTimeout(function(){
_3f(_49.trim().replace(/&gt;/g,">").replace(/&lt;/g,"<"));
},0));
}else{
$("#content").empty().css("top","0px").append(_49);
delete Engine.methodCache;
Engine.methodCache={};
Engine.stripLeadingText("#content");
$("#sidebar").empty();
$("#ActionStrip").appendTo("#sidebar");
$("#engine-commands").each(function(){
var _4e=this.innerHTML;
Engine.registerProcess(window.setTimeout(function(){
window.eval(_4e.replace(/&gt;/g,">").replace(/&lt;/g,"<"));
},0));
}).empty().remove();
Engine.rebindContent();
Engine.rebindActionStrip();
Engine.showYouTube();
Engine.windowResize();
Engine.currentPath=Engine.getCurrentPath();
$("#lk-mobile").attr("href",Engine.pathMobile+Engine.currentPath);
}
},error:function(xhr,_50){
if(_50=="error"){
Engine.showModal("warning","Error "+xhr.status+": "+xhr.statusText,"The server experienced an error while processing your request. Please try again later.",_45);
if(_3f){
Engine.registerProcess(window.setTimeout(function(){
_3f("");
},0));
}
}else{
Engine.showModal("warning","Server Timeout","The server timed out while processing the request. Please try again in a few seconds.",_45);
}
}});
};
Engine.navigate=function(_51,_52,_53){
var uri=Engine.stripUri(_52);
if(!_51){
_51=window.event;
}
var _55=function(e){
if(!e){
return false;
}
if(e.preventDefault){
e.preventDefault();
}else{
e.returnValue=false;
}
return false;
};
if(_51.which&&!$.browser.msie){
switch(_51.which){
case 2:
if($.browser.safari||_53){
window.open(_52,"_blank");
}
return _55(_51);
case 1:
if(_52.indexOf(window.location.hostname)==-1){
window.open(_52,"_blank");
}else{
Engine.dispatch(uri);
}
return _55(_51);
default:
return _55(_51);
}
}else{
switch(_51.button){
case 4:
if(_53){
window.open(_52,"_blank");
}
return _55(_51);
case 1:
if(_52.indexOf(window.location.hostname)==-1){
top.location=_52;
}else{
Engine.dispatch(uri);
}
return _55(_51);
default:
return _55(_51);
}
}
return true;
};
Engine.rebindContent=function(){
$("input:checkbox").checkbox({empty:"/pixie.png"});
$("#content").find("a[class != 'function']").unbind("click").unbind("mousedown").unbind("mouseup").click(function(){
return false;
}).mousedown(function(){
return false;
}).mouseup(function(_57){
return Engine.navigate(_57,this.href,true);
});
};
Engine.rebindActionStrip=function(){
$("#ActionStrip").find("a[class != 'function']").unbind("click").unbind("mousedown").unbind("mouseup").click(function(){
return false;
}).mousedown(function(){
return false;
}).mouseup(function(_58){
if($(this).find("span.function").size()>0){
window.eval($(this).find("span.function").html().replace("&gt;",">").replace("&lt;","<"));
if(!_58){
return false;
}
if(_58.preventDefault){
_58.preventDefault();
}else{
_58.returnValue=false;
}
return false;
}else{
return Engine.navigate(_58,this.href,true);
}
});
};
Engine.load=function(){
$(window).resize(Engine.windowResize);
$(window).resize();
Engine.hideModal();
if($.browser.msie){
$("div.win-bt-bg").hide();
$("div.win-bb-bg").hide();
}else{
$("div.win-bt-bg").xalpha(0);
$("div.win-bb-bg").xalpha(0);
}
$("div.win-bt-re").mouseenter(function(){
if($.browser.msie){
$("#"+this.id+"-bg").show();
}else{
$("#"+this.id+"-bg").xstop().xfade(0,1,100);
}
}).mouseleave(function(){
if($.browser.msie){
$("#"+this.id+"-bg").hide();
}else{
$("#"+this.id+"-bg").xstop().xfade(1,0,100);
}
});
$("div.win-bb-re").mouseenter(function(){
if($.browser.msie){
$("#"+this.id+"-bg").show();
}else{
$("#"+this.id+"-bg").xstop().xfade(0,1,100);
}
}).mouseleave(function(){
if($.browser.msie){
$("#"+this.id+"-bg").hide();
}else{
$("#"+this.id+"-bg").xstop().xfade(1,0,100);
}
});
$("#modal-link").mouseenter(function(){
document.getElementById("modal-link").style.backgroundPosition="0 -24px";
}).mouseleave(function(){
document.getElementById("modal-link").style.backgroundPosition="0 0";
}).click(function(){
Engine.hideModal();
});
Engine.naviStack.push(Engine.getCurrentPath());
Engine.naviPushed=true;
$.historyInit(Engine.navi);
$("#load-status").hide();
};
Engine.main=function(){
$(window).resize();
var _59=Engine.getCurrentPath()!=""?Engine.getCurrentPath():Session.read("redirect");
if(_59){
_59=_59.replace(/\%2F/g,"/").replace("#",",");
window.location.hash=_59;
Engine.currentPath=_59;
Engine.dispatch(_59);
}else{
Engine.dispatch("home");
}
Engine.running=true;
};
})();
