// tile demo by qFox
// this script is minified. but if you were looking for the source, check the source of the html document :)

var CDE=function(dom){if(dom)this._id=CDE._getId(dom);dom._id=this._id;};CDE.prototype.toString=function(){return"[CDE "+this._id+" ("+this._strId+")]";};CDE.wrap=function(mix,boolPlaceholder){var bool=true;if(!mix)bool=false;if(bool&&mix.isCde)return mix;if(bool&&typeof mix=='string')mix=document.getElementById(mix);if(!mix)bool=false;if(bool)return new CDE(mix);if(boolPlaceholder)return new CDE();return null;};CDE.toDom=function(mix){if(!mix)return null;if(typeof(mix)=='string')return document.getElementById(mix);if(mix.isCde)return mix.dom();return mix;};CDE._getId=function(dom){var id;if(!dom){debug("CDE._getId: element is falsy");return 0;}
if(!CDE._doms){CDE._doms=[0];CDE._cacheSize=0;}
id=dom._id;if(!id||!CDE._doms[id]){CDE._doms[id=CDE._doms.length]=dom;++CDE._cacheSize;CDE.debug('cacheSize');}
return id;};CDE.uncache=function(dom,boolAndChilderen,boolSkipDom){var i;if(!dom)return;if(!boolSkipDom)CDE._uncache(dom,true);if(boolAndChilderen){i=dom.childNodes.length;while(i--)CDE.uncache(dom.childNodes[i],true);}
return null;};CDE._uncache=function(id,boolIdIsDom){if(boolIdIsDom&&id)id=id._id;if(id&&CDE._doms&&CDE._doms[id]){delete CDE._doms[id];--CDE._cacheSize;CDE.debug('cacheSize');}};CDE._gcAdd=function(cde,target){if(!target)target='standard';if(!CDE._arrGc)CDE._arrGc={};if(!CDE._arrGc[target])CDE._arrGc[target]=[cde];else CDE._arrGc[target].push(cde);return cde;};CDE.gc=function(target){var cde,a;if(CDE._arrGc){if(target){a=CDE._arrGc[target];}else{a=CDE._arrGc.standard;}
try{if(a){while(cde=a.pop()){cde.uncache();}}}catch(er){debug("CDE.gc("+target+") error:"+target+":"+er.message);}}};CDE.prototype.isCde=true;CDE.prototype._boolFailProof=false;CDE.prototype.dom=function(){var e=CDE._doms[this._id];if(!e)debug("Error: CDE.prototype.dom("+this._id+") "+(this._strId?"["+this._strId+"] ":"")+"is empty. Most likely it was deleted (from another object?)...");return e;};CDE.prototype.add=function(){var i,e=this.dom();if(arguments.length==0||(this._boolFailProof&&!e))return this;for(i=0;i<arguments.length;++i){if(!arguments[i]||arguments[i].length===0)continue;if(typeof arguments[i]==='string')e.appendChild(CDE.toDom(arguments[i]));else if(typeof arguments[i].length=='number')this.add.apply(this,Array.prototype.slice.call(arguments[i]));else if(arguments[i].isCde)e.appendChild(arguments[i].dom());else e.appendChild(arguments[i]);}
return this;};CDE.prototype.addTo=function(mix){if(this._boolFailProof&&!this.dom())return this;CDE.toDom(mix).appendChild(this.dom());return this;};CDE.prototype.ins=function(mixTarget,boolAsFirstChildOfThis){var e=this.dom();if(this._boolFailProof&&!e)return this;mixTarget=CDE.toDom(mixTarget);if(boolAsFirstChildOfThis){e.insertBefore(mixTarget,e.firstChild);}else{mixTarget.parentNode.insertBefore(e,mixTarget);}
return this;};CDE.prototype.replace=function(cde){cde.ins(this);this.del();return cde;};CDE.prototype.del=function(boolAlsoFromCache,boolAndAllChildNodes){var e=this.dom();if(this._boolFailProof&&!e)return this;if(e.parentNode)e.parentNode.removeChild(e);if(boolAlsoFromCache)this.uncache(boolAndAllChildNodes);return this;};CDE.prototype.uncache=function(boolChilderenToo){var arr,i;if(this._boolFailProof&&!this.dom())return this;if((arr=this.dom().arrEaseObjects)&&(i=arr.length)>0){while(i--){if(arr[i])clearInterval(arr[i].timer);}}
CDE.uncache(this.dom(),boolChilderenToo);return null;};CDE.prototype.gc=function(target){return CDE._gcAdd(this,target);};CDE.prototype.atr=function(mix,mixValue){if(!mix||(this._boolFailProof&&!this.dom()))return this;var that=this;var f=function(dom,name,value){if(name=='id')that._strId=value;try{dom[name]=value;}catch(er){if(window.debug)debug('CDE.atr fail: e:['+dom+'], key:['+name+'], val:['+value+'], err:['+er.description+']');}};if(arguments.length==2)f(this.dom(),mix,mixValue);else if(typeof mix==='string')f(this.dom(),'className',mix);else for(var key in mix)f(this.dom(),key,mix[key]);return this;};CDE.prototype.css=function(mix,mixValue){var s;if(!mix||(this._boolFailProof&&!this.dom()))return this;if(this._boolTextNode){debug("Error: Unable to apply .css to a text node... "+this+".css("+mix+","+mixValue+")");return;}
s=this.dom().style;if(arguments.length==2)this._css(mix,arguments[1],s);else if(typeof mix==='string')this.atr('className',mix);else for(var key in mix)this._css(key,mix[key],s);return this;};CDE.prototype._css=function(name,value,s){var key=name;if(name=='float')key='cssFloat';if(name=='opacity'){if(typeof value!=='number'){if(window.debug)window.debug("cde._css("+name+","+value+","+s+"): Error: invalid opacity value: "+value+" (not a number)");return;}
if(value<0||value>1){if(window.debug)window.debug("cde._css("+name+","+value+","+s+"): Error: Invalid value for opacity: use 0..1 ("+value+")");if(value<0)value=0;if(value>1)value=1;}}
try{if(key=='opacity'){if(typeof(s.filter)!='undefined')s.filter="alpha(opacity="+Math.round(value*100)+")";try{s[key]=value;}catch(er){if(window.debug)window.debug("cde._css("+name+","+value+","+s+"): "+er.message);}}
else if(key=='cssFloat'&&document.all)s.styleFloat=value;else s[key]=value;}catch(er){if(key=='overflow'&&value=='-moz-scrollbars-vertical'){}else if(window.debug)debug('<span style="color:red;">CDE._css fail</span>: Tried setting ['+key+'] to ['+value+'] on ['+s+']. '+er);}};CDE.prototype.ease=function(targets,options){var that,atr,stepTime,easeTime,startTime,currentDisplay,currentVis,obj,arr,oldTargets,i,cb,bool,_;if(this._boolFailProof&&!this.dom())return this;if(!targets)return this;if(!options)options={};that=this;for(atr in targets){if(atr=='margin'||atr=='padding'){targets[atr+'Top']=targets[atr];targets[atr+'Right']=targets[atr];targets[atr+'Bottom']=targets[atr];targets[atr+'Left']=targets[atr];delete targets[atr];}else if(atr=='border'){}}
if(!options.boolIgnoreRunningEase&&(arr=this.dom().arrEaseObjects)&&(i=arr.length)){while(i--){if(!arr[i])continue;oldTargets=arr[i].targets;for(atr in oldTargets){if(atr in targets){delete oldTargets[atr];}}
bool=false;for(_ in oldTargets){bool=true;break;};if(bool)continue;clearInterval(arr[i].timer);cb=arr[i].options.callback;arr[i].options._that.uncache();oldTargets=arr[i]=arr[i].options=arr[i].targets=arr[i].timer=null;if(!options.boolCancelOldCallback&&cb){if(cb.constructor==Function)cb();else debug("CDE.ease(): old callback was not a function... ["+cb+"]");}}}
stepTime=options.intStepTime||10;easeTime=options.intEaseTime||1000;startTime=(new Date()).getTime();for(atr in targets){obj=targets[atr]={target:targets[atr],suffix:'px'};if(atr=='opacity'){obj.noRound=true;obj.suffix=0;currentDisplay=this.getStl('display');currentVis=this.getStl('visibility');obj.current=parseFloat(currentDisplay==='none'||currentVis==='hidden'?0:this.getStl('opacity'))||0;if(currentDisplay==='none'){this.o(0);if(options.boolDisplayInline)this.di();else this.db();}
if(currentVis==='hidden')this.o(0).vv();}else{if(atr=='top'||atr=='left'){if(atr=='left')obj.current=this.pos(true).x;else obj.current=this.pos(true).y;}else{obj.current=this.getStl(atr);}
if(atr=='color'||atr=='backgroundColor'){obj.isColor=true;obj.suffix='';obj.noRound=true;obj.current=CDE.nColor(obj.current);obj.currentRgb=CDE.rgb(obj.current);obj.target=CDE.nColor(obj.target);obj.targetRgb=CDE.rgb(obj.target);}else{obj.current=parseFloat(obj.current)||0;obj.target=parseFloat(obj.target)||0;}}}
obj={targets:targets,options:options};obj.timer=setInterval(function(){var timeNow,pos,newValue;timeNow=(new Date()).getTime();pos=(timeNow-startTime)/easeTime;pos=pos<0?0:(pos>1?1:pos);if(!options.boolEase)pos=(-Math.cos(pos*Math.PI)/2)+0.5;if(pos>=1){for(atr in targets)that.css(atr,targets[atr].target+targets[atr].suffix);clearInterval(that.dom().arrEaseObjects[i].timer);if(atr=='opacity'&&targets[atr].target==0&&!options.boolNoDisplayChange)that.dn();that.dom().arrEaseObjects[i]=that.dom().arrEaseObjects[i].timer=null;if(options.callback){if(options.callback.constructor==Function)options.callback();else debug("CDE.ease(): options.callback was not a function...["+options.callback+"]");options.callback=null;}
if(options.boolAfterFadeDelete)that.del();if(options.boolAfterEaseUncacheCompletely)that.uncache(true);else if(options.boolAfterEaseUncache)that.uncache;}else{for(atr in targets){obj=targets[atr];if(obj.isColor)newValue=CDE.rgb(Math.round(obj.currentRgb.r+((obj.targetRgb.r-obj.currentRgb.r)*pos)),Math.round(obj.currentRgb.g+((obj.targetRgb.g-obj.currentRgb.g)*pos)),Math.round(obj.currentRgb.b+((obj.targetRgb.b-obj.currentRgb.b)*pos)));else newValue=obj.current+((obj.target-obj.current)*pos);if(!obj.noRound)newValue=Math.round(newValue);that.css(atr,newValue+obj.suffix);}}},stepTime);if(!this.dom().arrEaseObjects)this.dom().arrEaseObjects=[];i=this.dom().arrEaseObjects.length;this.dom().arrEaseObjects[i]=obj;return this;};CDE.prototype.pos=function(boolToParent,boolInner){var w,h,e=this.dom(),intTotalTop=0,intTotalLeft=0;if(this._boolFailProof&&!e)return{x:0,y:0,w:0,h:0};if(boolInner){w=e.clientWidth;h=e.clientHeight;}else{w=e.offsetWidth;h=e.offsetHeight;}
do{intTotalTop+=e.offsetTop;intTotalLeft+=e.offsetLeft;e=e.offsetParent;}while(!boolToParent&&e&&e.nodeName&&e.nodeName.toUpperCase()!='BODY');return{x:intTotalLeft,y:intTotalTop,w:w,h:h};};CDE.prototype.qpos=function(boolInner){var e=this.dom();if(this._boolFailProof&&!e)return{x:0,y:0,w:0,h:0};if(boolInner){return{x:e.clientLeft,y:e.clientTop,w:e.clientWidth,h:e.clientHeight};}
return{x:e.offsetLeft,y:e.offsetTop,w:e.offsetWidth,h:e.offsetHeight};};CDE.prototype.dba=function(){if(this._boolFailProof&&!this.dom())return this;return CDE.dba(this);};CDE.prototype.on=function(strEvent,func,mixType){var that,cdeTarget,e=this.dom();if(this._boolFailProof&&!e)return this;that=this;if(mixType&&typeof mixType!='string'){if(mixType.isCde)cdeTarget=mixType;else cdeTarget=mixType;mixType='element';}
if(!cdeTarget)cdeTarget=that;if(!func&&window.debug)debug("CDE.on: no function passed on...");if(!func)return;if(e.addEventListener)e.addEventListener(strEvent,CDE._onFx(mixType,func,cdeTarget,that),false);else e.attachEvent('on'+strEvent,CDE._onIe(mixType,func,cdeTarget,that));return this;};CDE._onFx=function(mixType,func,cdeTarget,cdeOrg){return function(evt){var intButton=(evt.which<2)?CDE.BUTTON_LEFT:((evt.which==2)?CDE.BUTTON_MIDDLE:CDE.BUTTON_RIGHT);switch(mixType){case'screen':func.call(cdeTarget.dom(),evt,evt.screenX,evt.screenY,cdeOrg.dom(),intButton);break;case'viewport':func.call(cdeTarget.dom(),evt,evt.clientX,evt.clientY,cdeOrg.dom(),intButton);break;case'element':var pos=cdeTarget.pos();func.call(cdeTarget.dom(),evt,evt.pageX-pos.x,evt.pageY-pos.y,cdeOrg.dom(),intButton);break;case'body':func.call(cdeTarget.dom(),evt,evt.pageX,evt.pageY,cdeOrg.dom(),intButton);break;case'keyboard':func.call(cdeTarget.dom(),evt,evt.keyCode,cdeOrg.dom());break;default:func.call(cdeTarget.dom(),evt,cdeOrg.dom());}};};CDE._onIe=function(mixType,func,cdeTarget,cdeOrg){return function(){var intButton=(event.button<2)?CDE.BUTTON_LEFT:((event.button==4)?CDE.BUTTON_MIDDLE:CDE.BUTTON_RIGHT);switch(mixType){case'screen':func.call(cdeTarget.dom(),event,event.screenX,event.screenY,cdeOrg.dom(),intButton);break;case'viewport':func.call(cdeTarget.dom(),event,event.clientX,event.clientY,cdeOrg.dom(),intButton);break;case'element':case'body':var d=(document.documentElement&&document.documentElement.scrollLeft!=null)?document.documentElement:document.body;var pageX=event.clientX+d.scrollLeft;var pageY=event.clientY+d.scrollTop;if(mixType=='element'){var pos=cdeTarget.pos();func.call(cdeTarget.dom(),event,pageX-pos.x,pageY-pos.y,cdeOrg.dom(),intButton);}else{func.call(cdeTarget.dom(),event,pageX,pageY,cdeOrg.dom(),intButton);}
break;case'keyboard':func.call(cdeTarget.dom(),event,event.keyCode,cdeOrg.dom());break;default:func.call(cdeTarget.dom(),event,cdeOrg.dom());}};};CDE.BUTTON_LEFT=1;CDE.BUTTON_MIDDLE=2;CDE.BUTTON_RIGHT=3;CDE.prototype.empty=function(){var f,e=this.dom();if(this._boolFailProof&&!e)return this;this.html('');while(f=e.firstChild)e.removeChild(f);return this;};CDE.prototype.getStl=function(strName,boolNormColor){var a,b,e=this.dom();if(this._boolFailProof&&!e)return this;if(window.getComputedStyle){strName=CDE.jsToCss(strName);if(strName=='float'||strName=='styleFloat')strName='cssFloat';if((a=document.defaultView)&&(b=a.getComputedStyle(e,null))){if(boolNormColor)return CDE.nColor(b.getPropertyValue(strName));return b.getPropertyValue(strName);}}else if(e.currentStyle){if(strName=='opacity'){try{return e.filters.item("DXImageTransform.Microsoft.Alpha").opacity/100;}catch(er){try{return e.filters('alpha').opacity/100;}catch(er2){return 1;}}}else{strName=CDE.cssToJs(strName);if(strName=='float'||strName=='cssFloat')strName='styleFloat';if(boolNormColor)return CDE.nColor(e.currentStyle[strName]);return e.currentStyle[strName];}}
if(window.debug)debug("CDE.getStl: Did not know what to do... [strName]");return NaN;};CDE.prototype.addCss=function(str){return this.add(CDE.css(str));};CDE.prototype.ifExists=function(){this._boolFailProof=true;return this;};CDE.prototype.ifDom=function(){this._boolFailProof=true;return this;};CDE.prototype.endIf=function(){this._boolFailProof=false;return this;};CDE.prototype.focus=function(){if(this._boolFailProof&&!this.dom())return this;this.dom().focus();return this;};CDE.prototype.blur=function(){if(this._boolFailProof&&!this.dom())return this;this.dom().blur();return this;};CDE.prototype.clone=function(boolDeep){var dom=this.dom().cloneNode(boolDeep||false);delete(dom._id);dom.id='';return CDE.wrap(dom);};CDE.dom=function(strType){var dom=document.createElement(strType);return CDE.wrap(dom);};CDE.html=function(str){return CDE.span(str);};CDE.txt=function(str){debug("CDE.txt is depricated. Use CDE.html instead.");return CDE.span(str);};CDE.text=function(str){var cde=CDE.wrap(document.createTextNode(str));cde._boolTextNode=true;return cde;};CDE.div=function(str){var cde=CDE.dom('div');if(typeof str!='undefined')cde.html(str);return cde;};CDE.span=function(str){var cde=CDE.dom('span');if(typeof str!='undefined')cde.html(str);return cde;};CDE.img=function(src,alt){if(typeof src=='undefined')src='';return CDE.dom('img').atr({src:src,alt:alt||'',title:alt||''});};CDE.inp=function(strType,name,value,bool){var cde,e;if(!strType)strType='text';if(strType=='radio'){cde=CDE.html('<input type="radio" />');e=cde.dom().firstChild;while(e&&e.nextSibling)e=e.nextSibling;cde=CDE.wrap(e);}else{cde=CDE.dom('input').atr({type:strType});}
if(typeof name!='undefined')cde.name(name);if(typeof value!='undefined')cde.val(value);if(bool&&strType=='option')cde.sel(true);else if(bool)cde.chk(true);return cde;};CDE.lnk=function(txt,funcOnclick,boolNoLine){if(typeof txt=='undefined')txt='';var cde=CDE.span(txt).ns().cp();if(funcOnclick)cde.on('click',funcOnclick);if(!boolNoLine)cde.on('mouseover',CDE._tdu).on('mouseout',CDE._tdn);return cde;};CDE._tdu=function(){this.style.textDecoration='underline';};CDE._tdn=function(){this.style.textDecoration='none';};CDE.btn=function(txt,funcOnclick){if(typeof txt=='undefined')txt='';if(!funcOnclick)funcOnclick=function(){};return CDE.dom("button").on('click',funcOnclick).html(txt);};CDE.a=function(txt,url,boolTb){if(typeof txt=='undefined')txt='';var obj={href:url};if(boolTb)obj.target='_blank';return CDE.dom('a').html(txt).atr(obj);};CDE.br=function(n){if(typeof n!=='number'||n<=0)n=1;if(n===1)return CDE.dom('br');var brs=[];for(var i=0;i<n;++i)brs.push(CDE.dom('br'));return brs;};CDE.dba=function(_args){CDE.wrap(document.body).add(Array.prototype.slice.call(arguments));return arguments[0];};CDE.ljs=function(url,funcOnload,boolNoAntiCache,boolSilent){var funcCallback,funcDebugDone,cde,boolLoaded=false,strUrl;if(!boolNoAntiCache){if(url.indexOf('?')>=0)url+='&'+Math.random();else url+='?'+Math.random();}
if(window.debug&&!boolSilent){strUrl=url.substring(0,20);debug('Importing '+strUrl+"...");funcDebugDone=function(){window.debug("Imported "+strUrl+"...");};}
funcCallback=function(){if(boolLoaded)return;boolLoaded=true;if(funcDebugDone)funcDebugDone();if(funcOnload)funcOnload();cde.del(true);cde=null;};cde=CDE.dom('script').on('load',funcCallback).on('readystatechange',function(){if(this.readyState==='loaded'||this.readyState==='complete')funcCallback();}).atr({type:'text/javascript',language:'javascript',src:url}).dba();};CDE.th=function(txt){if(typeof txt=='undefined')txt='';return CDE.dom('th').html(txt);};CDE.td=function(txt){if(typeof txt=='undefined')txt='';return CDE.dom('td').html(txt);};CDE.table=function(arrArrMix,stl,atr,tdStl,tdAtr,thStl,thAtr){if(arrArrMix){var th,td,tr,i=0,j,cdeTbody,cdeTable;cdeTable=CDE.dom('table').css(stl).atr(atr).add(CDE.dom('thead'),cdeTbody=CDE.dom('tbody'));if(arrArrMix.length>0){tr=CDE.dom('tr');for(j=0;j<arrArrMix[i].length;++j){th=CDE.th().css(thStl).atr(thAtr);if(typeof arrArrMix[i][j]==='string')th.html(arrArrMix[i][j]);else th.add(CDE.wrap(arrArrMix[i][j]));tr.add(th);}
cdeTbody.add(tr);} 
for(i=1;i<arrArrMix.length;++i){tr=CDE.dom('tr');for(j=0;j<arrArrMix[i].length;++j){td=CDE.td('',tdStl,tdAtr);if(typeof arrArrMix[i][j]==='string'||typeof arrArrMix[i][j]==='number')td.html(arrArrMix[i][j]);else td.add(CDE.wrap(arrArrMix[i][j]));tr.add(td);}
cdeTbody.add(tr);}
return cdeTable;}else{if(window.debug)window.debug("CDE.table: no data received");}
return{};};CDE.select=function(arrDesc,arrValue,objOpts){var cde,val,i;if(!objOpts)objOpts={};cde=CDE.dom('select').css(objOpts.stl).atr(objOpts.atr);for(i=0;i<arrDesc.length;++i){val=arrValue?arrValue[i]:(objOpts.boolUseDescAsValue?arrDesc[i]:i);CDE.dom('option').css(objOpts.optionStl).atr(objOpts.optionAtr).val(val).html(arrDesc[i]).sel((objOpts.boolSelectByValue?val:i)==objOpts.intSelectedIndex).addTo(cde);}
return cde;};CDE.sprite=function(src,x,y,tw,th,ow,oh,alt){var img,cde;cde=CDE.div().oh().rel().wh(tw,th);img=new Image();img.onload=function(){var w,h,dw,dh;dw=tw/ow;dh=th/oh;w=img.width*dw;h=img.height*dh;x*=dw;y*=dh;img=null;CDE.img(src,alt).abs(-Math.round(x)+'px',-Math.round(y)+'px',Math.round(w),Math.round(h)).ns().addTo(cde).uncache();};img.src=src;return cde;};CDE.css=function(str){var cde=CDE.dom('style').atr({type:'text/css'});if(cde.dom().styleSheet)cde._boolStyleSheet=true;if(str)cde.text(str);return cde;};CDE.textarea=function(){return CDE.dom('textarea');};CDE.prototype.html=function(str,boolAppend,boolPrepend){if(this._boolFailProof&&!this.dom())return this;if(arguments.length==0)return this.dom().innerHTML;if(boolAppend)this.dom().innerHTML+=str;else if(boolPrepend)this.dom().innerHTML=str+this.dom().innerHTML;else this.dom().innerHTML=str;return this;};CDE.prototype.txt=function(str,boolAppend,boolPrepend){if(this._boolFailProof&&!this.dom())return this;if(arguments.length==0)return this.dom().innerHTML;if(boolAppend)this.dom().innerHTML+=str;else if(boolPrepend)this.dom().innerHTML=str+this.dom().innerHTML;else this.dom().innerHTML=str;return this;};CDE.prototype.text=function(str,boolClear,boolPrepend){var dom;if(this._boolFailProof&&!this.dom())return this;if(this._boolStyleSheet){this.dom().styleSheet.cssText=str;}else{dom=document.createTextNode(str);if(boolClear)this.empty();if(boolPrepend)this.dom().insertBefore(dom,this.dom().firstChild);else this.add(dom);}
return this;};CDE.prototype.txtn=function(str){return this.text(str);};CDE.prototype.val=function(str){if(this._boolFailProof&&!this.dom())return this;if(arguments.length==0)return this.dom().value;return this.atr('value',str);};CDE.prototype.sel=function(boolState,boolTxt){var e=this.dom();if(this._boolFailProof&&!e)return this;if(typeof boolState=='undefined'){if(boolTxt)return e.options[e.selectedIndex].innerHTML;return e.options[e.selectedIndex].value;}
return this.atr('selected',boolState);};CDE.prototype.chk=function(bool){if(this._boolFailProof&&!this.dom())return this;if(arguments.length==0)return this.dom().checked;return this.atr('checked',!!bool);};CDE.prototype.id=function(strId){if(arguments.length==0)return this.dom().id;return this.atr('id',strId);};CDE.prototype.name=function(strName){if(arguments.length==0)return this.dom().name;return this.atr('name',strName);};CDE.prototype.src=function(src){if(this._boolFailProof&&!this.dom())return this;if(arguments.length==0)return this.dom().src;return this.atr('src',src);};CDE.prototype.abs=function(x,y,w,h){return this.css({position:'absolute'}).x(x).y(y).w(w).h(h);};CDE.prototype.wh=function(w,h){return this.w(w).h(h);};CDE.prototype.w=function(w){if(typeof(w)!=='undefined'&&w!==false)this.css('width',w+(typeof w=='number'?'px':''));return this;};CDE.prototype.h=function(h){if(typeof(h)!=='undefined'&&h!==false)this.css('height',h+(typeof h=='number'?'px':''));return this;};CDE.prototype.xy=function(x,y){return this.x(x).y(y);};CDE.prototype.x=function(x){if(typeof(x)=='number'&&x<0)return this.r(-x);if(typeof(x)!='undefined'&&x!==false)this.css('left',x+((typeof x=='number')?'px':''));return this;};CDE.prototype.y=function(y){if(typeof(y)=='number'&&y<0)return this.b(-y);if(typeof(y)!='undefined'&&y!==false)this.css('top',y+((typeof y=='number')?'px':''));return this;};CDE.prototype.r=function(r){if(typeof(r)=='number'&&r<0)return this.x(-r);if(typeof(r)!='undefined'&&r!==false)this.css('right',r+((typeof r=='number')?'px':''));return this;};CDE.prototype.b=function(b){if(typeof(b)=='number'&&b<0)return this.y(-b);if(typeof(b)!='undefined'&&b!==false)this.css('bottom',b+((typeof b=='number')?'px':''));return this;};CDE.prototype.bg=function(strUrl,strRepeat,intPosX,intPosY){var obj={backgroundImage:'url('+strUrl+')'};obj.backgroundRepeat=strRepeat||'repeat';if(arguments.length>=2)obj.backgroundPosition=(intPosX||0)+'px '+(intPosY||0)+'px';return this.css(obj);};CDE.prototype.bgpos=function(intPosX,intPosY){return this.css('backgroundPosition','-'+(intPosX||0)+'px -'+(intPosY||0)+'px');};CDE.prototype.sprite=function(sprite,x,y){return this.bg(sprite,'no-repeat',-x||0,-y||0);};CDE.prototype.spriteTo=function(x,y,tw,th,ow,oh){var w,h,dw,dh,img,dom;dom=this.dom().getElementsByTagName('img')[0];img=new Image();img.src=dom.src;dw=tw/ow;dh=th/oh;w=img.width*dw;h=img.height*dh;x*=dw;y*=dh;CDE.wrap(dom).abs(-(~~x)+'px',-(~~y)+'px',~~w,~~h);};CDE.prototype.bgc=function(strColor){return this.css('backgroundColor',strColor);};CDE.prototype.bold=function(){debug("cde.bold is depricated. Please use cde.fwb");return this.css('fontWeight','bolder');};CDE.prototype.unbold=function(){debug("cde.unbold is depricated. Please use cde.fwn");return this.css('fontWeight','normal');};CDE.prototype.sb=function(strColor,px){return this.css('border',(px||1)+'px solid '+(strColor||'black'));};CDE.prototype.bb=function(w,c,s){return this._setBorder('Bottom',w,c,s);};CDE.prototype.bl=function(w,c,s){return this._setBorder('Left',w,c,s);};CDE.prototype.br=function(w,c,s){return this._setBorder('Right',w,c,s);};CDE.prototype.bt=function(w,c,s){return this._setBorder('Top',w,c,s);};CDE.prototype._setBorder=function(d,w,c,s){if(w===false)w=1;if(c===false)c='black';if(s===false)s='solid';if(typeof w!='undefined')this.css('border'+d+'Width',w+(typeof w=='number'?'px':''));if(typeof c!='undefined')this.css('border'+d+'Color',c);if(typeof s!='undefined')this.css('border'+d+'Style',s);return this;};CDE.prototype.b3d=function(strColorTopLeft,strColorBottomRight,px){return this.sb(strColorTopLeft,px).css({borderRight:(px||1)+'px solid '+strColorBottomRight,borderBottom:(px||1)+'px solid '+strColorBottomRight});};CDE.prototype.c=function(str){return this.css('color',str);};CDE.prototype.center=function(boolNotHor,boolNotVer){if(boolNotHor&&boolNotVer)return this;var cp=CDE.scrollPos();var vp=CDE.viewportSize();this.abs();var pos=this.pos();if(!boolNotHor)this.x(Math.round((cp.x+(vp.w/2))-(pos.w/2)));if(!boolNotVer)this.y(Math.round((cp.y+(vp.h/2))-(pos.h/2)));vp=pos=null;return this;};CDE.prototype.cl=function(){return this.css('clear','left');};CDE.prototype.cr=function(){return this.css('clear','right');};CDE.prototype.cb=function(){return this.css('clear','both');};CDE.prototype.cc=function(){return this.css('cursor','crosshair');};CDE.prototype.cd=function(){return this.css('cursor','default');};CDE.prototype.cp=function(){return this.css('cursor','pointer');};CDE.prototype.cm=function(){return this.css('cursor','move');};CDE.prototype.dn=function(){return this.css('display','none');};CDE.prototype.di=function(){return this.css('display','inline');};CDE.prototype.db=function(){return this.css('display','block');};CDE.prototype.fl=function(){return this.css('cssFloat','left');};CDE.prototype.fr=function(){return this.css('cssFloat','right');};CDE.prototype.fs=function(px){return this.css('fontSize',(px||1)+'px');};CDE.prototype.fwb=function(){return this.css('fontWeight','bolder');};CDE.prototype.fwn=function(){return this.css('fontWeight','normal');};CDE.prototype.hover=function(on,off){var that=this;return CDE.on('mouseover',function(){that.css(on);}).on('mouseout',function(){that.css(off);});};CDE.prototype.lh=function(px){return this.css('lineHeight',(px||1)+'px');};CDE.prototype.m=function(px){return this.css('margin',px+(typeof px=='number'?'px':''));};CDE.prototype.mt=function(px){return this.css('marginTop',px+(typeof px!='string'?'px':''));};CDE.prototype.mr=function(px){return this.css('marginRight',px+(typeof px!='string'?'px':''));};CDE.prototype.mb=function(px){return this.css('marginBottom',px+(typeof px!='string'?'px':''));};CDE.prototype.ml=function(px){return this.css('marginLeft',px+(typeof px!='string'?'px':''));};CDE.prototype.ns=function(){this.dom().onmousedown=function(){return false;};this.dom().onselectstart=function(){return false;};this.dom().ondragstart=function(){return false;};return this.css({MozUserSelect:'none'});};CDE.prototype.o=function(value){return this.css('opacity',value);};CDE.prototype.oh=function(){return this.css('overflow','hidden');};CDE.prototype.ov=function(){return this.css('overflow','visible');};CDE.prototype.p=function(px){return this.css('padding',px+(typeof px=='number'?'px':''));};CDE.prototype.pt=function(px){return this.css('paddingTop',px+(typeof px!='string'?'px':''));};CDE.prototype.pr=function(px){return this.css('paddingRight',px+(typeof px!='string'?'px':''));};CDE.prototype.pb=function(px){return this.css('paddingBottom',px+(typeof px!='string'?'px':''));};CDE.prototype.pl=function(px){return this.css('paddingLeft',px+(typeof px!='string'?'px':''));};CDE.prototype.rel=function(){return this.css('position','relative');};CDE.prototype.strike=function(){return this.css('textDecoration','line-through');};CDE.prototype.tac=function(){return this.css('textAlign','center');};CDE.prototype.tal=function(){return this.css('textAlign','left');};CDE.prototype.tar=function(){return this.css('textAlign','right');};CDE.prototype.taj=function(){return this.css('textAlign','justify');};CDE.prototype.tdn=function(){return this.css('textDecoration','none');};CDE.prototype.vh=function(){return this.css('visibility','hidden');};CDE.prototype.vv=function(){return this.css('visibility','visible');};CDE.prototype.vam=function(){return this.css('verticalAlign','middle');};CDE.prototype.wsn=function(){return this.css('whiteSpace','normal');};CDE.prototype.wsnw=function(){return this.css('whiteSpace','nowrap');};CDE.prototype.wsp=function(){return this.css('whiteSpace','pre');};CDE.prototype.wspl=function(){return this.css('whiteSpace','pre-line');};CDE.prototype.wspw=function(){return this.css('whiteSpace','pre-wrap');};CDE.prototype.z=function(z){return this.css('zIndex',z);};CDE.clearLeft=function(){return CDE.div().cl();};CDE.clearRight=function(){return CDE.div().cr();};CDE.clearBoth=function(){return CDE.div().cb();};CDE.prototype.fadeDel=function(cb,options){if(!options)options={};options.boolAfterFadeDelete=true;options.callback=cb;return this.ease({opacity:0},options);};CDE.prototype.fadeDelUncache=function(cb,options){if(!options)options={};options.boolAfterEaseUncacheCompletely=true;return this.fadeDel(cb,options);};CDE.prototype.fadeIn=function(func,options,max){if(!options)options={};if(func)options.callback=func;return this.ease({opacity:max||1},options);};CDE.prototype.fadeOut=function(func,options,min){if(!options)options={};if(func)options.callback=func;return this.ease({opacity:min>0?min:0},options);};CDE.prototype.centerFade=function(options,max){return this.o(0).dba().center().fadeIn(false,options,max);};CDE.prototype.addToFading=function(cde,options,max){return this.o(0).addTo(cde).fadeIn(false,options,max);};CDE.prototype.draggable=function(parent,options){var that=this;if(!options)options={};if(!parent)parent=document.body;if(parent===true)parent=this;else parent=CDE.wrap(parent);this.ns().on('mousedown',function(_,x,y,_,btn){var bool,pos=that.pos(true);CDE.move={cde:that,options:options,parent:parent,cdeX:pos.x,cdeY:pos.y,mouseX:x,mouseY:y,ondrag:options.ondrag,onstop:options.onstop};if(options.onstart){bool=options.onstart.call(that,x,y,btn);if(bool===false)CDE.move=false;}},parent);if(!parent.dom()._boolDraggable){CDE.wrap(parent).on('mousemove',function(_,x,y){var dx,dy,tx,ty;if(!CDE.move)return;if(this!=CDE.move.parent.dom())return;dx=x-CDE.move.mouseX;dy=y-CDE.move.mouseY;tx=CDE.move.cdeX+dx;ty=CDE.move.cdeY+dy;if((typeof options.intMinX)=='number')tx=Math.max(tx,options.intMinX);if((typeof options.intMinY)=='number')ty=Math.max(ty,options.intMinY);if((typeof options.intMaxX)=='number')tx=Math.min(tx,options.intMaxX);if((typeof options.intMaxY)=='number')ty=Math.min(ty,options.intMaxY);if(!options.boolNoMove)CDE.move.cde.xy(tx+"px",ty+"px");if(CDE.move.ondrag)CDE.move.ondrag.call(CDE.move.cde,x,y,dx,dy,tx,ty);},parent).on('mouseup',function(_,x,y){if(!CDE.move)return;if(this!=CDE.move.parent.dom())return;if(CDE.move.onstop)CDE.move.onstop.call(CDE.move.cde,x,y);CDE.move=false;},parent);parent.dom()._boolDraggable=true;}
return this;};CDE.docSize=function(){return{w:document.documentElement.scrollWidth,h:document.documentElement.scrollHeight};};CDE.viewportSize=function(){var size={w:0,h:0};if(window.innerWidth){size.w=window.innerWidth;size.h=window.innerHeight;}else if(document.documentElement&&document.documentElement.clientHeight){size.w=document.documentElement&&document.documentElement.clientWidth;size.h=document.documentElement&&document.documentElement.clientHeight;}else if(document.body&&document.body.offsetWidth){size.w=document.body.offsetWidth;size.h=document.body.offsetHeight;}
return size;};CDE.scrollPos=function(){var pos={x:0,y:0};if(typeof(window.pageYOffset)=='number'){pos.x=window.pageXOffset;pos.y=window.pageYOffset;}else if(document.body&&(document.body.scrollLeft||document.body.scrollTop)){pos.x=document.body.scrollLeft;pos.y=document.body.scrollTop;}else if(document.documentElement&&(document.documentElement.scrollLeft||document.documentElement.scrollTop)){pos.x=document.documentElement.scrollLeft;pos.y=document.documentElement.scrollTop;}
return pos;};CDE.disablePage=function(id,trans,z){var size=CDE.docSize();return CDE.div().z(z||1000).bgc('black').id(id).abs(0,0,size.w,size.h).o(0).dba().ease({'opacity':trans||0.5});};CDE.popup=function(strTitle,content,funcOk,options){var cdeBlack,cdeButtons,cdePopup,boolClosed,boolCancelButton,cdeOk,cdeCancel,funcs;if(!options)options={};if(!options.boolNoDisable)cdeBlack=CDE.disablePage();boolClosed=false;funcs={};funcs.ok=function(){boolClosed=true;cdePopup.fadeDelUncache(options.funcAfterFade);if(cdeBlack)cdeBlack.fadeDelUncache();if(funcOk)funcOk();};funcs.cancel=function(){boolClosed=true;cdePopup.fadeDelUncache(options.funcAfterFade);if(cdeBlack)cdeBlack.fadeDelUncache(false,true,true);if(options.funcCancel)options.funcCancel();};funcs.center=function(){cdePopup.center();};if(typeof content=='string')content=CDE.html(content);else content=CDE.wrap(content);boolCancelButton=!!(!options.boolNoCancel&&(funcOk||options.funcCancel));cdePopup=CDE.div().cd().z(1001).abs(0,0).o(0).css(options.objPopupStyles).add(CDE.div().p(2).bgc('blue').c('white').css(options.objHeadStyles).rel().add(CDE.div().w(100).h(1),CDE.lnk('X',boolCancelButton?funcs.cancel:funcs.ok).abs().r(5).ns(),CDE.html(strTitle||'')),CDE.div().br(1,'black').bb(1,'black','solid').p(3).bgc('white').css(options.objBodyStyles).rel().add(content,cdeButtons=CDE.div().cb().add(cdeOk=CDE.lnk(options.strOk||'Ok',funcs.ok).c('blue'),(boolCancelButton?[CDE.html('&nbsp;&nbsp;'),cdeCancel=CDE.lnk(options.strCancel||'Cancel',funcs.cancel).c('blue')]:null)))).dba();if(!options.boolNoFocus&&boolCancelButton&&!options.boolFocusOk)cdeCancel.dom().focus();else if(!options.boolNoFocus)cdeOk.dom().focus();funcs.hideButtons=function(boolFade){if(boolFade)cdeButtons.ease({opacity:0});else cdeButtons.dn();};funcs.showButtons=function(boolFade){if(boolFade)cdeButtons.ease({opacity:1});else cdeButtons.o(1).db();};funcs.show=function(){cdePopup.ease({opacity:1});};funcs.hide=function(){cdePopup.ease({opacity:0});};funcs.cde=cdePopup;funcs.center();funcs.show();return funcs;};CDE.nColor=function(str,noHash){var r,m,obj,hash=(noHash?'':'#');str=(str+'').toLowerCase();r=/^#?([0-9a-f]{6})$/;if(m=r.exec(str))return hash+m[1];r=/^#?([0-9a-f])([0-9a-f])([0-9a-f])$/;if(m=r.exec(str))return hash+m[1]+m[1]+m[2]+m[2]+m[3]+m[3];r=/^#?[0-9a-f]{2}([0-9a-f]{6})$/;if(m=r.exec(str))return hash+m[1];r=/^rgb\((\d{1,3}), ?(\d{1,3}), ?(\d{1,3})\)$/;m=r.exec(str);if(m&&m.index==0){return hash+
(m[1]%256<16?'0':'')+(parseInt(m[1],10)%256).toString(16)+(m[2]%256<16?'0':'')+(parseInt(m[2],10)%256).toString(16)+(m[3]%256<16?'0':'')+(parseInt(m[3],10)%256).toString(16);}
r=/^rgba\((\d{1,3}), ?(\d{1,3}), ?(\d{1,3}), ?(?:1|(?:0(?:\.\d*)))\)$/;m=r.exec(str);if(m&&m.index==0){return hash+(m[1]%256<16?'0':'')+(parseInt(m[1],10)%256).toString(16)+(m[2]%256<16?'0':'')+(parseInt(m[2],10)%256).toString(16)+(m[3]%256<16?'0':'')+(parseInt(m[3],10)%256).toString(16);}
obj={black:'000000',blue:'0000ff',brown:'a52a2a',cyan:'00ffff',gray:'808080',green:'008000',lime:'00ff00',magenta:'ff00ff',orange:'ffa500',pink:'ffc0cb',purple:'800080',red:'ff0000',turquoise:'40e0d0',violet:'ee82ee',white:'ffffff',yellow:'ffff00'};if(obj[str])return hash+obj[str];return hash+'ffffff';};CDE.rgb=function(color,g,b,noHash){if(arguments.length>=3){return CDE.nColor("rgb("+color+","+g+","+b+")",noHash);}
color=CDE.nColor(color,true);return{r:parseInt(color.substring(0,2),16),g:parseInt(color.substring(2,4),16),b:parseInt(color.substring(4,6),16)};};CDE.enableActiveElement=function(){document.body.focus();if(typeof document.enableActiveElement!=='undefined'||!document.addEventListener)return;var trackOn=function(evt){if(evt&&evt.target){document.activeElement=evt.target==document?null:evt.target;}};var trackOff=function(evt){document.activeElement=null;};document.addEventListener("focus",trackOn,true);document.addEventListener("blur",trackOff,true);};CDE.stopEvent=function(evt){if(evt.stopPropagation)evt.stopPropagation();if(evt.preventDefault)evt.preventDefault();evt.cancelBubble=true;evt.returnValue=false;return false;};CDE.cssToJs=function(str){return str.replace(/(-.)/g,function(c){return c.substring(1,2).toUpperCase();});};CDE.jsToCss=function(str){return str.replace(/([A-Z])/g,function(c){return'-'+c.toLowerCase();});};CDE.escapeHtml=function(s){if(typeof s=='undefined')s='';return s.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');};CDE.escapeUrl=function(s){if(typeof s!=='string')return s;return s.replace(/%/g,'%25').replace(/&/g,'%26');};CDE.prototype.getCaretPos=function(){var e=this.dom();if(this._boolFailProof&&!e)return;if("selectionStart"in e)return e.selectionStart;var bookmark=document.selection.createRange().getBookmark();var selection=e.createTextRange();selection.moveToBookmark(bookmark);var before=e.createTextRange();before.collapse(true);before.setEndPoint("EndToStart",selection);return before.text.length;};CDE.prototype.setCaretPos=function(pos){var e=this.dom();if(this._boolFailProof&&!e)return this;if(e.createTextRange){var range=e.createTextRange();range.move('character',pos);range.select();}else if(e.selectionStart){e.focus();e.setSelectionRange(pos,pos);}
return this;};CDE.prototype.putCaretPos=function(str){var old,e=this.dom(),before='',after='',pos;if(this._boolFailProof&&!e)return this;this.focus();pos=this.getCaretPos();old=this.val();if(pos>0)before=old.substring(0,pos);if(pos<old.length)after=old.substring(pos);this.val(before+str+after);this.setCaretPos(pos+1);return this;};CDE.parseTimestamp=function(strStamp,boolToSeconds,intHint1,intHint2,intHint3,intHint4){var free={1:1,2:2,3:3,4:4},parse,date;free[intHint1||1]=false;free[intHint2||2]=false;free[intHint3||3]=false;free[intHint4||4]=false;parse=function(hint){if(!~hint)return false;if(!hint)hint=free[1]||free[2]||free[3]||free[4];free[hint]=false;try{switch(hint){case 1:return CDE.parseTimeYdmHis(strStamp);case 2:return CDE.parseTimeRfc3999(strStamp);case 3:return CDE.parseTimeLoose(strStamp,false,true);case 4:return new Date(strStamp);}}catch(er){return false;}
return false;};date=parse(intHint1);if(!date||date.getTime()<=1)date=parse(intHint2);if(!date||date.getTime()<=1)date=parse(intHint3);if(!date||date.getTime()<=1)date=parse(intHint4);if(boolToSeconds){if(date)return date.getTime()/1000;return 1;}
return date;};CDE.parseTimeYdmHis=function(stamp,boolToSeconds){var match,regex,date;regex=/^([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})[ ]?([p])?.*$/;match=regex.exec(stamp);if(!match||match.length<6)throw{message:"CDE.parseTimeYdmHis(): Invalid timestamp ["+stamp+"]"};if(match[7]=='p'&&parseInt(match[4],10)<12)match[7]=12;else match[7]=0;date=new Date(parseInt(match[1],10),parseInt(match[2],10)-1,parseInt(match[3],10),(parseInt(match[4],10)+parseInt(match[7],10)),parseInt(match[5],10),parseInt(match[6],10));if(boolToSeconds)return date.getTime()/1000;return date;};CDE.parseTimeRfc3999=function(stamp,boolToSeconds){var date,tz,regex,match;regex=/(\d{4}-\d{2}-\d{2}[ T]{1}\d{2}:\d{2}:\d{2})(.*)/;match=regex.exec(stamp);if(!match)throw{message:"CDE.parseTimeRfc3999 was unable to parse stamp ["+stamp+"]"};date=CDE.parseTimeYdmHis(match[1].replace(/T/,' '));if(tz=parseInt(match[2]))date.setTime(date.getTime()+(tz*60*60*1000));if(boolToSeconds)return date.getTime()/1000;return date;};CDE.parseTimeLoose=function(stamp,boolToSeconds,boolSkip3999){var regex,match,date;if(!stamp||stamp=='')return 0;try{date=CDE.parseTimeRfc3999(stamp);}catch(er){regex=/^([0-9]{4})[-]?([0-9]{0,2})[-]?([0-9]{0,2})$/;match=regex.exec(stamp);if(!match)throw{message:"CDE.parseTimeLoose: bad timestamp ["+stamp+"]"};date=new Date(parseInt(match[1],10),parseInt(match[2],10)-1,parseInt(match[3],10));}
if(boolToSeconds)return date.getTime()/1000;return date;};CDE.toYdmHis=function(dt,boolNoDate,boolNoTime,boolIsUnix){var date='',time='';if(boolIsUnix)dt=new Date(dt*1000);if(!boolNoDate)date=dt.getFullYear()+'-'+(dt.getMonth()<9?'0':'')+(dt.getMonth()+1)+'-'+(dt.getDate()<10?'0':'')+dt.getDate();if(!boolNoTime)time=(dt.getHours()<10?'0':'')+dt.getHours()+':'+(dt.getMinutes()<10?'0':'')+dt.getMinutes()+':'+(dt.getSeconds()<10?'0':'')+dt.getSeconds();return CDE.trim(date+' '+time);};CDE.now=function(sec,min,hour,day,week,month,year){var t=(new Date()).getTime()/1000;if(arguments.length==0)return t;t+=(parseInt(sec)||0);t+=((parseInt(min)||0)*60);t+=((parseInt(hour)||0)*3600);t+=((parseInt(day)||0)*86400);t+=((parseInt(week)||0)*604800);t+=((parseInt(month)||0)*2592000);t+=((parseInt(year)||0)*31536000);return t;};CDE.preload=function(url){setTimeout(function(){(new Image()).src=url;},1);};CDE.trim=function(str){if(String.trim)return str.trim();return str.replace(/^\s+|\s+$/g,'');};window.debugId='_dbg_';window.debug=function(str2,boolNoReturn2,boolHtmlEncode2){var objDebug,cde,i;if(CDE._debugInit){CDE._debugInit.push(str2);return str2;}
CDE._debugInit=[];objDebug=document.getElementById(window.debugId);window.debugId=undefined;if(!objDebug){window.debug=function(str){return str;};}else{CDE.wrap(objDebug).abs(-5,5,300).css('minHeight','50px').css('maxHeight','100%').css('overflow','auto').bgc('white').c('black').css('border','2px solid black').z(5000).add(CDE.div().id('__CDE_menu').bb(1,'black','solid').add(CDE.span().fr().id('__CDE_cache__').fs(10).c('black').gc(),CDE.html('Debug | ').id('__CDE_first').c('black').gc(),CDE.span().html('Clear').id('__CDE_clear').cp().c('black').on('click',function(){cde.html('');}).gc(),CDE.html(' | ').id('__CDE_second').c('black').gc(),CDE.span().html('Close').id('__CDE_close').cp().c('black').on('click',function(){cde=CDE.wrap(cde.dom().parentNode).del();}).gc(),CDE.html(' | ').id('__CDE_third').c('black').gc(),CDE.span().html('Hide').id('__CDE_hide').cp().c('black').on('click',function(){CDE.wrap(cde.dom().parentNode).dn();}).gc(),CDE.html(' | ').id('__CDE_fourth').c('black').gc(),CDE.span().html('Cache').id('__CDE_cache').cp().c('black').on('click',function(){CDE.debug('cache',true);}).gc()).gc(),cde=CDE.div().id('__CDE_body').p(2).c('black').fs(10)).gc();CDE.gc();objDebug=null;window.debug=function(str,boolNoReturn,boolHtmlEncode){if(!cde){window.debug=function(str){return str;};return str;}
if(boolHtmlEncode&&typeof(str)==='string')str=CDE.escapeHtml(str);CDE.html(str+(boolNoReturn?"":"<br />")).id("debugtext"+Math.random()).addTo(cde).uncache();cde.db();return str;};}
if(CDE._debugInit&&CDE._debugInit.length){window.debug("Pre debug messages:");for(i=0;i<CDE._debugInit.length;++i)debug(CDE._debugInit[i]);debug("End pre debug");CDE._debugInit=null;}
window.debug(str2,boolNoReturn2,boolHtmlEncode2);return str2;};CDE.debug=function(strType,arg1){var i,s,f;if(strType=='cacheSize'){f=function(){CDE._intCacheDebugTimer=false;var e=document.getElementById('__CDE_cache__');if(e)e.innerHTML=CDE._cacheSize;};if(!CDE._intCacheDebugTimer)CDE._intCacheDebugTimer=setTimeout(f,20);if(arg1)f();}else if(strType=='cache'){i=0;s='';while(++i<CDE._doms.length){if(CDE._doms[i]||!arg1){s+="<div style='color:black;' title='"+CDE.escapeHtml((CDE._doms[i].innerHTML+'').substring(0,300))+"'>"+i+" = ["+CDE._doms[i]+"]"+(CDE._doms[i]?" ("+CDE._doms[i].id+")":"")+"</div>";}}
debug(s,true);}};CDE._unload=function(){CDE._doms=null;};CDE.wrap(window).on('unload',CDE._unload);CDE.ColorPicker={hsv:[0,0,1],rgb:[1,1,1],strCurBg:'',cdeCp:null,cdeTarget:null,cdeX:null,cdePnt:null,cdeVal:null,cdePrv:null,cdeTxt:null,settings:{mixTarget:false,boolNoAutoUpdate:false,intZ:2,intOffsetX:0,intOffsetY:0,strStartColor:false,strStartBg:false,onChangeColor:null,onChangeBg:null,onClose:null,spriteUrl:'sprite.png',boolColorBoxes:false,strColor0:'#ffffff',strColor1:'#000000',strColor2:'#ffff00',strColor3:'#00ff00',strColor4:'#00ffff',strColor5:'#0000ff',strColor6:'#800080',strColor7:'#a52a2a',strColor8:'#ff0000',strColor9:'#ffaa00',boolBackgrounds:false,strBg0:'http://qfox.nl/img/bg1.png',strBg1:'http://qfox.nl/img/bg2.png',strBg2:'http://qfox.nl/img/bg3.png',strBg3:'http://qfox.nl/img/bg4.png',strBg4:'http://qfox.nl/img/bg5.png',_:0},show:function(dom,ops){if(this.cdeCp)this.remove();if(!ops)ops={};var that=this,strStartColor,strStartBg,boolDown,pos,key;for(key in ops)this.settings[key]=ops[key];this.cdeTarget=CDE.wrap(this.settings.mixTarget||dom);strStartColor=that.settings.strStartColor||this.cdeTarget.getStl('backgroundColor',true);strStartBg=that.settings.strStartBg||this.cdeTarget.getStl('backgroundImage');if(strStartBg&&strStartBg.substring(0,4)=='url(')strStartBg=strStartBg.substring(4,strStartBg.length-1);pos=CDE.wrap(dom).pos();dom=null;var onLeftMove=function(_,x,y){if(!boolDown)return;if(x>180)x=180;if(y>101)y=101;if(x<0)x=0;if(y<0)y=0;that.setHsv((x-1)*2,101-y);return CDE.stopEvent(_);};var onRightMove=function(_,x,y){if(!boolDown)return boolDown;that.setHsv(false,false,101-y);return CDE.stopEvent(_);};var onLeftDown=function(_,x,y){boolDown=true;onLeftMove(_,x,y);};var onRightDown=function(_,x,y){boolDown=true;onRightMove(_,_,y);};var onUp=function(_){boolDown=false;};this.cdeCp=CDE.div().bgc('#ccc').z(that.settings.intZ).abs(pos.x+parseInt(that.settings.intOffsetX),pos.y+parseInt(that.settings.intOffsetY),270,135+(that.settings.boolColorBoxes?25:0)+(this.settings.boolBackgrounds?48:0)).sb('black').on('mouseup',onUp).add(CDE.lnk('close',function(){that.remove();}).c('black').fr().mr(5),that.cdeTxt=CDE.div().c('black').txt(strStartColor+' bg: '+strStartBg).ml(5),CDE.div().css({cursor:'crosshair'}).oh().fl().sprite(that.settings.spriteUrl).wh(181,101).m(5).ml(that.settings.boolColorBoxes||this.settings.boolBackgrounds?9:5).rel().on('mousemove',onLeftMove,'element').on('mousedown',onLeftDown,'element').on('mouseup',onUp).add(that.cdeX=CDE.div().sprite(that.settings.spriteUrl,206,0).abs(0,0,11,11).ns()),this.cdeVal=CDE.div().css('color').fl().rel().wh(25,101).m(5).sprite(that.settings.spriteUrl,181).on('mousemove',onRightMove,'element').on('mousedown',onRightDown,'element').on('mouseup',onUp).add(that.cdePnt=CDE.div().sprite(that.settings.spriteUrl,206,12).abs("-7px","-3px",5,9).ns()),that.cdePrv=CDE.div().fl().wh(25,101).m(5).ns()).o(0).dba().draggable();if(this.settings.boolColorBoxes){var onExampleColor=function(){var c=CDE.wrap(this).getStl('background-color',true);that.setRgb(c);};this.cdeCp.add(CDE.clearLeft(),CDE.div().ml(3).fl().wh(20,20).sb('black').cp().ns().on('click',onExampleColor).bgc(this.settings.strColor0).gc('_cp'),CDE.div().ml(5).fl().wh(20,20).sb('black').cp().ns().on('click',onExampleColor).bgc(this.settings.strColor1).gc('_cp'),CDE.div().ml(5).fl().wh(20,20).sb('black').cp().ns().on('click',onExampleColor).bgc(this.settings.strColor2).gc('_cp'),CDE.div().ml(5).fl().wh(20,20).sb('black').cp().ns().on('click',onExampleColor).bgc(this.settings.strColor3).gc('_cp'),CDE.div().ml(5).fl().wh(20,20).sb('black').cp().ns().on('click',onExampleColor).bgc(this.settings.strColor4).gc('_cp'),CDE.div().ml(5).fl().wh(20,20).sb('black').cp().ns().on('click',onExampleColor).bgc(this.settings.strColor5).gc('_cp'),CDE.div().ml(5).fl().wh(20,20).sb('black').cp().ns().on('click',onExampleColor).bgc(this.settings.strColor6).gc('_cp'),CDE.div().ml(5).fl().wh(20,20).sb('black').cp().ns().on('click',onExampleColor).bgc(this.settings.strColor7).gc('_cp'),CDE.div().ml(5).fl().wh(20,20).sb('black').cp().ns().on('click',onExampleColor).bgc(this.settings.strColor8).gc('_cp'),CDE.div().ml(5).fl().wh(20,20).sb('black').cp().ns().on('click',onExampleColor).bgc(this.settings.strColor9).gc('_cp'),CDE.clearLeft());}
if(this.settings.boolBackgrounds){var onExampleBg=function(){that.setBg(that.getBg(CDE.wrap(this)));};this.cdeCp.add(this.cdeBg1=CDE.div().ml(3).mt(3).fl().wh(47,47).sb('black').cp().ns().on('click',onExampleBg).bg(this.settings.strBg0).cl().gc('_cp'),this.cdeBg2=CDE.div().ml(5).mt(3).fl().wh(47,47).sb('black').cp().ns().on('click',onExampleBg).bg(this.settings.strBg1).gc('_cp'),this.cdeBg3=CDE.div().ml(5).mt(3).fl().wh(47,47).sb('black').cp().ns().on('click',onExampleBg).bg(this.settings.strBg2).gc('_cp'),this.cdeBg4=CDE.div().ml(5).mt(3).fl().wh(47,47).sb('black').cp().ns().on('click',onExampleBg).bg(this.settings.strBg3).gc('_cp'),this.cdeBg5=CDE.div().ml(5).mt(3).fl().wh(47,47).sb('black').cp().ns().on('click',onExampleBg).bg(this.settings.strBg4).gc('_cp'));}
this.setRgb(strStartColor);if(this.settings.boolBackgrounds)this.setBg(strStartBg,true);this.cdeCp.fadeIn();},setRgb:function(str){if(!this.cdeCp){if(window.debug)debug("CDE.ColorPicker.setRgb: no panel...");return;}
this.hexToRgb(str);this.rgbToHsv();},setHsv:function(h,s,v){if(typeof h=='number')this.hsv[0]=Math.max(Math.min(parseInt(h),360),0);if(typeof s=='number')this.hsv[1]=Math.max(Math.min(parseInt(s),100),0)/100;if(typeof v=='number')this.hsv[2]=Math.max(Math.min(parseInt(v),100),0)/100;this.hsvToRgb(false,false,1);this.cdeVal.bgc(this.rgbToHex());this.hsvToRgb();this.cdePrv.bgc(this.rgbToHex());if(!this.settings.boolNoAutoUpdate)this.cdeTarget.bgc(this.rgbToHex());this.cdeX.xy(Math.floor(this.hsv[0]/2)-5,99-Math.floor(this.hsv[1]*100)-4);this.cdePnt.y(100-Math.floor(this.hsv[2]*100)-6);this.updateTxt();if(this.settings.onChangeColor)this.settings.onChangeColor(this.rgbToHex());},remove:function(){if(this.cdeCp){this.cdeCp.fadeDel(false,true,true);CDE.gc('_cp');this.cdeBg1=this.cdeBg2=this.cdeBg3=this.cdeBg4=this.cdeBg5=this.cdeCp=this.cdeTarget=this.cdeX=this.cdePnt=this.cdeVal=this.cdePrv=this.cdeTxt=null;if(this.settings.onClose)this.settings.onClose(this.rgbToHex());}},rgbToHsv:function(r,g,b){if(typeof r!='number')r=this.rgb[0];if(typeof g!='number')g=this.rgb[1];if(typeof b!='number')b=this.rgb[2];r/=255;g/=255;b/=255;var min=Math.min(Math.min(r,g),b);var max=Math.max(Math.max(r,g),b);var h,s,v;s=max==0?0:(max-min)/max;v=max;if(max==min)h=0;else if(r>g&&r>b)h=((((g-b)/(max-min))*60)+360)%360;else if(g>b)h=(((b-r)/(max-min))*60)+120;else h=(((r-g)/(max-min))*60)+240;this.setHsv(h,s*100,v*100);},hsvToRgb:function(h,s,v){if(typeof h!='number')h=this.hsv[0];if(typeof s!='number')s=this.hsv[1];if(typeof v!='number')v=this.hsv[2];var hi=Math.floor(h/60)%6;var f=(h/60)-hi;var p=v*(1-s);var q=v*(1-s*f);var t=v*(1-(1-f)*s);var r;switch(hi){case 0:r=[v,t,p];break;case 1:r=[q,v,p];break;case 2:r=[p,v,t];break;case 3:r=[p,q,v];break;case 4:r=[t,p,v];break;case 5:r=[v,p,q];break;}
this.rgb=[Math.floor(r[0]*255),Math.floor(r[1]*255),Math.floor(r[2]*255)];return this.rgb;},rgbToHex:function(){return CDE.rgb(this.rgb[0],this.rgb[1],this.rgb[2]);},hexToRgb:function(str){var rgb=CDE.rgb(str);this.rgb=[rgb.r,rgb.g,rgb.b];return this.rgb;},setBg:function(url,boolStart){if(url==this.strCurBg&&!boolStart){url='none';}
this.strCurBg=url;if(this.settings.onChangeBg)this.settings.onChangeBg(url);this.cdeBg1.sb(this.settings.strBg0==url?'red':'black');this.cdeBg2.sb(this.settings.strBg1==url?'red':'black');this.cdeBg3.sb(this.settings.strBg2==url?'red':'black');this.cdeBg4.sb(this.settings.strBg3==url?'red':'black');this.cdeBg5.sb(this.settings.strBg4==url?'red':'black');this.cdePrv.bg(url);if(!this.settings.boolNoAutoUpdate)this.cdeTarget.bg(url);},getBg:function(cde){var c=cde.getStl('background-image');if(c=='none'||c.substring(0,3)!='url')return'none';return(new RegExp('url\\((\'|\")?([^)\'\"]*)(\'|\")?\\)')).exec(c)[2];},updateTxt:function(){if(!this.cdeCp){if(window.debug)debug("CDE.ColorPicker.setRgb: no panel...");return;}
this.cdeTxt.txt(this.rgbToHex());},_:0};var Grid=function(tileSize,tileWidth,tileHeight){this.intTileSize=tileSize;this.intTileWidth=tileWidth;this.intTileHeight=tileHeight;this.intW=tileSize*tileWidth;this.intH=tileSize*tileHeight;this.intX=0;this.intY=0;this.intBeforeBounds={x1:200,y1:200,x2:300,y2:300};};Grid.prototype.getTileSize=function(){return this.intTileSize;};Grid.prototype.x=function(x){if(arguments.length==1)this.intX=x;return this.intX;};Grid.prototype.y=function(y){if(arguments.length==1)this.intY=y;return this.intY;};Grid.prototype.addX=function(x){this.intX+=x;return this.intX;};Grid.prototype.addY=function(y){this.intY+=y;return this.intY;};Grid.prototype.w=function(){return this.intW;};Grid.prototype.h=function(){return this.intH;};Grid.prototype.toString=function(){return"[Grid: "+this.x+"x"+this.y+", "+this.w+" "+this.h+"]";};var Player=function(x,y){this.health=100;this.vpPos={x:x,y:y};};Player.prototype.x=function(x){if(arguments.length==1)this.vpPos.x=x;return this.vpPos.x;};Player.prototype.y=function(y){if(arguments.length==1)this.vpPos.y=y;return this.vpPos.y;};Player.prototype.addX=function(x){this.vpPos.x+=x;return this.vpPos.x;};Player.prototype.addY=function(y){this.vpPos.y+=y;return this.vpPos.y;};var Timer=function(f,t){this.f=f;this.t=t;this.timer=setInterval(f,t);};Timer.prototype.changeTime=function(t){t=~~t;this.t=t;clearInterval(this.timer);this.timer=setInterval(this.f,t);};Timer.prototype.stop=function(){clearInterval(this.timer);};Timer.prototype.start=function(){this.changeTime(this.t);};var TileEditor={factor:6,size:4,img:new Image(),offset:0};TileEditor.plot=function(_,x,y){x=~~(x/TileEditor.factor);y=~~(y/TileEditor.factor);if(x==100||y==100)return;x-=~~((TileEditor.size-1)/2);y-=~~((TileEditor.size-1)/2);TileEditor.cdeCoord.txt(~~(x/TileEditor.factor)+"x"+~~(y/TileEditor.factor));TileEditor.cvs.fillRect(x*TileEditor.factor,y*TileEditor.factor,TileEditor.size*TileEditor.factor,TileEditor.size*TileEditor.factor);if(TileEditor.plotTimer)clearTimeout(TileEditor.plotTimer);TileEditor.plotTimer=setTimeout(function(){TileEditor.arrPreview[4].atr('src',TileEditor.cdeCanvas.dom().toDataURL());TileEditor.plotTimer=0;},100);};TileEditor.dragStart=function(x,y,btn){if(btn!=CDE.BUTTON_LEFT)return false;x-=25;y-=25;CDE.move.cde=this.clone().ns().o(0.5).abs(x,y).dba();CDE.move.cdeX=x;CDE.move.cdeY=y;};TileEditor.dragStop=function(x,y){var drag,prev,tx,ty;drag=this.pos();drag.x+=25;drag.y+=25;prev=TileEditor.arrPreview[0].pos();tx=~~((drag.x-prev.x)/100);ty=~~((drag.y-prev.y)/100);if(tx>=0&&tx<3&&ty>=0&&ty<3&&!(tx==1&&ty==1)){TileEditor.arrPreview[(ty*3)+tx].src(this.src());}else{prev=TileEditor.cdeCanvas.pos();if(drag.x>=0&&drag.y>0&&drag.x<prev.x+(TileEditor.factor*100)&&ty<prev.y+(TileEditor.factor*100)){TileEditor.img.src=this.src();TileEditor.cvs.drawImage(TileEditor.img,0,0,TileEditor.factor*100,TileEditor.factor*100);}}
this.del(true);};TileEditor.createListItem=function(id){var x,y,tx,ty;x=id%5;y=~~(id/5);tx=x*50+Math.max(0,x*10);ty=y*50+Math.max(0,y*10);return CDE.img(TileEditor.arrTiles[id]).id("list"+x+"x"+y).abs(tx,ty,50,50).cm().bgc('white').z(100).draggable(CDE.wrap(document.body),{onstart:TileEditor.dragStart,onstop:TileEditor.dragStop});};TileEditor.createList=function(){var i,parent;TileEditor.arrList=[];parent=CDE.div().abs(610,330,300,300);for(i=0;i<25;++i)TileEditor.arrList[i]=TileEditor.createListItem(i);return parent.add(TileEditor.arrList);};TileEditor.updateList=function(intOffset){var i;TileEditor.offset=Math.max(0,intOffset)||0;for(i=0;i<TileEditor.arrList.length;++i){TileEditor.arrList[i].src(TileEditor.arrTiles[TileEditor.offset+i]);}};TileEditor.createPreview=function(){TileEditor.arrPreview=[];return CDE.div().abs(605,0,300,300).add(TileEditor.arrPreview[0]=CDE.img(TileEditor.arrTiles[0]).abs(0,0,100,100).bgc('white'),TileEditor.arrPreview[1]=CDE.img().abs(100,0,100,100).bgc('white'),TileEditor.arrPreview[2]=CDE.img(TileEditor.arrTiles[1]).abs(200,0,100,100).bgc('white'),TileEditor.arrPreview[3]=CDE.img().abs(0,100,100,100).bgc('white'),TileEditor.arrPreview[4]=CDE.img().abs(100,100,100,100).bgc('white'),TileEditor.arrPreview[5]=CDE.img().abs(200,100,100,100).bgc('white'),TileEditor.arrPreview[6]=CDE.img(TileEditor.arrTiles[2]).abs(0,200,100,100).bgc('white'),TileEditor.arrPreview[7]=CDE.img().abs(100,200,100,100).bgc('white'),TileEditor.arrPreview[8]=CDE.img(TileEditor.arrTiles[3]).abs(200,200,100,100).bgc('white'));};TileEditor.onCanvasClick=function(_,x,y){if(!TileEditor.boolRect)TileEditor.plot(_,x,y);};TileEditor.onCanvasMouseDown=function(_,x,y){var rgb;if(TileEditor.boolRect){TileEditor.img.src=TileEditor.cdeCanvas.dom().toDataURL();TileEditor.startX=x;TileEditor.startY=y;rgb=CDE.rgb(TileEditor.cvs.fillStyle);TileEditor.cvs.fillStyle='rgba('+rgb.r+','+rgb.g+','+rgb.b+',0.5)';}
TileEditor.boolDragging=true;};TileEditor.onCanvasMouseMove=function(_,x,y){if(!TileEditor.boolDragging)return;if(TileEditor.boolRect){if(!TileEditor.imgTimer){TileEditor.imgTimer=setTimeout(function(){var w,h;w=Math.abs(x-TileEditor.startX);h=Math.abs(y-TileEditor.startY);x=Math.min(x,TileEditor.startX);y=Math.min(y,TileEditor.startY);TileEditor.imgTimer=0;try{TileEditor.cvs.drawImage(TileEditor.img,0,0);TileEditor.cvs.fillRect(x,y,w,h);TileEditor.cvs.strokeRect(x,y,w,h);}catch(er){}},~~(1000/30));}}else{TileEditor.plot(_,x,y);}};TileEditor.onCanvasMouseUp=function(_,x,y){if(TileEditor.boolRect){TileEditor.cvs.drawImage(TileEditor.img,0,0);TileEditor.img.src='';TileEditor.cvs.fillStyle=CDE.nColor(TileEditor.cvs.fillStyle);TileEditor.cvs.fillRect(Math.min(x,TileEditor.startX),Math.min(y,TileEditor.startY),Math.abs(x-TileEditor.startX),Math.abs(y-TileEditor.startY));if(TileEditor.rectTimer)clearTimeout(TileEditor.rectTimer);TileEditor.rectTimer=setTimeout(function(){var str=TileEditor.cdeCanvas.dom().toDataURL();TileEditor.arrPreview[4].atr('src',str);TileEditor.rectTimer=0;},100);}
TileEditor.boolDragging=false;};TileEditor.start=function(){var cdeBlack,cdeEditor,cdeSize;Game.objTimer.stop();cdeBlack=CDE.disablePage('disablething',false,20);cdeEditor=CDE.div().id('tileeditor').wh(820,610).z(21).o(0).add(TileEditor.createPreview(),CDE.lnk("P",function(){TileEditor.updateList(TileEditor.offset-5);}).abs(610,305,20,20).bgc('white').tac(),CDE.lnk("N",function(){TileEditor.updateList(TileEditor.offset+5);}).abs(880,305,20,20).bgc('white').tac(),TileEditor.createList(),TileEditor.cdeMenu=CDE.div().bgc('lightblue').w(595).h(20).ml(1).pl(5).rel().add(CDE.lnk('close',function(){cdeBlack.fadeDelUncache();cdeEditor.fadeDelUncache();Game.objTimer.start();}).fr().mr(5),CDE.lnk('list',function(){debug(JSON.stringify(TileEditor.arrTiles));}).id('uri').fr().mr(20),CDE.lnk('uri',function(){debug(TileEditor.cdeCanvas.dom().toDataURL());debug("<hr>");var cde,url;TileEditor.img.src=TileEditor.cdeCanvas.dom().toDataURL();cde=CDE.dom('canvas').atr('width',100).atr('height',100);cde.dom().getContext('2d').drawImage(TileEditor.img,0,0,100,100);url=cde.dom().toDataURL();debug(url);}).id('uri').fr().mr(5),TileEditor.cdeCoord=CDE.html().id('tilecoords').mr(5).fr(),CDE.lnk('',function(){CDE.ColorPicker.show(this,{intZ:1050,boolColorBoxes:true,spriteUrl:'colorpicker_sprite.png',onChangeColor:function(c){TileEditor.cvs.fillStyle=TileEditor.cvs.strokeStyle=c;}});}).fl().wh(16,16).bgc('black').sb('black').mr(5).mt(1),CDE.text('['),CDE.lnk('-',function(){cdeSize.txt(TileEditor.size=Math.max(1,TileEditor.size-1));}).id('smaller').ml(5).mr(5),cdeSize=CDE.html(TileEditor.size).id('size').mr(5),CDE.lnk('+',function(){cdeSize.txt(TileEditor.size=Math.min(20,TileEditor.size+1));}).id('larger').mr(5),CDE.text(']'),CDE.lnk('rect',function(){TileEditor.boolRect=!TileEditor.boolRect;this.style.fontWeight=TileEditor.boolRect?'bolder':'normal';}).id('rect').ml(5).mr(20),CDE.lnk('save',function(){var cde,url;TileEditor.img.src=TileEditor.cdeCanvas.dom().toDataURL();cde=CDE.dom('canvas').atr('width',100).atr('height',100);cde.dom().getContext('2d').drawImage(TileEditor.img,0,0,100,100);url=cde.dom().toDataURL();TileEditor.arrTiles.push(url);TileEditor.updateList();setKey(TileEditor.arrTiles,'tiles');}).id('save').mr(5),CDE.lnk('clear',function(){TileEditor.cvs.fillStyle='white';TileEditor.cvs.fillRect(0,0,TileEditor.factor*100,TileEditor.factor*100);TileEditor.cvs.fillStyle='black';}).id('clear').mr(5),CDE.lnk('help',function(){CDE.popup("Tile editor help","This is the tile editor. You can add new tiles here.<br />"+"Start drawing from scratch or drag an existing tile from the bottom-right to the center. You can<br />"+"also drag a tile to the top-right to check border-connections. The center will automatically show<br />"+"your current creation when you start drawing.<br />"+"The pen-size can be changed by pressing + or -.<br />"+"The color can be changed by clicking on the colored square.<br />"+"There are two drawing modes; regular and rectangle. Clicking on 'rectangle' will toggle this.<br />"+"Pressing save will add your current painting to the list. Tiles are saved using sessionStorage<br />"+"which is NOT supported by Chrome. There is no server interaction.<br />"+"You can use created tiles immediately in the grid editor.<br />"+"Additionally there's a method to print the dataUrl for the current painting and for all tiles.<br />"+"I know the paint methods are very simple (probably still an understatement) but this is just<br />"+"a proof of concept... :)<br />"+"I might add the importing of images from a local computer (using HTML5 File API) some day...<br /><br />");}).id('help').ml(50)),TileEditor.cdeCanvas=CDE.dom('canvas').atr('cursor','crosshair').wh(TileEditor.factor*100,TileEditor.factor*100).atr('width',TileEditor.factor*100).atr('height',TileEditor.factor*100).fl().sb('black').bgc('white').cc().css('image-rendering','optimizeQuality').on('click',TileEditor.onCanvasClick,'element').on('mousedown',TileEditor.onCanvasMouseDown,'element').on('mousemove',TileEditor.onCanvasMouseMove,'element').on('mouseup',TileEditor.onCanvasMouseUp,'element')).dba().centerFade();TileEditor.cvs=TileEditor.cdeCanvas.dom().getContext('2d');TileEditor.cvs.fillStyle="white";TileEditor.cvs.fillRect(0,0,TileEditor.factor*100,TileEditor.factor*100);TileEditor.cvs.fillStyle="black";};GridEditor={empty:'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAlgAAAJYCAYAAAC+ZpjcAAAKqElEQVR4nO3WQQkAMAzAwPo3vZoIDMqdgjwzDwCA1PwOAAC4xmABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAzGABAMQMFgBAbAFY5E9dFFEQ0wAAAABJRU5ErkJggg==',gridX:0,gridY:0,width:5,height:5,size:10,listPos:0};GridEditor.wh=GridEditor.width*GridEditor.height;GridEditor.createGrid=function(cdeGrid){var i,j,t,x,y;GridEditor.arrGridCde=[];for(i=0;i<GridEditor.wh;++i){x=i%GridEditor.width;y=~~(i/GridEditor.height);if(i>=GridEditor.arrGrid.length)t=GridEditor.empty;else t=TileEditor.arrTiles[GridEditor.arrGrid[x+(y*GridEditor.size)]]||GridEditor.empty;GridEditor.arrGridCde[i]=CDE.img(t).abs(x*100,y*100,100,100).addTo(cdeGrid);}};GridEditor.updateGrid=function(x,y){var i,n,t;GridEditor.gridX=x;GridEditor.gridY=y;for(i=0;i<GridEditor.wh;++i){x=(i%GridEditor.width)+GridEditor.gridX;y=~~(i/GridEditor.height)+GridEditor.gridY;n=x+(y*GridEditor.size);if(n>=GridEditor.arrGrid.length)t=GridEditor.empty;else t=TileEditor.arrTiles[GridEditor.arrGrid[n]]||GridEditor.empty;GridEditor.arrGridCde[i].src(t);}};GridEditor.createList=function(cdeList){var i;GridEditor.arrCdeImg=[];for(i=0;i<20;++i){CDE.div().abs((i%2)*51,~~(i/2)*51,50,50).bb(1,false,false).br(1,false,false).add(GridEditor.arrCdeImg[i]=CDE.img(TileEditor.arrTiles[i]).abs(0,0,50,50).cm().draggable(false,{onstop:(function(i){return function(x,y){var pos=GridEditor.arrGridCde[0].pos();if(x>pos.x&&x<(pos.x+500)&&y>pos.y&&y<(pos.y+500)){x=~~((x-pos.x)/100);y=~~((y-pos.y)/100);GridEditor.arrGridCde[x+(y*GridEditor.width)].src(TileEditor.arrTiles[i+GridEditor.listPos]);GridEditor.arrGrid[(x+GridEditor.gridX)+((y+GridEditor.gridY)*GridEditor.size)]=i+GridEditor.listPos;setKey(GridEditor.arrGrid,'grid');}
this.xy(0,0);};})(i)})).addTo(cdeList);}};GridEditor.updateList=function(){var i;for(i=0;i<20;++i){GridEditor.arrCdeImg[i].src(TileEditor.arrTiles[i+GridEditor.listPos]);}};GridEditor.start=function(){var cdeBlack,cdeEditor,cdeGrid,cdeList,startX,startY,i,j,n;Game.objTimer.stop();cdeBlack=CDE.disablePage();cdeEditor=CDE.div().wh(630,540).z(1000).o(0).bgc('white').add(CDE.div().add(CDE.lnk('down',function(){GridEditor.listPos+=2;GridEditor.updateList();}).fr().mr(10),CDE.lnk('up',function(){GridEditor.listPos-=2;GridEditor.updateList();}).fr().mr(50),CDE.lnk('close',function(){cdeEditor.fadeDelUncache();cdeBlack.fadeDelUncache();Gui.updateTiles();}).ml(10).mr(10),CDE.lnk('show',function(){debug(GridEditor.arrGrid);}).mr(50),CDE.lnk('help',function(){CDE.popup('Grid editor help',"This editor allows you to change the grid used in the back of the demo.<br />"+"You can drag tiles from the list on the right to the grid to change<br />"+"the tile facing. Changes are saved immediately, to sessionStorage (not<br />"+"supported by Chrome right now!), there is no server interaction.<br />"+"You can drag the grid to see more of it.<br />"+"You can see more tiles (if you have them) by clicking up and down.<br />"+"Right now, changes to the grid are only visible on reload.<br />"+"(So that won't work on Chrome, no)<br /><br />");})),CDE.div().rel().add(cdeGrid=CDE.div().abs(10,10,500,500).sb('black').add(CDE.div().id('eventLayer').abs(0,0,500,500).z(5).cm().draggable(true,{boolNoMove:true,onstart:function(x,y){startX=GridEditor.gridX;startY=GridEditor.gridY;},ondrag:function(_,_,dx,dy){x=~~(-dx/100)+startX;y=~~(-dy/100)+startY;x=Math.max(0,Math.min(GridEditor.size-GridEditor.width,x));y=Math.max(0,Math.min(GridEditor.size-GridEditor.height,y));if(GridEditor.gridX!=x||GridEditor.gridY!=y){GridEditor.updateGrid(x,y);}}}))),cdeList=CDE.div().abs(520,20,101,510).sb('black').bb(0).br(0)).centerFade();GridEditor.createGrid(cdeGrid);GridEditor.createList(cdeList);};var Game={};var Gui={keys:{}};Gui.addTilesToGrid=function(){var x,y,tx,ty,rcolor,arr,tile;Gui.arrTiles=arr=[];for(x=0;x<Gui.intTileWidth;++x){arr[x]=[];for(y=0;y<Gui.intTileHeight;++y){tx=x*Gui.intTileSize;ty=y*Gui.intTileSize;tile=TileEditor.arrTiles[GridEditor.arrGrid[x+(y*10)]];arr[x][y]=CDE.img(tile).id("tile"+x+"x"+y).abs(tx+"px",ty+"px",Gui.intTileSize,Gui.intTileSize).addTo(Gui.cdeGrid);}}};Gui.updateTiles=function(){var x,y,tile,arr=Gui.arrTiles;for(x=0;x<Gui.intTileWidth;++x){for(y=0;y<Gui.intTileHeight;++y){tile=TileEditor.arrTiles[GridEditor.arrGrid[x+(y*10)]];arr[x][y].src(tile);}}};Gui.showViewport=function(){CDE.div().add(CDE.div().mb(5).add(Gui.cdeFps=CDE.div().fr(),CDE.lnk('stop',function(){Game.objTimer.stop();}).id('stop').mr(5),CDE.lnk('30fps',function(){Game.objTimer.changeTime(1000/30);}).id('fps30').mr(5),CDE.lnk('60fps',function(){Game.objTimer.changeTime(1000/60);}).id('fps60').mr(5),CDE.lnk('100fps',function(){Game.objTimer.changeTime(1000/100);}).id('fps100').mr(5),CDE.lnk('120fps',function(){Game.objTimer.changeTime(1000/120);}).id('fps120').mr(5),CDE.lnk('200fps',function(){Game.objTimer.changeTime(1000/200);}).id('fps200').mr(5),CDE.lnk('300fps',function(){Game.objTimer.changeTime(1000/300);}).id('fps300').mr(5)),CDE.div().mb(3).add(CDE.html('Press any directional key').c('red').fr(),CDE.lnk("Tile editor",TileEditor.start).mr(10),CDE.lnk("Grid editor",GridEditor.start).mr(20),CDE.lnk("Help",function(){CDE.popup('Tile demo help',"This is little proof of concept that got out of hand.<br />"+"You can move around by the directional keys (left, up, etc).<br />"+"The background is a grid of tiles. You can create your own<br />"+"tiles using the tile editor and you can change the layout<br />"+"of the grid using the grid editor.<br />"+"The entire thing is created using Javascript. The tile<br />"+"editor uses canvas for drawing. The result is refreshed<br />"+"using a Javascript timer. This timer executes the function<br />"+"every 1000/fps miliseconds. Various browsers give various<br />"+"results. The displayed fps is literal.<br />"+"It will not work on IE. Chrome does not support sessionData<br />"+"but gets by far the most fps.<br />"+"The entire application does not communicate with the server.<br />"+"SessionData (html5) is used for storage, canvas (html5) is used<br />"+"for drawing. DataUrls are used to the max :).<br />"+"See credits for author details. The editors have their own help.<br /><br />");}).mr(5),CDE.lnk('Author',function(){CDE.popup("About the author","Created by Peter van der Zee (qFox), January 2010<br /><br />"+"It was meant as a scroll demo. The red 'player' will move only<br />"+"in the center part of the viewport. Otherwise the grid in the<br />"+"back will move, until a border is reached. This gives you a<br />"+"very natural movement using Javascript.<br /><br />"+"Of course, I figured why not create some tiles to actually have<br />"+"a background to scroll. And then I added a grid editor and the<br />"+"whole thing just got out of hand :)<br /><br />"+"Anyways, I'm quite content with the results and I'll probably<br />"+"continue working on it. Maybe even build it up to a platform.<br /><br />"+"The whole thing took less than a week (about 50 hours, I'd say)<br /><br />"+"Improvements: Importing local files to tiles (html5 file api),<br />"+"being able to mark areas as forbidden (and collision detection),<br />"+"adding enemies and enemy behaviour (through scripting), being<br />"+"able to model the player (and other actors), improving the tile<br />"+"editor (more brushes, copy, spriting, undo, etc.) and more... :)<br /><br />"+"You can visit my site here: <a href='http://qfox.nl' target='_blank'>qfox.nl</a>.<br />"+"Or follow me as <a href='http://twitter.com/kuvos' target='_blank'>@kuvos</a> on twitter :)<br /><br />");})),Gui.cdeViewport=CDE.div().rel().oh().id('viewport').wh(Gui.intViewportWidth+2,Gui.intViewportHeight+2)).dba().center();};Gui.listenToKeyboard=function(){CDE.wrap(window).on('keydown',function(evt,key){if(key>=37&&key<=40){switch(key){case 37:Gui.keys.left=true;break;case 38:Gui.keys.up=true;break;case 39:Gui.keys.right=true;break;case 40:Gui.keys.down=true;break;}
return CDE.stopEvent(evt);}},'keyboard').on('keyup',function(evt,key){if(key>=37&&key<=40){switch(key){case 37:Gui.keys.left=false;break;case 38:Gui.keys.up=false;break;case 39:Gui.keys.right=false;break;case 40:Gui.keys.down=false;break;}
return CDE.stopEvent(evt);}},'keyboard').on('keypress',function(evt,key){if(key>=37&&key<=40){return CDE.stopEvent(evt);}},'keyboard');};Gui.init=function(){Gui.center={x:0,y:0};Gui.intTileSize=100;Gui.intTileWidth=10;Gui.intTileHeight=10;Gui.intViewportWidth=500;Gui.intViewportHeight=500;Game.objGrid=new Grid(Gui.intTileSize,Gui.intTileWidth,Gui.intTileHeight);Game.objPlayer=new Player(45,180);Gui.showViewport();Gui.cdeGrid=CDE.div().z(1).id('gridLayer').abs(0,0,Gui.intTileWidth*Gui.intTileSize,Gui.intTileHeight*Gui.intTileSize);Gui.addTilesToGrid();Gui.cdeGrid.addTo(Gui.cdeViewport);Gui.cdePlayer=CDE.div().id('player').sprite('player.png',0,0).z(10).abs(30,30,20,20).addTo(Gui.cdeViewport);CDE.div().id('wire').z(2).abs(0,0,Gui.intViewportWidth,Gui.intViewportHeight).sb('red').addTo(Gui.cdeViewport).uncache();Gui.listenToKeyboard();CDE.gc('main');};Gui.start=function(){var lastGrid,lastPlayer,secondNow,lastSecond,frames;lastGrid={};lastPlayer={};secondNow=lastSecond=0;frames=0;Game.objTimer=new Timer(function(){var moved,t=CDE.now()*1000;secondNow=~~(t/1000)%10;if(secondNow!=lastSecond){lastSecond=secondNow;Gui.cdeFps.txt(frames+" fps");frames=1;}else{++frames;}
moved=(Game.objGrid.x()!=lastGrid.x||Game.objGrid.y()!=lastGrid.y);if(moved){lastGrid.x=Game.objGrid.x();lastGrid.y=Game.objGrid.y();Gui.cdeGrid.xy(-lastGrid.x+'px',-lastGrid.y+'px');}
if(Gui.keys.left){if(Game.objPlayer.x()<Game.objGrid.intBeforeBounds.x1&&Game.objGrid.x()>=0)Game.objGrid.addX(-1);else if(Game.objPlayer.x()>0)Game.objPlayer.addX(-1);}
if(Gui.keys.up){if(Game.objPlayer.y()<Game.objGrid.intBeforeBounds.y1&&Game.objGrid.y()>=0)Game.objGrid.addY(-1);else if(Game.objPlayer.y()>0)Game.objPlayer.addY(-1);}
if(Gui.keys.right){if(Game.objPlayer.x()>=Game.objGrid.intBeforeBounds.x2&&Game.objGrid.x()<=(Game.objGrid.w()-Gui.intViewportWidth-2))Game.objGrid.addX(1);else if(Game.objPlayer.x()<=(Gui.intViewportWidth-20))Game.objPlayer.addX(1);}
if(Gui.keys.down){if(Game.objPlayer.y()>=Game.objGrid.intBeforeBounds.y2&&Game.objGrid.y()<=(Game.objGrid.h()-Gui.intViewportHeight-2))Game.objGrid.addY(1);else if(Game.objPlayer.y()<=(Gui.intViewportHeight-20))Game.objPlayer.addY(1);}
moved=(Game.objPlayer.x()!=lastPlayer.x||Game.objPlayer.y()!=lastPlayer.y);if(moved){lastPlayer.x=Game.objPlayer.x();lastPlayer.y=Game.objPlayer.y();Gui.cdePlayer.xy(lastPlayer.x+'px',lastPlayer.y+'px');}},~~(1000/60));};