//MooTools More, <http://mootools.net/more>. Copyright (c) 2006-2009 Aaron Newton <http://clientcide.com/>, Valerio Proietti <http://mad4milk.net> & the MooTools team <http://mootools.net/developers>, MIT Style License.

MooTools.More={version:"1.2.3.1"};Fx.Elements=new Class({Extends:Fx.CSS,initialize:function(b,a){this.elements=this.subject=$$(b);this.parent(a);},compute:function(g,h,j){var c={};
for(var d in g){var a=g[d],e=h[d],f=c[d]={};for(var b in a){f[b]=this.parent(a[b],e[b],j);}}return c;},set:function(b){for(var c in b){var a=b[c];for(var d in a){this.render(this.elements[c],d,a[d],this.options.unit);
}}return this;},start:function(c){if(!this.check(c)){return this;}var h={},j={};for(var d in c){var f=c[d],a=h[d]={},g=j[d]={};for(var b in f){var e=this.prepare(this.elements[d],b,f[b]);
a[b]=e.from;g[b]=e.to;}}return this.parent(h,j);}});var Accordion=Fx.Accordion=new Class({Extends:Fx.Elements,options:{display:0,show:false,height:true,width:false,opacity:true,fixedHeight:false,fixedWidth:false,wait:false,alwaysHide:false,trigger:"click",initialDisplayFx:true},initialize:function(){var c=Array.link(arguments,{container:Element.type,options:Object.type,togglers:$defined,elements:$defined});
this.parent(c.elements,c.options);this.togglers=$$(c.togglers);this.container=document.id(c.container);this.previous=-1;if(this.options.alwaysHide){this.options.wait=true;
}if($chk(this.options.show)){this.options.display=false;this.previous=this.options.show;}if(this.options.start){this.options.display=false;this.options.show=false;
}this.effects={};if(this.options.opacity){this.effects.opacity="fullOpacity";}if(this.options.width){this.effects.width=this.options.fixedWidth?"fullWidth":"offsetWidth";
}if(this.options.height){this.effects.height=this.options.fixedHeight?"fullHeight":"scrollHeight";}for(var b=0,a=this.togglers.length;b<a;b++){this.addSection(this.togglers[b],this.elements[b]);
}this.elements.each(function(e,d){if(this.options.show===d){this.fireEvent("active",[this.togglers[d],e]);}else{for(var f in this.effects){e.setStyle(f,0);
}}},this);if($chk(this.options.display)){this.display(this.options.display,this.options.initialDisplayFx);}},addSection:function(d,b){d=document.id(d);
b=document.id(b);var e=this.togglers.contains(d);this.togglers.include(d);this.elements.include(b);var a=this.togglers.indexOf(d);d.addEvent(this.options.trigger,this.display.bind(this,a));
if(this.options.height){b.setStyles({"padding-top":0,"border-top":"none","padding-bottom":0,"border-bottom":"none"});}if(this.options.width){b.setStyles({"padding-left":0,"border-left":"none","padding-right":0,"border-right":"none"});
}b.fullOpacity=1;if(this.options.fixedWidth){b.fullWidth=this.options.fixedWidth;}if(this.options.fixedHeight){b.fullHeight=this.options.fixedHeight;}b.setStyle("overflow","hidden");
if(!e){for(var c in this.effects){b.setStyle(c,0);}}return this;},display:function(a,b){b=$pick(b,true);a=($type(a)=="element")?this.elements.indexOf(a):a;
if((this.timer&&this.options.wait)||(a===this.previous&&!this.options.alwaysHide)){return this;}this.previous=a;var c={};this.elements.each(function(f,e){c[e]={};
var d=(e!=a)||(this.options.alwaysHide&&(f.offsetHeight>0));this.fireEvent(d?"background":"active",[this.togglers[e],f]);for(var g in this.effects){c[e][g]=d?0:f[this.effects[g]];
}},this);return b?this.start(c):this.set(c);}});Fx.Scroll=new Class({Extends:Fx,options:{offset:{x:0,y:0},wheelStops:true},initialize:function(b,a){this.element=this.subject=document.id(b);
this.parent(a);var d=this.cancel.bind(this,false);if($type(this.element)!="element"){this.element=document.id(this.element.getDocument().body);}var c=this.element;
if(this.options.wheelStops){this.addEvent("start",function(){c.addEvent("mousewheel",d);},true);this.addEvent("complete",function(){c.removeEvent("mousewheel",d);
},true);}},set:function(){var a=Array.flatten(arguments);this.element.scrollTo(a[0],a[1]);},compute:function(c,b,a){return[0,1].map(function(d){return Fx.compute(c[d],b[d],a);
});},start:function(c,h){if(!this.check(c,h)){return this;}var e=this.element.getSize(),f=this.element.getScrollSize();var b=this.element.getScroll(),d={x:c,y:h};
for(var g in d){var a=f[g]-e[g];if($chk(d[g])){d[g]=($type(d[g])=="number")?d[g].limit(0,a):a;}else{d[g]=b[g];}d[g]+=this.options.offset[g];}return this.parent([b.x,b.y],[d.x,d.y]);
},toTop:function(){return this.start(false,0);},toLeft:function(){return this.start(0,false);},toRight:function(){return this.start("right",false);},toBottom:function(){return this.start(false,"bottom");
},toElement:function(b){var a=document.id(b).getPosition(this.element);return this.start(a.x,a.y);},scrollIntoView:function(c,e,d){e=e?$splat(e):["x","y"];
var h={};c=document.id(c);var f=c.getPosition(this.element);var i=c.getSize();var g=this.element.getScroll();var a=this.element.getSize();var b={x:f.x+i.x,y:f.y+i.y};
["x","y"].each(function(j){if(e.contains(j)){if(b[j]>g[j]+a[j]){h[j]=b[j]-a[j];}if(f[j]<g[j]){h[j]=f[j];}}if(h[j]==null){h[j]=g[j];}if(d&&d[j]){h[j]=h[j]+d[j];
}},this);if(h.x!=g.x||h.y!=g.y){this.start(h.x,h.y);}return this;}});Fx.Slide=new Class({Extends:Fx,options:{mode:"vertical"},initialize:function(b,a){this.addEvent("complete",function(){this.open=(this.wrapper["offset"+this.layout.capitalize()]!=0);
if(this.open&&Browser.Engine.webkit419){this.element.dispose().inject(this.wrapper);}},true);this.element=this.subject=document.id(b);this.parent(a);var c=this.element.retrieve("wrapper");
this.wrapper=c||new Element("div",{styles:$extend(this.element.getStyles("margin","position"),{overflow:"hidden"})}).wraps(this.element);this.element.store("wrapper",this.wrapper).setStyle("margin",0);
this.now=[];this.open=true;},vertical:function(){this.margin="margin-top";this.layout="height";this.offset=this.element.offsetHeight;},horizontal:function(){this.margin="margin-left";
this.layout="width";this.offset=this.element.offsetWidth;},set:function(a){this.element.setStyle(this.margin,a[0]);this.wrapper.setStyle(this.layout,a[1]);
return this;},compute:function(c,b,a){return[0,1].map(function(d){return Fx.compute(c[d],b[d],a);});},start:function(b,e){if(!this.check(b,e)){return this;
}this[e||this.options.mode]();var d=this.element.getStyle(this.margin).toInt();var c=this.wrapper.getStyle(this.layout).toInt();var a=[[d,c],[0,this.offset]];
var g=[[d,c],[-this.offset,0]];var f;switch(b){case"in":f=a;break;case"out":f=g;break;case"toggle":f=(c==0)?a:g;}return this.parent(f[0],f[1]);},slideIn:function(a){return this.start("in",a);
},slideOut:function(a){return this.start("out",a);},hide:function(a){this[a||this.options.mode]();this.open=false;return this.set([-this.offset,0]);},show:function(a){this[a||this.options.mode]();
this.open=true;return this.set([0,this.offset]);},toggle:function(a){return this.start("toggle",a);}});Element.Properties.slide={set:function(b){var a=this.retrieve("slide");
if(a){a.cancel();}return this.eliminate("slide").store("slide:options",$extend({link:"cancel"},b));},get:function(a){if(a||!this.retrieve("slide")){if(a||!this.retrieve("slide:options")){this.set("slide",a);
}this.store("slide",new Fx.Slide(this,this.retrieve("slide:options")));}return this.retrieve("slide");}};Element.implement({slide:function(d,e){d=d||"toggle";
var b=this.get("slide"),a;switch(d){case"hide":b.hide(e);break;case"show":b.show(e);break;case"toggle":var c=this.retrieve("slide:flag",b.open);b[c?"slideOut":"slideIn"](e);
this.store("slide:flag",!c);a=true;break;default:b.start(d,e);}if(!a){this.eliminate("slide:flag");}return this;}});var Drag=new Class({Implements:[Events,Options],options:{snap:6,unit:"px",grid:false,style:true,limit:false,handle:false,invert:false,preventDefault:false,modifiers:{x:"left",y:"top"}},initialize:function(){var b=Array.link(arguments,{options:Object.type,element:$defined});
this.element=document.id(b.element);this.document=this.element.getDocument();this.setOptions(b.options||{});var a=$type(this.options.handle);this.handles=((a=="array"||a=="collection")?$$(this.options.handle):document.id(this.options.handle))||this.element;
this.mouse={now:{},pos:{}};this.value={start:{},now:{}};this.selection=(Browser.Engine.trident)?"selectstart":"mousedown";this.bound={start:this.start.bind(this),check:this.check.bind(this),drag:this.drag.bind(this),stop:this.stop.bind(this),cancel:this.cancel.bind(this),eventStop:$lambda(false)};
this.attach();},attach:function(){this.handles.addEvent("mousedown",this.bound.start);return this;},detach:function(){this.handles.removeEvent("mousedown",this.bound.start);
return this;},start:function(c){if(this.options.preventDefault){c.preventDefault();}this.mouse.start=c.page;this.fireEvent("beforeStart",this.element);
var a=this.options.limit;this.limit={x:[],y:[]};for(var d in this.options.modifiers){if(!this.options.modifiers[d]){continue;}if(this.options.style){this.value.now[d]=this.element.getStyle(this.options.modifiers[d]).toInt();
}else{this.value.now[d]=this.element[this.options.modifiers[d]];}if(this.options.invert){this.value.now[d]*=-1;}this.mouse.pos[d]=c.page[d]-this.value.now[d];
if(a&&a[d]){for(var b=2;b--;b){if($chk(a[d][b])){this.limit[d][b]=$lambda(a[d][b])();}}}}if($type(this.options.grid)=="number"){this.options.grid={x:this.options.grid,y:this.options.grid};
}this.document.addEvents({mousemove:this.bound.check,mouseup:this.bound.cancel});this.document.addEvent(this.selection,this.bound.eventStop);},check:function(a){if(this.options.preventDefault){a.preventDefault();
}var b=Math.round(Math.sqrt(Math.pow(a.page.x-this.mouse.start.x,2)+Math.pow(a.page.y-this.mouse.start.y,2)));if(b>this.options.snap){this.cancel();this.document.addEvents({mousemove:this.bound.drag,mouseup:this.bound.stop});
this.fireEvent("start",[this.element,a]).fireEvent("snap",this.element);}},drag:function(a){if(this.options.preventDefault){a.preventDefault();}this.mouse.now=a.page;
for(var b in this.options.modifiers){if(!this.options.modifiers[b]){continue;}this.value.now[b]=this.mouse.now[b]-this.mouse.pos[b];if(this.options.invert){this.value.now[b]*=-1;
}if(this.options.limit&&this.limit[b]){if($chk(this.limit[b][1])&&(this.value.now[b]>this.limit[b][1])){this.value.now[b]=this.limit[b][1];}else{if($chk(this.limit[b][0])&&(this.value.now[b]<this.limit[b][0])){this.value.now[b]=this.limit[b][0];
}}}if(this.options.grid[b]){this.value.now[b]-=((this.value.now[b]-(this.limit[b][0]||0))%this.options.grid[b]);}if(this.options.style){this.element.setStyle(this.options.modifiers[b],this.value.now[b]+this.options.unit);
}else{this.element[this.options.modifiers[b]]=this.value.now[b];}}this.fireEvent("drag",[this.element,a]);},cancel:function(a){this.document.removeEvent("mousemove",this.bound.check);
this.document.removeEvent("mouseup",this.bound.cancel);if(a){this.document.removeEvent(this.selection,this.bound.eventStop);this.fireEvent("cancel",this.element);
}},stop:function(a){this.document.removeEvent(this.selection,this.bound.eventStop);this.document.removeEvent("mousemove",this.bound.drag);this.document.removeEvent("mouseup",this.bound.stop);
if(a){this.fireEvent("complete",[this.element,a]);}}});Element.implement({makeResizable:function(a){var b=new Drag(this,$merge({modifiers:{x:"width",y:"height"}},a));
this.store("resizer",b);return b.addEvent("drag",function(){this.fireEvent("resize",b);}.bind(this));}});Drag.Move=new Class({Extends:Drag,options:{droppables:[],container:false,precalculate:false,includeMargins:true,checkDroppables:true},initialize:function(c,b){this.parent(c,b);
this.droppables=$$(this.options.droppables);this.container=document.id(this.options.container);if(this.container&&$type(this.container)!="element"){this.container=document.id(this.container.getDocument().body);
}var a=this.element.getStyle("position");if(a=="static"){a="absolute";}if([this.element.getStyle("left"),this.element.getStyle("top")].contains("auto")){this.element.position(this.element.getPosition(this.element.offsetParent));
}this.element.setStyle("position",a);this.addEvent("start",this.checkDroppables,true);this.overed=null;},start:function(f){if(this.container){var b=this.container.getCoordinates(this.element.getOffsetParent()),c={},e={};
["top","right","bottom","left"].each(function(g){c[g]=this.container.getStyle("border-"+g).toInt();e[g]=this.element.getStyle("margin-"+g).toInt();},this);
var d=this.element.offsetWidth+e.left+e.right;var a=this.element.offsetHeight+e.top+e.bottom;if(this.options.includeMargins){$each(e,function(h,g){e[g]=0;
});}if(this.container==this.element.getOffsetParent()){this.options.limit={x:[0-e.left,b.right-c.left-c.right-d+e.right],y:[0-e.top,b.bottom-c.top-c.bottom-a+e.bottom]};
}else{this.options.limit={x:[b.left+c.left-e.left,b.right-c.right-d+e.right],y:[b.top+c.top-e.top,b.bottom-c.bottom-a+e.bottom]};}}if(this.options.precalculate){this.positions=this.droppables.map(function(g){return g.getCoordinates();
});}this.parent(f);},checkAgainst:function(c,b){c=(this.positions)?this.positions[b]:c.getCoordinates();var a=this.mouse.now;return(a.x>c.left&&a.x<c.right&&a.y<c.bottom&&a.y>c.top);
},checkDroppables:function(){var a=this.droppables.filter(this.checkAgainst,this).getLast();if(this.overed!=a){if(this.overed){this.fireEvent("leave",[this.element,this.overed]);
}if(a){this.fireEvent("enter",[this.element,a]);}this.overed=a;}},drag:function(a){this.parent(a);if(this.options.checkDroppables&&this.droppables.length){this.checkDroppables();
}},stop:function(a){this.checkDroppables();this.fireEvent("drop",[this.element,this.overed,a]);this.overed=null;return this.parent(a);}});Element.implement({makeDraggable:function(a){var b=new Drag.Move(this,a);
this.store("dragger",b);return b;}});var Asset={javascript:function(f,d){d=$extend({onload:$empty,document:document,check:$lambda(true)},d);var b=new Element("script",{src:f,type:"text/javascript"});
var e=d.onload.bind(b),a=d.check,g=d.document;delete d.onload;delete d.check;delete d.document;b.addEvents({load:e,readystatechange:function(){if(["loaded","complete"].contains(this.readyState)){e();
}}}).set(d);if(Browser.Engine.webkit419){var c=(function(){if(!$try(a)){return;}$clear(c);e();}).periodical(50);}return b.inject(g.head);},css:function(b,a){return new Element("link",$merge({rel:"stylesheet",media:"screen",type:"text/css",href:b},a)).inject(document.head);
},image:function(c,b){b=$merge({onload:$empty,onabort:$empty,onerror:$empty},b);var d=new Image();var a=document.id(d)||new Element("img");["load","abort","error"].each(function(e){var f="on"+e;
var g=b[f];delete b[f];d[f]=function(){if(!d){return;}if(!a.parentNode){a.width=d.width;a.height=d.height;}d=d.onload=d.onabort=d.onerror=null;g.delay(1,a,a);
a.fireEvent(e,a,1);};});d.src=a.src=c;if(d&&d.complete){d.onload.delay(1);}return a.set(b);},images:function(d,c){c=$merge({onComplete:$empty,onProgress:$empty,onError:$empty,properties:{}},c);
d=$splat(d);var a=[];var b=0;return new Elements(d.map(function(e){return Asset.image(e,$extend(c.properties,{onload:function(){c.onProgress.call(this,b,d.indexOf(e));
b++;if(b==d.length){c.onComplete();}},onerror:function(){c.onError.call(this,b,d.indexOf(e));b++;if(b==d.length){c.onComplete();}}}));}));}};var Color=new Native({initialize:function(b,c){if(arguments.length>=3){c="rgb";
b=Array.slice(arguments,0,3);}else{if(typeof b=="string"){if(b.match(/rgb/)){b=b.rgbToHex().hexToRgb(true);}else{if(b.match(/hsb/)){b=b.hsbToRgb();}else{b=b.hexToRgb(true);
}}}}c=c||"rgb";switch(c){case"hsb":var a=b;b=b.hsbToRgb();b.hsb=a;break;case"hex":b=b.hexToRgb(true);break;}b.rgb=b.slice(0,3);b.hsb=b.hsb||b.rgbToHsb();
b.hex=b.rgbToHex();return $extend(b,this);}});Color.implement({mix:function(){var a=Array.slice(arguments);var c=($type(a.getLast())=="number")?a.pop():50;
var b=this.slice();a.each(function(d){d=new Color(d);for(var e=0;e<3;e++){b[e]=Math.round((b[e]/100*(100-c))+(d[e]/100*c));}});return new Color(b,"rgb");
},invert:function(){return new Color(this.map(function(a){return 255-a;}));},setHue:function(a){return new Color([a,this.hsb[1],this.hsb[2]],"hsb");},setSaturation:function(a){return new Color([this.hsb[0],a,this.hsb[2]],"hsb");
},setBrightness:function(a){return new Color([this.hsb[0],this.hsb[1],a],"hsb");}});var $RGB=function(d,c,a){return new Color([d,c,a],"rgb");};var $HSB=function(d,c,a){return new Color([d,c,a],"hsb");
};var $HEX=function(a){return new Color(a,"hex");};Array.implement({rgbToHsb:function(){var b=this[0],c=this[1],j=this[2];var g,f,h;var i=Math.max(b,c,j),e=Math.min(b,c,j);
var k=i-e;h=i/255;f=(i!=0)?k/i:0;if(f==0){g=0;}else{var d=(i-b)/k;var a=(i-c)/k;var l=(i-j)/k;if(b==i){g=l-a;}else{if(c==i){g=2+d-l;}else{g=4+a-d;}}g/=6;
if(g<0){g++;}}return[Math.round(g*360),Math.round(f*100),Math.round(h*100)];},hsbToRgb:function(){var c=Math.round(this[2]/100*255);if(this[1]==0){return[c,c,c];
}else{var a=this[0]%360;var e=a%60;var g=Math.round((this[2]*(100-this[1]))/10000*255);var d=Math.round((this[2]*(6000-this[1]*e))/600000*255);var b=Math.round((this[2]*(6000-this[1]*(60-e)))/600000*255);
switch(Math.floor(a/60)){case 0:return[c,b,g];case 1:return[d,c,g];case 2:return[g,c,b];case 3:return[g,d,c];case 4:return[b,g,c];case 5:return[c,g,d];
}}return false;}});String.implement({rgbToHsb:function(){var a=this.match(/\d{1,3}/g);return(a)?a.rgbToHsb():null;},hsbToRgb:function(){var a=this.match(/\d{1,3}/g);
return(a)?a.hsbToRgb():null;}});var Group=new Class({initialize:function(){this.instances=Array.flatten(arguments);this.events={};this.checker={};},addEvent:function(b,a){this.checker[b]=this.checker[b]||{};
this.events[b]=this.events[b]||[];if(this.events[b].contains(a)){return false;}else{this.events[b].push(a);}this.instances.each(function(c,d){c.addEvent(b,this.check.bind(this,[b,c,d]));
},this);return this;},check:function(c,a,b){this.checker[c][b]=true;var d=this.instances.every(function(f,e){return this.checker[c][e]||false;},this);if(!d){return;
}this.checker[c]={};this.events[c].each(function(e){e.call(this,this.instances,a);},this);}});Hash.Cookie=new Class({Extends:Cookie,options:{autoSave:true},initialize:function(b,a){this.parent(b,a);
this.load();},save:function(){var a=JSON.encode(this.hash);if(!a||a.length>4096){return false;}if(a=="{}"){this.dispose();}else{this.write(a);}return true;
},load:function(){this.hash=new Hash(JSON.decode(this.read(),true));return this;}});Hash.each(Hash.prototype,function(b,a){if(typeof b=="function"){Hash.Cookie.implement(a,function(){var c=b.apply(this.hash,arguments);
if(this.options.autoSave){this.save();}return c;});}});var Scroller=new Class({Implements:[Events,Options],options:{area:20,velocity:1,onChange:function(a,b){this.element.scrollTo(a,b);
},fps:50},initialize:function(b,a){this.setOptions(a);this.element=document.id(b);this.listener=($type(this.element)!="element")?document.id(this.element.getDocument().body):this.element;
this.timer=null;this.bound={attach:this.attach.bind(this),detach:this.detach.bind(this),getCoords:this.getCoords.bind(this)};},start:function(){this.listener.addEvents({mouseenter:this.bound.attach,mouseleave:this.bound.detach});
},stop:function(){this.listener.removeEvents({mouseenter:this.bound.attach,mouseleave:this.bound.detach});this.timer=$clear(this.timer);},attach:function(){this.listener.addEvent("mousemove",this.bound.getCoords);
},detach:function(){this.listener.removeEvent("mousemove",this.bound.getCoords);this.timer=$clear(this.timer);},getCoords:function(a){this.page=(this.listener.get("tag")=="body")?a.client:a.page;
if(!this.timer){this.timer=this.scroll.periodical(Math.round(1000/this.options.fps),this);}},scroll:function(){var b=this.element.getSize(),a=this.element.getScroll(),f=this.element.getOffsets(),c=this.element.getScrollSize(),e={x:0,y:0};
for(var d in this.page){if(this.page[d]<(this.options.area+f[d])&&a[d]!=0){e[d]=(this.page[d]-this.options.area-f[d])*this.options.velocity;}else{if(this.page[d]+this.options.area>(b[d]+f[d])&&a[d]+b[d]!=c[d]){e[d]=(this.page[d]-b[d]+this.options.area-f[d])*this.options.velocity;
}}}if(e.y||e.x){this.fireEvent("change",[a.x+e.x,a.y+e.y]);}}});var Tips=new Class({Implements:[Events,Options],options:{onShow:function(a){a.setStyle("visibility","visible");
},onHide:function(a){a.setStyle("visibility","hidden");},title:"title",text:function(a){return a.get("rel")||a.get("href");},showDelay:100,hideDelay:100,className:null,offset:{x:16,y:16},fixed:false},initialize:function(){var a=Array.link(arguments,{options:Object.type,elements:$defined});
if(a.options&&a.options.offsets){a.options.offset=a.options.offsets;}this.setOptions(a.options);this.container=new Element("div",{"class":"tip"});this.tip=this.getTip();
if(a.elements){this.attach(a.elements);}},getTip:function(){return new Element("div",{"class":this.options.className,styles:{visibility:"hidden",display:"none",position:"absolute",top:0,left:0}}).adopt(new Element("div",{"class":"tip-top"}),this.container,new Element("div",{"class":"tip-bottom"})).inject(document.body);
},attach:function(b){var a=function(d,c){if(d==null){return"";}return $type(d)=="function"?d(c):c.get(d);};$$(b).each(function(d){var e=a(this.options.title,d);
d.erase("title").store("tip:native",e).retrieve("tip:title",e);d.retrieve("tip:text",a(this.options.text,d));var c=["enter","leave"];if(!this.options.fixed){c.push("move");
}c.each(function(f){d.addEvent("mouse"+f,d.retrieve("tip:"+f,this["element"+f.capitalize()].bindWithEvent(this,d)));},this);},this);return this;},detach:function(a){$$(a).each(function(c){["enter","leave","move"].each(function(d){c.removeEvent("mouse"+d,c.retrieve("tip:"+d)||$empty);
});c.eliminate("tip:enter").eliminate("tip:leave").eliminate("tip:move");if($type(this.options.title)=="string"&&this.options.title=="title"){var b=c.retrieve("tip:native");
if(b){c.set("title",b);}}},this);return this;},elementEnter:function(b,a){$A(this.container.childNodes).each(Element.dispose);["title","text"].each(function(d){var c=a.retrieve("tip:"+d);
if(!c){return;}this[d+"Element"]=new Element("div",{"class":"tip-"+d}).inject(this.container);this.fill(this[d+"Element"],c);},this);this.timer=$clear(this.timer);
this.timer=this.show.delay(this.options.showDelay,this,a);this.tip.setStyle("display","block");this.position((!this.options.fixed)?b:{page:a.getPosition()});
},elementLeave:function(b,a){$clear(this.timer);this.tip.setStyle("display","none");this.timer=this.hide.delay(this.options.hideDelay,this,a);},elementMove:function(a){this.position(a);
},position:function(d){var b=window.getSize(),a=window.getScroll(),e={x:this.tip.offsetWidth,y:this.tip.offsetHeight},c={x:"left",y:"top"},f={};for(var g in c){f[c[g]]=d.page[g]+this.options.offset[g];
if((f[c[g]]+e[g]-a[g])>b[g]){f[c[g]]=d.page[g]-this.options.offset[g]-e[g];}}this.tip.setStyles(f);},fill:function(a,b){if(typeof b=="string"){a.set("html",b);
}else{a.adopt(b);}},show:function(a){this.fireEvent("show",[this.tip,a]);},hide:function(a){this.fireEvent("hide",[this.tip,a]);}});

