/* http://keith-wood.name/countdown.html
   Countdown for jQuery v1.5.5.
   Written by Keith Wood (kbwood{at}iinet.com.au) January 2008.
   Dual licensed under the GPL (http://dev.jquery.com/browser/trunk/jquery/GPL-LICENSE.txt) and 
   MIT (http://dev.jquery.com/browser/trunk/jquery/MIT-LICENSE.txt) licenses. 
   Please attribute the author if you use it. */
(function($){function Countdown(){this.regional=[];this.regional['']={labels:['Years','Months','Weeks','Days','Hours','Minutes','Seconds'],labels1:['Year','Month','Week','Day','Hour','Minute','Second'],compactLabels:['y','m','w','d'],timeSeparator:':',isRTL:false};this._defaults={until:null,since:null,timezone:null,serverSync:null,format:'dHMS',layout:'',compact:false,description:'',expiryUrl:'',expiryText:'',alwaysExpire:false,onExpiry:null,onTick:null};$.extend(this._defaults,this.regional[''])}var w='countdown';var Y=0;var O=1;var W=2;var D=3;var H=4;var M=5;var S=6;$.extend(Countdown.prototype,{markerClassName:'hasCountdown',_timer:setInterval(function(){$.countdown._updateTargets()},980),_timerTargets:[],setDefaults:function(a){this._resetExtraLabels(this._defaults,a);extendRemove(this._defaults,a||{})},UTCDate:function(a,b,c,e,f,g,h,i){if(typeof b=='object'&&b.constructor==Date){i=b.getMilliseconds();h=b.getSeconds();g=b.getMinutes();f=b.getHours();e=b.getDate();c=b.getMonth();b=b.getFullYear()}var d=new Date();d.setUTCFullYear(b);d.setUTCDate(1);d.setUTCMonth(c||0);d.setUTCDate(e||1);d.setUTCHours(f||0);d.setUTCMinutes((g||0)-(Math.abs(a)<30?a*60:a));d.setUTCSeconds(h||0);d.setUTCMilliseconds(i||0);return d},_settingsCountdown:function(a,b){if(!b){return $.countdown._defaults}var c=$.data(a,w);return(b=='all'?c.options:c.options[b])},_attachCountdown:function(a,b){var c=$(a);if(c.hasClass(this.markerClassName)){return}c.addClass(this.markerClassName);var d={options:$.extend({},b),_periods:[0,0,0,0,0,0,0]};$.data(a,w,d);this._changeCountdown(a)},_addTarget:function(a){if(!this._hasTarget(a)){this._timerTargets.push(a)}},_hasTarget:function(a){return($.inArray(a,this._timerTargets)>-1)},_removeTarget:function(b){this._timerTargets=$.map(this._timerTargets,function(a){return(a==b?null:a)})},_updateTargets:function(){for(var i=0;i<this._timerTargets.length;i++){this._updateCountdown(this._timerTargets[i])}},_updateCountdown:function(a,b){var c=$(a);b=b||$.data(a,w);if(!b){return}c.html(this._generateHTML(b));c[(this._get(b,'isRTL')?'add':'remove')+'Class']('countdown_rtl');var d=this._get(b,'onTick');if(d){d.apply(a,[b._hold!='lap'?b._periods:this._calculatePeriods(b,b._show,new Date())])}var e=b._hold!='pause'&&(b._since?b._now.getTime()<=b._since.getTime():b._now.getTime()>=b._until.getTime());if(e&&!b._expiring){b._expiring=true;if(this._hasTarget(a)||this._get(b,'alwaysExpire')){this._removeTarget(a);var f=this._get(b,'onExpiry');if(f){f.apply(a,[])}var g=this._get(b,'expiryText');if(g){var h=this._get(b,'layout');b.options.layout=g;this._updateCountdown(a,b);b.options.layout=h}var i=this._get(b,'expiryUrl');if(i){window.location=i}}b._expiring=false}else if(b._hold=='pause'){this._removeTarget(a)}$.data(a,w,b)},_changeCountdown:function(a,b,c){b=b||{};if(typeof b=='string'){var d=b;b={};b[d]=c}var e=$.data(a,w);if(e){this._resetExtraLabels(e.options,b);extendRemove(e.options,b);this._adjustSettings(a,e);$.data(a,w,e);var f=new Date();if((e._since&&e._since<f)||(e._until&&e._until>f)){this._addTarget(a)}this._updateCountdown(a,e)}},_resetExtraLabels:function(a,b){var c=false;for(var n in b){if(n.match(/[Ll]abels/)){c=true;break}}if(c){for(var n in a){if(n.match(/[Ll]abels[0-9]/)){a[n]=null}}}},_adjustSettings:function(a,b){var c=this._get(b,'serverSync');c=(c?c.apply(a,[]):null);var d=new Date();var e=this._get(b,'timezone');e=(e==null?-d.getTimezoneOffset():e);b._since=this._get(b,'since');if(b._since){b._since=this.UTCDate(e,this._determineTime(b._since,null));if(b._since&&c){b._since.setMilliseconds(b._since.getMilliseconds()+d.getTime()-c.getTime())}}b._until=this.UTCDate(e,this._determineTime(this._get(b,'until'),d));if(c){b._until.setMilliseconds(b._until.getMilliseconds()+d.getTime()-c.getTime())}b._show=this._determineShow(b)},_destroyCountdown:function(a){var b=$(a);if(!b.hasClass(this.markerClassName)){return}this._removeTarget(a);b.removeClass(this.markerClassName).empty();$.removeData(a,w)},_pauseCountdown:function(a){this._hold(a,'pause')},_lapCountdown:function(a){this._hold(a,'lap')},_resumeCountdown:function(a){this._hold(a,null)},_hold:function(a,b){var c=$.data(a,w);if(c){if(c._hold=='pause'&&!b){c._periods=c._savePeriods;var d=(c._since?'-':'+');c[c._since?'_since':'_until']=this._determineTime(d+c._periods[0]+'y'+d+c._periods[1]+'o'+d+c._periods[2]+'w'+d+c._periods[3]+'d'+d+c._periods[4]+'h'+d+c._periods[5]+'m'+d+c._periods[6]+'s');this._addTarget(a)}c._hold=b;c._savePeriods=(b=='pause'?c._periods:null);$.data(a,w,c);this._updateCountdown(a,c)}},_getTimesCountdown:function(a){var b=$.data(a,w);return(!b?null:(!b._hold?b._periods:this._calculatePeriods(b,b._show,new Date())))},_get:function(a,b){return(a.options[b]!=null?a.options[b]:$.countdown._defaults[b])},_determineTime:function(k,l){var m=function(a){var b=new Date();b.setTime(b.getTime()+a*1000);return b};var n=function(a){a=a.toLowerCase();var b=new Date();var c=b.getFullYear();var d=b.getMonth();var e=b.getDate();var f=b.getHours();var g=b.getMinutes();var h=b.getSeconds();var i=/([+-]?[0-9]+)\s*(s|m|h|d|w|o|y)?/g;var j=i.exec(a);while(j){switch(j[2]||'s'){case's':h+=parseInt(j[1],10);break;case'm':g+=parseInt(j[1],10);break;case'h':f+=parseInt(j[1],10);break;case'd':e+=parseInt(j[1],10);break;case'w':e+=parseInt(j[1],10)*7;break;case'o':d+=parseInt(j[1],10);e=Math.min(e,$.countdown._getDaysInMonth(c,d));break;case'y':c+=parseInt(j[1],10);e=Math.min(e,$.countdown._getDaysInMonth(c,d));break}j=i.exec(a)}return new Date(c,d,e,f,g,h,0)};var o=(k==null?l:(typeof k=='string'?n(k):(typeof k=='number'?m(k):k)));if(o)o.setMilliseconds(0);return o},_getDaysInMonth:function(a,b){return 32-new Date(a,b,32).getDate()},_generateHTML:function(c){c._periods=periods=(c._hold?c._periods:this._calculatePeriods(c,c._show,new Date()));var d=false;var e=0;for(var f=0;f<c._show.length;f++){d|=(c._show[f]=='?'&&periods[f]>0);c._show[f]=(c._show[f]=='?'&&!d?null:c._show[f]);e+=(c._show[f]?1:0)}var g=this._get(c,'compact');var h=this._get(c,'layout');var i=(g?this._get(c,'compactLabels'):this._get(c,'labels'));var j=this._get(c,'timeSeparator');var k=this._get(c,'description')||'';var l=function(a){var b=$.countdown._get(c,'compactLabels'+periods[a]);return(c._show[a]?periods[a]+(b?b[a]:i[a])+' ':'')};var m=function(a){var b=$.countdown._get(c,'labels'+periods[a]);return(c._show[a]?'<span class="countdown_section"><span class="countdown_amount">'+periods[a]+'</span><br/>'+(b?b[a]:i[a])+'</span>':'')};return(h?this._buildLayout(c,h,g):((g?'<span class="countdown_row countdown_amount'+(c._hold?' countdown_holding':'')+'">'+l(Y)+l(O)+l(W)+l(D)+(c._show[H]?this._minDigits(periods[H],2):'')+(c._show[M]?(c._show[H]?j:'')+this._minDigits(periods[M],2):'')+(c._show[S]?(c._show[H]||c._show[M]?j:'')+this._minDigits(periods[S],2):''):'<span class="countdown_row countdown_show'+e+(c._hold?' countdown_holding':'')+'">'+m(Y)+m(O)+m(W)+m(D)+m(H)+m(M)+m(S))+'</span>'+(k?'<span class="countdown_row countdown_descr">'+k+'</span>':'')))},_buildLayout:function(c,d,e){var f=this._get(c,(e?'compactLabels':'labels'));var g=function(a){return($.countdown._get(c,(e?'compactLabels':'labels')+c._periods[a])||f)[a]};var h=function(a,b){return Math.floor(a/b)%10};var j={desc:this._get(c,'description'),sep:this._get(c,'timeSeparator'),yl:g(Y),yn:c._periods[Y],ynn:this._minDigits(c._periods[Y],2),ynnn:this._minDigits(c._periods[Y],3),y1:h(c._periods[Y],1),y10:h(c._periods[Y],10),y100:h(c._periods[Y],100),y1000:h(c._periods[Y],1000),ol:g(O),on:c._periods[O],onn:this._minDigits(c._periods[O],2),onnn:this._minDigits(c._periods[O],3),o1:h(c._periods[O],1),o10:h(c._periods[O],10),o100:h(c._periods[O],100),o1000:h(c._periods[O],1000),wl:g(W),wn:c._periods[W],wnn:this._minDigits(c._periods[W],2),wnnn:this._minDigits(c._periods[W],3),w1:h(c._periods[W],1),w10:h(c._periods[W],10),w100:h(c._periods[W],100),w1000:h(c._periods[W],1000),dl:g(D),dn:c._periods[D],dnn:this._minDigits(c._periods[D],2),dnnn:this._minDigits(c._periods[D],3),d1:h(c._periods[D],1),d10:h(c._periods[D],10),d100:h(c._periods[D],100),d1000:h(c._periods[D],1000),hl:g(H),hn:c._periods[H],hnn:this._minDigits(c._periods[H],2),hnnn:this._minDigits(c._periods[H],3),h1:h(c._periods[H],1),h10:h(c._periods[H],10),h100:h(c._periods[H],100),h1000:h(c._periods[H],1000),ml:g(M),mn:c._periods[M],mnn:this._minDigits(c._periods[M],2),mnnn:this._minDigits(c._periods[M],3),m1:h(c._periods[M],1),m10:h(c._periods[M],10),m100:h(c._periods[M],100),m1000:h(c._periods[M],1000),sl:g(S),sn:c._periods[S],snn:this._minDigits(c._periods[S],2),snnn:this._minDigits(c._periods[S],3),s1:h(c._periods[S],1),s10:h(c._periods[S],10),s100:h(c._periods[S],100),s1000:h(c._periods[S],1000)};var k=d;for(var i=0;i<7;i++){var l='yowdhms'.charAt(i);var m=new RegExp('\\{'+l+'<\\}(.*)\\{'+l+'>\\}','g');k=k.replace(m,(c._show[i]?'$1':''))}$.each(j,function(n,v){var a=new RegExp('\\{'+n+'\\}','g');k=k.replace(a,v)});return k},_minDigits:function(a,b){a=''+a;if(a.length>=b){return a}a='0000000000'+a;return a.substr(a.length-b)},_determineShow:function(a){var b=this._get(a,'format');var c=[];c[Y]=(b.match('y')?'?':(b.match('Y')?'!':null));c[O]=(b.match('o')?'?':(b.match('O')?'!':null));c[W]=(b.match('w')?'?':(b.match('W')?'!':null));c[D]=(b.match('d')?'?':(b.match('D')?'!':null));c[H]=(b.match('h')?'?':(b.match('H')?'!':null));c[M]=(b.match('m')?'?':(b.match('M')?'!':null));c[S]=(b.match('s')?'?':(b.match('S')?'!':null));return c},_calculatePeriods:function(f,g,h){f._now=h;f._now.setMilliseconds(0);var i=new Date(f._now.getTime());if(f._since){if(h.getTime()<f._since.getTime()){f._now=h=i}else{h=f._since}}else{i.setTime(f._until.getTime());if(h.getTime()>f._until.getTime()){f._now=h=i}}var j=[0,0,0,0,0,0,0];if(g[Y]||g[O]){var k=$.countdown._getDaysInMonth(h.getFullYear(),h.getMonth());var l=$.countdown._getDaysInMonth(i.getFullYear(),i.getMonth());var m=(i.getDate()==h.getDate()||(i.getDate()>=Math.min(k,l)&&h.getDate()>=Math.min(k,l)));var n=function(a){return(a.getHours()*60+a.getMinutes())*60+a.getSeconds()};var o=Math.max(0,(i.getFullYear()-h.getFullYear())*12+i.getMonth()-h.getMonth()+((i.getDate()<h.getDate()&&!m)||(m&&n(i)<n(h))?-1:0));j[Y]=(g[Y]?Math.floor(o/12):0);j[O]=(g[O]?o-j[Y]*12:0);var p=function(a,b,c){var d=(a.getDate()==c);var e=$.countdown._getDaysInMonth(a.getFullYear()+b*j[Y],a.getMonth()+b*j[O]);if(a.getDate()>e){a.setDate(e)}a.setFullYear(a.getFullYear()+b*j[Y]);a.setMonth(a.getMonth()+b*j[O]);if(d){a.setDate(e)}return a};if(f._since){i=p(i,-1,l)}else{h=p(new Date(h.getTime()),+1,k)}}var q=Math.floor((i.getTime()-h.getTime())/1000);var r=function(a,b){j[a]=(g[a]?Math.floor(q/b):0);q-=j[a]*b};r(W,604800);r(D,86400);r(H,3600);r(M,60);r(S,1);if(q>0&&!f._since){var s=[1,12,4.3482,7,24,60,60];var t=S;var u=1;for(var v=S;v>=Y;v--){if(g[v]){if(j[t]>=u){j[t]=0;q=1}if(q>0){j[v]++;q=0;t=v;u=1}}u*=s[v]}}return j}});function extendRemove(a,b){$.extend(a,b);for(var c in b){if(b[c]==null){a[c]=null}}return a}$.fn.countdown=function(a){var b=Array.prototype.slice.call(arguments,1);if(a=='getTimes'||a=='settings'){return $.countdown['_'+a+'Countdown'].apply($.countdown,[this[0]].concat(b))}return this.each(function(){if(typeof a=='string'){$.countdown['_'+a+'Countdown'].apply($.countdown,[this].concat(b))}else{$.countdown._attachCountdown(this,a)}})};$.countdown=new Countdown()})(jQuery);


