var What={extend:function(obj,collection,override){for(var i in collection){if(typeof collection[i]=='function'){if((typeof obj[i]=='undefined')||(typeof override=='boolean'&&override)){obj[i]=collection[i];}}}return obj;}};String.prototype.camelize=function(){var parts=this.split('-');var _string=parts[0];for(var i=1,j;j=parts[i];i++){var f=j.substring(0,1);_string+=f.toUpperCase()+j.substring(1);}return _string;};String.prototype.hyphenate=function(){var _string=this.charAt(0);for(var i=1,j;j=this.charAt(i);i++){var regexp=/[A-Z]/;if(regexp.test(j)){j='-'+j.toLowerCase();}_string+=j;}return _string;};String.prototype.parseColor=function(){var o={r:0,g:0,b:0};var _string=this.toUpperCase();if(this.indexOf('rgb')!=-1){var a=_string.match(/(\d*)\s*,\s*(\d*)\s*,\s*(\d*)/);o.r=parseInt(a[1])||0;o.g=parseInt(a[2])||0;o.b=parseInt(a[3])||0;}else{if(_string.substring(0,1)=='#'){_string=_string.substring(1);}if(_string.length==3){for(var i=0,j,k='';j=_string.charAt(i);i++){k+=(j+''+j);}_string=k;}o.r=parseInt('0x'+_string.substring(0,2));o.g=parseInt('0x'+_string.substring(2,4));o.b=parseInt('0x'+_string.substring(4,6));}return o;};Array.prototype.contains=function(needle){return((','+this.toString()+',').indexOf(','+needle+',')!==-1);};Array.prototype.map=function(fn){var temp=new Array();for(var i=0;i<this.length;i++){temp.push(fn(this[i]));return temp;}};Array.prototype.empty=function(){this.length=0;return this;};Array.prototype.empty=function(){this.length=0;return this;};Array.prototype.first=function(){return this[0];};Array.prototype.last=function(){return this[this.length-1];};
What.AJAX={queue:[],request:function(url,method,postData,async){var req=What.AJAX.makeRequestObject();if(!req){return false;}else{var ajax=new What.AJAXConnection(req,What.AJAX);ajax.init(url,method,postData,async);What.AJAX.queue.push(ajax);if(What.AJAX.queue.length==1&&What.AJAX.queue[0]===ajax){What.AJAX.queue[0].goAhead=true;}return ajax;}},onConnectionDone:function(){What.AJAX.queue.shift();What.AJAX.onQueueChange();},onQueueChange:function(){if(What.AJAX.queue.length>0){What.AJAX.queue[0].goAhead=true;}},makeRequestObject:function(){var obj=null;if(window.XMLHttpRequest){obj=new XMLHttpRequest();}else if(window.ActiveXObject){try{obj=new ActiveXObject('Msxml2.XMLHTTP');}catch(e){try{obj=new ActiveXObject('Microsoft.XMLHTTP');}catch(e){obj=false;}}}return obj;},isSupported:function(){return!!What.AJAX.makeRequestObject();}};What.AJAXConnection=function(request,manager){this.xhr=request;this.manager=manager;this.url;this.method='GET';this.postData=null;this.loadInterval=null;this.async=true;this.goAhead=false;this.response;this.init=function(url,method,postData,async){this.url=url;this.method=method||'GET';this.postData=postData||null;this.async=typeof async=='boolean'?async:true;var s=this;this.xhr.onreadystatechange=function(){if(s.xhr.readyState==4){if(s.xhr.status==200||s.xhr.status==304){var xml=s.xhr.responseXML;var text=s.xhr.responseText;s.response={xml:xml,text:text,parseJSON:function(){return eval('('+text+')');}};s.broadcastEvent('onReady');s.manager.onConnectionDone();}else{s.broadcastEvent('onFailure');}}}};this.load=function(){this.broadcastEvent('onLoading');if(this.loadInterval){clearTimeout(this.loadInterval);this.loadInterval=null;}if(this.goAhead){this.connect();}else{var s=this;this.loadInterval=setTimeout(function(){s.load();},30);}};this.connect=function(){this.xhr.open(this.method,this.url,this.async);this.xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');this.xhr.send(this.postData);};What.extend(What.AJAXConnection.prototype,What.Event.Manager);this.registerEvents('onLoading','onReady','onFailure');};
What.Animation={};What.Animation.easeInOut=function(minValue,maxValue,totalSteps,actualStep,powr){var delta=maxValue-minValue;var stepp=minValue+(Math.pow(((1/totalSteps)*actualStep),powr)*delta);return Math.ceil(stepp);};What.Animation.Fade=function(elm,to,steps){this.el=$(elm);this.ed=to;this.theSteps=0;this.maxSteps=steps;this.power=1;this.interval=30;this.init=function(){this.broadcastEvent('onAnimationStart');this.halt();var s=this;this.timer=setInterval(function(){s.setOpac(What.Animation.easeInOut(s.getOpac(),s.ed,s.maxSteps,s.theSteps,s.power));s.theSteps++;s.broadcastEvent('onAnimationChange');if(s.theSteps>s.maxSteps){s.halt();s.broadcastEvent('onAnimationEnd');}},s.interval);};this.setOpac=function(percent){with(this.el.style){opacity=(percent/100);MozOpacity=(percent/100);KhtmlOpacity=(percent/100);filter='alpha(opacity='+percent+')';}};this.getOpac=function(){if(this.el.getStyle('opacity')!=''&&this.el.getStyle('opacity')!=undefined){return this.el.getStyle('opacity')*100;}else if(this.el.getStyle('-moz-opacity')!=''&&this.el.getStyle('-moz-opacity')!=undefined){return this.el.getStyle('-moz-opacity')*100;}else if(this.el.getStyle('-khtml-opacity')!=''&&this.el.getStyle('-khtml-opacity')!=undefined){return this.el.getStyle('-khtml-opacity')*100;}else if(typeof this.el.filters=='object'){if(typeof this.el.filters.alpha=='object'&&typeof this.el.filters.alpha.opacity=='number'){return this.el.filters.alpha.opacity;}}else{return 100;}};this.ease=function(easing){if(easing=='in'){this.power=1.1;}else if(easing=='out'){this.power=0.9;}};this.halt=function(){if(this.timer){clearInterval(this.timer);this.timer=null;}};What.extend(What.Animation.Fade.prototype,What.Event.Manager);this.registerEvents('onAnimationStart','onAnimationChange','onAnimationEnd');};What.Animation.Move=function(elm,destinationX,destinationY,steps){this.el=$(elm);this.dsx=destinationX;this.dsy=destinationY;this.stlX='left';this.stlY='top';this.theSteps=0;this.maxSteps=steps;this.interval=30;this.units='px';this.power=1;this.init=function(){this.broadcastEvent('onAnimationStart');this.halt();var s=this;this.timer=setInterval(function(){s.el.currentPosX=What.Animation.easeInOut(s.el.currentPosX,s.dsx,s.maxSteps,s.theSteps,s.power);s.el.currentPosY=What.Animation.easeInOut(s.el.currentPosY,s.dsy,s.maxSteps,s.theSteps,s.power);s.el.style[s.stlX]=s.el.currentPosX+s.units;s.el.style[s.stlY]=s.el.currentPosY+s.units;s.theSteps++;s.broadcastEvent('onAnimationChange');if(s.theSteps>s.maxSteps){s.halt();s.broadcastEvent('onAnimationEnd');}},s.interval);};this.setInitialStyle=function(prop){if(isNaN(parseInt(this.el.style[prop.camelize()]))){if(isNaN(parseInt(this.el.getStyle(prop.hyphenate())))){this.el.style[prop.camelize()]='0';}else{this.el.style[prop.camelize()]=this.el.getStyle(prop.hyphenate());}}};this.ease=function(easing){if(easing=='in'){this.power=1.1;}else if(easing=='out'){this.power=0.9;}};this.halt=function(){if(this.timer){clearInterval(this.timer);this.timer=null;}};this.setInitialStyle('left');this.setInitialStyle('top');this.el.currentPosX=parseInt(this.el.style[this.stlX]);this.el.currentPosY=parseInt(this.el.style[this.stlY]);What.extend(What.Animation.Move.prototype,What.Event.Manager);this.registerEvents('onAnimationStart','onAnimationEnd','onAnimationEnd');};What.Animation.Blend=function(elm,prop,to,steps){this.el=$(elm);this.prop=prop;this.initialVal=this.el.getStyle(prop.hyphenate());this.el.currentR=this.initialVal.parseColor().r;this.el.currentG=this.initialVal.parseColor().g;this.el.currentB=this.initialVal.parseColor().b;this.newred=to[0];this.newgreen=to[1];this.newblue=to[2];this.theSteps=0;this.maxSteps=steps;this.interval=30;this.power=1;this.init=function(){this.broadcastEvent('onAnimationStart');this.halt();var s=this;this.timer=setInterval(function(){s.el.currentR=What.Animation.easeInOut(s.el.currentR,s.newred,s.maxSteps,s.theSteps,s.power);s.el.currentG=What.Animation.easeInOut(s.el.currentG,s.newgreen,s.maxSteps,s.theSteps,s.power);s.el.currentB=What.Animation.easeInOut(s.el.currentB,s.newblue,s.maxSteps,s.theSteps,s.power);s.el.style[prop.camelize()]='rgb('+s.el.currentR+','+s.el.currentG+','+s.el.currentB+')';s.theSteps++;s.broadcastEvent('onAnimationChange');if(s.theSteps>s.maxSteps){s.halt();s.broadcastEvent('onAnimationEnd');}},s.interval);};this.ease=function(easing){if(easing=='in'){this.power=1.1;}else if(easing=='out'){this.power=0.9;}};this.halt=function(){if(this.timer){clearInterval(this.timer);this.timer=null;}};What.extend(What.Animation.Blend.prototype,What.Event.Manager);this.registerEvents('onAnimationStart','onAnimationChange','onAnimationEnd');};What.Animation.CSS=function(elm,prop,to,steps){this.el=$(elm);this.prop=prop;this.to=to instanceof Array?to[0]:to;this.units=to instanceof Array?to[1]:'px';this.theSteps=0;this.maxSteps=steps;this.interval=30;this.power=1;this.init=function(){this.broadcastEvent('onAnimationStart');this.halt();var s=this;this.timer=setInterval(function(){s.el.currentVal=What.Animation.easeInOut(s.el.currentVal,s.to,s.maxSteps,s.theSteps,s.power);s.el.style[prop.camelize()]=s.el.currentVal+s.units;s.theSteps++;s.broadcastEvent('onAnimationChange');if(s.theSteps>s.maxSteps){s.halt();s.broadcastEvent('onAnimationEnd');}},s.interval);};this.ease=function(easing){if(easing=='in'){this.power=1.1;}else if(easing=='out'){this.power=0.9;}};this.halt=function(){if(this.timer){clearInterval(this.timer);this.timer=null;}};this.setInitialStyle=function(prop){if(isNaN(parseInt(this.el.style[prop.camelize()]))){if(isNaN(parseInt(this.el.getStyle(prop.hyphenate())))){this.el.style[prop.camelize()]='0';}else{this.el.style[prop.camelize()]=this.el.getStyle(prop.hyphenate());}}};this.setInitialStyle(this.prop);this.el.currentVal=parseInt(this.el.style[this.prop.camelize()]);What.extend(What.Animation.CSS.prototype,What.Event.Manager);this.registerEvents('onAnimationStart','onAnimationChange','onAnimationEnd');};
What.Cookiejar={bake:function(cookieName,cookieValue,days,path){var expires='';if(days){var date=new Date();date.setTime(date.getTime()+(days*24*60*60*1000));expires="; expires="+date.toGMTString();}var thePath='; path=/';if(path){thePath='; path='+path;}document.cookie=cookieName+'='+escape(cookieValue)+expires+thePath;},fetch:function(cookieName){var nameEQ=cookieName+'=';var ca=document.cookie.split(';');for(var i=0;i<ca.length;i++){var c=ca[i];while(c.charAt(0)==' '){c=c.substring(1,c.length);}if(c.indexOf(nameEQ)==0){return unescape(c.substring(nameEQ.length,c.length));}}return null;},crumble:function(cookieName){What.Cookiejar.bake(cookieName,'',-1);}};What.Subcookiejar={nameValueSeparator:'$$:$$',subcookieSeparator:'$$/$$',bake:function(cookieName,subcookieObj,days,path){var cookieValue='';for(var i in subcookieObj){cookieValue+=i+What.Subcookiejar.nameValueSeparator;cookieValue+=subcookieObj[i];cookieValue+=What.Subcookiejar.subcookieSeparator;}cookieValue=cookieValue.substring(0,cookieValue.length-What.Subcookiejar.subcookieSeparator.length);What.Cookiejar.bake(cookieName,cookieValue,days,path);},fetch:function(cookieName,subcookieName){var cookieValue=What.Cookiejar.fetch(cookieName);if(cookieValue){var subcookies=cookieValue.split(What.Subcookiejar.subcookieSeparator);for(var i=0;i<subcookies.length;i++){var sc=subcookies[i].split(What.Subcookiejar.nameValueSeparator);if(sc[0]==subcookieName){return sc[1];}}}return null;},crumble:function(cookieName,subcookieName,days,path){var cookieValue=What.Cookiejar.fetch(cookieName);var newCookieObj={};var subcookies=cookieValue.split(What.Subcookiejar.subcookieSeparator);for(var i=0;i<subcookies.length;i++){var sc=subcookies[i].split(What.Subcookiejar.nameValueSeparator);if(sc[0]!=subcookieName){newCookieObj[sc[0]]=sc[1];}}What.Subcookiejar.bake(cookieName,newCookieObj,days,path);}};
What.DragDrop=function(elm,dragHandle,dropSpots,restriction){this.elm=$(elm);if(typeof dragHandle!='undefined'&&!!dragHandle){this.dragHandle=$(dragHandle);}this.initialX=null;this.initialY=null;this.startX=null;this.startY=null;this.restriction=(typeof restriction!='undefined')?restriction:null;this.dropSpots=(dropSpots instanceof Array)?dropSpots:null;this.snap=false;var s=this;this.init=function(){if(this.elm.getStyle('position')!='absolute'||this.elm.getStyle('position')!='fixed'){this.elm=this.elm.absolutize();}if(!this.dragHandle){this.elm.addEvent('mousedown',s.initDrag);}else{this.dragHandle.addEvent('mousedown',s.initDrag);}};this.initDrag=function(e){s.startDrag();var ev=e||window.event;s.initialX=ev.clientX;s.initialY=ev.clientY;s.elm.originalX=parseInt(s.elm.style.left);s.elm.originalY=parseInt(s.elm.style.top);What.Event.add(document,'mousemove',s.drag);What.Event.add(document,'mouseup',s.drop);What.Event.preventDefault(e);return false;};this.startDrag=function(){this.broadcastEvent('onStartDrag');this.startX=this.elm.offsetLeft;this.startY=this.elm.offsetTop;this.elm.addClass('dragged');};this.drag=function(e){s.broadcastEvent('onDrag');var ev=e||window.event;var dx=ev.clientX-s.initialX;var dy=ev.clientY-s.initialY;s.setPosition(dx,dy);What.Event.preventDefault(e);return false;};this.drop=function(e){s.broadcastEvent('onDrop');What.Event.del(document,'mousemove',s.drag);What.Event.del(document,'mouseup',s.drop);s.elm.removeClass('dragged');var ds=s.inDropSpot();if(!ds){s.elm.style.left=s.elm.originalX+'px';s.elm.style.top=s.elm.originalY+'px';s.broadcastEvent('onDropWrong');}else{if(s.snap){var p=ds.getPerimeter();s.elm.style.top=p.topleft.y+'px';s.elm.style.left=p.topleft.x+'px';}if(typeof ds.onDrop=='function'){ds.onDrop(s.elm);}s.broadcastEvent('onDropRight',ds);}};this.setPosition=function(dx,dy){if(typeof this.restriction=='string'){if(this.restriction!='y'){this.elm.style.left=(this.startX+dx)+'px';}if(this.restriction!='x'){this.elm.style.top=(this.startY+dy)+'px';}}else if(!!this.restriction){this.restriction=$(this.restriction);var restrictionpos=this.restriction.getPerimeter();var elmperimeter=this.elm.getPerimeter();var boundTop=restrictionpos.topleft.y;var boundRight=(restrictionpos.topright.x-elmperimeter.width);var boundBottom=(restrictionpos.bottomleft.y-elmperimeter.height);var boundLeft=restrictionpos.topleft.x;var ndx=this.startX+dx;var ndy=this.startY+dy;if(ndx>boundRight){ndx=boundRight;}else if(ndx<boundLeft){ndx=boundLeft;}if(ndy<boundTop){ndy=boundTop;}else if(ndy>boundBottom){ndy=boundBottom;}this.elm.style.left=ndx+'px';this.elm.style.top=ndy+'px';}else{this.elm.style.left=(this.startX+dx)+'px';this.elm.style.top=(this.startY+dy)+'px';}var ds=this.inDropSpot();if(ds){if(typeof ds.onDragOver=='function'){ds.onDragOver(this.elm);this.broadcastEvent('onEnterDropSpot',ds);}}if(this.dropSpots instanceof Array){for(var q=0,k;k=this.dropSpots[q];q++){if(typeof k.onDragOut=='function'&&k!==ds){k.onDragOut(this.elm);}}}};this.inDropSpot=function(){if(this.dropSpots instanceof Array){var ep=this.elm.getPerimeter();for(var i=0,j=this.dropSpots.length;i<j;i++){var ds=$(this.dropSpots[i]);var dsp=ds.getPerimeter();var validY=!!((ep.topleft.y>dsp.topleft.y&&ep.topleft.y<dsp.bottomleft.y)||(ep.bottomleft.y>dsp.topleft.y&&ep.bottomleft.y<dsp.bottomleft.y));var validX=!!((ep.topleft.x>dsp.topleft.x&&ep.topleft.x<dsp.topright.x)||(ep.topright.x>dsp.topleft.x&&ep.topright.x<dsp.topright.x));if(validY&&validX){return ds;}}return false;}else{return true;}};What.extend(What.DragDrop.prototype,What.Event.Manager);this.registerEvents('onDrag','onDrop','onStartDrag','onDropWrong','onDropRight','onEnterDropSpot');};
What.Element={getClasses:function(){return this.className.split(' ');},hasClass:function(className){return new RegExp(("(^|\\s)"+className+"(\\s|$)"),"i").test(this.className);},addClass:function(className){var currentClass=this.className;if(!new RegExp(("(^|\\s)"+className+"(\\s|$)"),"i").test(currentClass)){this.className=currentClass+((currentClass.length>0)?" ":"")+className;}return this;},removeClass:function(className){var classToRemove=new RegExp(("(^|\\s)"+className+"(\\s|$)"),"i");this.className=this.className.replace(classToRemove,"").replace(/^\s+|\s+$/g,"");return this;},getStyle:function(cssRule){var cssVal="";if(document.defaultView&&document.defaultView.getComputedStyle){cssVal=document.defaultView.getComputedStyle(this,"").getPropertyValue(cssRule);}else if(this.currentStyle){cssVal=cssRule.replace(/\-(\w)/g,function(match,p1){return p1.toUpperCase();});cssVal=this.currentStyle[cssVal];}return cssVal;},absolutize:function(){var coordinates=What.Position.getElementPosition(this);this.style.position='absolute';this.style.left=coordinates[0]+'px';this.style.top=coordinates[1]+'px';return this;},getPerimeter:function(){var coordinates=What.Position.getElementPosition(this);var w=this.offsetWidth;var h=this.offsetHeight;return{width:w,height:h,topleft:{x:coordinates[0],y:coordinates[1]},topright:{x:coordinates[0]+w,y:coordinates[1]},bottomleft:{x:coordinates[0],y:coordinates[1]+h},bottomright:{x:coordinates[0]+w,y:coordinates[1]+h}};},addEvent:function(type,fn){What.Event.add(this,type,fn);},delEvent:function(type,fn){What.Event.del(this,type,fn);},create:function(tag,attrObj,children){var elm=$(document.createElement(tag));if(typeof attrObj=='object'){elm.setAttributes(attrObj);}if(typeof children=='object'){children.map(function(e){if(typeof e=='string'){elm.appendChild(document.createTextNode(e));}else{elm.appendChild(e);}});}return elm;},remove:function(){this.parentNode.removeChild(this);},insertAfter:function(newChild,sibling){if(sibling.next()){this.insertBefore(newChild,sibling.next());}else{this.appendChild(newChild);}return newChild;},next:function(){var ns=this.nextSibling;while(ns&&ns.nodeType!=1){ns=ns.nextSibling;}return ns;},prev:function(){var ps=this.previousSibling;while(ps&&ps.nodeType!=1){ps=ps.previousSibling;}return ps;},addChildren:function(children){var s=this;children.map(function(e){if(typeof e=='string'){s.appendChild(document.createTextNode(e));}else{s.appendChild(e);}});return this;},setAttributes:function(attrObj){for(var i in attrObj){if(i=='class'||i=='className'){this.className=attrObj[i];}else if(i=='for'||i=='htmlFor'){this.htmlFor=attrObj[i];}else{this.setAttribute(i,'');this[i]=attrObj[i];}}},empty:function(tag){var nodes=(tag)?this.getElementsByTagName(tag):this.childNodes;for(var i=nodes.length;i>0;i--){var node=nodes[i-1];this.removeChild(node);}return this;},getElementsByClassName:function(className,tagName,callback){var collection=[];var elements=((!tagName||tagName=='*')&&this.all)?this.all:this.$$(tagName||'*');for(var i=0;i<elements.length;i++){if(typeof elements[i].className=='undefined'||elements[i].nodeType!=1){continue;}if($(elements[i]).hasClass(className)){var element=elements[i];if(typeof callback=='function'){element=callback(elements[i])||elements[i];}collection.push(element);}}return collection;},getElementsByAttribute:function(attribute,attrValue,tagName,callback){var collection=[];var elements=((!tagName||tagName=='*')&&this.all)?this.all:this.$$(tagName||'*');for(var i=0;i<elements.length;i++){if(typeof elements[i].getAttribute=='undefined'){continue;}var valid=false;if(attribute=='className'||attribute=='class'){if(attrValue){valid=$(elements[i]).hasClass(attrValue);}else{valid=$(elements[i]).getAttribute('class')||$(elements[i]).getAttribute('className');}}else if(attribute=='for'){valid=((elements[i].getAttribute('htmlFor')||elements[i].getAttribute('for'))&&(attrValue&&elements[i].htmlFor==attrValue)||!attrValue);}else if(elements[i].getAttribute(attribute)){valid=attrValue?(elements[i].getAttribute(attribute)==attrValue):elements[i].getAttribute(attribute)!='';}if(valid){var element=elements[i];if(typeof callback=='function'){element=callback(elements[i])||elements[i];}collection.push(element);}}return collection;}};
function $(o){if(typeof(o)=='string'){var elm=document.getElementById(o);}else{var elm=o;}if(elm){return What.extend(elm,What.Element);}else{return null;}}
function $$(tag,elm){var el=elm?elm:document;var collection=el.getElementsByTagName(tag);collection.toArray=function(){var _store=[];for(var i=0;i<this.length;i++){_store.push(this[i]);}return _store;};return collection;}document.$=$;document.$$=function(tag){return $$(tag,this);};document.getElementsByClassName=What.Element.getElementsByClassName;document.getElementsByAttribute=What.Element.getElementsByAttribute;What.Element.$=function(id){return $(id);};What.Element.$$=function(tag){return $$(tag,this);};
What.Event={store:[],add:function(obj,type,fn){if(obj.addEventListener){obj.addEventListener(type,fn,false);}else if(obj.attachEvent){obj["e"+type+fn]=fn;obj[type+fn]=function(){obj["e"+type+fn](window.event);};obj.attachEvent("on"+type,obj[type+fn]);}},del:function(obj,type,fn){if(obj.removeEventListener){obj.removeEventListener(type,fn,false);}else if(obj.detachEvent){obj.detachEvent("on"+type,obj[type+fn]);obj[type+fn]=null;obj["e"+type+fn]=null;}},preventDefault:function(e){(e&&e.preventDefault)?e.preventDefault():event.returnValue=false;},cancelBubble:function(e){(e&&e.stopPropagation)?e.stopPropagation():event.cancelBubble=true;},getTarget:function(e){if(e.target){return e.target;}else{return e.srcElement||false;}},Manager:{registerEvents:function(){if(!this.storedEvents){this.storedEvents={};}for(var i=0,event;event=arguments[i];i++){this.storedEvents[event]=true;}},broadcastEvent:function(event){if(event in this.storedEvents&&typeof this[event]=='function'){var args=[];for(var i=1;i<arguments.length;i++){args.push(arguments[i]);}this[event].apply(this,args);}}}};What.Event.add(window,'unload',
function(){for(var i=0;i<What.Event.store.length;i++){What.Event.del(What.Event.store[i].e,What.Event.store[i].t,What.Event.store[i].f);}});
What.Position={getScrollingPosition:function(){var position=[0,0];if(typeof window.pageYOffset!='undefined'){position=[window.pageXOffset,window.pageYOffset];}if(typeof document.documentElement.scrollTop!='undefined'&&document.documentElement.scrollTop>0){position=[document.documentElement.scrollLeft,document.documentElement.scrollTop];}else if(typeof document.body.scrollTop!='undefined'){position=[document.body.scrollLeft,document.body.scrollTop];}return position;},getViewportSize:function(){if(typeof window.innerWidth!='undefined'){return[window.innerWidth,window.innerHeight];}else if(typeof document.documentElement!='undefined'&&typeof document.documentElement.clientWidth!='undefined'&&document.documentElement.clientWidth!=0){return[document.documentElement.clientWidth,document.documentElement.clientHeight];}else{return[document.getElementsByTagName('body')[0].clientWidth,document.getElementsByTagName('body')[0].clientHeight];}return[0.0];},getPageDimensions:function(){var body=$$("body")[0];var bodyOffsetWidth=0;var bodyOffsetHeight=0;var bodyScrollWidth=0;var bodyScrollHeight=0;var pageDimensions=[0,0];if(typeof document.documentElement!="undefined"&&typeof document.documentElement.scrollWidth!="undefined"){pageDimensions[0]=document.documentElement.scrollWidth;pageDimensions[1]=document.documentElement.scrollHeight;}bodyOffsetWidth=body.offsetWidth;bodyOffsetHeight=body.offsetHeight;bodyScrollWidth=body.scrollWidth;bodyScrollHeight=body.scrollHeight;if(bodyOffsetWidth>pageDimensions[0]){pageDimensions[0]=bodyOffsetWidth;}if(bodyOffsetHeight>pageDimensions[1]){pageDimensions[1]=bodyOffsetHeight;}if(bodyScrollWidth>pageDimensions[0]){pageDimensions[0]=bodyScrollWidth;}if(bodyScrollHeight>pageDimensions[1]){pageDimensions[1]=bodyScrollHeight;}return pageDimensions;},getElementPosition:function(element){var left=0,top=0;if(element.offsetParent){left=element.offsetLeft;top=element.offsetTop;while(element=element.offsetParent){left+=element.offsetLeft;top+=element.offsetTop;}}return[left,top];}};

/**
 * whatJS Javascript framework
 * GUI widget utility version 1.0
 * Providing various custom GUI elements
 * 
 * @author Harmen Janssen
 * @requires
 * 	- What.js
 *  - Animation.js
 *  - DragDrop.js
 */

What.GUI = {};

What.GUI.DropSheet = function (){
	this.elm = null;
	this.create = function (){
		var body = $$("body")[0];
		var pageDimensions = What.Position.getPageDimensions();
		var viewportSize = What.Position.getViewportSize();
		if (viewportSize[1] > pageDimensions[1]){
			pageDimensions[1] = viewportSize[1];
		}
		var dropSheet = What.Element.create ('div',{id:'dropSheet'});
		dropSheet.style.position = "absolute";
		dropSheet.style.left = "0";
		dropSheet.style.top = "0";
		dropSheet.style.width = pageDimensions[0] + "px";
		dropSheet.style.height = pageDimensions[1] + "px";
		dropSheet.style.backgroundColor = "#000";
		dropSheet.style.visibility = 'hidden';
		body.appendChild(dropSheet);
		this.elm = dropSheet;
		var s = this;
		var ani = new What.Animation.Fade (dropSheet,0,1);
		ani.onAnimationEnd = function(){
			dropSheet.style.visibility = 'visible';
			var ani2 = new What.Animation.Fade (dropSheet,50,15);
			ani2.onAnimationEnd = function(){
				s.broadcastEvent ('onReady');
			};
			ani2.init();
		};
		ani.init();
	};
	this.close = function(){
		s = this;
		var ani = new What.Animation.Fade (this.elm,0,15);
		ani.onAnimationEnd = function (){
			s.elm.remove();
			s.elm = null;
			s.broadcastEvent('onClose');
		}
		ani.init();
	};
	What.extend(What.GUI.DropSheet.prototype,What.Event.Manager);
	this.registerEvents('onReady','onClose');
	this.create ();
};

What.GUI.CustomDialog = function (dialogID){
	this.dialogID = dialogID || 'dialog';
	this.useDropSheet = true;
	this.useESCToClose = true;
	this.draggable = true;
	this.xPos = 'center';
	this.yPos = 'center';
	var s = this;
	this.init = function (){
		this.create();
	};
	this.create = function (){
		if (this.useDropSheet){
			this.dropSheet = new What.GUI.DropSheet ();
			this.dropSheet.onReady = function (){
				s.createDialog();
			}
		} else {
			s.createDialog();
		}
	};
	this.createDialog = function(){
		var pageDimensions = What.Position.getPageDimensions();
		var viewportSize = What.Position.getViewportSize();
		var scrollingPosition = What.Position.getScrollingPosition();
		if (viewportSize[1] > pageDimensions[1]){
			pageDimensions[1] = viewportSize[1];
		}
		s.containerElement = What.Element.create ('div',{id:s.dialogID});
		s.containerElement.className = 'dialog';
		s.containerElement.style.visibility = 'hidden';
		s.containerElement.style.position = 'absolute';
		$$('body')[0].appendChild(s.containerElement);
		
		switch (s.xPos){
			default:
			case 'center':
				s.containerElement.style.left = scrollingPosition[0] + parseInt(viewportSize[0] / 2) - parseInt(s.containerElement.offsetWidth / 2) + 'px';
				break;
			case 'left':
				s.containerElement.style.left = '0px';
				break;
			case 'right':
				s.containerElement.style.left = parseInt(viewportSize[0]) - parseInt(s.containerElement.offsetWidth) + 'px';
				break;
		}
		
		switch (s.yPos){
			default:
			case 'center':
				s.containerElement.style.top = scrollingPosition[1] + parseInt(viewportSize[1] / 2) - parseInt(s.containerElement.offsetHeight / 2) + 'px';
				break;
			case 'top':
				s.containerElement.style.top = scrollingPosition[1] + 'px';
				break;
			case 'bottom':
				s.containerElement.style.top = scrollingPosition[1] + parseInt(viewportSize[1]) - parseInt(s.containerElement.offsetHeight) + 'px';
				break;
		}
		
		s.containerElement.style.visibility = "visible";
		if (s.draggable){
			var dragHandle = What.Element.create ('div',{id:dialogID+'-dragHandle',className:'dialog-dragHandle'});
			s.addContent(dragHandle);
			var dd = new What.DragDrop(s.containerElement,dragHandle);
			dd.init();
		}
		
		s.broadcastEvent('onReady');
		if (s.useESCToClose){
			What.Event.add (document,'keydown',s.keyboardClose);
		}
	};
	this.addContent = function (children){
		var c = children instanceof Array ? children : [children];
		if (this.containerElement){
			this.containerElement.addChildren(c);
		} else {
			setTimeout (function(){
				s.addContent (c);
			},30);
		}
	};
	this.close = function (){
		if (this.dropSheet){
			this.dropSheet.close();
			this.dropSheet = null;
		}
		if (this.useESCToClose){
			What.Event.del(document,'keydown',s.keyboardClose);
		}
		this.containerElement.remove();
		this.containerElement = null;
		this.broadcastEvent('onClose');
	};
	this.keyboardClose = function (e){
		if (e.keyCode == 27){
			s.close();
		}
	};
	What.extend(What.GUI.CustomDialog.prototype,What.Event.Manager);
	this.registerEvents('onReady','onClose');
};