function hide(obj){
	obj=$(obj);if(!obj){return;}
	if(obj.getStyle("display")=='none'){if(obj.hasClass("hide")){obj.removeClass("hide").setStyle("display","");}else{obj.setStyle("display",'').setStyle("visibility","visible");}
	}else if(obj.hasClass('hide')){obj.removeClass('hide');if(obj.getProperty("id")=="k" || obj.getProperty("id")=="zprava"){document.getElementById('km').focus();}
	}else{obj.addClass('hide');}
}

function check_mail(mail){
	re = /^[^.]+(\.[^.]+)*@([^.]+[.])+[a-z]{2,3}$/;
	return mail.search(re) == 0;
}
function conf(link){
	r=confirm("Jste si jist(a)?");
	if(r==true){
		window.location.href = link;
	}
}
function vloz_tag(znacka){var spravne=false;var kom=document.getElementById('km');switch(znacka){case "b":case "i":case "u":case "color1":case "color2":case "color3":start="{"+znacka+"}";end="{/}";spravne=true;break;}if(spravne){if(document.selection){kom.focus();sel=document.selection.createRange();sel.text=start+sel.text+end;kom.focus();}else if(kom.selectionStart||kom.selectionStart=='0'){var startPos=kom.selectionStart;var endPos=kom.selectionEnd;var cursorPos=endPos;if(startPos!=endPos){kom.value=kom.value.substring(0,startPos)+start+kom.value.substring(startPos,endPos)+end+kom.value.substring(endPos,kom.value.length);cursorPos+=end.length;}else{kom.value=kom.value.substring(0,startPos)+start+end+kom.value.substring(endPos,kom.value.length);}cursorPos+=start.length;kom.focus();kom.selectionStart=cursorPos;kom.selectionEnd=cursorPos;}else{kom.value+=start+end;kom.focus();}}}
function editor(type){switch (type){case 1:request = "{b}{/}";break;case 2:request = "{i}{/}";break;case 3:request = "{u}{/}";break;case 4:po = prompt("Zadejte odkaz včetně http://","");if (po.length > 0){if (po.indexOf('http://') == 0 || po.indexOf('ftp://') == 0 || po.indexOf('https://') == 0) request = "{link}"+po+"{/}";else {request = "{link}http://"+po+"{/}";}}break;case 5:po = prompt("Zadejte cestu k obrázku","");if (po.length > 0){request = "{link}"+po+"{/}";}break;}textContent = document.forms['txt']['mess'].value;textContent = textContent.concat(request);document.forms['txt']['mess'].value=textContent;po = "";request = "";}
function react(re){
	re="{i}"+re+"{/}";
	document.getElementById('km').value=document.getElementById('km').value.concat(re+"\n");
	if($('k').hasClass('hide')){
		$('k').removeClass('hide');
	}
	else if (document.getElementById('k').style.display=='none') {
		document.getElementById('k').style.display="block";
	}
	document.getElementById('km').focus();
	return false;
}
function throw_dices(t){if(t.nodeType==3){t=t.parentNode;}while(t.parentNode&&t.tagName.toUpperCase()!="A"){t=t.parentNode;}xK=prompt("Počet kostek (1 - 10)");if(xK>0&&!isNaN(xK)&&(xK>0&&xK<=10)){yK=prompt("Nejvyšší hodnota na kostce (minimální hod je napevno 1, maximální si určíte)");if(yK>0&&!isNaN(yK)&&(yK>1&&yK<=10000)){if(t.href.indexOf("&")>0){a=t.href.split("&");t.href=a[0];}t.href+="&x="+xK+"&y="+yK;return true;}}return false;}
function send_xmlhttprequest(after, meth, url, content, heads) {
var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}catch(E){xmlhttp = false;}
}
@end @*/
if(!xmlhttp&&typeof XMLHttpRequest!='undefined'){try{xmlhttp=new XMLHttpRequest();}catch(e){xmlhttp=false;}}if(!xmlhttp&&window.createRequest){try{xmlhttp=window.createRequest();}catch(e){xmlhttp=false;}}if(!xmlhttp){return false;}xmlhttp.open(meth,url);xmlhttp.onreadystatechange=function(){after(xmlhttp);};if(heads){for(var key in heads){xmlhttp.setRequestHeader(key,heads[key]);}}xmlhttp.setRequestHeader('Pragma','no-cache');xmlhttp.setRequestHeader("Cache-Control", "no-cache");xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');if(xmlhttp.overrideMimeType){xmlhttp.setRequestHeader('Connection','close');}if(content) {xmlhttp.send(content);}else{xmlhttp.send(null);}return true;}