/*
Uploadify v2.1.0
Release Date: August 24, 2009

Copyright (c) 2009 Ronnie Garcia, Travis Nickels

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

if(jQuery){(function(a){a.extend(a.fn,{uploadify:function(b){a(this).each(function(){settings=a.extend({id:a(this).attr("id"),uploader:"uploadify.swf",script:"uploadify.php",expressInstall:null,folder:"",height:30,width:110,cancelImg:"cancel.png",wmode:"opaque",scriptAccess:"sameDomain",fileDataName:"Filedata",method:"POST",queueSizeLimit:999,simUploadLimit:1,queueID:false,displayData:"percentage",onInit:function(){},onSelect:function(){},onQueueFull:function(){},onCheck:function(){},onCancel:function(){},onError:function(){},onProgress:function(){},onComplete:function(){},onAllComplete:function(){}},b);var e=location.pathname;e=e.split("/");e.pop();e=e.join("/")+"/";var f={};f.uploadifyID=settings.id;f.pagepath=e;if(settings.buttonImg){f.buttonImg=escape(settings.buttonImg)}if(settings.buttonText){f.buttonText=escape(settings.buttonText)}if(settings.rollover){f.rollover=true}f.script=settings.script;f.folder=escape(settings.folder);if(settings.scriptData){var g="";for(var d in settings.scriptData){g+="&"+d+"="+settings.scriptData[d]}f.scriptData=escape(g.substr(1))}f.width=settings.width;f.height=settings.height;f.wmode=settings.wmode;f.method=settings.method;f.queueSizeLimit=settings.queueSizeLimit;f.simUploadLimit=settings.simUploadLimit;if(settings.hideButton){f.hideButton=true}if(settings.fileDesc){f.fileDesc=settings.fileDesc}if(settings.fileExt){f.fileExt=settings.fileExt}if(settings.multi){f.multi=true}if(settings.auto){f.auto=true}if(settings.sizeLimit){f.sizeLimit=settings.sizeLimit}if(settings.checkScript){f.checkScript=settings.checkScript}if(settings.fileDataName){f.fileDataName=settings.fileDataName}if(settings.queueID){f.queueID=settings.queueID}if(settings.onInit()!==false){a(this).css("display","none");a(this).after('<div id="'+a(this).attr("id")+'Uploader"></div>');swfobject.embedSWF(settings.uploader,settings.id+"Uploader",settings.width,settings.height,"9.0.24",settings.expressInstall,f,{quality:"high",wmode:settings.wmode,allowScriptAccess:settings.scriptAccess});if(settings.queueID==false){a("#"+a(this).attr("id")+"Uploader").after('<div id="'+a(this).attr("id")+'Queue" class="uploadifyQueue"></div>')}}if(typeof(settings.onOpen)=="function"){a(this).bind("uploadifyOpen",settings.onOpen)}a(this).bind("uploadifySelect",{action:settings.onSelect,queueID:settings.queueID},function(j,h,i){if(j.data.action(j,h,i)!==false){var k=Math.round(i.size/1024*100)*0.01;var l="KB";if(k>1000){k=Math.round(k*0.001*100)*0.01;l="MB"}var m=k.toString().split(".");if(m.length>1){k=m[0]+"."+m[1].substr(0,2)}else{k=m[0]}if(i.name.length>20){fileName=i.name.substr(0,20)+"..."}else{fileName=i.name}queue="#"+a(this).attr("id")+"Queue";if(j.data.queueID){queue="#"+j.data.queueID}a(queue).append('<div id="'+a(this).attr("id")+h+'" class="uploadifyQueueItem"><div class="cancel"><a href="javascript:jQuery(\'#'+a(this).attr("id")+"').uploadifyCancel('"+h+'\')"><img src="'+settings.cancelImg+'" border="0" /></a></div><span class="fileName">'+fileName+" ("+k+l+')</span><span class="percentage"></span><div class="uploadifyProgress"><div id="'+a(this).attr("id")+h+'ProgressBar" class="uploadifyProgressBar"><!--Progress Bar--></div></div></div>')}});if(typeof(settings.onSelectOnce)=="function"){a(this).bind("uploadifySelectOnce",settings.onSelectOnce)}a(this).bind("uploadifyQueueFull",{action:settings.onQueueFull},function(h,i){if(h.data.action(h,i)!==false){alert("The queue is full.  The max size is "+i+".")}});a(this).bind("uploadifyCheckExist",{action:settings.onCheck},function(m,l,k,j,o){var i=new Object();i=k;i.folder=e+j;if(o){for(var h in k){var n=h}}a.post(l,i,function(r){for(var p in r){if(m.data.action(m,l,k,j,o)!==false){var q=confirm("Do you want to replace the file "+r[p]+"?");if(!q){document.getElementById(a(m.target).attr("id")+"Uploader").cancelFileUpload(p,true,true)}}}if(o){document.getElementById(a(m.target).attr("id")+"Uploader").startFileUpload(n,true)}else{document.getElementById(a(m.target).attr("id")+"Uploader").startFileUpload(null,true)}},"json")});a(this).bind("uploadifyCancel",{action:settings.onCancel},function(l,h,k,m,j){if(l.data.action(l,h,k,m,j)!==false){var i=(j==true)?0:250;a("#"+a(this).attr("id")+h).fadeOut(i,function(){a(this).remove()})}});if(typeof(settings.onClearQueue)=="function"){a(this).bind("uploadifyClearQueue",settings.onClearQueue)}var c=[];a(this).bind("uploadifyError",{action:settings.onError},function(l,h,k,j){if(l.data.action(l,h,k,j)!==false){var i=new Array(h,k,j);c.push(i);a("#"+a(this).attr("id")+h+" .percentage").text(" - "+j.type+" Error");a("#"+a(this).attr("id")+h).addClass("uploadifyError")}});a(this).bind("uploadifyProgress",{action:settings.onProgress,toDisplay:settings.displayData},function(j,h,i,k){if(j.data.action(j,h,i,k)!==false){a("#"+a(this).attr("id")+h+"ProgressBar").css("width",k.percentage+"%");if(j.data.toDisplay=="percentage"){displayData=" - "+k.percentage+"%"}if(j.data.toDisplay=="speed"){displayData=" - "+k.speed+"KB/s"}if(j.data.toDisplay==null){displayData=" "}a("#"+a(this).attr("id")+h+" .percentage").text(displayData)}});a(this).bind("uploadifyComplete",{action:settings.onComplete},function(k,h,j,i,l){if(k.data.action(k,h,j,unescape(i),l)!==false){a("#"+a(this).attr("id")+h+" .percentage").text(" - Completed");a("#"+a(this).attr("id")+h).fadeOut(250,function(){a(this).remove()})}});if(typeof(settings.onAllComplete)=="function"){a(this).bind("uploadifyAllComplete",{action:settings.onAllComplete},function(h,i){if(h.data.action(h,i)!==false){c=[]}})}})},uploadifySettings:function(f,j,c){var g=false;a(this).each(function(){if(f=="scriptData"&&j!=null){if(c){var i=j}else{var i=a.extend(settings.scriptData,j)}var l="";for(var k in i){l+="&"+k+"="+escape(i[k])}j=l.substr(1)}g=document.getElementById(a(this).attr("id")+"Uploader").updateSettings(f,j)});if(j==null){if(f=="scriptData"){var b=unescape(g).split("&");var e=new Object();for(var d=0;d<b.length;d++){var h=b[d].split("=");e[h[0]]=h[1]}g=e}return g}},uploadifyUpload:function(b){a(this).each(function(){document.getElementById(a(this).attr("id")+"Uploader").startFileUpload(b,false)})},uploadifyCancel:function(b){a(this).each(function(){document.getElementById(a(this).attr("id")+"Uploader").cancelFileUpload(b,true,false)})},uploadifyClearQueue:function(){a(this).each(function(){document.getElementById(a(this).attr("id")+"Uploader").clearFileUploadQueue(false)})}})})(jQuery)};


/*	SWFObject v2.2 <http://code.google.com/p/swfobject/> 
	is released under the MIT License <http://www.opensource.org/licenses/mit-license.php> 
*/
var swfobject=function(){var D="undefined",r="object",S="Shockwave Flash",W="ShockwaveFlash.ShockwaveFlash",q="application/x-shockwave-flash",R="SWFObjectExprInst",x="onreadystatechange",O=window,j=document,t=navigator,T=false,U=[h],o=[],N=[],I=[],l,Q,E,B,J=false,a=false,n,G,m=true,M=function(){var aa=typeof j.getElementById!=D&&typeof j.getElementsByTagName!=D&&typeof j.createElement!=D,ah=t.userAgent.toLowerCase(),Y=t.platform.toLowerCase(),ae=Y?/win/.test(Y):/win/.test(ah),ac=Y?/mac/.test(Y):/mac/.test(ah),af=/webkit/.test(ah)?parseFloat(ah.replace(/^.*webkit\/(\d+(\.\d+)?).*$/,"$1")):false,X=!+"\v1",ag=[0,0,0],ab=null;if(typeof t.plugins!=D&&typeof t.plugins[S]==r){ab=t.plugins[S].description;if(ab&&!(typeof t.mimeTypes!=D&&t.mimeTypes[q]&&!t.mimeTypes[q].enabledPlugin)){T=true;X=false;ab=ab.replace(/^.*\s+(\S+\s+\S+$)/,"$1");ag[0]=parseInt(ab.replace(/^(.*)\..*$/,"$1"),10);ag[1]=parseInt(ab.replace(/^.*\.(.*)\s.*$/,"$1"),10);ag[2]=/[a-zA-Z]/.test(ab)?parseInt(ab.replace(/^.*[a-zA-Z]+(.*)$/,"$1"),10):0}}else{if(typeof O.ActiveXObject!=D){try{var ad=new ActiveXObject(W);if(ad){ab=ad.GetVariable("$version");if(ab){X=true;ab=ab.split(" ")[1].split(",");ag=[parseInt(ab[0],10),parseInt(ab[1],10),parseInt(ab[2],10)]}}}catch(Z){}}}return{w3:aa,pv:ag,wk:af,ie:X,win:ae,mac:ac}}(),k=function(){if(!M.w3){return}if((typeof j.readyState!=D&&j.readyState=="complete")||(typeof j.readyState==D&&(j.getElementsByTagName("body")[0]||j.body))){f()}if(!J){if(typeof j.addEventListener!=D){j.addEventListener("DOMContentLoaded",f,false)}if(M.ie&&M.win){j.attachEvent(x,function(){if(j.readyState=="complete"){j.detachEvent(x,arguments.callee);f()}});if(O==top){(function(){if(J){return}try{j.documentElement.doScroll("left")}catch(X){setTimeout(arguments.callee,0);return}f()})()}}if(M.wk){(function(){if(J){return}if(!/loaded|complete/.test(j.readyState)){setTimeout(arguments.callee,0);return}f()})()}s(f)}}();function f(){if(J){return}try{var Z=j.getElementsByTagName("body")[0].appendChild(C("span"));Z.parentNode.removeChild(Z)}catch(aa){return}J=true;var X=U.length;for(var Y=0;Y<X;Y++){U[Y]()}}function K(X){if(J){X()}else{U[U.length]=X}}function s(Y){if(typeof O.addEventListener!=D){O.addEventListener("load",Y,false)}else{if(typeof j.addEventListener!=D){j.addEventListener("load",Y,false)}else{if(typeof O.attachEvent!=D){i(O,"onload",Y)}else{if(typeof O.onload=="function"){var X=O.onload;O.onload=function(){X();Y()}}else{O.onload=Y}}}}}function h(){if(T){V()}else{H()}}function V(){var X=j.getElementsByTagName("body")[0];var aa=C(r);aa.setAttribute("type",q);var Z=X.appendChild(aa);if(Z){var Y=0;(function(){if(typeof Z.GetVariable!=D){var ab=Z.GetVariable("$version");if(ab){ab=ab.split(" ")[1].split(",");M.pv=[parseInt(ab[0],10),parseInt(ab[1],10),parseInt(ab[2],10)]}}else{if(Y<10){Y++;setTimeout(arguments.callee,10);return}}X.removeChild(aa);Z=null;H()})()}else{H()}}function H(){var ag=o.length;if(ag>0){for(var af=0;af<ag;af++){var Y=o[af].id;var ab=o[af].callbackFn;var aa={success:false,id:Y};if(M.pv[0]>0){var ae=c(Y);if(ae){if(F(o[af].swfVersion)&&!(M.wk&&M.wk<312)){w(Y,true);if(ab){aa.success=true;aa.ref=z(Y);ab(aa)}}else{if(o[af].expressInstall&&A()){var ai={};ai.data=o[af].expressInstall;ai.width=ae.getAttribute("width")||"0";ai.height=ae.getAttribute("height")||"0";if(ae.getAttribute("class")){ai.styleclass=ae.getAttribute("class")}if(ae.getAttribute("align")){ai.align=ae.getAttribute("align")}var ah={};var X=ae.getElementsByTagName("param");var ac=X.length;for(var ad=0;ad<ac;ad++){if(X[ad].getAttribute("name").toLowerCase()!="movie"){ah[X[ad].getAttribute("name")]=X[ad].getAttribute("value")}}P(ai,ah,Y,ab)}else{p(ae);if(ab){ab(aa)}}}}}else{w(Y,true);if(ab){var Z=z(Y);if(Z&&typeof Z.SetVariable!=D){aa.success=true;aa.ref=Z}ab(aa)}}}}}function z(aa){var X=null;var Y=c(aa);if(Y&&Y.nodeName=="OBJECT"){if(typeof Y.SetVariable!=D){X=Y}else{var Z=Y.getElementsByTagName(r)[0];if(Z){X=Z}}}return X}function A(){return !a&&F("6.0.65")&&(M.win||M.mac)&&!(M.wk&&M.wk<312)}function P(aa,ab,X,Z){a=true;E=Z||null;B={success:false,id:X};var ae=c(X);if(ae){if(ae.nodeName=="OBJECT"){l=g(ae);Q=null}else{l=ae;Q=X}aa.id=R;if(typeof aa.width==D||(!/%$/.test(aa.width)&&parseInt(aa.width,10)<310)){aa.width="310"}if(typeof aa.height==D||(!/%$/.test(aa.height)&&parseInt(aa.height,10)<137)){aa.height="137"}j.title=j.title.slice(0,47)+" - Flash Player Installation";var ad=M.ie&&M.win?"ActiveX":"PlugIn",ac="MMredirectURL="+O.location.toString().replace(/&/g,"%26")+"&MMplayerType="+ad+"&MMdoctitle="+j.title;if(typeof ab.flashvars!=D){ab.flashvars+="&"+ac}else{ab.flashvars=ac}if(M.ie&&M.win&&ae.readyState!=4){var Y=C("div");X+="SWFObjectNew";Y.setAttribute("id",X);ae.parentNode.insertBefore(Y,ae);ae.style.display="none";(function(){if(ae.readyState==4){ae.parentNode.removeChild(ae)}else{setTimeout(arguments.callee,10)}})()}u(aa,ab,X)}}function p(Y){if(M.ie&&M.win&&Y.readyState!=4){var X=C("div");Y.parentNode.insertBefore(X,Y);X.parentNode.replaceChild(g(Y),X);Y.style.display="none";(function(){if(Y.readyState==4){Y.parentNode.removeChild(Y)}else{setTimeout(arguments.callee,10)}})()}else{Y.parentNode.replaceChild(g(Y),Y)}}function g(ab){var aa=C("div");if(M.win&&M.ie){aa.innerHTML=ab.innerHTML}else{var Y=ab.getElementsByTagName(r)[0];if(Y){var ad=Y.childNodes;if(ad){var X=ad.length;for(var Z=0;Z<X;Z++){if(!(ad[Z].nodeType==1&&ad[Z].nodeName=="PARAM")&&!(ad[Z].nodeType==8)){aa.appendChild(ad[Z].cloneNode(true))}}}}}return aa}function u(ai,ag,Y){var X,aa=c(Y);if(M.wk&&M.wk<312){return X}if(aa){if(typeof ai.id==D){ai.id=Y}if(M.ie&&M.win){var ah="";for(var ae in ai){if(ai[ae]!=Object.prototype[ae]){if(ae.toLowerCase()=="data"){ag.movie=ai[ae]}else{if(ae.toLowerCase()=="styleclass"){ah+=' class="'+ai[ae]+'"'}else{if(ae.toLowerCase()!="classid"){ah+=" "+ae+'="'+ai[ae]+'"'}}}}}var af="";for(var ad in ag){if(ag[ad]!=Object.prototype[ad]){af+='<param name="'+ad+'" value="'+ag[ad]+'" />'}}aa.outerHTML='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'+ah+">"+af+"</object>";N[N.length]=ai.id;X=c(ai.id)}else{var Z=C(r);Z.setAttribute("type",q);for(var ac in ai){if(ai[ac]!=Object.prototype[ac]){if(ac.toLowerCase()=="styleclass"){Z.setAttribute("class",ai[ac])}else{if(ac.toLowerCase()!="classid"){Z.setAttribute(ac,ai[ac])}}}}for(var ab in ag){if(ag[ab]!=Object.prototype[ab]&&ab.toLowerCase()!="movie"){e(Z,ab,ag[ab])}}aa.parentNode.replaceChild(Z,aa);X=Z}}return X}function e(Z,X,Y){var aa=C("param");aa.setAttribute("name",X);aa.setAttribute("value",Y);Z.appendChild(aa)}function y(Y){var X=c(Y);if(X&&X.nodeName=="OBJECT"){if(M.ie&&M.win){X.style.display="none";(function(){if(X.readyState==4){b(Y)}else{setTimeout(arguments.callee,10)}})()}else{X.parentNode.removeChild(X)}}}function b(Z){var Y=c(Z);if(Y){for(var X in Y){if(typeof Y[X]=="function"){Y[X]=null}}Y.parentNode.removeChild(Y)}}function c(Z){var X=null;try{X=j.getElementById(Z)}catch(Y){}return X}function C(X){return j.createElement(X)}function i(Z,X,Y){Z.attachEvent(X,Y);I[I.length]=[Z,X,Y]}function F(Z){var Y=M.pv,X=Z.split(".");X[0]=parseInt(X[0],10);X[1]=parseInt(X[1],10)||0;X[2]=parseInt(X[2],10)||0;return(Y[0]>X[0]||(Y[0]==X[0]&&Y[1]>X[1])||(Y[0]==X[0]&&Y[1]==X[1]&&Y[2]>=X[2]))?true:false}function v(ac,Y,ad,ab){if(M.ie&&M.mac){return}var aa=j.getElementsByTagName("head")[0];if(!aa){return}var X=(ad&&typeof ad=="string")?ad:"screen";if(ab){n=null;G=null}if(!n||G!=X){var Z=C("style");Z.setAttribute("type","text/css");Z.setAttribute("media",X);n=aa.appendChild(Z);if(M.ie&&M.win&&typeof j.styleSheets!=D&&j.styleSheets.length>0){n=j.styleSheets[j.styleSheets.length-1]}G=X}if(M.ie&&M.win){if(n&&typeof n.addRule==r){n.addRule(ac,Y)}}else{if(n&&typeof j.createTextNode!=D){n.appendChild(j.createTextNode(ac+" {"+Y+"}"))}}}function w(Z,X){if(!m){return}var Y=X?"visible":"hidden";if(J&&c(Z)){c(Z).style.visibility=Y}else{v("#"+Z,"visibility:"+Y)}}function L(Y){var Z=/[\\\"<>\.;]/;var X=Z.exec(Y)!=null;return X&&typeof encodeURIComponent!=D?encodeURIComponent(Y):Y}var d=function(){if(M.ie&&M.win){window.attachEvent("onunload",function(){var ac=I.length;for(var ab=0;ab<ac;ab++){I[ab][0].detachEvent(I[ab][1],I[ab][2])}var Z=N.length;for(var aa=0;aa<Z;aa++){y(N[aa])}for(var Y in M){M[Y]=null}M=null;for(var X in swfobject){swfobject[X]=null}swfobject=null})}}();return{registerObject:function(ab,X,aa,Z){if(M.w3&&ab&&X){var Y={};Y.id=ab;Y.swfVersion=X;Y.expressInstall=aa;Y.callbackFn=Z;o[o.length]=Y;w(ab,false)}else{if(Z){Z({success:false,id:ab})}}},getObjectById:function(X){if(M.w3){return z(X)}},embedSWF:function(ab,ah,ae,ag,Y,aa,Z,ad,af,ac){var X={success:false,id:ah};if(M.w3&&!(M.wk&&M.wk<312)&&ab&&ah&&ae&&ag&&Y){w(ah,false);K(function(){ae+="";ag+="";var aj={};if(af&&typeof af===r){for(var al in af){aj[al]=af[al]}}aj.data=ab;aj.width=ae;aj.height=ag;var am={};if(ad&&typeof ad===r){for(var ak in ad){am[ak]=ad[ak]}}if(Z&&typeof Z===r){for(var ai in Z){if(typeof am.flashvars!=D){am.flashvars+="&"+ai+"="+Z[ai]}else{am.flashvars=ai+"="+Z[ai]}}}if(F(Y)){var an=u(aj,am,ah);if(aj.id==ah){w(ah,true)}X.success=true;X.ref=an}else{if(aa&&A()){aj.data=aa;P(aj,am,ah,ac);return}else{w(ah,true)}}if(ac){ac(X)}})}else{if(ac){ac(X)}}},switchOffAutoHideShow:function(){m=false},ua:M,getFlashPlayerVersion:function(){return{major:M.pv[0],minor:M.pv[1],release:M.pv[2]}},hasFlashPlayerVersion:F,createSWF:function(Z,Y,X){if(M.w3){return u(Z,Y,X)}else{return undefined}},showExpressInstall:function(Z,aa,X,Y){if(M.w3&&A()){P(Z,aa,X,Y)}},removeSWF:function(X){if(M.w3){y(X)}},createCSS:function(aa,Z,Y,X){if(M.w3){v(aa,Z,Y,X)}},addDomLoadEvent:K,addLoadEvent:s,getQueryParamValue:function(aa){var Z=j.location.search||j.location.hash;if(Z){if(/\?/.test(Z)){Z=Z.split("?")[1]}if(aa==null){return L(Z)}var Y=Z.split("&");for(var X=0;X<Y.length;X++){if(Y[X].substring(0,Y[X].indexOf("="))==aa){return L(Y[X].substring((Y[X].indexOf("=")+1)))}}}return""},expressInstallCallback:function(){if(a){var X=c(R);if(X&&l){X.parentNode.replaceChild(l,X);if(Q){w(Q,true);if(M.ie&&M.win){l.style.display="block"}}if(E){E(B)}}a=false}}}}();

(function(){
    var special = jQuery.event.special,
        uid1 = 'D' + (+new Date()),
        uid2 = 'D' + (+new Date() + 1);

    jQuery.event.special.focus = {
        setup: function() {
            var _self = this,
                handler = function(e) {
                    e = jQuery.event.fix(e);
                    e.type = 'focus';
                    if (_self === document) {
                        jQuery.event.handle.call(_self, e);
                    }
                };

            jQuery(this).data(uid1, handler);

            if (_self === document) {
                /* Must be live() */
                if (_self.addEventListener) {
                    _self.addEventListener('focus', handler, true);
                } else {
                    _self.attachEvent('onfocusin', handler);
                }
            } else {
                return false;
            }

        },
        teardown: function() {
            var handler = jQuery(this).data(uid1);
            if (this === document) {
                if (this.removeEventListener) {
                    this.removeEventListener('focus', handler, true);
                } else {
                    this.detachEvent('onfocusin', handler);
                }
            }
        }
    };

    jQuery.event.special.blur = {
        setup: function() {
            var _self = this,
                handler = function(e) {
                    e = jQuery.event.fix(e);
                    e.type = 'blur';
                    if (_self === document) {
                        jQuery.event.handle.call(_self, e);
                    }
                };

            jQuery(this).data(uid2, handler);

            if (_self === document) {
                /* Must be live() */
                if (_self.addEventListener) {
                    _self.addEventListener('blur', handler, true);
                } else {
                    _self.attachEvent('onfocusout', handler);
                }
            } else {
                return false;
            }

        },
        teardown: function() {
            var handler = jQuery(this).data(uid2);
            if (this === document) {
                if (this.removeEventListener) {
                    this.removeEventListener('blur', handler, true);
                } else {
                    this.detachEvent('onfocusout', handler);
                }
            }
        }
    };

})();


/*
 * JavaScript Pretty Date
 * Copyright (c) 2008 John Resig (jquery.com)
 * Licensed under the MIT license.
 */

// Takes an ISO time and returns a string representing how
// long ago the date represents.
function prettyDate(ztime){  
  var diff=parseInt(jQuery('#lastfetch').attr('val'))-parseInt(ztime);
  var day_diff=Math.floor(diff / 86400);
	return day_diff == 0 && (
		diff < 60 && "0 min" ||
		diff < 120 && "1 min" ||
		diff < 3600 && Math.floor( diff / 60 ) + " mins" ||
		diff < 7200 && "1 hr" ||
		diff < 86400 && Math.floor( diff / 3600 ) + " hrs") ||
		day_diff == 1 && "Yesterday" ||
		day_diff < 7 && day_diff + " days" ||
		day_diff < 31 && Math.ceil( day_diff / 7 ) + " weeks";
}

	
	
	
function StreamUp() {
  jQuery('#twix').hide();
  jQuery.streamfrom=jQuery('#lastfetch').attr('val');
  var i=0;
  var stream=Array();
  jQuery('.sli').each(function() {
    stream[i++]=jQuery(this).attr('id');
  });
  stream.sort();
  stream.reverse();
  jQuery.each(stream,function(b,a) {
    jQuery('#twi').append(jQuery('#'+a));
    var x=jQuery('#'+a);
    x.find('.tda').html(prettyDate(x.attr('id').replace("stri",""))+' <a class="rep" uli="'+x.attr('from')+'">R</a>');
    if (x.find('.mp').length!=1 && parseInt(jQuery('#modp').attr('val'))>0 && jQuery('#pts').attr('uid')!=x.attr('cuid') && x.attr('cuid')!='sys') {x.prepend('<div class="mp" cid="'+x.attr('cid')+'" cuid="'+x.attr('cuid')+'"></div>');}
    if (x.find('.cic').length!=1) {x.prepend('<div class="cic" id="ic'+x.attr('type')+'">');}
    x.find('b').attr('uli',x.attr('cuid'));
    x.find('b').addClass('dnyl');
  });
  
  jQuery.get("/ui/1889_twitter_shouts.php",function(data) {
    jQuery('#pretwi').remove();
    jQuery('#twi').prepend("<div id='pretwi'>"+data+"</div>");
  });



}

// Update function.  Run every second, doing random stuff
function up() {
  jQuery.up=jQuery.up-1; // first, count down another second

  // every second, update the progress ticker
  var hw=100/30*jQuery.up;
  jQuery('#tmrb').css({"width":(jQuery('#tmr').width()/30*jQuery.up)});
  
  if (jQuery('#rfpcounter').length!=0) {
    jQuery('#rfpcounter').html("Updating in "+jQuery.up+" &mdash; Do not refresh the whole page!");
    if (jQuery.up<=0) {
      jQuery('#cinside').load('/ploadinside?zs='+jQuery.tpage);
    }
  }

  
  // at the end of 60 seconds, run this...
  if (jQuery.up<=0) {
    jQuery.get("/ui/1889_tips.php",function(html) { // see if there are new tips
      if(html) { // if so, update 'em
        jQuery('#noti').html(html);
        jQuery('#noti').show();
        fs();
      } else { // if not, hide the notifier
        jQuery('#noti').hide();
        fs();
      }
    });
    
    jQuery('#pts').load("/ui/1889_points.php"); // update the points count
    if (jQuery('#twix').length==1) {
      jQuery('#twix').load("/ui/1889_twitter.php?from="+jQuery.streamfrom+"&back="+jQuery.streamback, StreamUp); // and the twitter stream
    }
    
    if (jQuery('.qsfocus').length!=1) {
      jQuery('#ql').load("/ui/lw/questions.php",function() {
      jQuery('.qs').each(function() {
        jQuery(this).addClass('def');
        jQuery(this).val(jQuery(this).attr('def'));
      });
    });
    }
  
    jQuery.get('/ui/lw/chapter.php',function(bata) {
      jQuery('#chn').html(bata);
    });
    
    jQuery('#chli').load("/ui/lw/record.php");
    jQuery('#lwrel').load("/ui/1889_relatedlink.php");


        
    jQuery.up=30; // set things back to 60 
  }
}


// function to resize various elements onscreen
function fs() {
  // define the variables
  var tl=jQuery('#tws').offset().top;
  var tlp=jQuery('#tw').offset().top;
  var tx=jQuery('#ud').offset().top;
  var sh=jQuery(window).height();
  var mh=sh-jQuery('#content').offset().top;

  // set heights
  jQuery('#tws').css({"height":sh-tl-jQuery('#dirstream').height()-jQuery('#socm').height()-30});
  jQuery('#ud').css({"height":sh-tx-(sh-tlp)-15});
  jQuery('#c').css({"height":sh-jQuery('#c').offset().top});
  $('#searchri').css({"height":jQuery(window).height()-jQuery('#searchri').offset().top-150});
  //jQuery('#content').css({"height":jQuery('#xg').height()});
  
  if (jQuery('#xg').height()>mh) { // if the content area inside a book is taller than the content window...
    $('#content').css({"height":sh-jQuery('#content').offset().top-30}); // grow the content window
  }
  

  if (jQuery('#allbg').height()<jQuery(window).height()) {
    jQuery('#allbg').css({"height":jQuery(window).height(),"width":"auto"});
  }

  if (jQuery('#allbg').width()<jQuery(window).width()) {
    jQuery('#allbg').css({"width":jQuery(window).width(),"height":"auto"});
  }

  
  // if the console is offscreen, we need to know before setting widths
  if (jQuery('#console').offset().left>=jQuery(window).width()) {
    var cswi=0;
  } else {
    var cswi=jQuery('#console').width();
  }
    
  // fix for small windows.  If the window width can't fit the console easily, we need to resize the content area
  if (jQuery(window).width()<jQuery('#c').offset().left+jQuery.pgw+cswi) {
    jQuery('#c').css({"width":jQuery(window).width()-jQuery('#c').offset().left-cswi-131}); // shrink the content window
    jQuery('#cb').css("left",jQuery('#c').offset().left+jQuery('#c').width()+80);
  } else {
    jQuery('#c').css({"width":jQuery.pgw-131}); // otherwise, leave things alone
    jQuery('#cb').css("left",jQuery.pgw);
  }
    
    //jQuery('#c').css({"left":(jQuery(window).width()-jQuery('#console').width()-jQuery('#c').width())/2});

  // scroll to top of page, since some browsers like to mess around with that
  jQuery(window).scrollTop(0);
}


// Function to active the mystery box.  Holy hell this is confusing
function mysteryOn() {
  if (jQuery.mode=="box") {
    jQuery('#orbitb,#prog,#count,.hint,#orbit,#hintspace').fadeOut(function(){
      jQuery('#orbit,#orbitb').css({"width":1,"height":1,"left":250,"bottom":250});
      jQuery('#box').animate({"bottom":0, "left":-40},function() {
        jQuery('#ma').fadeOut("fast",function() {jQuery('#ma').hide();});
        jQuery('#box').css({'z-index':10});
      });
    });
    jQuery.mode="";
  } else {
    jQuery('#mys').load("/ui/1889_mystery.php", function() {
      jQuery.mode="box";
      jQuery('#box').css({'z-index':505});
      jQuery('#orbit,#orbitb').css({"width":1,"height":1,"left":250,"bottom":250});
      jQuery('#ma').fadeIn(function() {
        jQuery('#box').animate({"bottom":100, "left":100},function(){
        jQuery('#ma').show();
        jQuery('#ma').css({"opacity":1});
        jQuery('#box').css({'z-index':505});
          jQuery('#orbit').animate({"width":400,"height":400,"left":50,"bottom":50},"slow");
          jQuery('#orbitb').animate({"width":300,"height":300,"left":100,"bottom":100},"slow",function() {
            jQuery('#prog,#count,.hint,#hintspace').fadeIn();
          });
        });
      });
    });
  }
}


// Here's where things get messy. Messier.  Shut up.
jQuery(document).ready(function() {

  // basic settings 
  if (jQuery("#cwid").length==1) {
    jQuery.pgw=parseInt(jQuery('#cwid').attr('cx'));
  } else {
    jQuery.pgw=560;
  }
  
  // EVERYWHERE FUNCTIONS //
  //////////////////////////
  
  fs(); // resize everything.
  
  // make some settings!
  jQuery.settings=new Array();
  
  jQuery.up=0; // this will let us refresh the content immediately
  up(); // this does the updating.
  
  $(window).resize(function() { fs(); }); // if we resize, we need to resize EVERYTHING
  
  // Google Analytics code
  var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
  jQuery.getScript(gaJsHost + "google-analytics.com/ga.js", function(){
    try {
      jQuery.pageTracker = _gat._getTracker("UA-8396657-1");
      jQuery.pageTracker._trackPageview();
    } catch(err) {}
  });
  
  // if the console is NOT offscreen, load the content
  if (jQuery('#console').offset().left==jQuery(window).width()-jQuery('#console').width()) {
    jQuery('#cin').load("/ui/1889_console.php?ver="+jQuery('#settings').attr('console'),function() {
        jQuery.streamback=jQuery('#loadup').attr('val')-(60*60*6);
        // LOAD MORE STREAM IF WE SCROLL LOW ENOUGH
        jQuery('#tws').scroll(function(){
          if  ($('#tws').scrollTop() == $('#twi').height() - $('#tws').height()){
            jQuery.streamback=parseInt(jQuery.streamback)-(60*60*6);
              jQuery('#twix').load("/ui/1889_twitter.php?from="+jQuery.streamfrom+"&back="+jQuery.streamback, StreamUp);
          //alert('bottom!');
              }
              //alert(jQuery('#twi').scrollTop()+"/"+jQuery('#twi *').height());
      });
    
      jQuery.up=0; up();
    });
  }
  
  
  
  
  
  
  
  // Go back home...
  jQuery('#cir').click(function() {
    document.location='http://1889.ca';
  });
  
  // track the mouse position for the infospot
  jQuery("*").mousemove(function(e){
    if (e.pageX>jQuery(window).width()/2) { // if we're on the right side of the screen, flip the infospot to the left of the cursor
      var offleft=-310;
    } else {
      offleft=10;
    }
    jQuery("#infospot").css({'position' : 'absolute', 'marginLeft' : e.pageX+offleft, 'marginTop' : e.pageY+20, 'z-index' : '999'}); // follow!
  });
  
  // When hovering over a scroller item, show infospot
  jQuery(".nim,.nimb").hover(function() {
    jQuery("#infospot").html(jQuery(this).find('.hs').html());
    jQuery("#infospot").show();
  }, function() {
    jQuery("#infospot").hide();
  });
    
  // When clicking on an item from a scroller, load the page  
  jQuery('.nim a, .nimb a').live("click",function() {
    move(jQuery(this).attr('id')); // the load id is in the ID attr
    return false;
  });
  
  // When you click a window's close box...
  jQuery('#cb').click(function() {
    jQuery.moved=0;
    offit();
  });


  // opening and closing the console
  jQuery('#csli').click(function() {
    if (jQuery.con!=1) { // if the console is open, close it
      jQuery('#nt').animate({"left":jQuery('#console').offset().left+260}); // move the next arrow, if it's there
      jQuery('#searchr').animate({"left":jQuery(window).width()-jQuery('#searchr').width()}); // move the search bar, if it's open
      jQuery('#console').animate({"right":-300},function() {jQuery('#cin').html('');}); // move the console itself and wipe it
      jQuery.con=1; // locally define the console as off
      jQuery('#lastfetch').attr('val',''); // wipe the last update value so we start from scratch again
      jQuery.streamfrom="";
      jQuery.get("/ui/1889_save.php?console=off"); // register the console as off
    } else {
      jQuery('#cin').load("/ui/1889_console.php?ver="+jQuery('#settings').attr('console'),function() { // first, load the console
        jQuery.streamback=jQuery('#loadup').attr('val');
        jQuery('#nt').animate({"left":jQuery('#console').offset().left-340}); // move the next arrow over if it's there.
        jQuery('#searchr').animate({"left":jQuery(window).width()-jQuery('#console').width()-jQuery('#searchr').width()}); // move the search bar left if necessary
        jQuery('#console').animate({"right":0}); // move the actual console over
        jQuery.get("/ui/1889_save.php?console=on"); // register the console as on
        jQuery.con=0; // locally register it as on
        jQuery.up=0; // update when ready
        up();
      });
    }
  });

  // Next stories in the slider
  jQuery('#nt').click(function() { 
    var hf=jQuery('#nin').css('marginLeft').replace("px", "");// get the current margin without px
    if (jQuery('#nin .nimb').size()==0) { // if we have nimbs, we're moving screens at a time
      var bw=jQuery(window).width()-jQuery('#console').width(); // get the amount we'd move
      jQuery('#nin').animate({"marginLeft":(hf-bw)}, "medium",function() { // move that much
        backbut();
        loadmore(); // load more stories, just in case.
      });
    } else { // otherwise, we're moving by elements
      jQuery('#nin').css("width",(jQuery('.nimb').width()+10)*jQuery('.nimb').size()); // extend the space as needed
      var bw=jQuery('.nimb').width()*3; // we're moving 3 at a time
      if (hf-bw+jQuery(window).width()-jQuery('#console').width()>bw*-1) { // if we're not going over the edge...
        jQuery('#nin').animate({"marginLeft":(hf-bw)}, "medium"); // slide it along
      } else if (hf*-1>0) { // otherwise, just align right
        jQuery('#nin').animate({"marginLeft":(jQuery('#nin').width()*-1)+jQuery(window).width()});
      }
    }
  });
  
  // Previous stories in the slider
  jQuery('#pt').click(function() {
    var hf=jQuery('#nin').css('marginLeft').replace("px", "");
    var bw=jQuery('body').width()-jQuery('#console').width();
    if (parseInt(bw)+parseInt(hf)>=0) { var mt=0; } else { var mt=parseInt(hf)+parseInt(bw); }
    jQuery('#nin').animate({"marginLeft":mt}, "medium",function() {
      backbut();
      loadmore();
    });
  });

  // Social media links...
  jQuery('#socm a').click(function() {
    if (jQuery(this).attr('id')!="feed" && jQuery('#ucode').val()!="") { // as long as this isn't the feed icon, and we have a usercode...
      var cdo="http://"+jQuery("#cdo").val(); // get this site's url
      if (jQuery.pgtype=="post") { // if we're looking at a post...
        cpo="http://1889.ca";
      } else { // or a book...
        cpo="http://books.1889.ca";
      }
      var mix=jQuery(this).attr('href').split('http%3A%2F%2F1889.ca'); // get the base of the url from the existing button
      var base=mix[0]; // just the first bit, of course
      if (window.location.hash.length>1) {
        var fixurl=str_replace('#','',cdo+'/'+cpo+window.location.hash).split("?"); // if there's a hash on the url already, split it
        fixurl=fixurl[0]; // we only want the stuff before the ?x=
      } else {
        var fixurl=str_replace("#","",cdo+'/'+window.location); // otherwise, just dump it straight
      }
      if (jQuery(this).attr("id")=="pml") { // if this is a permalink request...
        jQuery.get(fixurl+"@"+jQuery('#ucode').val(),function(data) {
          alert("The link to this page is: \n "+data); // tell us
        });
      } else if (jQuery(this).attr('id')!="sul") { // if this isn't stumbleupon...
        jQuery.get(fixurl+"@"+jQuery('#ucode').val(),function(data) {
          document.location=base+data; // go to the new url with the short url
        });
      } else {
        var turl=str_replace('#','','http://1889.ca'+window.location.hash).split("?");
        document.location="http://www.stumbleupon.com/submit?url="+turl[0]; // otherwise, go straight to the stumbleupon url
      }
      return false;
    }
  });



  // MAIN SITE FUNCTIONS //
  /////////////////////////
  
  jQuery.dis=1; // this tells us how many stories are loaded in the scroller by default  
  
  // Next books when the list is vertical
  jQuery('#nb').click(function() {
    var hf=jQuery('#bi').css('marginTop').replace("px", "");
    var bw=jQuery('#bi .nimb').height();
    jQuery('#bi').animate({"marginTop":(parseInt(hf)-150)}, "medium",function() {
      jQuery('#bi .nimb').filter(':first').clone(true).insertAfter(jQuery('#bi .nimb').filter(':last'));
      jQuery('#bi .nimb').filter(':first').remove();
      jQuery('#bi').css("marginTop",parseInt(hf));
    });
  });
  
  // Previous books when the list is vertical
  jQuery('#pb').click(function() {
    var hf=jQuery('#bi').css('marginTop').replace("px", "");
    var bw=jQuery('#bi .nimb').height();
    jQuery('#bi').animate({"marginTop":(parseInt(hf)+150)}, "medium",function() {
      jQuery('#bi .nimb').filter(':last').clone(true).insertBefore(jQuery('#bi .nimb').filter(':first'));
      jQuery('#bi .nimb').filter(':last').remove();
      jQuery('#bi').css("marginTop",parseInt(hf));
    });
  });
  
  // Mystery box!
  jQuery('#box').click(mysteryOn);
  
  // commenting (sigh)
  jQuery('.comment-reply-link').live("click",function() {
    jQuery('#ct').load(jQuery(this).attr('href'));
    return false;
  });

 jQuery('#cancel-comment-reply-link').live("click",function() {
    jQuery('#ct').load(jQuery(this).attr('href'));
    return false;
  });
  
  jQuery('#commentform #submit').live("click",function() {
    var exo="";
    jQuery('#commentform').find('input,textarea').each(function() { // for each item in the list...
        if (jQuery(this).val()!='') { // as long as the value isn't empty
          exo+=jQuery(this).attr('id')+'='+jQuery(this).val()+'&'; // add it to the query string
        }
      });

     jQuery.ajax({
      type: "POST",
      url: jQuery('#commentform').attr('action'), // submit the choice
      data: exo,
      success: function(html){
        jQuery('#ct').load(jQuery('#cancel-comment-reply-link').attr('href')); // dump the content back
      }
    });
    return false;
  });



  
  
  
  // 1889 BOOKS FUNCTIONS //
  //////////////////////////

  // Book-reading Meta Window functions
  if (jQuery('#meta').length==1) {
    jQuery.con=1; // turn the meta window on
    jQuery('#console').css({"right":jQuery('#console').width()*-1}); // turn off the console when reading books
    jQuery.get("/ui/1889_save.php?console=off"); // update prefs to confirm this in the future
  }

  
  // 1889 Books Purchasing Stuff //
  jQuery('#morepayment').click(function() { // activate the points stuff when buying
    jQuery('.mpd').show();
  });
  
  
  

  
  
  // PROMOTION ENGINE //
  //////////////////////
  
  // When you click on a "promote" button for a comment...
  jQuery('.mp').live("click",function() {
    if (jQuery('#mdp').html()!="") {
      jQuery('#mdp').html('');
      jQuery('#mdp').hide();
    } else {
      jQuery.cid=jQuery(this).attr('cid'); // globally define the comment id
      jQuery.cuid=jQuery(this).attr('cuid'); // and the user's id
      jQuery('#mdp').load("/ui/1889_badge.php",function() { // load the display window
        jQuery(this).css({"bottom":10});
        jQuery(this).show();
      });
    } 
  });
  
  // After choosing a moderation options...
  jQuery('.qcl').live("click",function() {
    jQuery.ajax({
      type: "POST",
      url: "/ui/1889_twitter.php?from="+jQuery.streamfrom+"&back="+jQuery.streamback, // submit the choice
      data: "promote="+jQuery.cuid+"&cuid="+jQuery.cid+"&with="+jQuery(this).html(),
      success: function(html){
        jQuery("#twix").html(html);
        jQuery('#mdp').hide(); // get rid of the window
        jQuery('#mdp').html(''); // and erase the guts
        streamUp();
        jQuery.up=0; // update everything, because you may be out of mod points
      }
    });
  });


  // BADGE SYSTEM //
  //////////////////
  
  // If we add a badge...
  jQuery('#addbadge').live("click",function() {
    jQuery('#ud').scrollTop(0);
    frm(jQuery(this),"/ui/1889_badge_make.php");
  });

  jQuery('#savelist').live("click",function() {
    jQuery('#ud').scrollTop(0);
    frm(jQuery(this),"/ui/1889_badge_list.php");
  });

  jQuery('#answertrivia').live("click",function() {
    jQuery('#ud').scrollTop(0);
    frm(jQuery(this),"/ui/1889_trivia_tag.php");
  });
  
  /*jQuery('#trivianext').live("keyup",function() {
    if (jQuery.nogo[jQuery(this).val()]==1) {
      jQuery('#trivianextbut').hide();
    } else {
      jQuery('#trivianextbut').show();
    }
  });
  */
  
  jQuery('#trivianextbut').live("click",function() {
    jQuery('#ud').scrollTop(0);
    frm(jQuery(this),"/ui/1889_trivia_tag.php");
  });

  jQuery('.badge').live("click",function() {
    jQuery('#ud').load("/ui/1889_badge_detail.php?q="+jQuery(this).attr('sd'));
  });
  
  jQuery('.qqb').live("click",function() {
    jQuery('#'+jQuery(this).attr('where')).load(jQuery(this).attr('what'));
  });
  
  jQuery('#sbbu').live("click",function() {
    jQuery('#twss').animate({scrollTop:jQuery('#twss').scrollTop()-jQuery('#twss').height()});  
  });
  jQuery('#sbbd').live("click",function() {
    jQuery('#twss').animate({scrollTop:jQuery('#twss').scrollTop()+jQuery('#twss').height()});  
  });
  
    // resize the content window ONCE (need to fix later) 
    var sh=jQuery(window).height();   
    //$('#content').css({"height":sh-jQuery('#content').offset().top-30}); // grow the content window


// IFFY STUFF
  
/*  jQuery('#ptsrd').click(function() {
      jQuery('#ud').load('/ui/1889_user_spend.php', function() {
        jQuery.ud=1;
        jQuery('#emf').focus();
      });
  });

*/

  // CONSOLE THINGS //
  ////////////////////

  // Tab control
  jQuery('#tb a').live("click",function() { // click on a tab and...
    var a=jQuery(this);
    jQuery('.ddm').hide();
    if (jQuery(this).attr('do')) {
      var c=jQuery('#'+jQuery(this).attr('do'));
      c.css({"left":a.offset().left-jQuery('#console').offset().left, "top":jQuery('#ud').offset().top});
      c.show();
      
    } else {
      jQuery('#ud').load("/ui/1889_"+jQuery(this).attr('go')+".php"); // go to the corresponding page
    }
    jQuery('#tb a').removeClass('tbon'); // flip around classes
    jQuery(this).addClass('tbon');
  });
  
  jQuery('.ddmi').live("click",function() {
    jQuery('#ud').load("/ui/1889_"+jQuery(this).attr('go')+".php");
    jQuery(this).parent().hide();
  });

jQuery('.gomo').live("click",function() {
    jQuery('#ud').load("/ui/"+jQuery(this).attr('go'));
  });

  
  // sliding open more content below items
  jQuery('.ncc b').live("click",function() {
    jQuery(this).parent().find('.rco').slideToggle();
  });

              // getting more info about something
              jQuery('#usercode').live("click",function() {
                jQuery('#usercodedetail').toggle();
              });
  
              // Editing items inline  
              jQuery('#utwi').live("click",function() {
                if (jQuery.utwi!=1) {
                  jQuery.utwi=1;
                  jQuery(this).html('<input id="utwiV" value="'+jQuery(this).html()+'" />');
                  jQuery('#utwiV').focus();
                }
              });
              
              jQuery('#utwiV').live("blur",function() {
                jQuery.utwi=0;
                jQuery('#utwi').html(jQuery(this).val());
              });
            
              jQuery('#ucom').live("click",function() {
                if (jQuery.ucom!=1) {
                  jQuery.ucom=1;
                  jQuery(this).html('<input id="ucomV" value="'+jQuery(this).html()+'" />');
                  jQuery('#ucomV').focus();
                }
              });
              
              jQuery('#ucomV').live("blur",function() {
                jQuery.ucom=0;
                jQuery('#ucom').html(jQuery(this).val());
              });
              
  // If we click on a comment link, we need to see that comment in action
  jQuery('.stcomment').live("click",function() {
    ldPg(jQuery(this).attr('link'));
  });

  // If we click on a user name, see the user's profile  
  jQuery('.dnyl').live("click",function() {
    jQuery('#ud').load('/ui/1889_user_profile.php?u='+jQuery(this).attr('uli'));
    return false;
  });
  
  jQuery('.rep').live("click",function() {
    jQuery('#dirst').focus();
    jQuery('#dirst').val('@'+jQuery(this).attr('uli')+": ");
    
    return false;
  });
  
  function addToStream() {
    var myv=jQuery('#dirst').val();
    jQuery('#dirst').val('');
    if (myv.length>0) {
      jQuery.ajax({
        type: "POST",
        url: "/ui/1889_twitter.php?back="+jQuery.streamback,
        data: ({"dirt":myv}),
        dataType: "html",
        success: function(html){
          jQuery('#twix').html(html);
          StreamUp();
        } 
      });  
    }
}



  jQuery('#addirt').live("click",function() {
    addToStream();
  });

  
  $('#dirst').live("keyup", function(e) {
    var code = (e.keyCode ? e.keyCode : e.which);
     if(code == 13) { //Enter keycode
       addToStream();
     }  
  });

  
  // Logging out
  jQuery('#logout').live("click",function() {
    document.location="/?logout=1";
  });
  
  // Click to switch to logging in...
  jQuery('#login').live("click",function() {
    jQuery('#register').removeClass('htabon');
    jQuery(this).addClass('htabon');
    jQuery('#registertab').hide();
    jQuery('#registerb').hide();
    jQuery('#loginb').show();
    jQuery('#lido').val('login');
    jQuery('#emf').focus();
  });

  // Click to switch to registering...
  jQuery('#register').live("click",function() {
    jQuery('#login').removeClass('htabon');
    jQuery(this).addClass('htabon');
    jQuery('#registertab').show();
    jQuery('#registerb').show();
    jQuery('#loginb').hide();
    jQuery('#lido').val('register');
    jQuery('#emf').focus();
  });
  
  
  // GETTING POINTS //
  ////////////////////
  
  // Adding a review
  jQuery('#addreview').live("click",function() {
    jQuery.ajax({
      type: "POST",
      url: "/ui/1889_cookiejar_catcher.php",
      data: "reviewurl="+jQuery('#addreviewurl').val()+"&type="+jQuery('#addreviewtype').val()+"&for="+jQuery('#addreviewfor').val(),
      success: function(html){
        jQuery('#reviewspace').html(html);
      }
    });    
  })
  
  // Handle any littler requests in the points pane
  jQuery('.pttra').live("click",function() {
    frm(jQuery(this),"/ui/1889_cookiejar_catcher.php");
  })
    
              jQuery('#ctrago').click(function(){
                document.location=jQuery('#ctraurl').val()+jQuery('#ctra').val();
              });
                
              jQuery('.hinton').live("click",function() {
                  jQuery('#hintspace').html("<h2>Hint #"+jQuery(this).attr('h')+"</h2>"+jQuery(this).find('i').html());
              });
  
  
  jQuery('#searchform').submit(function() {
    jQuery('#searchri').html('');
    jQuery('#searchr').fadeIn("fast",function() {
     // alert("/?ns=1&theme=1889_2010&s="+jQuery("#s").val());
    jQuery('#searchri').load("/ui/1889_search.php?ns=1&s="+jQuery("#s").val());
    jQuery('#searchri').css({"height":jQuery(window).height()-jQuery('#searchri').offset().top-150});
    });
    return false;
  });
  jQuery('#searchri').css({"height":jQuery(window).height()-jQuery('#searchri').offset().top-150});
  jQuery('#searchr').css({"left":jQuery('#console').offset().left-jQuery('#searchr').width()});
  jQuery('#s').blur(function() {
    if (jQuery(this).val()=="") {
      jQuery('#searchr').fadeOut();
    }
  });
  
  jQuery('#searchr a').live("click",function() {
    jQuery('#ct').html('');
    ldPg(jQuery(this).attr('sd'),jQuery(this).attr('iil'));
    return false;
  });
  
  
  jQuery('.fileupload').live("load",function() {
    alert('ready');
  });
  
  
  jQuery('.cbv').live("click",function() {
    if (jQuery(this).val()==1) {jQuery(this).val('0');} else {jQuery(this).val('1');}
  });
  
  
    
  jQuery('.qs').live("focus",function() {
    if (jQuery(this).val()==jQuery(this).attr('def')) {
      jQuery(this).removeClass('def');
      jQuery(this).addClass('qsfocus');
      jQuery(this).val('');
    }
  });
  
  jQuery('.qs').live("blur",function() {
    var myv=str_replace(" ","",jQuery(this).val());
    if (myv=="") {
      jQuery(this).addClass('def');
      jQuery(this).removeClass('qsfocus');
      jQuery(this).val(jQuery(this).attr('def'));
    }
  });

  jQuery('.sgi').live("click",function() {
    var gv=jQuery(this).attr('rid');
    var ev=jQuery('#'+gv).val();
    if (ev.length>0 && ev!=jQuery('#'+gv).attr('def')) {
      jQuery('#'+gv).val("Processing...");
      
      
      jQuery.ajax({
        type: "POST",
        url: "/ui/1889_twitter.php?t=ps",
        data: ({"sugg":"#"+gv+": "+ev,"suggpro":jQuery('#pro').val(),"suggid":gv}),
        dataType: "html",
        success: function(html){
          jQuery('#pst').html(html);
          jQuery('#'+gv).val(jQuery('#'+gv).attr('def'));
          jQuery('#'+gv).addClass('def');
        }
      });  
    }
  });
  

  jQuery('.addlwlink').live("click",function() {
    var ev=jQuery('#lwlink').val();
    var urlv=jQuery('#lwurl').val();
    if (ev.length>0) {
      jQuery.ajax({
        type: "POST",
        url: "/ui/1889_relatedlink.php",
        data: ({"dirt":ev,"url":urlv}),
        dataType: "html",
        success: function(html){
          jQuery('#lwrel').html(html);
          jQuery('#'+gv).val('');
        }
      });  
    }
  });
  

  jQuery('.loadchap').live("click",function() {
  var pid=jQuery(this).attr('cid');
    jQuery('#c').show();
  jQuery('#c').css({"opacity":1});
  jQuery('#c').animate({"top":60, "height":310},"medium", function() {
    jQuery('#ct').load("/ui/bookrsc/pages/inside.php?q="+jQuery('#pro').val()+"&t=en&p="+pid,function() {
      jQuery('#ci').hide();
    jQuery('#ct').css({"paddingTop":30});
    jQuery('#content').scrollTop(0);
      jQuery('.loadchap').removeClass('on');
      jQuery(this).addClass('on');
      jQuery('#ct').css({"height":"auto"});
      jQuery('#ct,#content').css({"width":jQuery.defwid});
      jQuery('#content').css({"left":(jQuery(window).width()/2)-(jQuery('#content').width()/2)});
      fs();
      jQuery.pageTracker._trackPageview('/'+jQuery('#pro').val()+'/en');
    });
  });
  });
  
  
  jQuery("#vote").submit(formProcess); // setup the submit handler
  jQuery("#addvote").click(addEntry); // setup the submit handler




  
});


function formProcess(event){
  event.preventDefault();
  var id = jQuery("input[@name='poll']:checked").attr("value");
  if (id) { 
    var chap=jQuery("#chp").attr("value");
    id = id.replace("opt",'');
    jQuery("#votecontainer").fadeOut("slow",function(){
      jQuery(this).empty();
      jQuery(this).show();
      jQuery(this).load("/ui/voting/display.php?c="+chap+"&v="+id);
    });
  }
}

function addEntry() {
  var id = jQuery("#addentry").attr("value");
  if (id) {
    jQuery("#votecontainer").fadeOut("slow",function(){
      jQuery(this).empty();
      jQuery(this).show();
      var chap=jQuery("#chp").attr("value");
      chap=escape(chap);encodeURIComponent
      jQuery.ajax({
        type: "POST",
        url: "/ui/voting/display.php",
        data: "c="+chap+"&a="+id,
        success: function(msg){
          jQuery("#votecontainer").load("/ui/voting/display.php?c="+chap);
        }
      });
    });
  }
}


function str_replace (search, replace, subject) {
  var result = '';
  var oldi = 0;
  for (i = subject.indexOf (search); i > -1; i = subject.indexOf (search, i)) {
    result += subject.substring (oldi, i);
    result += replace;
    i += search.length;
    oldi = i;
  }
  return result + subject.substring (oldi, subject.length);
}



function offit(idz) {
  window.location.hash='';
  jQuery('#cb').hide();
  jQuery('#c').animate({"top":119, "height":150,"width":230},"medium", function() {
    jQuery('#c').fadeOut("medium",function() {
      jQuery('#ct').html('');
      document.title="1889.ca";
        if (idz) {
          move(idz);
        }
    });
  });
}

/*function cpic(idz) {
    if (jQuery.moved==1) {
      offit(idz);
    } else {
      move(idz);
    }
    return false;
}
*/


function loadmore() {
  // load more stories if needed
  var bw=jQuery('body').width();
  var hl=jQuery('#nin').width();
  var hf=jQuery('#nin').css('marginLeft').replace("px", "");
  var rem=parseFloat(hl)+parseFloat(hf)-parseFloat(bw)-(parseFloat(bw));
  if (rem<bw) {
    jQuery.dis=jQuery.dis+9;
    jQuery.get('/rim?rio='+jQuery.dis,function(data){ 
      jQuery(data).appendTo('#nin'); 
      jQuery('#nin').css("width",((351*(jQuery.dis+10))+100));
    }); 
  }
}

function backbut() {
  if (jQuery('#nin').css('marginLeft').replace("px", "")<0) {jQuery('#pt').fadeIn();} else {jQuery('#pt').hide();} // if we can move back, add that arrow.  otherwise hide it
}


function move(idz) {
    jQuery.moved=1;
    //var im=jQuery('#'+idz).attr("im");
    var im=jQuery('#'+idz).find('img').attr('src');
    var im=str_replace('-350px','-550px',im);

    // move the bar over
    var imp=jQuery('#'+idz).offset();
    var spp=jQuery('#nin').css('marginLeft').replace("px", "");
    jQuery('#nin').animate({"marginLeft":(spp-imp.left+50)}, "medium",function() {
      backbut();
      jQuery('#ci').css("backgroundImage",'url('+im+')');
      if (im.length>1) { 
        jQuery('#ci').css({"height":260});
      } else {
        jQuery('#ci').css({"height":10});
      }

      jQuery('#c').show();
      $.load=1;  
      addTweak("ct");
      ldPg(idz,jQuery('#'+idz).attr('im'));
    });
}

function ldPg(idz,im) {
  if (idz*1==idz) { 
    jQuery.pgtype="post";
    var ww=430;
    var ur="/pload?zs="+idz;
    var ti="1889.ca";
    jQuery('.post-edit-link').attr('href','/wp-admin/post.php?action=edit&post='+idz);
    var slug=jQuery('#'+idz).attr('href')+'?x='+jQuery('#'+idz).attr('id');
    var cbs=560;
    loadmore();
    if (im) { 
      jQuery('#ci').css({"height":260});
      jQuery('#ci').css("backgroundImage",'url('+im+')');
      jQuery('#ci').show();
    } else {
      jQuery('#ci').css({"height":10});
      jQuery('#ci').css("backgroundImage",'');
    }
  } else {
    jQuery.pgtype="book";
    var ww=600;
    var ur="/rsc/pages/book.php?q="+idz;
    var ti="1889 Books";
    var slug="/"+jQuery('#'+idz).attr('id')+'?x=/'+jQuery('#'+idz).attr('id');
    var cbs=730;
    jQuery('#ci').hide();
  }
  
    jQuery.tpage=idz;

  jQuery.pgw=cbs;
  jQuery('#c').show();
  jQuery('#c').css({"opacity":1});
  jQuery('#c').animate({"top":60, "height":310,"width":ww},"medium", function() {
    jQuery("#ct").load(ur, function() {
      $.load=0;
      document.title=ti+" | "+jQuery("#ct h1").html();
      var slugb=slug.split("=");
      jQuery.pageTracker._trackPageview('/'+slugb[1]);
      window.location.hash=slug;
      jQuery('#c').animate({"height":jQuery(window).height()-60},"fast",function() {
        jQuery('#c').css("overflow-y","auto");
        jQuery('#cb').css("left",cbs);
        jQuery('#cb').fadeIn();   
            
      });
    });
  });
}

  
/*  function addTweak() {
    jQuery('#ct').html("<div id='rsi'></div><div id='rsl'>Loading...</div>");
    jQuery('#rsi').animate({marginLeft:100,opacity:0},3000, function() {
      jQuery('#rsi').css({marginLeft:0,opacity:1});
      jQuery('#rsi').animate({marginLeft:100,opacity:0},3000);
    });
  }
*/  
    function addTweak(t) {
      if ($.load==1) {
        jQuery('#'+t).html("<div id='rsi'></div>");
        jQuery('#'+t+' #rsi').animate({marginLeft:100,opacity:0},3000, function() {
          jQuery('#'+t+' #rsi').css({marginLeft:0,opacity:1});
          addTweak(t);
        });
      }
    }


  
  function frm(dis,url) {
    var exo='';
    var nix=0;
    var b=dis;
    b.parent().parent().find('input,select,textarea').each(function() { // for each item in the list...
      if (jQuery(this).attr('type')=="file") {

      }
      if (jQuery(this).val()!='') { // as long as the value isn't empty
        exo+=jQuery(this).attr('id')+'='+jQuery(this).val()+'&'; // add it to the query string
      } else {
        var nix=1;
      }
    });
    if (nix==0) { // as long as there are no nix marks (meaning it's all filled in)
      jQuery.ajax({
        type: "POST",
        enctype: 'multipart/form-data',
        url: url, // submit it
        data: exo,
        timeout: 5000,
        success: function(html){
          b.parent().parent().html(html); // replace all this space with a success report
        },
        error: function(request,error) {
          frm(dis,url);
        }
      }); 
    }
  }
  
  setInterval("up()",1000);

