/*
 * JSGUI
 * Copyright(c) 2006, MitriDAT Limited.
 */


Object.extend=function(destination,source){if(destination&&source&&typeof source=='object'){for(var property in source){destination[property]=source[property];}}
return destination;};var Class={create:function(){var parent=null,properties=Object.toArray(arguments);if(GUI.isFunction(properties[0])){parent=properties.shift();}
function klass(){this.initialize.apply(this,arguments);}
Object.extend(klass,Class.Methods);if(parent){klass.superclass=parent.prototype;var subclass=function(){};subclass.prototype=parent.prototype;klass.prototype=new subclass;}else{klass.superclass=null;}
for(var i=0;i<properties.length;i++){klass.addMethods(properties[i]);}
if(!klass.prototype.initialize){klass.prototype.initialize=GUI.emptyFunction;}
klass.prototype.constructor=klass;return klass;},Methods:{addMethods:function(source){var ancestor=this.superclass&&this.superclass.prototype;var properties=Object.keys(source);for(var i=0,length=properties.length;i<length;i++){var property=properties[i],value=source[property];this.prototype[property]=value;}
return this;}}};Object.extend(Object,{extendIf:function(destination,source){if(destination&&source&&typeof source=='object'){for(var property in source){if(typeof destination[property]=='undefined'){destination[property]=source[property];}}}
return destination;},clone:function(object){return Object.extend({},object);},toJson:function(object){},toArray:function(object){var length=object.length||0,results=new Array(length);while(length--){results[length]=object[length];}
return results;},keys:function(object){var keys=[];for(var property in object){keys.push(property);}
return keys;},values:function(object){var values=[];for(var property in object){values.push(object[property]);}
return values;}});(function(){function _toQueryString(uri,object,prepend){if(GUI.isNumber(object)||GUI.isString(object)||GUI.isBoolean(object)){if(!(GUI.isString(prepend)&&prepend!='')){throw new Error("At first object must be passed!");}
uri.push(prepend+'='+encodeURIComponent(object));}else if(GUI.isArray(object)){if(!(GUI.isString(prepend)&&prepend!='')){throw new Error("At first object must be passed!");}
for(var i=0,len=object.length;i<len;i++){_toQueryString(uri,object[i],prepend+'['+i+']');}}else if(GUI.isObject(object)){for(var key in object){var value=object[key];if(GUI.isFunction(value))continue;_toQueryString(uri,value,(GUI.isString(prepend)&&prepend!='')?prepend+'['+key+']':key);}}}
Object.extend(Object,{toQueryString:function(object){var uri=[];_toQueryString(uri,object,'');return uri.join('&');}});}());Object.extend(Function.prototype,{bind:function(){if(arguments.length<2&&GUI.isUndefined(arguments[0])){return this;}
var __method=this,args=Object.toArray(arguments),object=args.shift();return function(){return __method.apply(object,args.concat(Object.toArray(arguments)));}},defer:function(){var __method=this,args=Object.toArray(arguments),timeout=args.shift()*1000;return window.setTimeout(function(){return __method.apply(__method,args);},timeout);},methodize:function(){if(this._methodized){return this._methodized;}
var __method=this;return this._methodized=function(){return __method.apply(null,[this].concat(Object.toArray(arguments)));};}});Date.prototype.toJson=function(){return'"'+this.getUTCFullYear()+'-'+
(this.getUTCMonth()+1).toPaddedString(2)+'-'+
this.getUTCDate().toPaddedString(2)+'T'+
this.getUTCHours().toPaddedString(2)+':'+
this.getUTCMinutes().toPaddedString(2)+':'+
this.getUTCSeconds().toPaddedString(2)+'Z"';};Object.extend(String.prototype,{times:function(number){return(new Array(number)).fill(this).join('');},include:function(subString){return this.indexOf(subString)>-1;},isEmpty:function(){return this=='';}});(function(){var _trimRe=/^\s+|\s+$/g,_formatRe=/\{(\d+)\}/g;Object.extend(String.prototype,{trim:function(){return this.replace(_trimRe,"");},format:function(){var args=arguments;return this.replace(_formatRe,function(m,i){return args[i];});}});}());Object.extend(Number.prototype,{toPaddedString:function(length,radix){var string=this.toString(radix||10);return'0'.times(length-string.length)+string;},constrain:function(min,max){return Math.min(Math.max(this,min),max);}});Object.extend(Array.prototype,{fill:function(value){var len=this.length;while(len--){this[len]=value;}
return this;},indexOf:function(object){var len=this.length;while(len--){if(this[len]==object){return len;}}
return-1;},remove:function(object){var index=this.indexOf(o);if(index!=-1){this.splice(index,1);}
return this;},clone:function(){return[].concat(this);}});(function(){var
currentId=0,classReCache={},preloadedImages={},undoCache={},ua=navigator.userAgent.toLowerCase(),isOpera=!!window.opera,isIE=!!(window.attachEvent&&!window.opera),isIE6=isIE&&ua.indexOf("msie 6")>-1,isIE7=isIE&&ua.indexOf("msie 7")>-1,isSafari=(/webkit|khtml/).test(ua),isSafari3=isSafari&&ua.indexOf('webkit/5')>-1,isGecko=!isSafari&&ua.indexOf('gecko')>-1,isMobileSafari=!!ua.match(/apple.*mobile.*safari/),isStrict=document.compatMode=="CSS1Compat",isBorderBox=isIE&&!isStrict,libPath=(window.libPath)?window.libPath:'',debug=!!window.debug;if(window.autoDestroy===undefined){window.autoDestroy=true;}
function getDim(str){var px=str.lastIndexOf('px');if(px){str=str.substring(0,px);}
if(str==''){return 0;}else{var res=parseInt(str,10);if(isNaN(res)){alert(typeof str);}
return res;}}
var blockSelectionHandler=function(e){GUI.stopEvent(e);}.bindAsEventListener();var GUI={emptyFunction:function(){},preloadedImages:preloadedImages,debug:debug,Constants:{libPath:libPath},isOpera:isOpera,isIE:isIE,isIE6:isIE6,isIE7:isIE7,isSafari:isSafari,isSafari3:isSafari3,isGecko:isGecko,isMobileSafari:isMobileSafari,isStrict:isStrict,isBorderBox:isBorderBox,getBody:function(){return window.GUI.Dom.extend(document.body||document.documentElement);},getUniqId:function(prefix){currentId++;if(!GUI.isSet(prefix)){var prefix='';}
return prefix+currentId;},onDOMReady:function(handler){document.on('dom:loaded',handler);},preloadImage:function(){var len=arguments.length;if(len==1){var src=arguments[0],img;if(!GUI.isString(src)){throw new Error('GUI.preloadImage(), src is undefined:',src);}
if(!preloadedImages[src]){preloadedImages[src]={start:new Date(),state:'loading',end:null,time:null};var item=preloadedImages[src];img=new Image();img.onload=function(){item.end=new Date();item.time=(item.end-item.start)/1000;item.state='ok';img.onload=null;img.onerror=null;}
img.onerror=function(){item.end=new Date();item.time=(item.end-item.start)/1000;item.state='error';img.onload=null;img.onerror=null;}
img.src=src;}}else{for(var i=0;i<len;i++){GUI.preloadImage(arguments[i]);}}},preloadCssImages:function(){var sheets=document.styleSheets,i,shLen=sheets.length,cssPile=new GUI.StringBuffer();for(i=0;i<shLen;i++){var csshref=(sheets[i].href)?sheets[i].href:window.location.href,baseURLarr=csshref.split('/');baseURLarr.pop();var baseURL=baseURLarr.join('/');if(baseURL!=""){baseURL+='/';}
cssPile.clear();if(sheets[i].cssRules){var thisSheetRules=sheets[i].cssRules;for(var j=0,rulesLen=thisSheetRules.length;j<rulesLen;j++){cssPile.append(thisSheetRules[j].cssText);}}else{cssPile.append(sheets[i].cssText);}
var imgUrls=cssPile.toString().match(/[^\(]+\.(gif|jpg|jpeg|png)/g);if(imgUrls!=null&&imgUrls.length>0&&imgUrls!=''){for(var j=0,len=imgUrls.length;j<len;j++){var src=imgUrls[j];src=(src[0]=='/'||src.match('http://'))?src:baseURL+src;GUI.preloadImage(src);};}}},appendClearDiv:function(to){var div=document.createElement('div');div.className='clear';to=GUI.$(to);to.appendChild(div);},isSet:function(val){return(val!==undefined)&&(val!==null);},isUndefined:function(val){return typeof val=='undefined';},isNumber:function(val){return typeof val=='number';},isBoolean:function(val){return typeof val=='boolean';},isString:function(val){return typeof val=='string';},isFunction:function(val){return typeof val=='function';},isArray:function(object){return object&&object.constructor===Array;},isObject:function(object){return typeof object=='object';},isDate:function(object){return object&&object.constructor===Date;},isEmpty:function(val){return(val===undefined)||(val===null)||(val===false)||(val==0)||(val=='')||((val&&val.constructor===Array)&&(val.length==0));},toArray:Object.toArray,arrayIndexOf:function(arr,obj){var len=arr.length;while(len--){if(arr[len]==obj){return len;}}
return-1;},arrayRemove:function(arr,o){var index=GUI.arrayIndexOf(arr,o);if(index!=-1){arr.splice(index,1);}
return arr;},extractPropertyValues:function(arr,name){var res=[],i,len=arr.length;for(i=0;i<len;i++){res.push(arr[i][name]);}
return res;},destroyObject:function(obj){for(var i in obj){if(GUI.isFunction(obj[i])){obj[i]=null;}else{delete obj[i];}}},constrain:function(value,min,max){return Math.min(Math.max(value,min),max);},getDisabledImageUrl:function(url){if(GUI.isString(url)){return url.replace(/^(.*)\.(jpg|gif|png|jpeg)$/i,'$1-disabled.$2');}},getHoverImageUrl:function(url){if(GUI.isString(url)){return url.replace(/^(.*)\.(jpg|gif|png|jpeg)$/i,'$1-hover.$2');}},getToggledImageUrl:function(url){if(GUI.isString(url)){return url.replace(/^(.*)\.(jpg|gif|png|jpeg)$/i,'$1-toggled.$2');}},escapeRe:function(s){return s.replace(/([.*+?^${}()|[\]\/\\])/g,"\\$1");},escape:function(string){return string.replace(/('|\\)/g,"\\$1");},toQueryString:Object.toQueryString,measureWidth:function(elem,styles){var tmp=document.createElement('SPAN');var style=tmp.style;if(GUI.isSet(styles)){$(tmp).setStyle(styles);}
style.position='absolute';style.left='-10000px';style.top='-10000px';document.body.appendChild(tmp);if(GUI.isString(elem)){tmp.innerHTML=elem;}else if(GUI.isString(elem.innerHTML)){tmp.innerHTML=elem.innerHTML;}
var width=Element.getWidth(tmp);document.body.removeChild(tmp);return width;},formatString:function(){var args=GUI.toArray(arguments);var str=args.shift();return str.replace(/\{(\d*?)\}/gm,function(match,name){return args[name];});},formatDate:function(date,format){var o='';for(var i=0,len=format.length;i<len;i++){var ch=format.charAt(i);var re='';switch(ch){case'd':re=date.getDate();re=(re<10)?'0'+re.toString():re.toString();break;case'm':re=date.getMonth()+1;re=(re<10)?'0'+re.toString():re.toString();break;case'Y':re=date.getFullYear();break;default:re=ch;break;}
o+=re;}
return o;},parseDate:function(str,format){var day,month,year;var delimeter=format.match(/[dmy](\W+)[dmy]/i);delimeter=delimeter[1];var arStr=str.split(delimeter);var arFormat=format.split(delimeter);for(var i=0;i<arFormat.length;i++){switch(arFormat[i]){case'd':day=parseInt(arStr[i],10);break;case'm':month=parseInt(arStr[i],10);break;case'Y':year=parseInt(arStr[i],10);break;case'y':year=parseInt(arStr[i],10);break;}}
if(!isNaN(day)&&!isNaN(month)&&!isNaN(year)){return new Date(year,month-1,day);}
return false;},$:function(elem,raw){if(GUI.isString(elem)){elem=document.getElementById(elem);}
return elem?raw?elem:window.GUI.Dom.extend(elem):null;},clean:function(node){var p;while(p=node.firstChild){node.removeChild(p);}},remove:function(element){element=GUI.$(element);element.parentNode.removeChild(element);},replace:function(old,replace){old.parentNode.replaceChild(replace,old);},show:function(elem){elem=GUI.$(elem);elem.style.display='';},hide:function(elem){elem=GUI.$(elem);elem.style.display='none';},toggle:function(elem){var style=GUI.$(elem).style;style.display=(style.display==='none')?'':'none';},isHidden:function(elem){elem=GUI.$(elem);return(elem.style.display=='none');},repaint:function(node){GUI.addClass(node,'x-repaint');setTimeout(function(){GUI.removeClass(node,'x-repaint');},1);},unselectable:function(node){if(GUI.isIE){node.unselectable="on";Event.observe(node,"selectstart",blockSelectionHandler);GUI.addClass("x-unselectable");}else{node.style.MozUserSelect='none';node.style.KhtmlUserSelect='none';}},createInput:function(name){var hidden;if(GUI.isString(name)&&name.length){if(GUI.isIE){hidden=document.createElement('<input name="'+name+'">');}else{hidden=document.createElement('input');hidden.name=name;}}else{hidden=document.createElement('input');}
return hidden;},renderIntoContainer:function(container,node){container.appendChild(node);},contains:function(container,containee){if(container.contains){GUI.contains=function(container,containee){if(!containee||!container){return false;}
return container.contains(containee);}}else if(container.compareDocumentPosition){GUI.contains=function(container,containee){if(!containee||!container){return false;}
return!!(container.compareDocumentPosition(containee)&16);}}else{GUI.contains=function(container,containee){if(!containee||!container){return false;}
var parent=containee;while(parent=parent.parentNode){if(parent==container){return true;}else if(!parent.tagName){return false;}}
return false;}}
return GUI.contains(container,containee);},findParentByTag:function(elem,tagName,to,className){to=to||document.body;tagName=tagName.toUpperCase();if(className){return GUI._findParentByTagAndClass(elem,tagName,to,className);}else{return GUI._findParentByTag(elem,tagName,to);}},_findParentByTag:function(elem,tagName,to){while(elem&&(elem!=to)){if(!elem.tagName){return false;}
if(elem.nodeName==tagName){return elem;}
elem=elem.parentNode;}
return false;},_findParentByTagAndClass:function(elem,tagName,to,className){while(elem&&(elem!=to)){if(!elem.tagName){return false;}
if(elem.nodeName==tagName){if(GUI.hasClass(elem,className)){return elem;}}
elem=elem.parentNode;}
return false;},addClass:function(elem,className){elem=GUI.$(elem);if(className&&!GUI.hasClass(elem,className)){elem.className=elem.className+' '+className;}},removeClass:function(elem,className){elem=GUI.$(elem);if(GUI.hasClass(elem,className)){var re=classReCache[className];if(!re){re=new RegExp('(?:^|\\s+)'+className+'(?:\\s+|$)',"g");classReCache[className]=re;}
elem.className=elem.className.replace(re,' ');}},hasClass:function(elem,className){elem=GUI.$(elem);return className&&(' '+elem.className+' ').indexOf(' '+className+' ')!=-1;},findChild:function(parent,search){var classes=search.split('.');var tagName=classes.shift();if(!tagName){tagName='*';}
var childs=parent.getElementsByTagName(tagName);var clsLen=classes.length;var i=childs.length,res=[];while(i--){var child=childs[i];var j=clsLen;var match=0;while(j--){if(!GUI.hasClass(child,classes[j])){break;}else{match++;}}
if(match==clsLen){res.push(child);}}
return res;},getHorizontalBorders:function(element){element=$(element);var lBorder=getDim(element.getStyle('border-left-width'));var rBorder=getDim(element.getStyle('border-right-width'));return lBorder+rBorder;},getVerticalBorders:function(element){element=$(element);var tBorder=getDim(element.getStyle('border-top-width'));var bBorder=getDim(element.getStyle('border-bottom-width'));return tBorder+bBorder;},getHorizontalPadding:function(element){element=$(element);var lPadding=getDim(element.getStyle('padding-left'));var rPadding=getDim(element.getStyle('padding-right'));return lPadding+rPadding;},getVerticalPadding:function(element){element=$(element);var tPadding=getDim(element.getStyle('padding-top'));var bPadding=getDim(element.getStyle('padding-bottom'));return tPadding+bPadding;},setOpacity:function(element,value){if(GUI.isIE){GUI.setOpacity=function(element,value)
{function stripAlpha(filter)
{return filter.replace(/alpha\([^\)]*\)/gi,'');}
var currentStyle=element.currentStyle;if((currentStyle&&!currentStyle.hasLayout)||(!currentStyle&&element.style.zoom=='normal')){element.style.zoom=1;}
var filter=element.style.filter,style=element.style;if(value===''){if(filter=stripAlpha(filter)){style.filter=filter;}else{style.removeAttribute('filter');}
return element;}else if(value<0.00001){value=0;}
style.filter=stripAlpha(filter)+'alpha(opacity='+
(value*100)+')';return element;};}else{GUI.setOpacity=function(element,value)
{element.style.opacity=(value==='')?'':(value<0.00001)?0:value;return element;}}
return GUI.setOpacity(element,value);},getEventTarget:function(e){var targ=e.target||e.srcElement;if(targ.nodeType==3){targ=targ.parentNode;}
return targ;},getRelatedTarget:function(evt){if(evt.type=='mouseover'){return evt.relatedTarget||evt.fromElement;}else if(evt.type=='mouseout'){return evt.relatedTarget||evt.toElement;}else{throw new Error("getRelatedTarget can be called only for mover/mout");}},preventDefault:function(e){if(GUI.isIE){e.returnValue=false;}else{e.preventDefault();}},stopPropagation:function(e){if(GUI.isIE){e.cancelBubble=true;}else{e.stopPropagation();}},stopEvent:function(e){GUI.stopPropagation(e);GUI.preventDefault(e);},cloneEvent:function(evt){var e={};Object.extend(e,evt);return e;},isMouseEnter:function(node,evt){var relTarget=evt.relatedTarget||evt.fromElement;return!((node==relTarget)||GUI.contains(node,relTarget));},isMouseLeave:function(node,evt){var relTarget=evt.relatedTarget||evt.toElement;return!((node==relTarget)||GUI.contains(node,relTarget));},isButton:function(event,code){if(GUI.isIE){var buttonMap={0:1,1:4,2:2};GUI.isButton=function(event,code){return event.button==buttonMap[code];};}else if(GUI.isSafari){GUI.isButton=function(event,code){switch(code){case 0:return event.which==1&&!event.metaKey;case 1:return event.which==1&&event.metaKey;default:return false;}};}else{GUI.isButton=function(event,code){return event.which?(event.which===code+1):(event.button===code);};}
return GUI.isButton(event,code);},isLeftClick:function(event){return GUI.isButton(event,0)},isMiddleClick:function(event){return GUI.isButton(event,1)},isRightClick:function(event){return GUI.isButton(event,2)},isNavKeyPress:function(event){var k=event.keyCode;return(k>=33&&k<=40)||k==Event.KEY_RETURN||k==Event.KEY_TAB||k==Event.KEY_ESC;},pointerXY:function(event){return{x:event.pageX||(event.clientX+
(document.documentElement.scrollLeft||document.body.scrollLeft)),y:event.pageY||(event.clientY+
(document.documentElement.scrollTop||document.body.scrollTop))};},makeVisible:function(node){p=node;var hiddenNodes=[];while(p&&p.tagName){if(GUI.isHidden(p)){hiddenNodes.push(p);}
p=p.parentNode;}
var len=hiddenNodes.length,elem;if(len-->0){elem=hiddenNodes[len];style=elem.style;node._oldposition=style.position;node._olddisplay=style.display;node._oldleft=style.left;node._oldtop=style.top;node._olddisplay=style.display;style.position='absolute';style.display='block';style.left='-10000px';style.top='-10000px';}
while(len-->0){GUI.show(hiddenNodes[len]);}
node._cacheId=GUI.getUniqId('tmp-');undoCache[node._cacheId]=hiddenNodes;},undoVisible:function(node){var hiddenNodes=undoCache[node._cacheId];var len=hiddenNodes.length,elem;if(len-->0){elem=hiddenNodes[len];style=elem.style;style.display=node._olddisplay;style.position=node._oldposition;style.left=node._oldleft;style.top=node._oldtop;node._olddisplay=undefined;node._oldposition=undefined;node._oldleft=undefined;node._oldtop=undefined;}
while(len-->0){GUI.hide(hiddenNodes[len]);}
delete undoCache[node._cacheId];node._cacheId=null;},getClientWidth:function(node){GUI.makeVisible(node);var w=node.clientWidth;GUI.undoVisible(node);return w;},getClientHeight:function(node){GUI.makeVisible(node);var h=node.clientHeight;GUI.undoVisible(node);return h;},getFullWidth:function(node){var w=GUI.getDimensions(node).width;return w;},getFullHeight:function(node){var h=GUI.getDimensions(node).height;return h;},runDomVisible:function(element,wasVisibleCb,wasHiddenCb){element=$(element);var display=$(element).getStyle('display');if(display!='none'&&display!=null){if(GUI.isFunction(wasVisibleCb)){return wasVisibleCb(element);}else{return;}}
wasHiddenCb=wasHiddenCb||wasVisibleCb;if(!GUI.isFunction(wasHiddenCb)){return;}
var els=element.style;var originalVisibility=els.visibility;var originalPosition=els.position;var originalDisplay=els.display;els.position='absolute';els.display='block';var res=wasHiddenCb(element);els.display=originalDisplay;els.position=originalPosition;return res;},getDimensions:function(node){return GUI.runDomVisible(node,function(element){return{width:element.offsetWidth,height:element.offsetHeight};},function(element){return{width:element.clientWidth,height:element.clientHeight}});},setFullWidth:function(element,width){element=$(element);var clientWidth=width;if(!GUI.isBorderBox){var padding=GUI.getHorizontalPadding(element);var borders=GUI.getHorizontalBorders(element);clientWidth-=padding+borders;if(clientWidth<0){clientWidth=0;}}
element.style.width=clientWidth.toString()+'px';},setFullHeight:function(element,height){element=$(element);var height=parseInt(height,10);if(height<0){throw new Error('setting negative height!!');}
var clientHeight=height;if(!GUI.isBorderBox){var padding=GUI.getVerticalPadding(element);var borders=GUI.getVerticalBorders(element);clientHeight-=padding+borders;if(clientHeight<0){clientHeight=0;}}
element.style.height=clientHeight.toString()+'px';},getViewportWidth:function(){if(GUI.isIE){return GUI.isStrict?document.documentElement.clientWidth:document.body.clientWidth;}else{return self.innerWidth;}},getViewportHeight:function(){if(GUI.isIE){return GUI.isStrict?document.documentElement.clientHeight:document.body.clientHeight;}else{return self.innerHeight;}},getInnerHeight:function(element){element=GUI.$(element);var tPadding=getDim(element.getStyle('padding-top'));var bPadding=getDim(element.getStyle('padding-bottom'));return element.offsetHeight-tPadding-bPadding;},getInnerNodesHeight:function(elem){var h=0;var i=elem.childNodes.length;while(i--){h+=parseInt(elem.childNodes[i].offsetHeight,10)}
return h;},getScroll:function(elem){var mode=document.compatMode;var d=elem,doc=document;if((d==doc)||(d==doc.body)){var l,t;if(GUI.isIE&&GUI.isStrict){l=doc.documentElement.scrollLeft||(doc.body.scrollLeft||0);t=doc.documentElement.scrollTop||(doc.body.scrollTop||0);}else{l=window.pageXOffset||(doc.body.scrollLeft||0);t=window.pageYOffset||(doc.body.scrollTop||0);}
return{left:l,top:t};}else{return{left:d.scrollLeft,top:d.scrollTop};}},getScrollableContainer:function(elem){var parent=elem.parentNode;while(parent){if($(parent).getStyle('overflow')===null){return parent;}else if(!parent.tagName||parent.tagName.toUpperCase()=="HTML"){return false;}
parent=parent.parentNode;}
return false;},getTotalScroll:function(element,to){to=to||document.body;var left=0,top=0;var parent=element.parentNode;while(parent){if((parent==to)||!parent.tagName||(parent.tagName=='HTML')){break;}
if(!GUI.isOpera||((parent.nodeName!='TR')&&(Element.getStyle(parent,'display')!='inline'))){left+=parent.scrollLeft;top+=parent.scrollTop;}
if(Element.getStyle(parent,'position')=='absolute'){break;}
parent=parent.parentNode;}
return[left,top];},scrollIntoView:function(cont,elem){var p1=GUI.getPosition(elem,true),p2=GUI.getPosition(cont,true);relPos=[p1.left-p2.left,p1.top-p2.top];var
elemLeft=relPos[0],elemTop=relPos[1],dim=GUI.getDimensions(elem);var elemWidth=dim.width;var elemHeight=dim.height;var contWidth=cont.clientWidth;var contHeight=cont.clientHeight;if(elemTop<0){cont.scrollTop-=elemTop;}else if(elemTop+elemHeight>contHeight){cont.scrollTop+=elemTop+elemHeight-contHeight;}
if((elemLeft<0)||(elemWidth>contWidth)){cont.scrollLeft-=elemLeft;}else if(elemLeft+elemWidth>contWidth){cont.scrollLeft+=elemLeft+elemWidth-contWidth;}},getPosition:function(node){return GUI.runDomVisible(node,function(element){var top=0,left=0;if(element.getBoundingClientRect){var b=element.getBoundingClientRect(),bt=0,bl=0;if(GUI.isIE){bt=parseInt(Element.getStyle(element,"borderTopWidth"),10)||0;bl=parseInt(Element.getStyle(element,"borderLeftWidth"),10)||0;}
if(GUI.isIE&&(node==document.body||node==document.documentElement)){return[b.left-bl,b.top-bt];}else{var scroll=GUI.getScroll(document);return[b.left-bl+scroll.left,b.top-bt+scroll.top];}}
var parent=element;do{if(GUI.isOpera&&(parent.tagName==='TD')){continue;}else{top+=parent.offsetTop||0;left+=parent.offsetLeft||0;}}while(parent=parent.offsetParent);var scroll=GUI.getTotalScroll(element);left-=scroll[0];top-=scroll[1];var res=[left,top];res.left=left;res.top=top;return res;});},getLocalCoordinates:function(elem,xy){if((elem==document)||(elem==document.body)||(!elem.offsetParent)){return xy;}
var offParent=GUI.getPosition(elem.offsetParent,true);var res=[];res[0]=xy[0]-offParent[0];res[1]=xy[1]-offParent[1];res.left=res[0];res.top=res[1];return res;},getRelativeOffset:function(elem,cont){var p1=GUI.getPosition(elem,true),p2=GUI.getPosition(cont,true);return[p1.left-p2.left,p1.top-p2.top];},registerObject:function(obj){GUI._registeredObjects[GUI._registeredObjectsIdx++]=obj;},destroyObjects:function(){for(var i=0,obj;i<GUI._registeredObjectsIdx;i++){obj=GUI._registeredObjects[i];if(obj.removeEventListeners){try{obj.removeEventListeners();}catch(e){}}
if(obj.purgeListeners){obj.purgeListeners();}
GUI.destroyObject(obj);}
obj=null;},_registeredObjects:[],_registeredObjectsIdx:0};if(GUI.isIE){var StringBuffer=function(str){this.buf=[];this.length=0;if(GUI.isSet(str)){this.append(str);}};StringBuffer.prototype={append:function(str){this.buf[this.length++]=str;return this;},clear:function(){this.buf=[];this.length=0;return this;},toString:function(){return this.buf.join('');}};}else{var StringBuffer=function(str){this.buf=(GUI.isSet(str))?str:'';};StringBuffer.prototype={append:function(str){this.buf+=str;return this;},clear:function(){this.buf='';return this;},toString:function(){return this.buf;}};}
GUI.StringBuffer=StringBuffer;if(window.GUI){Object.extend(window.GUI,GUI);}else{window.GUI=GUI;}}());(function(){var Event={on:function(element,eventName,handler,scope){if(!element._jsguiElementId){var elementId=++Event._elementsCounter;element._jsguiElementId=elementId;var elementCache=Event._elementsCache[elementId]={};}else{var elementCache=Event._elementsCache[element._jsguiElementId];}
if(!elementCache[eventName]){var wrapperId=Event._addWrapper(element,eventName);elementCache[eventName]=wrapperId;}else{var wrapperId=elementCache[eventName];}
Event._addListener(wrapperId,handler,scope);},un:function(element,eventName,handler,scope){var elementId=element._jsguiElementId,elementCache=Event._elementsCache[elementId];if(typeof eventName=='undefined'){for(eventName in elementCache){Event.un(element,eventName);}}else{wrapperId=elementCache[eventName];if(Event._removeListener(wrapperId,handler,scope)){Event._removeWrapper(element,eventName,wrapperId);delete Event._elementsCache[elementId][eventName];}}},fire:function(element,eventName,data){Event.fire=(document.createEvent)?function(element,eventName,data){var event;event=document.createEvent("HTMLEvents");data=data||{};if(Event._isDomEvent(eventName)){event.initEvent(eventName,true,true);Object.extend(event,data);}else{event.initEvent('dataavailable',true,true);event.eventName=eventName;event.memo=data;}
element.dispatchEvent(event);}:function(element,eventName,data){var event;event=document.createEventObject();data=data||{};if(Event._isDomEvent(eventName)){Object.extend(event,data);event.eventType='on'+eventName;}else{event.eventType='ondataavailable';event.eventName=eventName;event.memo=data;}
element.fireEvent(event.eventType,event);}
return Event.fire(element,eventName);},_elementsCache:{},_elementsCounter:0,_listeners:{},_listenersCounter:0,_wrappers:{},_wrappersCounter:0,_getWrapper:function(){return new Function("GUI.Event._eventDispatcher(arguments, this)");},_getWrapper2:function(){return new Function("GUI.Event._eventDispatcher(arguments[0], this)");},_isDomEvent:function(eventName){return!eventName.include(':');},_eventDispatcher:function(args,sender){var c=args.callee,evt=args[0]||window.event;if(c.eventName&&(evt.eventName!==c.eventName)){return false;}
var listeners=GUI.Event._listeners,ls=c.listeners.clone(),len=ls.length,i,id,listener;GUI.Event.extend(evt);for(i=0;i<len;i++){id=ls[i];listener=listeners[id];try{listener[0].call(listener[1],evt);}catch(e){console.log("Error while dispatching event: ",e);}}},_addListener:function(wrapperId,listener,scope){var id=++Event._listenersCounter;Event._listeners[id]=[listener,scope];Event._wrappers[wrapperId].listeners.push(id);},_removeListener:function(wrapperId,listener,scope){var listeners=Event._wrappers[wrapperId].listeners,i=listeners.length;if(listener){while(i--){var listenerId=listeners[i],l=Event._listeners[listenerId];if((l[0]==listener)&&(l[1]==scope)){delete Event._listeners[listenerId];listeners.splice(i,1);break;}}
return(listeners.length==0);}
while(i--){delete Event._listeners[listeners[i]];}
Event._wrappers[wrapperId].listeners=[];return true;},_addWrapper:function(element,eventName){var id=++Event._wrappersCounter,wrapper;if(!GUI.isIE&&(eventName=='mouseenter'||eventName=='mouseleave')){var ow=Event._getWrapper2();wrapper=function(e){var rel=e.relatedTarget;if(!((element==rel)||GUI.contains(element,e.relatedTarget))){return ow.call(this,arguments);}};eventName=(eventName=='mouseenter')?'mouseover':'mouseout';}else{wrapper=Event._getWrapper();}
wrapper.listeners=[];Event._wrappers[id]=wrapper;if(!Event._isDomEvent(eventName)){wrapper.eventName=eventName;eventName='dataavailable';}
if(element.addEventListener){element.addEventListener(eventName,wrapper,false);}else{element.attachEvent('on'+eventName,wrapper);}
return id;},_removeWrapper:function(element,eventName,wrapperId){var wrapper=Event._wrappers[wrapperId];if(!GUI.isIE&&(eventName=='mouseenter'||eventName=='mouseleave')){eventName=(eventName=='mouseenter')?'mouseover':'mouseout';}
if(!Event._isDomEvent(eventName)){delete wrapper.eventName;eventName='dataavailable';}
if(element.removeEventListener){element.removeEventListener(eventName,wrapper,false);}else{element.detachEvent('on'+eventName,wrapper);}
delete wrapper.listeners;delete Event._wrappers[wrapperId];},_eventExtensions:{preventDefault:function(){this.returnValue=false;},cancelBubble:function(){this.cancelBubble=true;},stop:function(){this.preventDefault();this.cancelBubble();}},extend:function(evt){if(GUI.isIE){if(evt.type=='mouseover'){evt.relatedTarget=evt.fromElement;}else if(evt.type=='mouseout'){evt.relatedTarget=evt.toElement;}
Object.extend(evt,Event._eventExtensions);evt=null;}},dump:function(){}};GUI.Event=Event;Object.extend(document,{fire:Event.fire.methodize(),on:Event.on.methodize(),un:Event.un.methodize(),loaded:false});}());document.on('dom:loaded',function(){var bd=GUI.getBody();if(!bd){return;}
var cls=GUI.isIE?"x-ie "+(GUI.isIE6?'x-ie6':GUI.isIE7?'x-ie7':''):GUI.isGecko?"x-gecko":GUI.isOpera?"x-opera":GUI.isSafari?"x-safari":"";if(GUI.isBorderBox){cls+=' x-border-box';}
if(GUI.isStrict){var p=bd.parentNode;if(p){p.className+=' x-strict';}}
bd.addClass(cls);});(function(){if(GUI.isIE){function cleanUpFp(){var fp=Function.prototype;delete fp.defer;delete fp.bind;delete fp.bindAsEventListener;delete fp.methodize;GUI.Event.un(window,'unload',cleanUpFp);}
GUI.Event.on(window,'unload',cleanUpFp);}
if(autoDestroy){function cleanUpObjects(){GUI.destroyObjects();GUI.Event.un(window,'unload',cleanUpObjects);}
GUI.Event.on(window,'unload',cleanUpObjects);}}());(function(){var a;if(!window.HTMLElement&&(a=document.createElement('div').__proto__)&&(a==document.createElement('form').__proto__)){window.HTMLElement={};window.HTMLElement.prototype=a;}}());(function(){var Dom={_whereTable:{beforeBegin:'previousSibling',afterBegin:'firstChild',beforeEnd:'lastChild',afterEnd:'nextSibling'},insertAdjacentElement:function(node,where,fragment){if(window.HTMLElement&&window.HTMLElement.prototype.insertAdjacentElement){Dom.insertAdjacentElement=function(node,where,fragment){node.insertAdjacentElement(where,fragment);return node[Dom._whereTable[where]];};}else{Dom.insertAdjacentElement=function(node,where,fragment){switch(where){case'beforeBegin':node.parentNode.insertBefore(fragment,node);return node.previousSibling;case'afterBegin':node.insertBefore(fragment,node.firstChild);return node.firstChild;case'beforeEnd':node.appendChild(fragment);return node.lastChild;case'afterEnd':if(node.nextSibling){node.parentNode.insertBefore(fragment,node.nextSibling);}else{node.parentNode.appendChild(fragment);}
return node.nextSibling;default:throw new Error("Dom.insertAdjacentElement(): invalid where value: "+where);}};}
return Dom.insertAdjacentElement(node,where,fragment);},insertAdjacentHTML:function(node,where,html){if(document.createElement('div').insertAdjacentHTML){Dom.insertAdjacentHTML=function(node,where,html){node.insertAdjacentHTML(where,html);return node[Dom._whereTable[where]];};}else{Dom.insertAdjacentHTML=function(node,where,html){var r=node.ownerDocument.createRange();r.setStartBefore(node);var fragment=r.createContextualFragment(html);return Dom.insertAdjacentElement(node,where,fragment);};}
return Dom.insertAdjacentHTML(node,where,html);},insertAdjacentText:function(node,where,text){if(document.createElement('div').insertAdjacentHTML){Dom.insertAdjacentText=function(node,where,text){node.insertAdjacentText(where,text);}}else{Dom.insertAdjacentText=function(node,where,text){var fragment=document.createTextNode(text)
Dom.insertAdjacentElement(where,fragment)}}
return Dom.insertAdjacentText(node,where,html);},insertBefore:function(node,html){return Dom.insertAdjacentHTML(node,'beforeBegin',html);},append:function(node,html){return Dom.insertAdjacentHTML(node,'beforeEnd',html);},extend:function(node){if(!node._jsguiExtended){Object.extend(node,Dom._elementExtensions);node._jsguiExtended=true;}
return node;},_getClasses:function(node){if(!node._classCache){var re=/\s+/g,cls=node.className||'';cls=cls.replace(re,'');var arr=(cls.empty())?[]:cls.split(' ');node._classCache=arr;return arr;}else{return node._classCache;}},addClass:function(node,className){node=GUI.$(node);var classes=Dom._getClasses(node),idx=classes.indexOf(className);if(idx==-1){classes[classes.length]=className;node.className=classes.join(' ');}},removeClass:function(node,className){node=GUI.$(node);var classes=Dom._getClasses(node),idx=classes.indexOf(className);if(idx!=-1){classes.splice(idx,1);node.className=classes.join(' ');}},hasClass:function(node,className){node=GUI.$(node);var classes=Dom._getClasses(node);return classes.indexOf(className)!=-1;}};Dom._elementExtensions={on:GUI.Event.on.methodize(),un:GUI.Event.un.methodize(),addClass:Dom.addClass.methodize(),removeClass:Dom.removeClass.methodize(),hasClass:Dom.hasClass.methodize()};GUI.Dom=Dom;}());(function(){var timer;function fireContentLoadedEvent(){if(document.loaded){return;}
if(timer){window.clearInterval(timer);}else if(document.removeEventListener){document.removeEventListener("DOMContentLoaded",fireContentLoadedEvent,false);}
document.loaded=true;document.fire('dom:loaded');document.un('dom:loaded');}
if(document.addEventListener){if(GUI.isSafari){timer=window.setInterval(function(){if(/loaded|complete/.test(document.readyState)){fireContentLoadedEvent();}},0);GUI.Event.on(window,'load',fireContentLoadedEvent);}else{document.addEventListener("DOMContentLoaded",fireContentLoadedEvent,false);}}else{document.write("<script id=\"__onDOMContentLoaded\" defer=\"defer\" src=\"//:\"><\/script>");var defer=GUI.$('__onDOMContentLoaded');defer.onreadystatechange=function(){if(this.readyState=="complete"){this.onreadystatechange=null;GUI.remove(defer);defer=null;fireContentLoadedEvent();}};}}());

GUI.Utils={};

$.on=Event.observe;GUI.Utils.Observable=Class.create();GUI.Utils.Observable.prototype={initialize:function(){if(this.listeners){this.on(this.listeners);delete this.listeners;}
GUI.registerObject(this);},fireEvent:function(){var ce=this.events[arguments[0].toLowerCase()];if(typeof ce=="object"){return ce.fire.apply(ce,Array.prototype.slice.call(arguments,1));}else{return true;}},filterOptRe:/^(?:scope|delay|buffer|single)$/,addListener:function(eventName,fn,scope,o){if(typeof eventName=="object"){o=eventName;for(var e in o){if(this.filterOptRe.test(e)){continue;}
if(typeof o[e]=="function"){this.addListener(e,o[e],o.scope,o);}else{this.addListener(e,o[e].fn,o[e].scope,o[e]);}}
return;}
o=(!o||typeof o=="boolean")?{}:o;eventName=eventName.toLowerCase();var ce=this.events[eventName]||true;if(typeof ce=="boolean"){ce=new GUI.Utils.Event(this,eventName);this.events[eventName]=ce;}
ce.addListener(fn,scope,o);},removeListener:function(eventName,fn,scope){var ce=this.events[eventName.toLowerCase()];if(typeof ce=="object"){ce.removeListener(fn,scope);}},purgeListeners:function(){for(var evt in this.events){if(typeof this.events[evt]=="object"){this.events[evt].clearListeners();}}},addEvents:function(o){if(!this.events){this.events={};}
Object.extend(this.events,o);},hasListener:function(eventName){var e=this.events[eventName];return typeof e=="object"&&e.listeners.length>0;},capture:function(o,fn,scope){throw new Exception('Observable.capture is not implemented!');},releaseCapture:function(o){o.fireEvent=GUI.Utils.Observable.prototype.fireEvent;}};GUI.Utils.Observable.prototype.on=GUI.Utils.Observable.prototype.addListener;GUI.Utils.Observable.prototype.un=GUI.Utils.Observable.prototype.removeListener;(function(){var createBuffered=function(h,o,scope){var task=new GUI.Utils.DelayedTask();return function(){task.delay(o.buffer,h,scope,Array.prototype.slice.call(arguments,0));};};var createSingle=function(h,e,fn,scope){return function(){e.removeListener(fn,scope);return h.apply(scope,arguments);};};var createDelayed=function(h,o,scope){return function(){var args=Array.prototype.slice.call(arguments,0);setTimeout(function(){h.apply(scope,args);},o.delay||10);};};GUI.Utils.Event=Class.create();GUI.Utils.Event.prototype={initialize:function(obj,name){this.name=name;this.obj=obj;this.listeners=[];},addListener:function(fn,scope,options){var o=options||{};scope=scope||this.obj;if(!this.isListening(fn,scope)){var l={fn:fn,scope:scope,options:o};var h=fn;if(o.delay){h=createDelayed(h,o,scope);}
if(o.single){h=createSingle(h,this,fn,scope);}
if(o.buffer){h=createBuffered(h,o,scope);}
l.fireFn=h;if(!this.firing){this.listeners.push(l);}else{this.listeners=this.listeners.slice(0);this.listeners.push(l);}}},findListener:function(fn,scope){scope=scope||this.obj;var ls=this.listeners;for(var i=0,len=ls.length;i<len;i++){var l=ls[i];if(l.fn==fn&&l.scope==scope){return i;}}
return-1;},isListening:function(fn,scope){return this.findListener(fn,scope)!=-1;},removeListener:function(fn,scope){var index;if((index=this.findListener(fn,scope))!=-1){if(!this.firing){this.listeners.splice(index,1);}else{this.listeners=this.listeners.slice(0);this.listeners.splice(index,1);}
return true;}
return false;},clearListeners:function(){this.listeners=[];},fire:function(){var ls=this.listeners,scope,len=ls.length;if(len>0){this.firing=true;var args=Array.prototype.slice.call(arguments,0);for(var i=0;i<len;i++){var l=ls[i];if(l.fireFn.apply(l.scope||this.obj||window,arguments)===false){this.firing=false;return false;}}
this.firing=false;}
return true;}};}());

GUI.Utils.DelayedTask=function(fn,scope,args){var id=null,d,t;var call=function(){var now=new Date().getTime();if(now-t>=d){clearInterval(id);id=null;fn.apply(scope,args||[]);}};this.delay=function(delay,newFn,newScope,newArgs){if(id&&delay!=d){this.cancel();}
d=delay;t=new Date().getTime();fn=newFn||fn;scope=newScope||scope;args=newArgs||args;if(!id){id=setInterval(call,d);}};this.cancel=function(){if(id){clearInterval(id);id=null;}};};

GUI.Utils.Collection=Class.create();Object.extend(Object.extend(GUI.Utils.Collection.prototype,GUI.Utils.Observable.prototype),{initialize:function(allowFunctions,keyFn){this.allowFunctions=false;this.items=[];this.map={};this.keys=[];this.length=0;this.addEvents({"clear":true,"add":true,"replace":true,"remove":true,"sort":true});this.allowFunctions=allowFunctions===true;if(keyFn){this.getKey=keyFn;}
GUI.Utils.Observable.prototype.initialize.call(this);},add:function(key,o){if(arguments.length==1){o=arguments[0];key=this.getKey(o);}
if(typeof key=="undefined"||key===null){this.length++;this.items.push(o);this.keys.push(null);}else{var old=this.map[key];if(old){return this.replace(key,o);}
this.length++;this.items.push(o);this.map[key]=o;this.keys.push(key);}
this.fireEvent("add",this.length-1,o,key);return o;},getKey:function(o){return o.id;},replace:function(key,o){if(arguments.length==1){o=arguments[0];key=this.getKey(o);}
var old=this.item(key);if(typeof key=="undefined"||key===null||typeof old=="undefined"){return this.add(key,o);}
var index=this.indexOfKey(key);this.items[index]=o;this.map[key]=o;this.fireEvent("replace",key,old,o);return o;},addAll:function(objs){if(arguments.length>1||objs instanceof Array){var args=arguments.length>1?arguments:objs;for(var i=0,len=args.length;i<len;i++){this.add(args[i]);}}else{for(var key in objs){if(this.allowFunctions||typeof objs[key]!="function"){this.add(key,objs[key]);}}}},each:function(fn,scope){var items=[].concat(this.items);for(var i=0,len=items.length;i<len;i++){if(fn.call(scope||items[i],items[i],i,len)===false){break;}}},eachKey:function(fn,scope){for(var i=0,len=this.keys.length;i<len;i++){fn.call(scope||window,this.keys[i],this.items[i],i,len);}},find:function(fn,scope){for(var i=0,len=this.items.length;i<len;i++){if(fn.call(scope||window,this.items[i],this.keys[i])){return this.items[i];}}
return null;},insert:function(index,key,o){if(arguments.length==2){o=arguments[1];key=this.getKey(o);}
if(index>=this.length){return this.add(key,o);}
this.length++;this.items.splice(index,0,o);if(typeof key!="undefined"&&key!=null){this.map[key]=o;}
this.keys.splice(index,0,key);this.fireEvent("add",index,o,key);return o;},remove:function(o){return this.removeAt(this.indexOf(o));},removeAt:function(index){if(index<this.length&&index>=0){this.length--;var o=this.items[index];this.items.splice(index,1);var key=this.keys[index];if(typeof key!="undefined"){delete this.map[key];}
this.keys.splice(index,1);this.fireEvent("remove",o,key);return o;}
return false;},removeKey:function(key){return this.removeAt(this.indexOfKey(key));},getCount:function(){return this.length;},indexOf:function(o){return this.items.indexOf(o);},indexOfKey:function(key){return this.keys.indexOf(key);},item:function(key){var item=typeof this.map[key]!="undefined"?this.map[key]:this.items[key];return typeof item!='function'||this.allowFunctions?item:null;},itemAt:function(index){return this.items[index];},keyAt:function(index){return this.keys[index];},key:function(key){return this.map[key];},contains:function(o){return this.indexOf(o)!=-1;},containsKey:function(key){return typeof this.map[key]!="undefined";},clear:function(){this.length=0;this.items=[];this.keys=[];this.map={};this.fireEvent("clear");},first:function(){return this.items[0];},last:function(){return this.items[this.length-1];},_sort:function(property,dir,fn){var dsc=String(dir).toUpperCase()=="DESC"?-1:1;fn=fn||function(a,b){return a-b;};var c=[],k=this.keys,items=this.items;for(var i=0,len=items.length;i<len;i++){c[c.length]={key:k[i],value:items[i],index:i};}
c.sort(function(a,b){var v=fn(a[property],b[property])*dsc;if(v==0){v=(a.index<b.index?-1:1);}
return v;});for(var i=0,len=c.length;i<len;i++){items[i]=c[i].value;k[i]=c[i].key;}
this.fireEvent("sort",this);},sort:function(dir,fn){this._sort("value",dir,fn);},keySort:function(dir,fn){this._sort("key",dir,fn||function(a,b){return String(a).toUpperCase()-String(b).toUpperCase();});},getRange:function(start,end){var items=this.items;if(items.length<1){return[];}
start=start||0;end=Math.min(typeof end=="undefined"?this.length-1:end,this.length-1);var r=[];if(start<=end){for(var i=start;i<=end;i++){r[r.length]=items[i];}}else{for(var i=start;i>=end;i--){r[r.length]=items[i];}}
return r;},filter:function(property,value,anyMatch,caseSensitive){if(GUI.isSet(value)){return this.clone();}
value=this.createValueMatcher(value,anyMatch,caseSensitive);return this.filterBy(function(o){return o&&value.test(o[property]);});},filterBy:function(fn,scope){var r=new GUI.Utils.Collection();r.getKey=this.getKey;var k=this.keys,it=this.items;for(var i=0,len=it.length;i<len;i++){if(fn.call(scope||this,it[i],k[i])){r.add(k[i],it[i]);}}
return r;},findIndex:function(property,value,start,anyMatch,caseSensitive){if(GUI.isSet(value)){return-1;}
value=this.createValueMatcher(value,anyMatch,caseSensitive);return this.findBy(function(o){return o&&value.test(o[property]);},null,start);},findIndexBy:function(fn,scope,start){var k=this.keys,it=this.items;for(var i=(start||0),len=it.length;i<len;i++){if(fn.call(scope||this,it[i],k[i])){return i;}}
if(typeof start=='number'&&start>0){for(var i=0;i<start;i++){if(fn.call(scope||this,it[i],k[i])){return i;}}}
return-1;},createValueMatcher:function(value,anyMatch,caseSensitive){if(!value.exec){value=String(value);value=new RegExp((anyMatch===true?'':'^')+GUI.escapeRe(value),caseSensitive?'':'i');}
return value;},clone:function(){var r=new GUI.Utils.Collection();var k=this.keys,it=this.items;for(var i=0,len=it.length;i<len;i++){r.add(k[i],it[i]);}
r.getKey=this.getKey;return r;}});GUI.Utils.Collection.prototype.get=GUI.Utils.Collection.prototype.item;

(function()
{var ComponentMgr=Class.create();var prototype={initialize:function()
{this._components=[];this._indexByName={};},register:function(name,object)
{if(!GUI.isString(name)){object=name;name=name.getId();}
if(!name){return;}
var regName=this.isRegistered(object);if(regName){throw new Error("Object is already registered with name: "+regName);}else{var index=this._components.length;this._components[index]=object;this._indexByName[name]=index;}},unregister:function(object)
{var regName=this.isRegistered(object);if(!regName){throw new Error("Object is not registered to unregister!");}else{var index=this._indexByName[regName];delete this._components[index];delete this._indexByName[name];}},isRegistered:function(object){var i=this._components.length;while(i--){if(this._components[i]===object){return this._getNameByIndex(i);}}
return false;},get:function(name){var index=this._indexByName[name];if(GUI.isNumber(index)){return this._components[index];}else{return false;}},_getNameByIndex:function(index)
{for(var name in this._indexByName){if(this._indexByName[name]==index){return name;}}
return false;}};Object.extend(ComponentMgr.prototype,prototype);GUI.ComponentMgr=new ComponentMgr();GUI.getCmp=GUI.ComponentMgr.get.bind(GUI.ComponentMgr);})();

(function()
{var Region=function(t,r,b,l){this.top=t;this[1]=t;this.right=r;this.bottom=b;this.left=l;this[0]=l;};Region.prototype={contains:function(region){return(region.left>=this.left&&region.right<=this.right&&region.top>=this.top&&region.bottom<=this.bottom);},getArea:function(){return((this.bottom-this.top)*(this.right-this.left));},getHeight:function(){return this.bottom-this.top;},getWidth:function(){return this.right-this.left;},intersect:function(region){var t=Math.max(this.top,region.top);var r=Math.min(this.right,region.right);var b=Math.min(this.bottom,region.bottom);var l=Math.max(this.left,region.left);if(b>=t&&r>=l){return new Region(t,r,b,l);}else{return null;}},union:function(region){var t=Math.min(this.top,region.top);var r=Math.max(this.right,region.right);var b=Math.max(this.bottom,region.bottom);var l=Math.min(this.left,region.left);return new Region(t,r,b,l);},adjust:function(t,l,b,r){this.top+=t;this.left+=l;this.right+=r;this.bottom+=b;return this;}};Region.getRegion=function(el){var p=GUI.getPosition.getXY(el,true);var t=p[1];var r=p[0]+el.offsetWidth;var b=p[1]+el.offsetHeight;var l=p[0];return new Region(t,r,b,l);};var Point=function(x,y){if(x instanceof Array){y=x[1];x=x[0];}
this.x=this.right=this.left=this[0]=x;this.y=this.top=this.bottom=this[1]=y;};Point.prototype=new Region();GUI.Utils.Region=Region;GUI.Utils.Point=Point;}());

(function()
{var DragDropMgr=Class.create();var prototype={dragPixelThresh:3,dragTimeThresh:1000,dragTimeout:null,stopPropagation:false,preventDefault:true,useCache:true,initialize:function(config)
{this.handleIds={};this.registeredDDs={};this.dragOvers={};this.locationCache={};this.dragObj=null;this.mouseUpListener=this.onMouseUp.bindAsEventListener(this);this.mouseMoveListener=this.onMouseMove.bindAsEventListener(this);this.unloadListener=this.onUnLoad.bindAsEventListener(this);GUI.onDOMReady(this.onLoad.bind(this));},registerDD:function(ddObj,group){if(!this.registeredDDs[group]){this.registeredDDs[group]={};}
this.registeredDDs[group][ddObj.config.id]=ddObj;},unregisterDD:function(ddObj,group){if(this.dragObj==ddObj){this.stopDrag();}
delete this.registeredDDs[group][ddObj.config.id];},getDDById:function(id){for(var i in this.registeredDDs){if(this.registeredDDs[i][id]){return this.registeredDDs[i][id];}}},registerHandle:function(ddId,handleId){if(!this.handleIds[ddId]){this.handleIds[ddId]={};}
this.handleIds[ddId][handleId]=handleId;},unregisterHandle:function(ddId,handleId){delete this.handleIds[ddId][handleId];},isHandle:function(ddId,handleId){return(this.handleIds[ddId]&&this.handleIds[ddId][handleId]);},handleWasClicked:function(node,id){if(this.isHandle(id,node.id)){return true;}else{var p=node.parentNode;while(p){if(this.isHandle(id,p.id)){return true;}else{p=p.parentNode;}}}
return false;},handleMouseDown:function(e,ddObj){this.dragObj=ddObj;this.dragObjConfig=ddObj.ddConfig;var dom=ddObj.getDom();this.startX=Event.pointerX(e);this.startY=Event.pointerY(e);this.deltaX=this.startX-dom.offsetLeft;this.deltaY=this.startY-dom.offsetTop;this.dragThreshMet=false;this.dragTimeout=setTimeout(function(){var DDM=GUI.Utils.DDM;DDM.startDrag(DDM.startX,DDM.startY);},this.dragTimeThresh);},startDrag:function(x,y){clearTimeout(this.dragTimeout);if(this.dragObj){if(!this.dragObj.ddConfig.moveOnly){this.refreshCache(this.dragObj.ddConfig.groups);}
if(this.dragObj.onBeforeDragStart(x,y)!==false){this.dragObj.onDragStart(x,y);this.dragThreshMet=true;}else{this.dragObj=null;}}},stopDrag:function(e){if(this.dragObj){if(this.dragThreshMet){this.dragObj.onDragEnd(e);}}
this.dragObj=null;this.dragOvers={};},fireDragEvents:function(e,isDrop){var pt=new GUI.Utils.Point(Event.pointerX(e),Event.pointerY(e));var dc=this.dragObj;var oldOvers=[];var outEvts=[];var overEvts=[];var dropEvts=[];var enterEvts=[];for(var i in this.dragOvers){var ddo=this.dragOvers[i];if(!this.isOverTarget(pt,ddo)){outEvts.push(ddo);}
oldOvers[i]=true;delete this.dragOvers[i];}
for(var group in dc.ddConfig.groups){for(i in this.registeredDDs[group]){var oDD=this.registeredDDs[group][i];if(oDD.ddConfig.isTarget&&oDD!=dc){if(this.isOverTarget(pt,oDD)){if(isDrop){dropEvts.push(oDD);}else{if(!oldOvers[oDD.config.id]){enterEvts.push(oDD);}
overEvts.push(oDD);this.dragOvers[oDD.config.id]=oDD;}}}}}
var acceptsDrop=false;{var len=0;for(i=0,len=outEvts.length;i<len;++i){outEvts[i].onDragLeave(e,this.dragObj);}
for(i=0,len=enterEvts.length;i<len;++i){enterEvts[i].onDragEnter(e,this.dragObj);}
for(i=0,len=overEvts.length;i<len;++i){if(overEvts[i].onDragOver(e,this.dragObj,pt)===true){acceptsDrop=true;}}
for(i=0,len=dropEvts.length;i<len;++i){dropEvts[i].onDragDrop(e,this.dragObj);}}
if(isDrop&&!dropEvts.length){dc.onInvalidDrop(e);}
return acceptsDrop;},refreshCache:function(groups){for(var sGroup in groups){if("string"!=typeof sGroup){continue;}
for(var i in this.registeredDDs[sGroup]){var oDD=this.registeredDDs[sGroup][i];this.refreshCacheOne(oDD);}}},refreshCacheOne:function(oDD){var loc=this.getLocation(oDD);if(loc){this.locationCache[oDD.config.id]=loc;}else{delete this.locationCache[oDD.config.id];}},getLocation:function(oDD){var el=GUI.$(oDD.ddConfig.targetElId),pos,x1,x2,y1,y2,t,r,b,l;if(!el){return null;}
pos=GUI.getPosition(el,true);if(!pos){return null;}
x1=pos[0];x2=x1+el.offsetWidth;y1=pos[1];y2=y1+el.offsetHeight;t=y1;r=x2;b=y2;l=x1;var loc=new GUI.Utils.Region(t,r,b,l);if(oDD.ddConfig.clipElId){el=GUI.$(oDD.ddConfig.clipElId);pos=GUI.getPosition(el,true);l=pos[0];r=l+el.offsetWidth;t=pos[1];b=t+el.offsetHeight;var clip=new GUI.Utils.Region(t,r,b,l);loc=loc.intersect(clip);if(!loc){loc=new GUI.Utils.Point(-10000,-10000);}}
return loc;},isOverTarget:function(pt,oTarget,intersect){var loc=this.locationCache[oTarget.config.id];if(!loc||!this.useCache){loc=this.getLocation(oTarget);this.locationCache[oTarget.config.id]=loc;}
if(!loc){return false;}
oTarget.cursorIsOver=loc.contains(pt);var dc=this.dragObj;if(!dc||!dc.getTargetCoord||(!intersect&&!dc.constrainX&&!dc.constrainY)){return oTarget.cursorIsOver;}},stopEvent:function(e){if(this.stopPropagation){GUI.stopPropagation(e);}
if(this.preventDefault){GUI.preventDefault(e);}},onMouseMove:function(e){if(!this.dragObj){return true;}
if(!this.dragThreshMet){var diffX=Math.abs(this.startX-Event.pointerX(e));var diffY=Math.abs(this.startY-Event.pointerY(e));if(diffX>this.dragPixelThresh||diffY>this.dragPixelThresh){this.startDrag(this.startX,this.startY);}}else{var acceptsDrop=false;if(!this.dragObj.ddConfig.moveOnly){acceptsDrop=this.fireDragEvents(e,false);}
if(this.dragObj.onBeforeDrag(e)!==false){this.dragObj.onDrag(e,acceptsDrop);}}
this.stopEvent(e);},onMouseUp:function(e){if(!this.dragObj){return;}
clearTimeout(this.dragTimeout);if(this.dragThreshMet){this.fireDragEvents(e,true);}else{}
this.stopDrag(e);this.stopEvent(e);},onLoad:function(){Event.observe(document,'mouseup',this.mouseUpListener);Event.observe(document,'mousemove',this.mouseMoveListener);Event.observe(window,'unload',this.unloadListener);},onUnLoad:function(){Event.stopObserving(document,'mouseup',this.mouseUpListener);Event.stopObserving(document,'mousemove',this.mouseMoveListener);Event.stopObserving(window,'unload',this.unloadListener);}};Object.extend(DragDropMgr.prototype,prototype);GUI.Utils.DDM=new DragDropMgr();})();

(function()
{var Draggable=Class.create();var superproto=GUI.Utils.Observable.prototype;var prototype={initialize:function(config)
{var defCfg={dd:{linkedElId:null,dragElId:null,handleElId:null,targetElId:null,isTarget:false,moveOnly:true,disabled:false,groups:{'default':true},clipElId:null,hasOuterHandles:false}};Object.extend(defCfg,config);this.config=defCfg;superproto.initialize.call(this);this.DDM=GUI.Utils.DDM;this.ddConfig=this.config.dd;this.ddMouseDownListener=this.onDdMouseDown.bindAsEventListener(this);},initDD:function(){for(var i in this.ddConfig.groups){this.DDM.registerDD(this,i);}
var el=GUI.$(this.ddConfig.linkedElId);if(!el){console.log('no linkedEl',this.ddConfig.linkedElId);return;}
if(!this.ddConfig.targetElId){this.ddConfig.targetElId=this.ddConfig.linkedElId;}
Event.observe(el,'mousedown',this.ddMouseDownListener);},destroyDD:function(){Event.stopObserving(GUI.$(this.ddConfig.linkedElId),'mousedown',this.ddMouseDownListener);for(var i in this.ddConfig.groups){this.DDM.unregisterDD(this,i);}},setHandleElId:function(id){this.ddConfig.handleElId=id;this.DDM.registerHandle(this.ddConfig.linkedElId,id);},unsetHandleElId:function(id){if(this.ddConfig.handleElId==id)
this.ddConfig.handleElId=null;this.DDM.unregisterHandle(this.ddConfig.linkedElId,id);},setOuterHandleElId:function(id){Event.observe(GUI.$(id),'mousedown',this.ddMouseDownListener);this.setHandleElId(id);this.ddConfig.hasOuterHandles=true;},unsetOuterHandleElId:function(id){Event.stopObserving(GUI.$(id),'mousedown',this.ddMouseDownListener);this.unsetHandleElId(id);this.ddConfig.hasOuterHandles=false;},setStartPosition:function(e){var dom=GUI.$(this.ddConfig.linkedElId);this.startPageXY=[dom.offsetLeft,dom.offsetTop];},dragValidator:function(e){var target=GUI.getEventTarget(e);return(((target.nodeName!='INPUT')||(target.type!='checkbox'))&&(this.ddConfig.linkedElId==this.ddConfig.handleElId||this.DDM.handleWasClicked(target,this.ddConfig.linkedElId)));},enableDD:function(){this.ddConfig.disabled=false;},disableDD:function(){this.ddConfig.disabled=true;},onDdMouseDown:function(e){if(this.ddConfig.disabled){return true;}
this.DDM.refreshCacheOne(this);var pt=new GUI.Utils.Point(Event.pointerX(e),Event.pointerY(e));if(this.ddConfig.hasOuterHandles||this.DDM.isOverTarget(pt,this)){if(this.dragValidator(e)){this.setStartPosition(e);this.DDM.handleMouseDown(e,this);this.DDM.stopEvent(e);}}},onBeforeDragStart:function(e){},onDragStart:function(e){},onBeforeDrag:function(e){},onDrag:function(e,dropAccepted){},onBeforeDragEnd:function(e){},onDragEnd:function(e){},onDragEnter:function(e,dragObj){},onDragOver:function(e,dragObj){},onDragLeave:function(e,dragObj){},onDragDrop:function(e,dragObj){},onInvalidDrop:function(e){}};Object.extend(Draggable.prototype,superproto);Object.extend(Draggable.prototype,prototype);GUI.Utils.Draggable=Draggable;})();

(function()
{var WindowMgr=Class.create();var prototype={zseed:5000,initialize:function()
{this.registeredWindows={};this.activeWindow=null;this.accessList=[];this.keyUpListener=this.onKeyUp.bindAsEventListener(this);this.keyDownListener=this.onKeyDown.bindAsEventListener(this);this.keyPressListener=this.onKeyPress.bindAsEventListener(this);GUI.onDOMReady(this.onLoad.bind(this));},register:function(win){this.registeredWindows[win.config.id]=win;this.accessList.push(win);win.on('hide',this.activateLast,this);},unregister:function(win){delete this.registeredWindows[win.config.id];GUI.arrayRemove(this.accessList,win);win.un('hide',this.activateLast,this);if(win==this.activeWindow){this.activeWindow=null;}},get:function(id){return(GUI.isObject(id))?id:this.registeredWindows[id];},bringToFront:function(win){win=this.get(win);if(win!=this.activeWindow){win._lastAccess=new Date().getTime();this.orderWindows();return true;}
return false;},sendToBack:function(win){win=this.get(win);win._lastAccess=-(new Date().getTime());this.orderWindows();},getActive:function(){return this.activeWindow;},sortWindows:function(d1,d2){return(!d1._lastAccess||d1._lastAccess<d2._lastAccess)?-1:1;},orderWindows:function(){var a=this.accessList,len=a.length;if(len>0){a.sort(this.sortWindows);var seed=a[0].WM.zseed;for(var i=0;i<len;i++){var win=a[i];if(win&&win.visible){win.setZIndex(seed+(i*10));}}}
this.activateLast();},setActiveWin:function(win){if(win!=this.activeWindow){if(this.activeWindow){this.activeWindow.setActive(false);}
this.activeWindow=win;if(win){this.activeWindow.setActive(true);}}},activateLast:function(){for(var i=this.accessList.length-1;i>=0;--i){if(this.accessList[i].visible){this.setActiveWin(this.accessList[i]);return;}}
this.setActiveWin(null);},onKeyDown:function(e){if(this.activeWindow){this.activeWindow.onKeyDown(e);}},onKeyUp:function(e){if(this.activeWindow){this.activeWindow.onKeyUp(e);}},onKeyPress:function(e){if(this.activeWindow){this.activeWindow.onKeyPress(e);}},onLoad:function(){Event.observe(document,'keyup',this.keyUpListener);Event.observe(document,'keydown',this.keyDownListener);Event.observe(document,'keypress',this.keyPressListener);},onUnLoad:function(){Event.stopObserving(document,'keyup',this.keyUpListener);Event.stopObserving(document,'keyup',this.keyDownListener);Event.stopObserving(document,'keypress',this.keyPressListener);}};Object.extend(WindowMgr.prototype,prototype);GUI.Utils.WM=new WindowMgr();})();

GUI.Fx={};

(function()
{var Element=Class.create();var superproto=GUI.Utils.Draggable.prototype;var prototype={initialize:function(config){superproto.initialize.call(this,config);var cfg=this.config;Object.extend(cfg,{id:undefined,html:undefined,holder:undefined,className:undefined,disabled:false,visible:true});Object.extend(cfg,config);this.elementType='GUI.Element';this.disabled=cfg.disabled?1:0;this.visible=cfg.visible;this.addEvents({beforeRender:true,afterRender:true,show:true,hide:true});if(typeof cfg.onBeforeRender=='function'){this.on('beforeRender',cfg.onBeforeRender,this);}
if(typeof cfg.onAfterRender=='function'){this.on('afterRender',cfg.onAfterRender,this);}
if(typeof cfg.onShow=='function'){this.on('show',cfg.onShow,this);}
if(typeof cfg.onHide=='function'){this.on('hide',cfg.onHide,this);}},destroy:function(){if(this.dom){this.unrender();}
this.purgeListeners();GUI.destroyObject(this);},render:function(to){if(!this.fireEvent('beforeRender',this)){return;}
if(this.dom){this.unrender();}
var cfg=this.config;if(to){cfg.holder=to;}else{to=cfg.holder;}
to=GUI.$(to);if(!to){throw new Error(this.elementType+' error in method render(): No holder '+to+' found');}
this._render(to);this.attachEventListeners();this.fireEvent('afterRender',this);},unrender:function(){if(!this.dom){return false;}
this.removeEventListeners();GUI.remove(this.dom);this.dom=null;},show:function(){if(!this.visible){this.visible=true;if(this.dom){GUI.show(this.dom);}
this.fireEvent('show',this);}},hide:function(){if(this.visible){this.visible=false;if(this.dom){GUI.hide(this.dom);}
this.fireEvent('hide',this);}},disable:function(flag){if((flag!==undefined)&&(!flag)){this.enable();}else{this.disabled++;if(this.disabled==1){this._disable();}}},_disable:function(){},enable:function(){if(this.disabled>0){this.disabled--;if(this.disabled==0){this._enable();}}},_enable:function(){},isEnabled:function(){return!this.disabled;},isDisabled:function(){return!!this.disabled;},getId:function(){return this.config.id;},getHolder:function(){return this.config.holder;},getHtml:function(){return this.config.html;},getVisibility:function(){var id=this.config.id;if($(id)){if(($(id).style.display==='none')||($(id).style.visibility==='hidden')){return false;}else{return true;}}
throw new Error(this.elementType+' error in method getVisibility(). Invalid id: '+id);},getDom:function(){return this.dom;},setHtml:function(html){this.config.html=html;},_render:function(to){if(!to){throw new Error('Can not render to:'+to);}
var div=document.createElement('SPAN');var cfg=this.config;if(GUI.isString(cfg.id))
div.id=cfg.id;if(GUI.isString(cfg.html))
div.innerHTML=cfg.html;if(GUI.isString(cfg.className))
div.className=cfg.className;this.dom=div;if(!this.visible){GUI.hide(this.dom);}
to.appendChild(this.dom);},attachEventListeners:function(){},removeEventListeners:function(){}};Object.extend(Element.prototype,superproto);Object.extend(Element.prototype,prototype);GUI.Element=Element;}());

GUI.ActiveElement=Class.create();Object.extend(Object.extend(GUI.ActiveElement.prototype,GUI.Element.prototype),{initialize:function(config){GUI.Element.prototype.initialize.apply(this,arguments);var cfg=this.config;Object.extend(cfg,{id:GUI.getUniqId('x-activeelement-'),name:null,caption:undefined,hint:null,img:undefined,xtype:null,disabled:false,className:'x-toolbar-active-element'});Object.extend(cfg,config);if(cfg.xtype&&GUI.ButtonTypes&&GUI.ButtonTypes[cfg.xtype]){var btn=GUI.ButtonTypes[cfg.xtype];cfg.caption=btn.caption;cfg.img=btn.img;cfg.hint=btn.hint;}
this.elementType='GUI.ActiveElement';this.contentId=GUI.getUniqId('activeelement-content-');this.innerClass='static';this.pressed=false;this.hover=false;this.dom=null;this.mouseDownListener=this.onMouseDown.bindAsEventListener(this);this.mouseUpListener=this.onMouseUp.bindAsEventListener(this);this.mouseOverListener=this.onMouseOver.bindAsEventListener(this);this.mouseOutListener=this.onMouseOut.bindAsEventListener(this);this.clickListener=this.onClick.bindAsEventListener(this);this.addEvents({click:true});if(typeof cfg.onClick=='function'){this.on('click',cfg.onClick,this);}},destroy:function(){if(this.dom){this.removeEventListeners();GUI.remove(this.dom);}
GUI.destroyObject(this);},_disable:function(){this.setClass();if(this.config.img){var img=this.getImgNode();if(img){img.src=GUI.getDisabledImageUrl(this.config.img);}}},_enable:function(){this.setClass();if(this.config.img){var img=this.getImgNode();if(img){img.src=this.config.img;}}},caption:function(text){if(!GUI.isSet(text)){return this.config.caption;}
this.config.caption=text;if(this.dom){var cont=GUI.$(this.contentId);var childs=cont.childNodes,node;for(var i=0;i<childs.length;i++){node=childs[i];if(node.tagName.toLowerCase()=='a'){node.innerHTML=text;break;}}}},getImgNode:function(){if(!this.dom){return null;}
var cont=GUI.$(this.contentId);var childs=cont.childNodes,node;for(var i=0;i<childs.length;i++){node=childs[i];if(node.tagName.toLowerCase()=='img'){return node;}}
return null;},img:function(url){if(!GUI.isSet(url)){return this.config.img;}
this.config.img=url;if(this.dom){var img=this.getImgNode();if(img){img.src=url;}}},hint:function(hint){this.config.hint=hint;if(this.dom){GUI.Popup.Hint.add(this.dom,hint);}},getVisibility:function(){if(!this.dom){throw new Error('Element is not rendered while calling getVisibility()');}
var style=this.dom.style;if((style.display==='none')||(style.visibility==='hidden')){return false;}else{return true;}},getName:function(){return this.config.name;},_render:function(to){if(!to){throw new Error('Can not render to:'+to);}
var cfg=this.config;var o=[];var tmp=document.createElement('div');o.push('<table class="',cfg.className,' ',this.innerClass,'"><col/><tbody><tr>');o.push('<td class="x-tab-l"><div/></td><td id="',this.contentId,'" class="x-tab-c">');if((GUI.isSet(cfg.img))&&(cfg.img!='')){o.push('<img align="absmiddle" src="',cfg.img,'" alt="');if((GUI.isSet(cfg.caption))&&(cfg.caption!='')){o.push(cfg.caption);}
o.push('" />');}
if((GUI.isSet(cfg.caption))&&(cfg.caption!='')){o.push('<a href="javascript:void(0);">',cfg.caption,'</a>');}
o.push('</td><td class="x-tab-r"><div/></td></tr></tbody></table>');tmp.innerHTML=o.join('');this.dom=$(tmp.firstChild);tmp.removeChild(tmp.firstChild);tmp=null;if(GUI.Popup.Hint){if((GUI.isSet(cfg.hint))&&(cfg.hint!='')){GUI.Popup.Hint.add(this.dom,cfg.hint);}}
this.setClass();to.appendChild(this.dom);},attachEventListeners:function(){var elem=this.dom;Event.observe(elem,'mousedown',this.mouseDownListener);Event.observe(elem,'mouseup',this.mouseUpListener);Event.observe(elem,'mouseover',this.mouseOverListener);Event.observe(elem,'mouseout',this.mouseOutListener);Event.observe(elem,'click',this.clickListener);},removeEventListeners:function(){var elem=this.dom;Event.stopObserving(elem,'mousedown',this.mouseDownListener);Event.stopObserving(elem,'mouseup',this.mouseUpListener);Event.stopObserving(elem,'mouseover',this.mouseOverListener);Event.stopObserving(elem,'mouseout',this.mouseOutListener);Event.stopObserving(elem,'click',this.clickListener);},setClass:function(){var cls='static';if(this.disabled){cls='disabled';}else if(this.pressed){cls='toggled';}else if(this.hover){cls='hover';}
this.innerClass=cls;if(this.dom){this.dom.className=this.config.className+' '+cls;}},onClick:function(e){GUI.preventDefault(e);if(!this.disabled){this.fireEvent('click',this);}},onMouseDown:function(event){if(this.disabled){return;}
this.pressed=true;this.setClass();},onMouseUp:function(event){if(this.disabled){return;}
this.pressed=false;this.setClass();},onMouseOver:function(event){if(this.disabled){return;}
if(GUI.isMouseEnter(this.dom,event)){this.hover=true;this.setClass();}},onMouseOut:function(event){if(this.disabled){return;}
if(GUI.isMouseLeave(this.dom,event)){this.pressed=false;this.hover=false;this.setClass();}}});

GUI.Popup={};

GUI.Popup.Region=Class.create();GUI.Popup.Region.startzIndex=10000;GUI.Popup.Region.zIndexCounter=GUI.Popup.Region.startzIndex;GUI.Popup.Region.getzIndex=function(){var val=GUI.Popup.Region.zIndexCounter;GUI.Popup.Region.zIndexCounter+=5;return val;}
Object.extend(Object.extend(GUI.Popup.Region.prototype,GUI.Utils.Draggable.prototype),{initialize:function(config){GUI.Utils.Draggable.prototype.initialize.apply(this,arguments);var cfg=this.config;Object.extend(cfg,{parentNode:null,content:'',id:GUI.getUniqId('x-region-'),className:'x-region',dimensions:{top:0,left:0},useShim:false});Object.extend(cfg,config);this.visible=false;this.alignArgs=[];this.addEvents({show:true,beforeHide:true,hide:true});},alignTo:function(id,pos,offset){if(this.dom){this._alignTo(id,pos,offset);}else{this.alignArgs=$A(arguments);}},show:function(){var cfg=this.config;var style;if(!this.visible){var node=document.createElement('div');node.id=cfg.id;node.style.position='absolute';node.className=cfg.className;GUI.hide(node);this.dom=node;if(!cfg.parentNode){cfg.parentNode=document.body;}
cfg.parentNode.appendChild(node);node.innerHTML=cfg.content;this.visible=true;}
var dim=cfg.dimensions;var style=this.dom.style;if(GUI.isSet(dim.top)){style.top=dim.top+'px';}
if(GUI.isSet(dim.left)){style.left=dim.left+'px';}
if(GUI.isSet(dim.width)){if(typeof dim.width=='number'){GUI.setFullWidth(this.dom,dim.width);}else{style.width=dim.width;}}
if(GUI.isSet(dim.height)){if(typeof dim.height=='number'){style.height=dim.height+'px';}else{style.height=dim.height;}}
style.zIndex=cfg.zIndex||GUI.Popup.Region.getzIndex();if((GUI.isSet(this.alignArgs))&&(this.alignArgs.length>0)){this._alignTo.apply(this,this.alignArgs);this.alignArgs=[];}
GUI.show(this.dom);this.fireEvent('show',this);if(cfg.useShim){if(!this.shim){this.createShim();}else{GUI.show(this.shim);}
setTimeout(function(){this.syncShim();}.bind(this),10);}},hide:function(){if(this.visible){if(this.fireEvent('beforeHide',this)===false){return;}
if(this.shim){GUI.hide(this.shim);}
GUI.remove(this.dom);this.dom=null;this.visible=false;this.fireEvent('hide',this);}},takeRegion:function(id){var cfg=this.config;var dim=cfg.dimensions;var elem=$(id);var pos=GUI.getPosition(elem,true);var elemDim=elem.getDimensions();if(this.dom){this.dom.style.left='-10000px';this.dom.style.top='-10000px';var disp=this.dom.style.display;GUI.show(this.dom);var pos=GUI.getLocalCoordinates(this.dom,pos);this.dom.style.display=disp;this.dom.style.left='';this.dom.style.top='';}else{console.log('this.dom ???'+this.visible);}
dim.left=pos[0];dim.top=pos[1];dim.height=elemDim.height;dim.width=elemDim.width;if(this.visible){$(this.dom).setStyle({left:dim.left+'px',top:dim.top+'px',width:dim.width+'px',height:dim.height+'px'});}},takeDocument:function(extend){var cfg=this.config;var dim=cfg.dimensions;dim.left=0;dim.top=0;dim.height=dim.width='100%';if(this.dom){this.dom.setStyle({left:'0px',top:'0px',width:'100%',height:'100%'});}},setContent:function(content){this.config.content=content;if(this.visible){Element.update(this.dom,content);}},setDimensions:function(dimensions){Object.extend(this.config.dimensions,Object.clone(dimensions));if(this.visible){var style=this.dom.style;if(GUI.isNumber(dimensions.left)){style.left=dimensions.left+'px';}else if(GUI.isString(dimensions.left)){style.left=dimensions.left;}
if(GUI.isNumber(dimensions.top)){style.top=dimensions.top+'px';}else if(GUI.isString(dimensions.top)){style.top=dimensions.top;}
if(GUI.isNumber(dimensions.width)){style.width=dimensions.width+'px';}else if(GUI.isString(dimensions.width)){style.width=dimensions.width;}
if(GUI.isNumber(dimensions.height)){style.height=dimensions.height+'px';}else if(GUI.isString(dimensions.height)){style.height=dimensions.height;}}},getDimensions:function(){var xy=Position.cumulativeOffset(this.dom);var dim=Element.getDimensions(this.dom);var cfgDim=this.config.dimensions;cfgDim.left=xy[0];cfgDim.top=xy[1];cfgDim.width=dim.width;cfgDim.height=dim.height;return{left:cfgDim.left,top:cfgDim.top,width:cfgDim.width,height:cfgDim.height};},getElement:function(){return this.dom;},getDom:function(){return this.dom;},setZIndex:function(zIndex){this.config.zIndex=zIndex;if(this.visible){this.dom.style.zIndex=zIndex;}},getVisibility:function(){return this.visible;},_alignTo:function(id,pos,offset){var c=false;var p1="",p2="";offset=offset||[0,0];if(!pos){pos="tl-bl";}else if(pos=="?"){pos="tl-bl?";}else if(pos.indexOf("-")==-1){pos="tl-"+pos;}
pos=pos.toLowerCase();var m=pos.match(/^([a-z]+)-([a-z]+)(\?)?$/);if(!m){throw new Error("Element.alignTo with an invalid alignment "+pos);}
p1=m[1];p2=m[2];c=!!m[3];var elem=$(id);var dim=this.config.dimensions;var a1=this.getAnchorXY(this.dom,p1,true);var a2=this.getAnchorXY(elem,p2,false);var x=a2[0]-a1[0]+offset[0];var y=a2[1]-a1[1]+offset[1];var swapX=false,swapY=false;if(c){var w=GUI.getFullWidth(this.dom);var h=GUI.getFullHeight(this.dom);var r=this.getRegion(elem);var dw=GUI.getViewportWidth(elem),dh=GUI.getViewportHeight(elem);var p1y=p1.charAt(0),p1x=p1.charAt(p1.length-1);var p2y=p2.charAt(0),p2x=p2.charAt(p2.length-1);var swapY=((p1y=="t"&&p2y=="b")||(p1y=="b"&&p2y=="t"));var swapX=((p1x=="r"&&p2x=="l")||(p1x=="l"&&p2x=="r"));var doc=document;var scrollX=(doc.documentElement.scrollLeft||doc.body.scrollLeft||0);var scrollY=(doc.documentElement.scrollTop||doc.body.scrollTop||0);if((x+w)>dw){x=swapX?(r.left-w):(dw+scrollX-w);x-=offset[0];}
if((x+w)>dw+scrollX){x=swapX?(r.left-w):(dw+scrollX-w);x-=offset[0];}
if(x<scrollX){x=swapX?r.right:scrollX;x+=offset[0];}
if((y+h)>dh+scrollY){y=swapY?(r.top-h):(dh+scrollY-h);y-=offset[1];}
if(y<scrollY){y=swapY?r.bottom:scrollY;y+=offset[1];}}
var xy=GUI.getLocalCoordinates(this.dom,[x,y]);x=xy[0];y=xy[1];dim.left=x;dim.top=y;this.dom.setStyle({left:x+'px',top:y+'px'});},getRegion:function(elem){var pos=GUI.getPosition(elem,true);var dim=Element.getDimensions(elem);return{left:pos[0],top:pos[1],right:pos[0]+dim.width,bottom:pos[1]+dim.height};},getAnchorXY:function(elem,anchor,local,size){var dim=this.config.dimensions;var w,h,vp=false;if(!size){if(elem==document.body||elem==document){vp=true;w=GUI.getViewportWidth(elem);h=GUI.getViewportHeight(elem);}else{var _dim=GUI.getDimensions(elem);w=_dim.width;h=_dim.height;}}else{w=size.width;h=size.height;}
var x=0,y=0,r=Math.round;switch((anchor||"tl").toLowerCase()){case"c":x=r(w*0.5);y=r(h*0.5);break;case"t":x=r(w*0.5);y=0;break;case"l":x=0;y=r(h*0.5);break;case"r":x=w;y=r(h*0.5);break;case"b":x=r(w*0.5);y=h;break;case"tl":x=0;y=0;break;case"bl":x=0;y=h;break;case"br":x=w;y=h;break;case"tr":x=w;y=0;break;}
if(local===true){return[x,y];}
if(vp){return[x,y];}
var o=GUI.getPosition(elem,true);;return[x+o[0],y+o[1]];},createShim:function(){var iframe=document.createElement('iframe');iframe.className='x-shim';iframe.frameBorder='no';this.dom.parentNode.insertBefore(iframe,this.dom);this.shim=iframe;},syncShim:function(){if(this.dom){this.shim.style.left=this.dom.offsetLeft+'px';this.shim.style.top=this.dom.offsetTop+'px';this.shim.style.width=this.dom.offsetWidth+'px';this.shim.style.height=this.dom.offsetHeight+'px';}}});

(function()
{var Dialog=Class.create();var superproto=GUI.Popup.Region.prototype;var prototype={initialize:function(config){var defCfg={id:GUI.getUniqId('x-dialog-'),cls:'x-dialog',modal:false,title:'',toolbuttons:[{name:'close',img:GUI.Constants.libPath+'img/x-dialog/x-dialog-ico-close.gif'}],dimensions:{left:-10000,top:-10000},zIndex:5000,visible:false,animate:true,toolbar:null,toolbarHeight:25,dd:{linkedElId:null,dragElId:null,handleElId:null,isTarget:true,moveOnly:true,groups:{'default':true},enableDrag:false,dropReciever:false,dragType:''}};Object.extend(defCfg,config);defCfg.dd.linkedElId=defCfg.id;var titleId=GUI.getUniqId('x-dialog-title-');defCfg.dd.handleElId=titleId;superproto.initialize.call(this,defCfg);Object.extend(this.config,defCfg);var cfg=this.config;if(GUI.isIE){cfg.animate=false;}
this.WM=GUI.Utils.WM;this.elementType='GUI.Popup.Dialog';this.alignArgs=null;this.visible=cfg.visible;this.scrollable=false;this.state='normal';this.toolbarId=GUI.getUniqId('x-dialog-toolbar-');this.iconsBarId=GUI.getUniqId('x-dialog-iconsbar-');this.topId=GUI.getUniqId('x-dialog-top-');this.centerId=GUI.getUniqId('x-dialog-center-');this.bottomId=GUI.getUniqId('x-dialog-bottom-');this.contentId=GUI.getUniqId('x-dialog-content-');this.titleId=titleId;this.glass=null;this.rendered=false;this.restoreDimensions=null;this.closeOnHide=false;this.beforeLimitDim={};this.originalDim={};this.defHandlers={close:this.close,minimize:this.minimize,maximize:this.maximize,restore:this.restore}
this.toolBoxClickListener=this.onToolBoxClick.bind(this);this.browserResizeListener=this.onBrowserResize.bindAsEventListener(this);this.mouseDownListener=this.onMouseDown.bindAsEventListener(this);this.on('windowResize',this.windowResizeHandler,this,{buffer:50});this.addEvents({close:true,dialogAction:true,windowResize:true,beforeClose:true});if(!GUI.isSet(this.config.dimensions.width)){this.config.dimensions.width='';}
if(!GUI.isSet(this.config.dimensions.height)){this.config.dimensions.height='';}},create:function(){var cfg=this.config;if(!cfg.parentNode){cfg.parentNode=document.body;}
if(GUI.isArray(cfg.toolbar)){if(!GUI.isSet(cfg.toolbarHeight)){throw new Error('Dialog: You have to specify toolbarHeight when using toolbar!');}
this.toolbar=new GUI.ToolBar({elements:cfg.toolbar});}else{cfg.toolbarHeight=0;}
if(this.config.modal){var maskZIndex=(GUI.isNumber(cfg.zIndex))?cfg.zIndex-1:GUI.Popup.Region.getzIndex();this.glass=new GUI.Popup.Region({parentNode:cfg.parentNode,zIndex:maskZIndex,content:'<div class="glass">&nbsp</div>'});this.glass.takeDocument(true);}
var o,o1='<table class="x-dialog-holder"><tbody><tr class="dialog-title">'+'<td class="dialog-topl"><div/></td><td class="dialog-header">'+'<div class="container"><div id="'+this.titleId+'" class="title"><span class="shadow">'+
cfg.title+'</span><span class="txt">'+cfg.title+'</span></div><div class="ico">'+'<div class="ico-container" id="'+this.iconsBarId+'">'+'</div></div><div class="clear"/></div></td>'+'<td class="dialog-topr"><div/></td></tr>',o2,o3,o4,o5;if(this.toolbar){o2='<tr class="dialog-tools"><td colspan="3" class="dialog-tools">'+'<div class="dialog-tools-l"><div class="dialog-tools-r"><div class="dialog-tools-c">'+'<div id="'+this.toolbarId+'" class="dialog-tools-container"></div></div></div></div></td></tr>';}else{o2='';}
o3='<tr class="dialog-content"><td class="dialog-mdll"><div/></td>'+'<td class="dialog-mdlc"><div class="dialog-content-holder"'+' id="'+this.contentId+'" >';if(typeof cfg.content=='string'){o4=cfg.content;}else if(cfg.content.innerHTML!==undefined){o4=cfg.content.innerHTML;}else{throw new Error(this.elementType+' create() error: cfg.content is not string or domnode!');}
o5='</div></td><td class="dialog-mdlr"><div/></td></tr>'+'<tr class="dialog-bottom"><td class="dialog-btml"><div/></td>'+'<td class="dialog-btmc"><div/></td><td class="dialog-btmr"><div/>'+'</td></tr></tbody></table>';o=o1+o2+o3+o4+o5;var node=document.createElement('div');node.id=cfg.id;node.style.position='absolute';node.style.zIndex=cfg.zIndex||GUI.Popup.Region.getzIndex();node.className=cfg.cls+' normalize';GUI.hide(node);node.innerHTML=o;this.dom=node;cfg.parentNode.appendChild(node);var a=document.createElement('a');a.className='x-dlg-focus';a.href='#';a.innerHTML='&#160;';a.tabIndex=-1;this.focusEl=a;node.appendChild(a);if(this.scrollable){GUI.$(this.contentId).style.overflow='auto';}
this.setDimensions(cfg.dimensions);if(this.config.animate){var self=this;this.fadeEf=new Animator({duration:500,onComplete:function(){if(this.state){self._show();}else{self._hide();}}});this.fadeEf.addSubject(new NumericalStyleSubject(node,'opacity',0,0.999999));this.fadeClose=new Animator({duration:500,onComplete:function(){self._close();}});this.fadeEf.addSubject(new NumericalStyleSubject(node,'opacity',0,0.999999));}
this.toolBox=new GUI.ToolBox({items:this.config.toolbuttons,onClick:this.toolBoxClickListener});this.toolBox.render($(this.iconsBarId));if(this.toolbar){this.toolbar.render($(this.toolbarId));}
this.attachEvents();this.initDD();this.setHandleElId(this.titleId);this.WM.register(this);this.rendered=true;this.fireEvent('create',this);if(this.visible){this.show();}},unrender:function(){if(this.rendered){this.WM.unregister(this);this.destroyDD();if(this.fadeEf){this.fadeEf.destroy();}
if(this.toolBox){this.toolBox.unrender();}
if(this.toolbar){this.toolbar.unrender();}
this.removeEvents();GUI.remove(this.dom);this.rendered=false;}},destroy:function(){if(this.rendered){this.unrender();}
if(this.toolBox){this.toolBox.destroy();}
if(this.toolbar){this.toolbar.destroy();}
GUI.destroyObject(this);},setContent:function(content){if(GUI.isString(content)){this.config.content=content;if(this.dom){GUI.$(this.contentId).innerHTML=content;}}else if(GUI.isString(content.innerHTML)){GUI.$(this.contentId).innerHTML=content.innerHTML;}},appendContent:function(content){if(GUI.isString(content)){GUI.$(this.contentId).innerHTML+=content;}else if(GUI.isObject(content)){GUI.$(this.contentId).appendChild(content);}},setTitle:function(title){this.config.title=title;if(this.dom){var div=GUI.$(this.titleId);div.childNodes[0].innerHTML=title;div.childNodes[1].innerHTML=title;}},close:function(retVal){this.returnValue=retVal;if(this.fireEvent('beforeClose',this)===false){return;}
if(this.config.animate){var self=this;this.closeOnHide=true;this.hide();}else{this._close();}},_close:function(){GUI.hide(this.dom);this.toBack();if(this.glass){this.glass.hide();}
this.fireEvent('hide',this);this.fireEvent('close',this,this.returnValue);if(this.unrender){this.unrender();}},saveDimensions:function(){this.restoreDimensions=this.getDimensions();if(!GUI.isSet(this.config.dimensions.height)){this.restoreDimensions.height='';}
if(!GUI.isSet(this.config.dimensions.width)){this.restoreDimensions.width='';}},maximize:function(){if(this.state=='maximized'){return;}
if(this.state=='minimized'){this.toolBox.showItem('minimize');GUI.removeClass(this.dom,'minimize');}else{GUI.removeClass(this.dom,'normalize');this.saveDimensions();}
var dim={left:0,top:0,width:'',height:''}
GUI.addClass(this.dom,'maximize');this.setDimensions(dim);var h=document.body.offsetHeight;$(this.contentId).style.height=this.getContentHeightFromFull(h)+'px';this.disableDD();this.state='maximized';this.toolBox.hideItem('maximize');this.toolBox.showItem('restore');},getContentHeightFromFull:function(h){var h=h-28-14-this.config.toolbarHeight;return(h>0)?h:0;},getContentId:function(){return this.contentId;},minimize:function(){if(this.state=='minimized'){return;}
if(this.state=='normal'){GUI.removeClass(this.dom,'normalize');this.saveDimensions();}else{this.setDimensions(this.restoreDimensions);this.toolBox.showItem('maximize');GUI.removeClass(this.dom,'maximize');this.enableDD();}
GUI.addClass(this.dom,'minimize');this.center();this.state='minimized'
this.toolBox.hideItem('minimize');this.toolBox.showItem('restore');},restore:function(){if(this.state=='normal'){return;}
this.toolBox.hideItem('restore');if(this.state=='minimized'){GUI.removeClass(this.dom,'minimize');this.config.dimensions=this.getDimensions();this.toolBox.showItem('minimize');}else if(this.state=='maximized'){GUI.removeClass(this.dom,'maximize');this.toolBox.showItem('maximize');$(this.contentId).style.height='';this.enableDD();}
GUI.addClass(this.dom,'normalize');this.setDimensions(this.restoreDimensions);this.center();this.state='normal';},toFront:function(){if(this.WM.bringToFront(this)){}},toBack:function(){this.WM.sendToBack(this);},setActive:function(active){},show:function(){this.visible=true;this.setDimensions(this.config.dimensions);this.alignTo(document.body,'c-c');if(this.config.modal){this.glass.show();}
this.toFront();if(this.config.animate){GUI.setOpacity(this.dom,0);GUI.show(this.dom);this.focus();this.fadeEf.seekTo(1);}else{GUI.show(this.dom);this.focus();this._show();}
this.windowResizeHandler()},_show:function(){this.fireEvent('show',this);},hide:function(){this.visible=false;if(this.config.animate){this.fadeEf.seekTo(0);}else{this._hide();}},_hide:function(){if(this.closeOnHide){this.closeOnHide=false;return this._close();}
if(this.config.modal){this.glass.hide();}
GUI.hide(this.dom);this.toBack();this.fireEvent('hide',this);},setDim:function(node,dim,val){var style=node.style;if(GUI.isNumber(val)){if(dim=='width'){GUI.setFullWidth(node,val);}else if(dim=='height'){GUI.setFullHeight(node,val);}else{style[dim]=val+'px';}}else if(GUI.isString(val)){style[dim]=val;}},setDimensions:function(dim){Object.extend(this.config.dimensions,Object.clone(dim));if(this.dom){for(var name in dim){this.setDim(this.dom,name,dim[name]);}
var node=$(this.contentId);if(GUI.isNumber(dim.width)){var w=dim.width-22;this.setDim(node,'width',(w<0)?0:w);}else if(GUI.isString(dim.width)){this.setDim(node,'width',dim.width);}
if(GUI.isNumber(dim.height)){var h=this.getContentHeightFromFull(dim.height);this.setDim(node,'height',h);}else if(GUI.isString(dim.height)){this.setDim(node,'height',dim.height);}}},setZIndex:function(value){this.config.zIndex=value;if(this.dom){if(this.config.modal){this.glass.setZIndex(value-1);}
this.dom.style.zIndex=value;}},focus:function(){try{this.focusEl.focus();}catch(e){}},attachEvents:function(){Element.observe(window,'resize',this.browserResizeListener);Element.observe(this.dom,'mousedown',this.mouseDownListener);},removeEvents:function(){Element.stopObserving(window,'resize',this.browserResizeListener);Element.stopObserving(this.dom,'mousedown',this.mouseDownListener);},onMouseDown:function(e){this.toFront();},onToolBoxClick:function(tb,item){if(!this.fireEvent('dialogAction',this,item.name)){return;}
if(typeof this.defHandlers[item.name]=='function'){this.defHandlers[item.name].call(this);}},windowResizeHandler:function(event){var vw=GUI.getViewportWidth();var vh=GUI.getViewportHeight();var w=this.dom.offsetWidth;var h=this.dom.offsetHeight;var newDim={};if(w>vw){newDim.width=vw;if(!this.beforeLimitDim.width){this.beforeLimitDim.width=w;this.originalDim.width=this.config.dimensions.width;}}else if(w<vw){if(this.beforeLimitDim.width){if(vw<this.beforeLimitDim.width){newDim.width=vw;}else{newDim.width=this.originalDim.width;delete this.beforeLimitDim.width;delete this.originalDim.width;}}}
if(h>vh){newDim.height=vh;if(!this.beforeLimitDim.height){this.beforeLimitDim.height=h;this.originalDim.height=this.config.dimensions.height;}}else if(h<vh){if(this.beforeLimitDim.height){if(vh<this.beforeLimitDim.height){newDim.height=vh;}else{newDim.height=this.originalDim.height;delete this.beforeLimitDim.height;delete this.originalDim.height;}}}
this.setDimensions(newDim);var node=GUI.$(this.contentId);var cw=node.offsetWidth;var ch=node.offsetHeight;var csw=node.scrollWidth;var csh=node.scrollHeight
if(csw>cw||csh>ch){if(!this.scrollable){node.style.overflow="auto";this.scrollable=true;}}else{if(this.scrollable){node.style.overflow='';this.scrollable=false;}}
if(this.state=='maximized'){if(GUI.isIE){var h=document.body.offsetHeight-42+'px';this.dom.firstChild.style.height=h;}}else{this.center();}},onBrowserResize:function(event){this.fireEvent('windowResize',this,event);},onKeyDown:function(e){},onKeyUp:function(e){if(e.keyCode==Event.KEY_ESC){this.close();}},onKeyPress:function(e){},center:function(){this._alignTo(document,'c-c');},onDragStart:function(){this.dragProxy=new GUI.Popup.Region({className:'x-window-proxy',zIndex:this.config.zIndex+5});this.dom.style.visibility='hidden';this.dragProxy.show();this.dragProxy.takeRegion(this.dom);},onDrag:function(e){var x=Event.pointerX(e),y=Event.pointerY(e),style=this.dragProxy.dom.style;;style.left=(x-this.DDM.deltaX).toString()+'px';style.top=(y-this.DDM.deltaY).toString()+'px';},onDragEnd:function(e){if(e){var x=Event.pointerX(e),y=Event.pointerY(e);this.setDimensions({left:x-this.DDM.deltaX,top:y-this.DDM.deltaY});}
this.dragProxy.hide();this.dom.style.visibility='';}};Object.extend(Dialog.prototype,superproto);Object.extend(Dialog.prototype,prototype);GUI.Popup.Dialog=Dialog;}());

(function()
{var Hint=Class.create();var superproto=GUI.Popup.Region.prototype;var prototype={initialize:function(config)
{superproto.initialize.call(this);var cfg=this.config;Object.extend(cfg,{id:GUI.getUniqId('x-hint-'),className:'x-region x-hint',delay:500,hideDelay:3000});Object.extend(cfg,config);this.mouseOverListener=this.mouseOverHandler.bindAsEventListener(this);this.mouseOutListener=this.mouseOutHandler.bindAsEventListener(this);this.unloadListener=this.unloadHandler.bindAsEventListener(this);this.mouseOverTask=new GUI.Utils.DelayedTask(this._mouseOverHandler,this);this.hideTask=new GUI.Utils.DelayedTask(this.hide,this);this.addEvents({});},init:function(){this.attachEventListeners();},initFx:function(){},renderHint:function(hint){var o=[];if(!GUI.isString(hint.caption)){hint.caption='';}
o.push('<table><tbody><tr><td><div class="x-hint">');o.push('<div class="hint-top"><div class="hint-r">');o.push('<div class="hint-c"></div></div></div>');o.push('<div class="hint-mdl"><div class="hint-r">');o.push('<div class="hint-c"><div class="hint-data"');if(GUI.isNumber(hint.contentHeight)){o.push(' style="height: ',hint.contentHeight,'px"');}
o.push('>');o.push('<span>',hint.caption,'</span>');if(GUI.isString(hint.text)&&hint.text.length){var text=hint.text.replace(/(\r?\n)/g,'<br />');o.push('<p>',text,'</p>');}
o.push('</div></div></div></div><div class="hint-btm">');o.push('<div class="hint-r"><div class="hint-c"></div></div></div>');o.push('</div></td></tr></tbody></table>');o=o.join('');return o;},add:function(node,caption,text){var hint=caption;if(text&&text.length){hint+='\n'+text;}
if(hint&&hint.length){node.setAttribute('hint',hint);}},has:function(node){var hint;if(GUI.isIE){hint=node.hint;}else{hint=node.getAttribute('hint');}
return GUI.isString(hint)&&hint.length;},get:function(node){var hint=(GUI.isIE)?node.hint:node.getAttribute('hint');var firstCr=hint.indexOf('\n');var caption=hint.substring(0,firstCr);var text=hint.substring(firstCr+1);if(hint&&hint.length){return{caption:caption,text:text};}
return false;},show:function()
{if(!this.target){return;}
var hint;if(hint=this.get(this.target)){this.setContent(this.renderHint(hint));superproto.show.call(this);var dims=GUI.getDimensions(this.dom.firstChild),wWidth=GUI.getViewportWidth(),wHeight=GUI.getViewportHeight();pos=GUI.getScroll(document.body),toSet={};this._pointer.x+=10;this._pointer.y+=10;this.setDimensions({top:(this._pointer.y+dims.height>pos.top+wHeight)?pos.top+wHeight-dims.height:this._pointer.y,left:(this._pointer.x+dims.width>pos.left+wWidth)?pos.left+wWidth-dims.width:this._pointer.x});if(this.config.hideDelay){}}},attachEventListeners:function(){var elem=(GUI.isIE)?document.body:document;Event.observe(elem,'mouseover',this.mouseOverListener);Event.observe(elem,'mouseout',this.mouseOutListener);Event.observe(window,'unload',this.unloadListener);elem=null;},removeEventListeners:function(){var elem=(GUI.isIE)?document.body:document;Event.stopObserving(elem,'mouseover',this.mouseOverListener);Event.stopObserving(elem,'mouseout',this.mouseOutListener);Event.stopObserving(window,'unload',this.unloadListener);elem=null;},unloadHandler:function(){if(this.removeEventListeners){this.removeEventListeners();GUI.destroyObject(this);}},mouseOverHandler:function(e){this._target=GUI.getEventTarget(e);this._pointer=GUI.pointerXY(e);this.mouseOverTask.delay(this.config.delay);},_mouseOverHandler:function(){var target=this._target;var maxDepth=9;if(!this.target){while(target&&maxDepth--&&(target!=document)){if(this.has(target)){this.target=target;this.hideTask.cancel();this.show();return;}
target=target.parentNode;}}},mouseOutHandler:function(e){this.mouseOverTask.cancel();if(this.target){if(GUI.isMouseLeave(this.target,e)){var relTarg=GUI.getRelatedTarget(e);if(GUI.contains(this.dom,relTarg)){return;}
this.hideTask.cancel();this.hide();this.target=null;}}}};Object.extend(Hint.prototype,superproto);Object.extend(Hint.prototype,prototype);GUI.Popup.Hint=new Hint();GUI.onDOMReady(function(){GUI.Popup.Hint.init();})})();

(function(){GUI.Popup.Mask=Class.create();var i18n=GUI.i18n;Object.extend(Object.extend(GUI.Popup.Mask.prototype,GUI.Utils.Observable.prototype),{initialize:function(config){GUI.Utils.Observable.prototype.initialize.apply(this,arguments);this.config={element:false,text:i18n.GUI_LOADING};Object.extend(this.config,config);this.maskGlassId=GUI.getUniqId('x-mask-layout-');this.addEvents({show:true,hide:true});var self=this;this.fadeEf=new Animator({duration:500,interval:20,onComplete:function(){if(this.state==0){self._hide();}else{self._show();}}});this.region=new GUI.Popup.Region({className:'x-mask',content:'<div id="'+this.maskGlassId+'" class="glass"></div>'+'<div class="x-loader-case1"><div class="x-loader-case2">'+' <table class="x-loader"><col><tr><td>'+'  <div class="x-loader">'+'   <div class="top"><div><div></div></div></div>'+'   <div class="mdl"><div><div><span>'+this.config.text+'</span></div></div></div>'+'   <div class="btm"><div><div></div></div></div>'+'  </div>'+' </td></tr></table>'+'</div></div>'});},show:function(){var elem;if(this.config.element){elem=GUI.$(this.config.element);if(elem){this.region.config.parentNode=elem.parentNode;this.oldPosition=elem.parentNode.style.position;elem.parentNode.style.position='relative';if(GUI.isIE){elem.parentNode.style.zoom='1';}}}
if(!elem){console.log('Mask: No element... ',this.config.element);console.trace();return;}
this.region.show();if(GUI.isIE){GUI.setOpacity(this.region.getElement(),1);this._show();}else{this.fadeEf.clearSubjects();this.fadeEf.addSubject(new NumericalStyleSubject(this.region.getElement(),'opacity',0,1));this.fadeEf.seekTo(1);}},_show:function(){this.fireEvent('show',this);},hide:function(){if(GUI.isIE){this._hide();}else{this.fadeEf.seekTo(0);}},_hide:function(){this.region.hide();GUI.$(this.config.element).parentNode.style.position=this.oldPosition;this.fireEvent('hide',this);},destroy:function(){GUI.destroyObject(this);}});}());

(function()
{var ToolBox=Class.create();var superproto=GUI.Utils.Observable.prototype;var prototype={initialize:function(config)
{superproto.initialize.call(this);this.config={id:GUI.getUniqId('x-toolbox-'),className:'x-toolbox',items:[],onClick:null,holder:null};var cfg=this.config;Object.extend(cfg,config);this._indexById={};this._indexByName={};var i=cfg.items.length;while(i--){var item=cfg.items[i];var id=GUI.getUniqId('x-toolbox-button-');item.id=id;this._indexById[id]=this._indexByName[item.name]=i;}
this.clickListener=this.clickHandler.bindAsEventListener(this);this.addEvents({click:true});if(GUI.isFunction(cfg.onClick)){this.on('click',cfg.onClick);}
if(cfg.name){GUI.ComponentMgr.register(cfg.name,this);}},destroy:function(){this.unrender();this.purgeListeners();GUI.destroyObject(this);},unrender:function(){if(this.dom){this.removeEventListeners();this.dom.innerHTML='';this.dom=null;}},render:function(to){if(this.dom){this.removeEventListeners();GUI.remove(this.dom);this.dom=null;}
this.visible=false;var cfg=this.config;if(to){cfg.holder=to;}else{to=cfg.holder;}
to=GUI.$(to);var div=document.createElement('div');div.id=cfg.id;div.className=cfg.className;var o=[];for(var i=0,len=cfg.items.length;i<len;i++){var item=cfg.items[i];o.push('<a id="'+item.id+'"');if(item.hidden){o.push(' style="display: none;"');}
if(item.title){o.push(' hint="'+item.title+'"');}
o.push(' ><img align="absmiddle" src="'+item.img+'" alt="'+item.title+'" /></a>');}
div.innerHTML=o.join('');to.appendChild(div);this.dom=div;this.attachEventListeners();},hideItem:function(name){var item=this.getItemByName(name);if(item&&!item.hidden){item.hidden=true;if(this.dom){GUI.hide(item.id);}}},showItem:function(name){var item=this.getItemByName(name);if(item&&item.hidden){item.hidden=false;if(this.dom){GUI.show(item.id);}}},getItemById:function(id){var index=this._indexById[id];if(GUI.isNumber(index)){return this.config.items[index];}
return false;},getItemByName:function(name){var index=this._indexByName[name];if(GUI.isNumber(index)){return this.config.items[index];}
return false;},attachEventListeners:function(){Event.observe(this.dom,'click',this.clickListener);},removeEventListeners:function(){Event.stopObserving(this.dom,'click',this.clickListener);},clickHandler:function(e){Event.stop(e);var target=GUI.getEventTarget(e);var itemNode=GUI.findParentByTag(target,'A',this.dom);if(!itemNode){return;}
var item=this.getItemById(itemNode.id);if(GUI.isFunction(item.onClick)){item.onClick(item);}
this.fireEvent('click',this,item);}};Object.extend(ToolBox.prototype,superproto);Object.extend(ToolBox.prototype,prototype);GUI.ToolBox=ToolBox;})();

GUI.Bar=Class.create();Object.extend(Object.extend(GUI.Bar.prototype,GUI.Utils.Draggable.prototype),{initialize:function(config){GUI.Utils.Draggable.prototype.initialize.apply(this,arguments);var cfg=this.config;Object.extend(cfg,{id:GUI.getUniqId('x-bar-'),holder:undefined,className:'x-bar',elements:undefined,position:undefined,align:undefined,disabled:false});Object.extend(cfg,config);this.elementType='GUI.Bar';this.elements=new GUI.Utils.Collection();this.rendered=false;this.disabled=cfg.disabled;if(cfg.name){GUI.ComponentMgr.register(cfg.name,this);}},destroy:function(){if(this.config.name){GUI.ComponentMgr.unregister(this);}
this.elements.each(function(item){if(GUI.isFunction(item.destroy)){item.destroy();}},this);this.elements.clear();},add:function(name,elem){this.elements.add(name,elem);},remove:function(key){if(typeof key=='string'){return this.elements.removeKey(key);}else if(typeof key=='number'){return this.elements.removeAt(key);}},enable:function(){if(this.disabled){this.elements.each(function(elem){elem.enable();});this.disabled=false;}},disable:function(flag){if((flag!==undefined)&&(!flag)){this.enable();return;}
if(!this.disabled){this.elements.each(function(elem){elem.disable();});this.disabled=true;}},setPosition:function(){throw new Error('setPosition() is an abstract method!');},setAlign:function(){throw new Error('setAlign() is an abstract method!');},getPosition:function(){return this.config.position;},getAlign:function(){return this.config.align;},getElement:function(key){return this.elements.get(key);},getElementName:function(obj){var idx=this.elements.indexOf(obj);return(GUI.isSet(idx))?this.elements.keyAt(idx):null;},indexOf:function(obj){return this.elements.indexOf(obj);},render:function(elem){if(!this.fireEvent('beforeRender',this)){return;}
if(this.dom){this.unrender();}
var cfg=this.config;if(GUI.isSet(elem)){cfg.holder=elem;}
var containerNode=GUI.$(cfg.holder);if(containerNode){this._render(containerNode);this.rendered=true;}else{throw new Error(this.elementType+' error in method render(): Element with id='+this.config.holder+' not found');}
this.fireEvent('afterRender',this);},unrender:function(){if(!this.dom)return false;this.elements.each(function(item){item.unrender();},this);GUI.remove(this.dom);this.dom=null;},_render:function(){throw new Error(this.elementType+' error: _render() is an abstract method!');}});

GUI.TabBar=Class.create();Object.extend(Object.extend(GUI.TabBar.prototype,GUI.Bar.prototype),{positions:['top','right','bottom','left'],aligns:{horizontal:['left','right','center','none'],vertical:['top','middle','buttom']},initialize:function(config){GUI.Bar.prototype.initialize.apply(this,arguments);var cfg=this.config;Object.extend(cfg,{id:GUI.getUniqId('x-tabbar-'),className:'x-tabbar',position:'top',multiline:false});Object.extend(cfg,config);if(!GUI.isSet(cfg.align)){cfg.align=((cfg.position=='top')||(cfg.position=='bottom'))?'left':'top';}
this.elementType='GUI.TabBar';this.activeTab=undefined;this.rendered=false;this.lastContentHidden=false;this.addEvents({tabSwitch:true});if(typeof cfg.onTabSwitch=='function'){this.on('tabSwitch',cfg.onTabSwitch,this);}
var elems,len;if(cfg.multiline){for(var i=0,rows=cfg.elements.length;i<rows;i++){var row=cfg.elements[i];for(var j=0,len=row.length;j<len;j++){var elem=row[j];this.add(elem.name,elem.obj,i);}}}else{if((typeof(elems=cfg.elements)=='object')&&((len=cfg.elements.length)>0)){for(var i=0;i<len;i++){var elem=elems[i];this.add(elem.name,elem.obj);}}}},add:function(name,elem,rowIndex){GUI.Bar.prototype.add.apply(this,arguments);if((elem instanceof GUI.TabBar.Tab)||(elem instanceof GUI.TabBar.FilterTab)){elem.setBar(this);if(elem.isActive()){if(GUI.isSet(this.activeTab)){this.activeTab.deactivate();}
elem.activate();this.activeTab=elem;}}
if(!this.rendered)return;var tbody=this.dom.firstChild;if(['top','bottom'].include(this.config.position)){var td=document.createElement('td');elem.render(td);tbody.firstChild.appendChild(td);}else{var tr=document.createElement('tr');var td=tr.appendChild(document.createElement('td'));elem.render(td);tbody.appendChild(tr);}},remove:function(key){var elem=this.getElement(key);if(elem instanceof GUI.TabBar.Tab){elem.deactivate();}
if(this.rendered){if(elem===-1){throw new Error('trying to remove non-existent tab');}
elem=elem.getDom();if(['top','bottom'].include(this.config.position)){var td=elem.parentNode;td.parentNode.removeChild(td);delete td;}else{var tr=elem.parentNode.parentNode;tr.parentNode.removeChild(tr);delete tr;}}
return GUI.Bar.prototype.remove.apply(this,arguments);},switchTo:function(id){if(GUI.isString(id)){var newTab=this.elements.get(id);}else if((id instanceof GUI.TabBar.Tab)||((id instanceof GUI.TabBar.FilterTab))){var newTab=id;}else{throw new Error(this.elementType+' error: switchTo() unknown argument');}
if(!GUI.isSet(newTab)){return;}
var oldTab=this.activeTab;if(newTab===oldTab){return;}
if(GUI.isSet(oldTab)){oldTab.deactivate(newTab.hiddenContent);}
newTab.activate();this.activeTab=newTab;this.fireEvent('tabswitch',this,this.activeTab);},closeTab:function(tab){if(tab===this.activeTab){this.nextTab();}
this.remove(this.elements.indexOf(tab));},nextTab:function(){var count=this.elements.getCount();var index=this.elements.indexOf(this.activeTab);var i=index+1;for(var c=1;c<count;c++,i++){if(i===count){i=0;}
var item=this.elements.itemAt(i);if((item instanceof GUI.TabBar.Tab)&&(item.isEnabled())){this.switchTo(item);return item;}}
return false;},setPosition:function(pos){if(!this.positions.include(pos)){throw new Error('setPosition(): unknow position type specified: '+pos);}
this.config.position=pos;if(this.rendered){this.dom.firstChild.className=pos;}},setAlign:function(align){var cfg=this.config;if((cfg.position=='top')||(cfg.position=='bottom')){if(!this.aligns.horizontal.include(align)){throw new Error('setAlign(): incorrect align for horizontal position specified: '+align);}
if(this.dom&&(align!='none')){this.dom.align=align;}}else if((cfg.position=='left')||(cfg.position=='right')){if(!this.aligns.vertical.include(align)){throw new Error('setAlign(): incorrect align for vertical position specified: '+align);}
if(this.dom){}}
cfg.align=align;},_render:function(containerNode){if(this.config.multiline){this.dom=document.createElement('div');this.dom.className='x-multiline-tabbar';containerNode.appendChild(this.dom);var rows=this.config.elements;for(var i=0,len=rows.length;i<len;i++){this._renderBar(this.dom,rows[i]);}
return;}
var table=document.createElement('table');table.className=this.config.className;this.dom=table;var tbody=table.appendChild(document.createElement('tbody'));tbody.className=this.config.position;containerNode.appendChild(table);if(['top','bottom'].include(this.config.position)){var tr=tbody.appendChild(document.createElement('tr'));this.elements.each(function(elem){var td=document.createElement('td');tr.appendChild(td);elem.render(td);});}else{this.elements.each(function(elem){var tr=tbody.appendChild(document.createElement('tr'));var td=document.createElement('td');tr.appendChild(td);elem.render(td);});}
this.setAlign(this.config.align);return this.dom;},_renderBar:function(to,items){var table=document.createElement('table');table.className=this.config.className;var tbody=table.appendChild(document.createElement('tbody'));tbody.className=this.config.position;to.appendChild(table);if(['top','bottom'].include(this.config.position)){var tr=tbody.appendChild(document.createElement('tr'));for(var i=0,len=items.length;i<len;i++){var td=document.createElement('td');tr.appendChild(td);items[i].obj.render(td);};}else{for(var i=0,len=items.length;i<len;i++){var tr=tbody.appendChild(document.createElement('tr'));var td=document.createElement('td');tr.appendChild(td);items[i].render(td);};}}});

GUI.TabBar.Tab=Class.create();Object.extend(Object.extend(GUI.TabBar.Tab.prototype,GUI.ActiveElement.prototype),{initialize:function(config){GUI.ActiveElement.prototype.initialize.apply(this,arguments);var cfg=this.config;Object.extend(cfg,{id:GUI.getUniqId('x-tabbar-tab-'),active:false,assigned:undefined,className:'x-tab',bar:undefined,closeOnDblClick:false});Object.extend(cfg,config);this.elementType='GUI.TabBar.Tab';this.active=cfg.active;this.dblClickListener=this.onDblClick.bindAsEventListener(this);this.addEvents({afterActivate:true,afterDeactivate:true,beforeActivate:true,beforeDeactivate:true});if(GUI.isFunction(cfg.onBeforeActivate)){this.on('beforeActivate',cfg.onBeforeActivate);}
if(GUI.isFunction(cfg.onAfterActivate)){this.on('afterActivate',cfg.onAfterActivate);}
if(GUI.isFunction(cfg.onBeforeDeactivate)){this.on('beforeDeactivate',cfg.onBeforeDeactivate);}
if(GUI.isFunction(cfg.onAfterDeactivate)){this.on('afterDeactivate',cfg.onAfterDeactivate);}},activate:function(){if(this.disabled){return false;}
if(!this.fireEvent('beforeActivate',this)){return false;}
this.active=true;this.setClass();if(GUI.isSet(this.config.assigned)){$(this.config.assigned).style.display='block';}
this.fireEvent('afterActivate',this);},deactivate:function(){if(!this.fireEvent('beforeDeactivate',this)){return false;}
this.active=false;this.setClass();if(GUI.isSet(this.config.assigned)){$(this.config.assigned).style.display='none';}
this.fireEvent('afterDeactivate',this);},close:function(){var cfg=this.config;if((GUI.isSet(cfg.bar))&&((typeof cfg.bar.remove=='function'))){cfg.bar.closeTab(this);}else{this.deactivate();}},setBar:function(bar){if(bar instanceof GUI.TabBar){this.config.bar=bar;return;}
throw new Error(this.elementType+' error: setBar() - bar is not instance of TabBr');},setClassName:function(cls){this.config.className=cls;if(this.rendered){this.dom.className=cls;}},isActive:function(){return this.active;},setClass:function(){var cls='static';if(this.disabled){cls='disabled';}else if(this.toggled||this.active){cls='toggled';}else if(this.hover){cls='hover';}
this.innerClass=cls;if(this.dom){this.dom.className=this.config.className+' '+cls;}},attachEventListeners:function(){var elem=this.dom;if(!GUI.isSet(elem)){throw new Error(this.elementType+' attachEvents() error: $(this.config.id) is not set: '+this.config.id);}
Event.observe(elem,'dblclick',this.dblClickListener);GUI.ActiveElement.prototype.attachEventListeners.apply(this,arguments);},removeEventListeners:function(){var elem=this.dom;if(!GUI.isSet(elem)){throw new Error(this.elementType+' removeEvents() error: $(this.config.id) is not set: '+this.config.id);}
Event.stopObserving(elem,'dblclick',this.dblClickListener);GUI.ActiveElement.prototype.removeEventListeners.call(this);},onClick:function(e){if(!this.disabled){var cfg=this.config;if((GUI.isSet(cfg.bar))&&((typeof cfg.bar.switchTo)==='function')){cfg.bar.switchTo(this);}
this.fireEvent('click',this);}},onDblClick:function(event){if((!this.config.closeOnDblClick)||(!this.active)||(this.disabled)){return;}
this.close();}});

function Animator(options){this.setOptions(options);var _this=this;this.timerDelegate=function(){_this.onTimerEvent()};this.subjects=[];this.target=0;this.state=0;this.lastTime=null;};Animator.prototype={destroy:function(){if(this.intervalId){window.clearInterval(this.intervalId);this.intervalId=null;}
this.clearSubjects();this.options.onComplete=null;this.options.onStep=null;},setOptions:function(options){this.options=Animator.applyDefaults({interval:20,duration:400,onComplete:function(){},onStep:function(){},transition:Animator.tx.easeInOut},options);},seekTo:function(to){this.seekFromTo(this.state,to);},seekFromTo:function(from,to){this.target=Math.max(0,Math.min(1,to));this.state=Math.max(0,Math.min(1,from));this.lastTime=new Date().getTime();if(!this.intervalId){this.intervalId=window.setInterval(this.timerDelegate,this.options.interval);}},jumpTo:function(to){this.target=this.state=Math.max(0,Math.min(1,to));this.propagate();},toggle:function(){this.seekTo(1-this.target);},addSubject:function(subject){this.subjects[this.subjects.length]=subject;return this;},clearSubjects:function(){this.subjects=[];},propagate:function(){var value=this.options.transition(this.state);for(var i=0;i<this.subjects.length;i++){if(this.subjects[i].setState){this.subjects[i].setState(value);}else{this.subjects[i](value);}}},onTimerEvent:function(){var now=new Date().getTime();var timePassed=now-this.lastTime;this.lastTime=now;var movement=(timePassed/this.options.duration)*(this.state<this.target?1:-1);if(Math.abs(movement)>=Math.abs(this.state-this.target)){this.state=this.target;}else{this.state+=movement;}
try{this.propagate();}finally{this.options.onStep.call(this);if(this.target==this.state){window.clearInterval(this.intervalId);this.intervalId=null;this.options.onComplete.call(this,this);}}},play:function(){this.seekFromTo(0,1)},reverse:function(){this.seekFromTo(1,0)},inspect:function(){var str="#<Animator:\n";for(var i=0;i<this.subjects.length;i++){str+=this.subjects[i].inspect();}
str+=">";return str;},isRunning:function(){return!!this.intervalId;}}
Animator.applyDefaults=function(defaults,prefs){prefs=prefs||{};var prop,result={};for(prop in defaults)result[prop]=prefs[prop]!==undefined?prefs[prop]:defaults[prop];return result;}
Animator.makeArray=function(o){if(o==null)return[];if(!o.length)return[o];var result=[];for(var i=0;i<o.length;i++)result[i]=o[i];return result;}
Animator.camelize=function(string){var oStringList=string.split('-');if(oStringList.length==1)return oStringList[0];var camelizedString=string.indexOf('-')==0?oStringList[0].charAt(0).toUpperCase()+oStringList[0].substring(1):oStringList[0];for(var i=1,len=oStringList.length;i<len;i++){var s=oStringList[i];camelizedString+=s.charAt(0).toUpperCase()+s.substring(1);}
return camelizedString;}
Animator.apply=function(el,style,options){if(style instanceof Array){return new Animator(options).addSubject(new CSSStyleSubject(el,style[0],style[1]));}
return new Animator(options).addSubject(new CSSStyleSubject(el,style));}
Animator.makeEaseIn=function(a){return function(state){return Math.pow(state,a*2);}}
Animator.makeEaseOut=function(a){return function(state){return 1-Math.pow(1-state,a*2);}}
Animator.makeElastic=function(bounces){return function(state){state=Animator.tx.easeInOut(state);return((1-Math.cos(state*Math.PI*bounces))*(1-state))+state;}}
Animator.makeADSR=function(attackEnd,decayEnd,sustainEnd,sustainLevel){if(sustainLevel==null)sustainLevel=0.5;return function(state){if(state<attackEnd){return state/attackEnd;}
if(state<decayEnd){return 1-((state-attackEnd)/(decayEnd-attackEnd)*(1-sustainLevel));}
if(state<sustainEnd){return sustainLevel;}
return sustainLevel*(1-((state-sustainEnd)/(1-sustainEnd)));}}
Animator.makeBounce=function(bounces){var fn=Animator.makeElastic(bounces);return function(state){state=fn(state);return state<=1?state:2-state;}}
Animator.tx={easeInOut:function(pos){return((-Math.cos(pos*Math.PI)/2)+0.5);},linear:function(x){return x;},easeIn:Animator.makeEaseIn(1.5),easeOut:Animator.makeEaseOut(1.5),strongEaseIn:Animator.makeEaseIn(2.5),strongEaseOut:Animator.makeEaseOut(2.5),elastic:Animator.makeElastic(1),veryElastic:Animator.makeElastic(3),bouncy:Animator.makeBounce(1),veryBouncy:Animator.makeBounce(3)}
function NumericalStyleSubject(els,property,from,to,units){this.els=Animator.makeArray(els);if(property=='opacity'&&window.ActiveXObject){this.property='filter';}else{this.property=Animator.camelize(property);}
this.from=parseFloat(from);this.to=parseFloat(to);this.units=units!=null?units:'px';}
NumericalStyleSubject.prototype={setState:function(state){var style=this.getStyle(state);var visibility=(this.property=='opacity'&&state==0)?'hidden':'';var j=0;for(var i=0;i<this.els.length;i++){try{this.els[i].style[this.property]=style;}catch(e){if(this.property!='fontWeight')throw e;}
if(j++>20)return;}},getStyle:function(state){state=this.from+((this.to-this.from)*state);if(this.property=='filter')return"alpha(opacity="+Math.round(state*100)+")";if(this.property=='opacity')return state;return Math.round(state)+this.units;},inspect:function(){return"\t"+this.property+"("+this.from+this.units+" to "+this.to+this.units+")\n";}}
function ColorStyleSubject(els,property,from,to){this.els=Animator.makeArray(els);this.property=Animator.camelize(property);this.to=this.expandColor(to);this.from=this.expandColor(from);this.origFrom=from;this.origTo=to;}
ColorStyleSubject.prototype={expandColor:function(color){var hexColor,red,green,blue;hexColor=ColorStyleSubject.parseColor(color);if(hexColor){red=parseInt(hexColor.slice(1,3),16);green=parseInt(hexColor.slice(3,5),16);blue=parseInt(hexColor.slice(5,7),16);return[red,green,blue]}
if(window.DEBUG){alert("Invalid colour: '"+color+"'");}},getValueForState:function(color,state){return Math.round(this.from[color]+((this.to[color]-this.from[color])*state));},setState:function(state){var color='#'
+ColorStyleSubject.toColorPart(this.getValueForState(0,state))
+ColorStyleSubject.toColorPart(this.getValueForState(1,state))
+ColorStyleSubject.toColorPart(this.getValueForState(2,state));for(var i=0;i<this.els.length;i++){this.els[i].style[this.property]=color;}},inspect:function(){return"\t"+this.property+"("+this.origFrom+" to "+this.origTo+")\n";}}
ColorStyleSubject.parseColor=function(string){var color='#',match;if(match=ColorStyleSubject.parseColor.rgbRe.exec(string)){var part;for(var i=1;i<=3;i++){part=Math.max(0,Math.min(255,parseInt(match[i])));color+=ColorStyleSubject.toColorPart(part);}
return color;}
if(match=ColorStyleSubject.parseColor.hexRe.exec(string)){if(match[1].length==3){for(var i=0;i<3;i++){color+=match[1].charAt(i)+match[1].charAt(i);}
return color;}
return'#'+match[1];}
return false;}
ColorStyleSubject.toColorPart=function(number){if(number>255)number=255;var digits=number.toString(16);if(number<16)return'0'+digits;return digits;}
ColorStyleSubject.parseColor.rgbRe=/^rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/i;ColorStyleSubject.parseColor.hexRe=/^\#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;function DiscreteStyleSubject(els,property,from,to,threshold){this.els=Animator.makeArray(els);this.property=Animator.camelize(property);this.from=from;this.to=to;this.threshold=threshold||0.5;}
DiscreteStyleSubject.prototype={setState:function(state){var j=0;for(var i=0;i<this.els.length;i++){this.els[i].style[this.property]=state<=this.threshold?this.from:this.to;}},inspect:function(){return"\t"+this.property+"("+this.from+" to "+this.to+" @ "+this.threshold+")\n";}}
function CSSStyleSubject(els,style1,style2){els=Animator.makeArray(els);this.subjects=[];if(els.length==0)return;var prop,toStyle,fromStyle;if(style2){fromStyle=this.parseStyle(style1,els[0]);toStyle=this.parseStyle(style2,els[0]);}else{toStyle=this.parseStyle(style1,els[0]);fromStyle={};for(prop in toStyle){fromStyle[prop]=CSSStyleSubject.getStyle(els[0],prop);}}
var prop;for(prop in fromStyle){if(fromStyle[prop]==toStyle[prop]){delete fromStyle[prop];delete toStyle[prop];}}
var prop,units,match,type,from,to;for(prop in fromStyle){var fromProp=String(fromStyle[prop]);var toProp=String(toStyle[prop]);if(toStyle[prop]==null){if(window.DEBUG)alert("No to style provided for '"+prop+'"');continue;}
if(from=ColorStyleSubject.parseColor(fromProp)){to=ColorStyleSubject.parseColor(toProp);type=ColorStyleSubject;}else if(fromProp.match(CSSStyleSubject.numericalRe)&&toProp.match(CSSStyleSubject.numericalRe)){from=parseFloat(fromProp);to=parseFloat(toProp);type=NumericalStyleSubject;match=CSSStyleSubject.numericalRe.exec(fromProp);var reResult=CSSStyleSubject.numericalRe.exec(toProp);if(match[1]!=null){units=match[1];}else if(reResult[1]!=null){units=reResult[1];}else{units=reResult;}}else if(fromProp.match(CSSStyleSubject.discreteRe)&&toProp.match(CSSStyleSubject.discreteRe)){from=fromProp;to=toProp;type=DiscreteStyleSubject;units=0;}else{if(window.DEBUG){alert("Unrecognised format for value of "
+prop+": '"+fromStyle[prop]+"'");}
continue;}
this.subjects[this.subjects.length]=new type(els,prop,from,to,units);}}
CSSStyleSubject.prototype={parseStyle:function(style,el){var rtn={};if(style.indexOf(":")!=-1){var styles=style.split(";");for(var i=0;i<styles.length;i++){var parts=CSSStyleSubject.ruleRe.exec(styles[i]);if(parts){rtn[parts[1]]=parts[2];}}}
else{var prop,value,oldClass;oldClass=el.className;el.className=style;for(var i=0;i<CSSStyleSubject.cssProperties.length;i++){prop=CSSStyleSubject.cssProperties[i];value=CSSStyleSubject.getStyle(el,prop);if(value!=null){rtn[prop]=value;}}
el.className=oldClass;}
return rtn;},setState:function(state){for(var i=0;i<this.subjects.length;i++){this.subjects[i].setState(state);}},inspect:function(){var str="";for(var i=0;i<this.subjects.length;i++){str+=this.subjects[i].inspect();}
return str;}}
CSSStyleSubject.getStyle=function(el,property){var style;if(document.defaultView&&document.defaultView.getComputedStyle){style=document.defaultView.getComputedStyle(el,"").getPropertyValue(property);if(style){return style;}}
property=Animator.camelize(property);if(el.currentStyle){style=el.currentStyle[property];}
return style||el.style[property]}
CSSStyleSubject.ruleRe=/^\s*([a-zA-Z\-]+)\s*:\s*(\S(.+\S)?)\s*$/;CSSStyleSubject.numericalRe=/^-?\d+(?:\.\d+)?(%|[a-zA-Z]{2})?$/;CSSStyleSubject.discreteRe=/^\w+$/;CSSStyleSubject.cssProperties=['azimuth','background','background-attachment','background-color','background-image','background-position','background-repeat','border-collapse','border-color','border-spacing','border-style','border-top','border-top-color','border-right-color','border-bottom-color','border-left-color','border-top-style','border-right-style','border-bottom-style','border-left-style','border-top-width','border-right-width','border-bottom-width','border-left-width','border-width','bottom','clear','clip','color','content','cursor','direction','display','elevation','empty-cells','css-float','font','font-family','font-size','font-size-adjust','font-stretch','font-style','font-variant','font-weight','height','left','letter-spacing','line-height','list-style','list-style-image','list-style-position','list-style-type','margin','margin-top','margin-right','margin-bottom','margin-left','max-height','max-width','min-height','min-width','orphans','outline','outline-color','outline-style','outline-width','overflow','padding','padding-top','padding-right','padding-bottom','padding-left','pause','position','right','size','table-layout','text-align','text-decoration','text-indent','text-shadow','text-transform','top','vertical-align','visibility','white-space','width','word-spacing','z-index','opacity','outline-offset','overflow-x','overflow-y'];function AnimatorChain(animators,options){this.animators=animators;this.setOptions(options);for(var i=0;i<this.animators.length;i++){this.listenTo(this.animators[i]);}
this.forwards=false;this.current=0;}
AnimatorChain.prototype={setOptions:function(options){this.options=Animator.applyDefaults({resetOnPlay:true},options);},play:function(){this.forwards=true;this.current=-1;if(this.options.resetOnPlay){for(var i=0;i<this.animators.length;i++){this.animators[i].jumpTo(0);}}
this.advance();},reverse:function(){this.forwards=false;this.current=this.animators.length;if(this.options.resetOnPlay){for(var i=0;i<this.animators.length;i++){this.animators[i].jumpTo(1);}}
this.advance();},toggle:function(){if(this.forwards){this.seekTo(0);}else{this.seekTo(1);}},listenTo:function(animator){var oldOnComplete=animator.options.onComplete;var _this=this;animator.options.onComplete=function(){if(oldOnComplete)oldOnComplete.call(animator);_this.advance();}},advance:function(){if(this.forwards){if(this.animators[this.current+1]==null)return;this.current++;this.animators[this.current].play();}else{if(this.animators[this.current-1]==null)return;this.current--;this.animators[this.current].reverse();}},seekTo:function(target){if(target<=0){this.forwards=false;this.animators[this.current].seekTo(0);}else{this.forwards=true;this.animators[this.current].seekTo(1);}}}
function Accordion(options){this.setOptions(options);var selected=this.options.initialSection,current;if(this.options.rememberance){current=document.location.hash.substring(1);}
this.rememberanceTexts=[];this.ans=[];var _this=this;for(var i=0;i<this.options.sections.length;i++){var el=this.options.sections[i];var an=new Animator(this.options.animatorOptions);var from=this.options.from+(this.options.shift*i);var to=this.options.to+(this.options.shift*i);an.addSubject(new NumericalStyleSubject(el,this.options.property,from,to,this.options.units));an.jumpTo(0);var activator=this.options.getActivator(el);activator.index=i;activator.onclick=function(){_this.show(this.index)};this.ans[this.ans.length]=an;this.rememberanceTexts[i]=activator.innerHTML.replace(/\s/g,"");if(this.rememberanceTexts[i]===current){selected=i;}}
this.show(selected);}
Accordion.prototype={setOptions:function(options){this.options=Object.extend({sections:null,getActivator:function(el){return document.getElementById(el.getAttribute("activator"))},shift:0,initialSection:0,rememberance:true,animatorOptions:{}},options||{});},show:function(section){for(var i=0;i<this.ans.length;i++){this.ans[i].seekTo(i>section?1:0);}
if(this.options.rememberance){document.location.hash=this.rememberanceTexts[section];}}}