function check_login(z){new Request({'url':'/ajaxing.php?do=logining&heads=1&zal='+z+'&rndtmr='+$time(),'method':'get','onComplete':function(txt,xml){login_checker(xml);},'onFailure': function(txt,xml){setTimeout('check_login(true);',30*1000);}}).send();return true;}
function cestinaSklonuj(pocet,kus,kusy,kusu){
	if (pocet > 4 || pocet == 0) return kusu;
	else if (pocet > 1) return kusy;
	else return kus;
}
function login_checker(oXml){
	var ajaxF=true;
	var txt=0;
	var xtx=oXml.getElementsByTagName('xtx');
	for(var i=0;i<xtx.length;i++){if(xtx[i].firstChild.data!="off"){txt=Math.abs(txt-xtx[i].firstChild.data);ajaxF=false;}else{ajaxF=true;break;}}
	if(!ajaxF){
		var ajaxiBar = $('ajaxi-bar');
		var theprofilepostlink = $('theprofilepostlink');
		if (theprofilepostlink.hasClass('doT')) {
			if (!ajaxiBar.retrieve('puvTitle')) {ajaxiBar.store('puvTitle',document.title);}
			document.title = ajaxiBar.retrieve('puvTitle');
		}

		ajaxiBar.getFirst().setStyle('width',(100-Math.round(100*txt/60/60))+'%').setProperty('title','Do automatického odhlášení zbývá: '+Math.round(Math.abs(txt-60*60)/60)+' minut').getParent().setProperty('title','Do automatického odhlášení zbývá: '+Math.round(Math.abs(txt-60*60)/60)+' minut').setStyle('display','block');
		var mn=oXml.getElementsByTagName('mn');
		if(mn){
			for(var i=0;i<mn.length;i++){
				$(mn[i].getAttribute("id")).set("html",mn[i].firstChild.data);
			}
		}
		var npost=oXml.getElementsByTagName('np');
		if(npost.length==1){
			if(npost[0].firstChild.data>0){
				theprofilepostlink.set('html','pošta ('+npost[0].firstChild.data+') <img src="/system/ruzne/neprecteno.gif" title="Máte nepřečtenou poštu" alt="Máte nepřečtenou poštu)" />');
				if (theprofilepostlink.hasClass('doT'))
					document.title = npost[0].firstChild.data+'p] ' + ajaxiBar.retrieve('puvTitle');
			}
			else{
				theprofilepostlink.set('html','pošta');
				if (theprofilepostlink.hasClass('doT'))
					document.title = '0p] '+ajaxiBar.retrieve('puvTitle');
			}
			if (theprofilepostlink.hasClass('doT')) {
				var tx = $('dropmenu4').getElements('span');
				if (tx)
					document.title = '['+tx.length+'z/' + document.title;
				else
					document.title = '[0z/' + document.title;
			}
		}
		
		aTx = setTimeout('check_login(true);',60*1000);
	}
	else{
		$('ajaxi-bar').setStyle('display','none');
	}
}
function login_timer_maker(){new Element("div",{'id':'ajaxi-bar','title':'Ukazatel poslední aktivity','styles':{'cursor':'help','display':'none'}}).adopt(new Element("a",{'href':'#','title':'Ukazatel poslední aktivity','styles':{'cursor':'help'}}).adopt(new Element("small",{'text':"neaktivita",'styles':{'cursor':'help','fontSize':'9px','textIndent':'2px'}}))).inject(document.body);check_login(false);return true;}

var submited_checkfornewX = false;

function checkfornewX(xmlhttp){
	if(xmlhttp.readyState==4){
		var frm=document.forms["form_for_new"];
		var status=0;
		try{status=xmlhttp.status;}catch(e){};
		if(status!=200||!xmlhttp.responseXML){frm.submit();}
		var elm=xmlhttp.responseXML.documentElement.firstChild;
		if(elm.getAttribute("t")=="ok"){
			if (submited_checkfornewX){
				alert('Formulář se již odesílá.');
			}
			else {
				submited_checkfornewX = true;
				frm.submit();
			}
		}
		else{
			if(document.getElementById("ajax_for_new_info")){
				var aaa=document.getElementById("ajax_for_new_info");
			}
			else{
				var aaa=document.createElement("div");
				aaa.id="ajax_for_new_info";
				var dc=frm.parentNode.previousSibling;
				while(dc.nodeType==3){
					dc=dc.previousSibling;
				}
				dc=dc.previousSibling;
				dc.parentNode.insertBefore(aaa,dc);
			}
			aaa.innerHTML="<p class='info' id='inf-x'><span class='war' title='Varování'></span>"+elm.firstChild.data+" <a href=\"javascript: hide('inf-x')\" class='permalink2' title='Zavřít'>Zavřít</a></p>";
			if(elm.hasAttribute("f")){
				document.forms["form_for_new"][elm.getAttribute("f")].focus();
			}
			aaa.firstChild.style.visibility="visible";
			aaa.firstChild.style.display="";
		}
	}
}

function checkForNew(w,f,a,b){
	var f=document.getElementById(f);
	f=f.value;
	var frm=document.forms["form_for_new"];
	adv=new Array();
	if(b){	
		adv=a;
	}
	else{
		for(var aa=0;aa<a.length;aa++){
			frm[a[aa]].value=frm[a[aa]].value.trim();
			var t=frm[a[aa]];
			adv[aa]=a[aa]+':'+t.value.length;
			if((isNaN(t.value)&&t.value.length>=3)||t.value.length>0){
				continue;
			}
			while(t.parentNode&&t.tagName.toUpperCase()!="LABEL"){
				t=t.parentNode;
			}
			t=t.firstChild.innerHTML;
			if(t.indexOf(" (")>0){
				t=t.substr(0,t.indexOf(" ("));
			}
			if(frm[a[aa]].tagName.toLowerCase()=="select" && frm[a[aa]].options[frm[a[aa]].selectedIndex].value == ""){
				alert("Musíte vybrat jednu z možností pro '"+t+"'");
			}
			else if(frm[a[aa]].tagName.toLowerCase()=="input"&&frm[a[aa]].type.toLowerCase()=="file"&&frm[a[aa]].value.length<4){
				alert("Musíte vybrat soubor k odeslání.");
			}
			else{
				alert("Musíte vyplnit políčko '"+t+"'");
			}
			frm[a[aa]].focus();
			return false;
		}
		adv=adv.join(",");
	}
	if(!send_xmlhttprequest(checkfornewX,'POST','/ajaxing.php?do=checker&sekce='+w,'adv='+adv+'&co='+encodeURIComponent(f))){
		return true;
	}
	else{
		return false;
	}
}

var aTx;

window.addEvent("load",function(){
	if (document.body.className.indexOf("js") != -1 && Browser.Features.xhr) {
		aTx = setTimeout('login_timer_maker()',3000);
		var frm = $('k');
		var profilePost = $('theprofilepostlink');
		if (profilePost && frm) {
			if (profilePost.getPrevious().get("text") == "apophis") {
				disModuleAjaxSend(frm);
			}
		}
	}
});

function makeStats(section, login){

aP = new Request({'url':"/ajaxing.php?do=stats&sec="+section+"&loginStats="+login, 'method': 'post', 'onComplete': function(txt, xml){ flushStats(txt, xml); } });
aP.setHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
aP.setHeader('Pragma','no-cache');
aP.setHeader("Cache-Control", "no-cache");
aP.send();

}

function flushStats(txt, xml){
 var rows = "";

 data = xml.getElementsByTagName('stats');
 dataC = data.length;
 for (i = 0; i < dataC; i++){

    autor = data[i].getElementsByTagName('autor');
    pocet = data[i].getElementsByTagName('pocet');
    prumer = data[i].getElementsByTagName('prumer');
    koef = data[i].getElementsByTagName('koef');
    rows = rows.concat("<tr><td>"+autor[0].firstChild.data+"</td><td>"+pocet[0].firstChild.data+"</td><td>"+prumer[0].firstChild.data+"</td><td class='jsStatsK'>"+koef[0].firstChild.data+"</td></tr>");

 }
msg = xml.getElementsByTagName('msg');

statsContent = "<table class='jsStats' id='jsStatsContent' width='100%' cellspacing='3'><thead><tr><th>Autor</th><th>Počet děl</th><th>Průměrné hodnocení</th><th>Koeficient</th></tr></thead><tbody>";
statsContent = statsContent.concat(rows);
statsContent = statsContent.concat("</tbody></table>");
statsContent = statsContent.concat(msg[0].firstChild.data);

$('jsStats').set('html',statsContent); 

}

var thePreviewSender = false;
var thePreviewPSender = false;
var prew;

function do_preview(id){
	var firstTable = $('dis-module-x').getElement('table');
	if (!firstTable) {
		prew = new Element('div').adopt(new Element('table',{'cellspacing':0,'class':'commtb'}).adopt(new Element("tbody").adopt(new Element('tr').adopt(new Element('td',{'colspan':2,'class':'c1'}))).adopt(new Element('tr').adopt(new Element('td',{'class':'c2',"html":"<a href='#'></a>"})).adopt(new Element('td',{'class':'c3','html':"<p class='c4'></p>"}))))).injectTop($('dis-module-x')).addClass('hide');
	}
	else var prew = firstTable.getParent().clone(true);
	if (!thePreviewSender) {
		thePreviewSender = new Request({'url':"/ajaxing.php?do=preview",
			'method':"post",
			'onRequest':function(){
				if(!document.getElementById('preview_table')){
					firstTable = $('dis-module-x').getElement('table').getParent().removeClass('hide');
					prew.getElements('tr').erase('id');
					if (prew.getElement('tr').getNext().getFirst().hasClass('cspt')){
						prew.getElement('tr').getNext().dispose();
					}
					prew.getElement('tr').getNext().getElement('td').getElement('a').dispose();
					prew.setProperty('id','preview_table').getElement('p').empty().removeClass("unr");

					if (!firstTable) {
						prew.injectTop($('dis-module-x'));
					}
					prew.injectBefore(firstTable);
				}
				$("preview_table").getElement('td').set('html','Náhled příspěvku: Načítání ...');
			},
			'onComplete':function(txt,xml){
				prvTbl = $("preview_table");
				prvTbl.getElement('td').set('html','Náhled příspěvku');
				prvTbl.getElement('p').set('html',txt);
			},
			'onFailure':function(){
				if (document.getElementById('preview_table')) {
					prvTbl = $("preview_table");
					prvTbl.getElement('td').set('html','Náhled příspěvku: Chyba');
					prvTbl.getElement('p').set('html',"Načítání náhledu selhalo!<br /><br />Patrně je chyba ve spojení se serverem Aragorn.cz");
				}
			}
		});
	}
	thePreviewSender.send({'data':{'txt':$(id).get('value')}});
}

function do_previewP(id){
	if (!thePreviewPSender) {
		thePreviewPSender = new Request({'url':"/ajaxing.php?do=preview",
			'method':"post",
			'onRequest':function(){
				if(!document.getElementById('preview_table')){
					new Element("div",{'html':"<table class='commtb' cellspacing='0' id='preview_table' cellpadding='0'><tr><td class='c1' colspan='2'></td></tr><tr><td class='c2'></td><td class='c3'><p class='c4'></p></td></tr></table>"}).injectAfter($('zprava'));
				}
				$("preview_table").getElement('td').set('html','Náhled zprávy: Načítání ...');
			},
			'onComplete':function(txt,xml){
				prevTable = $("preview_table");
				prevTable.getElement('td').set('html','Náhled zprávy');
				prevTable.getElement('p').set('html',txt);
			},
			'onFailure':function(){
				if (document.getElementById('preview_table')) {
					prevTable = $("preview_table");
					prevTable.getElement('td').set('html','Náhled zprávy: Chyba');
					prevTable.getElement('p').set('html',"Načítání náhledu zprávy selhalo!<br /><br />Patrně je chyba ve spojení se serverem Aragorn.cz");
				}
			}
		});
	}
	thePreviewPSender.send({'data':{'txt':$(id).get('value')}});
}

function comm_del(){
pole = [];
cn=0;
ids = $$("#dis-module-x input[type=checkbox]");
for(i=0,idsl = ids.length; i < idsl; i++){
	if (ids[i].checked == true && ids[i].value != "") {
		pole[cn] = ids[i].value;
		cn++;
	}
}
if (pole.length > 0){
	var konc = "ek";
	doVymaz = false;
	if (pole.length > 1) konc = "ky";
	if (pole.length > 4) konc = "ků";

	if (pole.length < 2) doVymaz = true;
	else if (confirm('Opravdu smazat '+pole.length+' příspěv'+konc+' ???')) doVymaz = true;

	if (doVymaz) {
		vymaz = pole.join(",");
		window.location.assign(urlPartDiskuze+(urlPartDiskuze.indexOf("?") == -1?'?':'&')+"akce=comm-delete&ids="+vymaz);
	}
	else {
		return false;
	}
}else{
	alert("Žádné vybrané položky ke smazání");
}

}

function rep(to){
$('zprava').removeClass('hide');
document.getElementById('to').value = to;
document.getElementById('km').focus();
return false;
}

function rep2(toP){
$('zprava').removeClass('hide');
var to = $('to');
to.setProperty('value',to.getProperty('value').clean());

if ($type(toP) != "string") {
	toP = $(toP).get('text');
}
if (to.getProperty('value') != ""){
	toP = ", "+toP;
	to.setProperty('value',to.getProperty('value')+toP);
}
else {
	to.setProperty('value',toP);
}
document.getElementById('km').focus();
return false;
}

function post_del(){
pole=[];ids=$$('#postolka-all input[type=checkbox]');idsl=ids.length;cn=0;
for(i=0;i<idsl;i++){
	if(ids[i].checked && ids[i].value != ""){
		pole[cn]=ids[i].value;
		cn++;
	}
}
if(pole.length>0){
	vymaz=pole.join(",");
	window.location.href = urlPartPosta+"/?akce=postolka-delete&ids="+vymaz;
}else{
	alert("Žádné vybrané zprávy ke smazání");
}
}

function PostolkaMaker() {

	var t='#postolka-all ';
	var tpr0 = $$(t+'.pr-0').setProperty('title','Nepřečteno').set('text',' ');
	var tpr1 = $$(t+'.pr-1').setProperty('title','Přečteno').set('text',' ');
	var tpr2 = $$(t+'.pr-2').setProperty('title','Smazáno').set('text',' ');
	var tpr3 = $$(t+'.pr-3').setProperty('title','Smazáno').set('text',' ');
	var tprX = $$(t+'.m-in-unr').setProperty('title','Počet nepřečtených příchozích zpráv');
	$$(t+'#dis-module-x .c2 span').addClass('post-status');

	var GiveThemTips = new Tips($$(tpr0,tpr1,tpr2,tpr3,tprX), {
		'className':'tool-tip',fixed:true,offsets:{x:15,y:25},showDelay:0,hideDelay:0
	});
	var TRs = $$('#vypis-out TR','#vypis-in TR').each(function(t){
		t.lastChild.className='pd';
		t.lastChild.previousSibling.className='pt';
		t.lastChild.previousSibling.previousSibling.className='po';
		t.firstChild.nextSibling.className='pp';
		t.addEvent('mouseout',function(){this.removeClass('postolka-hlight')});
		t.addEvent('mouseover',function(){this.addClass('postolka-hlight')});
		t.addEvent('click',	function(e){var t;if(!e)var e=window.event;if(e.target){t=e.target;}else if(e.srcElement){t=e.srcElement;}if(t.nodeType==3)t=t.parentNode;if(t.tagName.toLowerCase()=="input"||t.tagName.toLowerCase()=="a"){return;}while(t.parentNode&&t.tagName.toUpperCase()!= "TR"){t=t.parentNode;}var q=t.getElementsByTagName("INPUT");for(var qw=0;qw<q.length;qw++){q[qw].checked=!q[qw].checked;}});
	});
	
	if (!Browser.Engine.trident4 && Browser.Features.xhr) {

		var ajaxCommSubmiter = function(event){
			var t,prev,prevId,trgtDiv,qq;
			t = $(event.target);
			if (t.get('tag') == 'a') {
				prev = t.getPrevious();
				prevId = 'tmp_'+prev.getProperty('href').replace('/posta/in/','').replace('/posta/out/','').replace(/\//g,'')+'_view';
				if (document.getElementById(prevId)){
					prevId = $(prevId);
					if (prevId.hasClass('opened')) {
						prevId.removeClass('opened').tween('height',0);
					}
					else {
						qq = prevId.removeClass('hide').getFirst().getHeight();prevId.addClass('opened').tween('height',qq);
					}
				}
				else {
					qq = prev;
					while(qq.get('tag') != 'tr' && qq.parentNode){
						qq = qq.getParent();
					}
					trgtDiv = new Element('tr',{
						styles:{
							'overflow':'hidden','height':'auto'
						}
					}).adopt(
						new Element('td',{
							colspan:5,styles:{
								'height':'auto','overflow':'hidden','padding':'0'
							}
						}).adopt(
							new Element('div',{
								'id':prevId,'styles':{'padding':'0','position':'relative','height':'0','overflow':'hidden'}
							}).set('tween',{
								'duration':500,'link':'cancel','onComplete':function(){
									if(this.element.offsetHeight<2){this.element.getParent().tween('height',0);this.element.addClass('hide');}
								},
								'onStart':function(){
									if(this.element.hasClass('hide')){this.element.removeClass('hide').getParent().tween('height',this.element.getFirst().getHeight());}
								}
							}).adopt(
								new Element('div',{
									'class':'postolkaPreviewText','styles':{'position':'absolute'}
								}).adopt(
									new Element('p',{'class':'c4','text':'Načítám...'})
								)
							)
						)
					).injectAfter(qq);
					trgtDiv = trgtDiv.getElement('div');
					qq = trgtDiv;
					trgtDiv = trgtDiv.getFirst();
					qq.tween('height',trgtDiv.getHeight())

					trgtDiv.set('load',{
						onSuccess:function(rTree,rEls,rHTML,rJS){
							this.set('html',rHTML);this.getParent().addClass('opened').tween('height',this.getHeight());
						}.bind(trgtDiv)
					});

					qq = prevId.replace('tmp_','').replace('_view','');
					trgtDiv.load('/ajaxing.php?do=postolka&num='+qq);
				}
			}
			event.stop();
			return false;
		};

		var q = new Element('a',{'class':'permalink2 nahled','href':'#','text':'Náhled','styles':{'fontSize':'80%','lineHeight':'150%','float':'right'}});
		q.addEvent('click',ajaxCommSubmiter.bindWithEvent(q));
		$$('#vypis-all a.r').each(function(el){
			q.clone(true).cloneEvents(q,'click').injectAfter(el);
		});
	}
}

function readIt(t){
	var q,e;
	e = $('unr_link_'+t) || false;
	if (e) {
		q = new Request({
			'url':'/ajaxing.php?do=postolka&read=1&num='+t,
			'method':'get',
			'onRequest':function(){
				this.removeEvent('click').addEvent('click',function(){return false;}).set('text','Zpracovávám...');
			}.bind(e.getElement('a')),
			'onSuccess':function(txt,xml){
				var a;
				txt = $('unr_link_'+txt) || false;
				if (txt) {
					txt.set('text','Status zprávy změněn na přečteno.').setStyle('overflow','hidden');
					a = txt;
					while(a.get('tag') != 'tr') {
						a = a.getParent();
					}
					a.getPrevious().getFirst().set({'class':'pr-1','title':'Přečteno'}).store('tip:title','Přečteno');
					txt.set('morph',{
						duration:2000,
						transition:'quad:in',
						onComplete:function(){
							var aa;
							aa = this.element.getParent().getParent();
							this.element.dispose();
							aa.tween('height',aa.getFirst().getHeight());
						}
					}).morph({'opacity':0,'height':0,'padding-top':0,'padding-bottom':0});
				}
			}
		});
		q.send();
	}
	return false;
}

function zaskrtnout(t){
	$$('#'+t+' input').each(function(el){el.checked=!el.checked;});
}

Element.Properties.disabled = {
 
    get: function(){
        return this.disabled;
    },
 
    set: function(value){
        this.disabled = !!value;
        this.setAttribute('disabled', !!value);
    }
 
};

function doAjaxSendForm(el,uri){
	el = $(el);
	el.getElements('input[type=submit]').setProperty('disabled',false);
	el.set('send',{
		'url':el.getProperty('action')+'&ajaxed=1',
		'onRequest':function(){
			form_ajax_loader.setStyles({'opacity':1,'top':0}).getElement("p").set("text",'Odesílám ...');
		},
		'onSuccess':function(txt,xml){
			if (txt == "off") {
				alert("Již nejste na serveru Aragorn.cz jako online uživatel.\n\nDoporučujeme otevřít nové okno, přihlásit se a odeslat tento příspěvek znovu.");
			}
			else if (txt == "--" || txt == "-") {
				alert('Neznámá chyba s odesláním příspěvku.');
				window.location.reload();
				return;
			}
			else if (txt == "right") {
				txt = "Nemáte práva na odeslání příspěvku.";
			}
			else if (txt == "text") {
				txt = "Příspěvek musí obsahovat nějaký text.";
			}
			else {
				txt = "Příspěvek odeslán.";
				this.reset();
			}
			var comms = $A(xml.getElementsByTagName('comm'));
			setTimeout(function(){
				form_ajax_loader.setStyle('top','100%');
			},2000);
			if (comms) {
				form_ajax_loader.getElement('p').set('html',txt);
				var disModule = $('dis-module-x').getElement('p');
				if (disModule && comms.length > 0) {
					if (document.getElementById('preview_table')){
						disModule = $('preview_table');
						if (disModule.getNext() && disModule.getNext().get('tag') == 'table' && disModule.getParent().get('tag') == 'div'){
							disModule = disModule.getParent();
						}
					}
					for (var a=0,cl=comms.length;a<cl;a++) {
						var elmnt = new Element("div",{'html':comms[a].firstChild.data}).inject(disModule,'after');
						disModule = elmnt;
					}
				}
			}
		}.bind(el),
		'onFailure':function(){
			alert('AJAX odeslání příspěvku selhalo na neznámé chybě.\n\nObnovuji stránku...');
			window.location.reload();
		}
	}).send();
	
}

var form_ajax_loader;

function disModuleAjaxSend(frm){
	var urlHere = window.location.pathname;
	if (urlHere.length > 1 && urlHere.indexOf("/",2)>0) {
		frm = frm.getElement('form');
		if (frm) {
			frm.setStyles({'position':'relative','top':0,'left':0,'overflow':'hidden'}).addEvent('submit',function(event){new Event(event).stop();doAjaxSendForm(this,urlHere);return false;});
			var sizes = frm.getSize();
			form_ajax_loader = new Element("div",{
				'class':'FormAjaxLoader t-a-c',
				'id':'form_ajax_loader',
				'styles':{
					'fontSize':'30px',
					'position':'absolute',
					'top':'100%','left':'0',
					'display':'block',
					'width':'100%',
					'height':'100%'
				}
			}).inject(frm,'bottom').adopt(new Element('div',{
				'styles':{
					'position':'absolute','top':0,'left':0,'height':'100%','width':'100%',
					'backgroundColor':'#000000','opacity':0.75
				}
			}),new Element('p',{'text':'Odesílám ...','class':'t-a-c','styles':{'color':'#ffffff','position':'absolute','padding':'0 0 32px 0','background':'url("/graphic/ajax-loader.gif") center bottom no-repeat','left':'0','width':'100%','top':'30px','lineHeight':'40px'}}));
		}
	}
}

function toplistMaker(){
	$('toplist_link_footer').adopt(new Element('img',{src:'http://toplist.cz/dot.asp?id=40769&wi='+escape(screen.width)+'&he='+escape(screen.height)+'&cd='+escape(window.screen.colorDepth)+'&t='+escape(document.title)+'&http='+escape(document.referrer)+'&_t='+$time(),width:1,height:1,border:0,alt:'TOPlist'}));
}

function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) {
				a.disabled = false;
			}
    }
  }
}

function setStyleSheeter(title){
	var aX;
	//  setActiveStyleSheet(title);
	if (title.camelCase) {
		aX = document.body;
		aX.className = 'js '+title.camelCase().toLowerCase();
		aX.parentNode.id='ht'+title.camelCase().toLowerCase();
		Cookie.dispose('style');
		aX = new Cookie.write('style', title.camelCase().toLowerCase(),{'path':'/','domain':window.location.host,'duration':365});
	}
}

function getActiveStyleSheet() {
  return document.body.className.replace('js','').clean().toLowerCase();
}

function getPreferredStyleSheet() {
  var i, a;
  return document.body.className.replace('js','').clean().lowerCase();
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function createCookie(name,value,days,v2) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

window.onload = function(e) {
  var cookiee = Cookie.read("style");
  var title = cookiee ? cookiee : "gallery";
  setStyleSheeter(title);
}

window.onunload = function(e) {
	var a;
	Cookie.dispose('style');
	a = new Cookie.write('style', getActiveStyleSheet(),{'path':'/','domain':window.location.host,'duration':365});
}

var cookiee = readCookie("style");
var titleeX = cookiee ? cookiee : 'gallery';


//Chrome Drop Down Menu- Author: Dynamic Drive (http://www.dynamicdrive.com)
//Last updated: Jan 1st, 06'

var cssdropdown={
disappeardelay:500,dropmenuobj:null,ie:document.all,firefox:document.getElementById&&!document.all,
getposOffset:function(what,offsettype){
var totaloffset=(offsettype=="left")?what.offsetLeft:what.offsetTop;
var parentEl=what.offsetParent;
while(parentEl!=null){
totaloffset=(offsettype=="left")?totaloffset+parentEl.offsetLeft:totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
},
showhide:function(obj,e,visible,hidden){
if(this.ie||this.firefox){this.dropmenuobj.style.left=this.dropmenuobj.style.top="-500px";}
if(e.type=="click"&&obj.visibility==hidden||e.type=="mouseover"){obj.visibility=visible;}
else if(e.type=="click"){obj.visibility=hidden;}
},
iecompattest:function(){
return (document.compatMode&&document.compatMode!="BackCompat")?document.documentElement:document.body;
},

clearbrowseredge:function(obj, whichedge){
var edgeoffset=0;
if(whichedge=="rightedge"){
var windowedge=this.ie&&!window.opera?this.iecompattest().scrollLeft+this.iecompattest().clientWidth-15:window.pageXOffset+window.innerWidth-15;
this.dropmenuobj.contentmeasure=this.dropmenuobj.offsetWidth;
if(windowedge-this.dropmenuobj.x<this.dropmenuobj.contentmeasure){edgeoffset=this.dropmenuobj.contentmeasure-obj.offsetWidth;}
}
else{
var topedge=((this.ie&&!window.opera)?this.iecompattest().scrollTop:window.pageYOffset);
var windowedge=(this.ie&&!window.opera)?this.iecompattest().scrollTop+this.iecompattest().clientHeight-15:window.pageYOffset+window.innerHeight-18;
this.dropmenuobj.contentmeasure=this.dropmenuobj.offsetHeight;
if(windowedge-this.dropmenuobj.y<this.dropmenuobj.contentmeasure){edgeoffset=this.dropmenuobj.contentmeasure+obj.offsetHeight;if((this.dropmenuobj.y-topedge)<this.dropmenuobj.contentmeasure){edgeoffset=this.dropmenuobj.y+obj.offsetHeight-topedge;}}
}
return edgeoffset;
},

dropit:function(obj,e,dropmenuID){
if(this.dropmenuobj!=null){this.dropmenuobj.style.visibility="hidden";}
this.clearhidemenu();
if(this.ie||this.firefox){
obj.onmouseout=function(){cssdropdown.delayhidemenu()};
this.dropmenuobj=document.getElementById(dropmenuID);
this.dropmenuobj.onmouseover=function(){cssdropdown.clearhidemenu()};
this.dropmenuobj.onmouseout=function(){cssdropdown.dynamichide(e)};
this.dropmenuobj.onclick=function(){cssdropdown.delayhidemenu()};
this.showhide(this.dropmenuobj.style, e,"visible","hidden");
this.dropmenuobj.x=this.getposOffset(obj,"left");
this.dropmenuobj.y=this.getposOffset(obj,"top");
this.dropmenuobj.style.left=this.dropmenuobj.x-this.clearbrowseredge(obj,"rightedge")+"px";
this.dropmenuobj.style.top=this.dropmenuobj.y-this.clearbrowseredge(obj,"bottomedge")+obj.offsetHeight+1+"px";
}
},

contains_firefox:function(a,b){
while(b.parentNode){if((b=b.parentNode)==a){return true;}}
return false;
},

dynamichide:function(e){
var evtobj=window.event?window.event:e;
if(this.ie&&!this.dropmenuobj.contains(evtobj.toElement)){this.delayhidemenu();}
else if(this.firefox&&e.currentTarget!=evtobj.relatedTarget&&!this.contains_firefox(evtobj.currentTarget,evtobj.relatedTarget)){this.delayhidemenu();}
},

delayhidemenu:function(){
this.delayhide=setTimeout("cssdropdown.dropmenuobj.style.visibility='hidden'",this.disappeardelay);
},

clearhidemenu:function(){if(this.delayhide!="undefined"){clearTimeout(this.delayhide);}}
}


/*
 * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
 * Digest Algorithm, as defined in RFC 1321.
 * Version 2.1 Copyright (C) Paul Johnston 1999 - 2002.
 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
 * Distributed under the BSD License
 * See http://pajhome.org.uk/crypt/md5 for more info.
 */

var hexcase = 0;  /* hex output format. 0 - lowercase; 1 - uppercase        */
var b64pad  = ""; /* base-64 pad character. "=" for strict RFC compliance   */
var chrsz   = 8;  /* bits per input character. 8 - ASCII; 16 - Unicode      */

function hex_md5(s){ return binl2hex(core_md5(str2binl(s), s.length * chrsz));}
function b64_md5(s){ return binl2b64(core_md5(str2binl(s), s.length * chrsz));}
function str_md5(s){ return binl2str(core_md5(str2binl(s), s.length * chrsz));}
function hex_hmac_md5(key, data) { return binl2hex(core_hmac_md5(key, data)); }
function b64_hmac_md5(key, data) { return binl2b64(core_hmac_md5(key, data)); }
function str_hmac_md5(key, data) { return binl2str(core_hmac_md5(key, data)); }

function core_md5(x, len)
{
  x[len >> 5] |= 0x80 << ((len) % 32);
  x[(((len + 64) >>> 9) << 4) + 14] = len;

  var a =  1732584193;
  var b = -271733879;
  var c = -1732584194;
  var d =  271733878;

  for(var i = 0; i < x.length; i += 16)
  {
    var olda = a;
    var oldb = b;
    var oldc = c;
    var oldd = d;

    a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936);
    d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586);
    c = md5_ff(c, d, a, b, x[i+ 2], 17,  606105819);
    b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330);
    a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897);
    d = md5_ff(d, a, b, c, x[i+ 5], 12,  1200080426);
    c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341);
    b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983);
    a = md5_ff(a, b, c, d, x[i+ 8], 7 ,  1770035416);
    d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417);
    c = md5_ff(c, d, a, b, x[i+10], 17, -42063);
    b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162);
    a = md5_ff(a, b, c, d, x[i+12], 7 ,  1804603682);
    d = md5_ff(d, a, b, c, x[i+13], 12, -40341101);
    c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290);
    b = md5_ff(b, c, d, a, x[i+15], 22,  1236535329);

    a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510);
    d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
    c = md5_gg(c, d, a, b, x[i+11], 14,  643717713);
    b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302);
    a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691);
    d = md5_gg(d, a, b, c, x[i+10], 9 ,  38016083);
    c = md5_gg(c, d, a, b, x[i+15], 14, -660478335);
    b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848);
    a = md5_gg(a, b, c, d, x[i+ 9], 5 ,  568446438);
    d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690);
    c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961);
    b = md5_gg(b, c, d, a, x[i+ 8], 20,  1163531501);
    a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467);
    d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784);
    c = md5_gg(c, d, a, b, x[i+ 7], 14,  1735328473);
    b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734);

    a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558);
    d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463);
    c = md5_hh(c, d, a, b, x[i+11], 16,  1839030562);
    b = md5_hh(b, c, d, a, x[i+14], 23, -35309556);
    a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
    d = md5_hh(d, a, b, c, x[i+ 4], 11,  1272893353);
    c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632);
    b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640);
    a = md5_hh(a, b, c, d, x[i+13], 4 ,  681279174);
    d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222);
    c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979);
    b = md5_hh(b, c, d, a, x[i+ 6], 23,  76029189);
    a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487);
    d = md5_hh(d, a, b, c, x[i+12], 11, -421815835);
    c = md5_hh(c, d, a, b, x[i+15], 16,  530742520);
    b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651);

    a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844);
    d = md5_ii(d, a, b, c, x[i+ 7], 10,  1126891415);
    c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905);
    b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055);
    a = md5_ii(a, b, c, d, x[i+12], 6 ,  1700485571);
    d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606);
    c = md5_ii(c, d, a, b, x[i+10], 15, -1051523);
    b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799);
    a = md5_ii(a, b, c, d, x[i+ 8], 6 ,  1873313359);
    d = md5_ii(d, a, b, c, x[i+15], 10, -30611744);
    c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380);
    b = md5_ii(b, c, d, a, x[i+13], 21,  1309151649);
    a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070);
    d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379);
    c = md5_ii(c, d, a, b, x[i+ 2], 15,  718787259);
    b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551);

    a = safe_add(a, olda);
    b = safe_add(b, oldb);
    c = safe_add(c, oldc);
    d = safe_add(d, oldd);
  }
  return Array(a, b, c, d);

}

function md5_cmn(q, a, b, x, s, t)
{
  return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b);
}
function md5_ff(a, b, c, d, x, s, t)
{
  return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
}
function md5_gg(a, b, c, d, x, s, t)
{
  return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
}
function md5_hh(a, b, c, d, x, s, t)
{
  return md5_cmn(b ^ c ^ d, a, b, x, s, t);
}
function md5_ii(a, b, c, d, x, s, t)
{
  return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
}

function core_hmac_md5(key, data)
{
  var bkey = str2binl(key);
  if(bkey.length > 16) bkey = core_md5(bkey, key.length * chrsz);

  var ipad = Array(16), opad = Array(16);
  for(var i = 0; i < 16; i++)
  {
    ipad[i] = bkey[i] ^ 0x36363636;
    opad[i] = bkey[i] ^ 0x5C5C5C5C;
  }

  var hash = core_md5(ipad.concat(str2binl(data)), 512 + data.length * chrsz);
  return core_md5(opad.concat(hash), 512 + 128);
}

function safe_add(x, y)
{
  var lsw = (x & 0xFFFF) + (y & 0xFFFF);
  var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
  return (msw << 16) | (lsw & 0xFFFF);
}
function bit_rol(num, cnt)
{
  return (num << cnt) | (num >>> (32 - cnt));
}

function str2binl(str)
{
  var bin = Array();
  var mask = (1 << chrsz) - 1;
  for(var i = 0; i < str.length * chrsz; i += chrsz)
    bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (i%32);
  return bin;
}

function binl2str(bin)
{
  var str = "";
  var mask = (1 << chrsz) - 1;
  for(var i = 0; i < bin.length * 32; i += chrsz)
    str += String.fromCharCode((bin[i>>5] >>> (i % 32)) & mask);
  return str;
}

function binl2hex(binarray)
{
  var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
  var str = "";
  for(var i = 0; i < binarray.length * 4; i++)
  {
    str += hex_tab.charAt((binarray[i>>2] >> ((i%4)*8+4)) & 0xF) +
           hex_tab.charAt((binarray[i>>2] >> ((i%4)*8  )) & 0xF);
  }
  return str;
}

function binl2b64(binarray)
{
  var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  var str = "";
  for(var i = 0; i < binarray.length * 4; i += 3)
  {
    var triplet = (((binarray[i   >> 2] >> 8 * ( i   %4)) & 0xFF) << 16)
                | (((binarray[i+1 >> 2] >> 8 * ((i+1)%4)) & 0xFF) << 8 )
                |  ((binarray[i+2 >> 2] >> 8 * ((i+2)%4)) & 0xFF);
    for(var j = 0; j < 4; j++)
    {
      if(i * 8 + j * 6 > binarray.length * 32) str += b64pad;
      else str += tab.charAt((triplet >> 6*(3-j)) & 0x3F);
    }
  }
  return str;
}

function _to_utf8(s) {
  var c, d = "";
  for (var i = 0; i < s.length; i++) {
    c = s.charCodeAt(i);
    if (c <= 0x7f) {
      d += s.charAt(i);
    } else if (c >= 0x80 && c <= 0x7ff) {
      d += String.fromCharCode(((c >> 6) & 0x1f) | 0xc0);
      d += String.fromCharCode((c & 0x3f) | 0x80);
    } else {
      d += String.fromCharCode((c >> 12) | 0xe0);
      d += String.fromCharCode(((c >> 6) & 0x3f) | 0x80);
      d += String.fromCharCode((c & 0x3f) | 0x80);
    }
  }
  return d;
} 

var loginFormElement = null;

function getChallenge(t){
	loginFormElement = t;
	new Asset.javascript('/ajaxing.php?challenge',{evalScript:true,onload:function(){md5form();}});
	return false;
}

function md5form(f) {
	if (!f) f = loginFormElement;
	f['password_hmac'].disabled = false;
	f['password_hmac'].value = hex_hmac_md5(hex_md5(_to_utf8(f['pass'].value)), f['challenge'].value);
	f['pass'].disabled = true;
	f.submit();
	f['pass'].disabled = false;
	f['password_hmac'].disabled = true;
	return false;
}


