sjcl.effect={Rect:function(left,top,width,height){this.left=left;this.top=top;this.width=width;this.height=height;this.right=left+width;this.bottom=top+height;},RectAnimation:function(rc1,rc2,callback,steps,color,interval){if(!steps)steps=10;if(!color)color="#6D7993";if(typeof interval!="number")interval=10;this.rect1=rc1;this.rect2=rc2;this.callback=callback;this.steps=steps;this.color=color;this.interval=interval;this.active=false;},SlideDown:function(element,anchor,height,callback){this._outer=element;this._inner=sjcl.dom.firstChild(element);this._anchor=anchor;this._height=height;this._callback=callback;this._initialize();},SlideUp:function(element,anchor,height,callback){this._outer=element;this._inner=sjcl.dom.firstChild(element);this._anchor=anchor;this._height=height;this._callback=callback;this._initialize();},alignRect:function(rc1,rc2,align,margin){if(typeof align=="undefined")align=sjcl.widget.Alignment.BottomLeft;if(typeof margin=="undefined")margin=2;switch(align){case sjcl.widget.Alignment.BottomLeft:rc1.left=ltr()?rc2.left:rc2.right-rc1.width;rc1.top=rc2.top+rc2.height+margin;break;case sjcl.widget.Alignment.BottomCenter:rc1.left=rc2.left-(rc1.width-rc2.width)/2;rc1.top=rc2.top+rc2.height+margin;break;case sjcl.widget.Alignment.BottomRight:rc1.left=rc2.left+rc2.width;rc1.top=rc2.top+rc2.height+margin;break;case sjcl.widget.Alignment.MiddleLeft:rc1.left=rc2.left;rc1.top=rc2.top-(rc1.height-rc2.height)/2;break;case sjcl.widget.Alignment.MiddleCenter:rc1.left=rc2.left-(rc1.width-rc2.width)/2;rc1.top=rc2.top-(rc1.height-rc2.height)/2;break;case sjcl.widget.Alignment.MiddleRight:rc1.left=rc2.left+rc2.width+margin;rc1.top=rc2.top-(rc1.height-rc2.height)/2;break;case sjcl.widget.Alignment.TopLeft:rc1.left=rc2.left;rc1.top=rc2.top-rc1.height-margin;break;case sjcl.widget.Alignment.TopCenter:rc1.left=rc2.left-(rc1.width-rc2.width)/2;rc1.top=rc2.top-rc1.height-margin;break;case sjcl.widget.Alignment.TopRight:rc1.left=rc2.left+rc2.width;rc1.top=rc2.top-rc1.height-margin;break;}},getCursorPos:function(rc,x,y){var delta=4,grip=12;var rc1,rc2;if(rtl())x-=SCROLL_WIDTH;rc1=new sjcl.effect.Rect(rc.left,rc.bottom-grip,delta,grip);rc2=new sjcl.effect.Rect(rc.left,rc.bottom-delta,grip,delta);if(rc1.contains(x,y)||rc2.contains(x,y))return sjcl.widget.CursorPos.SizeBottomLeft;rc1=new sjcl.effect.Rect(rc.right-delta,rc.bottom-grip,delta,grip);rc2=new sjcl.effect.Rect(rc.right-grip,rc.bottom-delta,grip,delta);if(rc1.contains(x,y)||rc2.contains(x,y))return sjcl.widget.CursorPos.SizeBottomRight;rc1=new sjcl.effect.Rect(rc.left,rc.top,delta,rc.height-grip);if(rc1.contains(x,y))return sjcl.widget.CursorPos.SizeLeft;rc1=new sjcl.effect.Rect(rc.right-delta,rc.top,delta,rc.height-grip);if(rc1.contains(x,y))return sjcl.widget.CursorPos.SizeRight;rc1=new sjcl.effect.Rect(rc.left+grip,rc.bottom-delta,rc.width-grip*2,delta);if(rc1.contains(x,y))return sjcl.widget.CursorPos.SizeBottom;return sjcl.widget.CursorPos.Default;},setCursor:function(e,pos){switch(pos){case sjcl.widget.CursorPos.SizeBottomLeft:e.style.cursor="ne-resize";break;case sjcl.widget.CursorPos.SizeBottomRight:e.style.cursor="nw-resize";break;case sjcl.widget.CursorPos.SizeLeft:case sjcl.widget.CursorPos.SizeRight:e.style.cursor="w-resize";break;case sjcl.widget.CursorPos.SizeBottom:e.style.cursor="s-resize";break;default:e.style.cursor="default";break;}},drag:function(e,evt,onDragStart,onDragEnd,onDrag,clip){var event=new sjcl.Event(evt);var rc=sjcl.dom.elementRect(e);var x=parseInt(e.style.left);var y=parseInt(e.style.top);var deltaX=event.pageX-x;var deltaY=event.pageY-y;var dragged=false;if(document.body.setCapture)document.body.setCapture();sjcl.event.add(document,"mousemove",onMouseMove);sjcl.event.add(document,"mouseup",onMouseUp);event.cancelDefault();function onMouseMove(evt){var event=new sjcl.Event(evt);var left=event.pageX-deltaX;var top=event.pageY-deltaY;if(!dragged){if(onDragStart)onDragStart();dragged=true;}if(clip){if(left<clip.left)e.style.left=clip.left+"px";else if(left>=clip.left&&left+rc.width>clip.right)e.style.left=clip.right-rc.width+"px";else e.style.left=left+"px";if(top<clip.top)e.style.top=clip.top+"px";else if(top>=clip.top&&top+rc.height>clip.bottom)e.style.top=clip.bottom-rc.height+"px";else e.style.top=top+"px";}else{e.style.left=left+"px";e.style.top=top+"px";}if(onDrag)onDrag();event.cancelPropagation();event.cancelDefault();}function onMouseUp(evt){var event=new sjcl.Event(evt);if(dragged&&onDragEnd)onDragEnd();if(document.body.releaseCapture)document.body.releaseCapture();sjcl.event.remove(document,"mousemove",onMouseMove);sjcl.event.remove(document,"mouseup",onMouseUp);event.cancelPropagation();event.cancelDefault();}},resize:function(e,evt,pos,onResizeStart,onResizeEnd,onResize,minWidth,minHeight,maxWidth,maxHeight,aspectRatio){var event=new sjcl.Event(evt);var filter=sjcl.dom.getFilter(e,"Shadow");if(filter)filter.enabled=false;var rc=sjcl.dom.elementRect(e);var div=createResizeRect();var x=div.offsetLeft;var y=div.offsetTop;var deltaX=rc.right-event.clientX;var deltaY=rc.bottom-event.clientY;var dragged=false;if(document.body.setCapture)document.body.setCapture();sjcl.effect.setCursor(document.body,pos);sjcl.event.add(document,"mousemove",onMouseMove);sjcl.event.add(document,"mouseup",onMouseUp);event.cancelDefault();function createResizeRect(){var div=document.createElement("DIV");div.style.position="absolute";div.style.border="solid 2px #4C566D";div.style.zIndex=sjcl.zIndex("Effect");div.style.left=rc.left+"px";div.style.top=rc.top+document.body.parentNode.scrollTop+"px";div.style.width=(rc.width-4)+"px";div.style.height=(rc.height-4)+"px";document.body.appendChild(div);return div;}function onMouseMove(evt){var event=new sjcl.Event(evt);var px=event.pageX;var py=event.pageY;var width,height;if(!dragged){if(onResizeStart)onResizeStart();dragged=true;}switch(pos){case sjcl.widget.CursorPos.SizeLeft:if(rtl())px-=SCROLL_WIDTH;div.style.width=Math.max(rc.right-px-4,minWidth)+"px";div.style.left=Math.min(px,rc.right-minWidth)+"px";break;case sjcl.widget.CursorPos.SizeRight:div.style.width=Math.max(px-x-4+deltaX,minWidth)+"px";break;case sjcl.widget.CursorPos.SizeBottom:div.style.height=Math.max(py-y-4+deltaY,minHeight)+"px";break;case sjcl.widget.CursorPos.SizeBottomLeft:div.style.width=Math.max(rc.right-px-4,minWidth)+"px";div.style.left=Math.min(px,rc.right-minWidth)+"px";div.style.height=Math.max(py-y-4+deltaY,minHeight)+"px";break;case sjcl.widget.CursorPos.SizeBottomRight:width=Math.max(px-x-4+deltaX,minWidth);height=aspectRatio?width:Math.max(py-y-4+deltaY,minHeight);if(aspectRatio&&width>Math.min(maxWidth,maxHeight))width=height=Math.min(maxWidth,maxHeight)-4;if(!maxWidth)div.style.width=width+"px";else div.style.width=width<=maxWidth?width+"px":maxWidth-4+"px";if(!maxHeight)div.style.height=height+"px";else div.style.height=height<=maxHeight?height+"px":maxHeight-4+"px";break;}if(onResize)onResize(div.offsetWidth,div.offsetHeight);event.cancelPropagation();event.cancelDefault();}function onMouseUp(evt){var event=new sjcl.Event(evt);var left=div.offsetLeft;var top=div.offsetTop-(sjcl.browser.fixedPositioning?document.body.parentNode.scrollTop:0);var width=div.offsetWidth-4;var height=Math.max(div.offsetHeight-4,minHeight);if(filter)filter.enabled=true;if(dragged){e.style.left=left+"px";e.style.top=top+"px";e.style.width=width+"px";e.style.height=height+"px";}if(document.body.releaseCapture)document.body.releaseCapture();div.parentNode.removeChild(div);document.body.style.cursor="default";sjcl.event.remove(document,"mousemove",onMouseMove);sjcl.event.remove(document,"mouseup",onMouseUp);event.cancelPropagation();event.cancelDefault();if(dragged&&onResizeEnd)onResizeEnd(left,top,width,height);}},vSplitter:function(e,evt,onStart,onEnd,minWidth,maxWidth){function createBar(rc){var div=document.createElement("DIV");div.className="VSplitter";div.style.position="absolute";div.style.zIndex=sjcl.zIndex("Effect");div.style.left=rc.left+"px";div.style.top=rc.top+"px";div.style.height=rc.height+"px";document.body.appendChild(div);return div;}function onMouseMove(evt){var event=new sjcl.Event(evt);var left=event.pageX-deltaX;if(!dragged){if(onStart)onStart();dragged=true;}if((!minWidth||(rc.left-left<minWidth))&&(!maxWidth||(left-rc.left<maxWidth)))bar.style.left=left+"px";event.cancelPropagation();event.cancelDefault();}function onMouseUp(evt){var event=new sjcl.Event(evt);var left=parseInt(bar.style.left);sjcl.event.remove(document,"mousemove",onMouseMove);sjcl.event.remove(document,"mouseup",onMouseUp);event.cancelPropagation();event.cancelDefault();sjcl.dom.removeElement(bar);if(dragged&&onEnd)onEnd(left-rc.left);}var event=new sjcl.Event(evt);var rc=sjcl.dom.elementRect(e);var bar=createBar(rc);var deltaX=event.pageX-rc.left;var dragged=false;event.cancelDefault();sjcl.event.add(document,"mousemove",onMouseMove);sjcl.event.add(document,"mouseup",onMouseUp);},expand:function(element,height,callback){var inner=sjcl.dom.firstChild(element);var top=0;var delay=0;inner.style.position="relative";inner.style.top=-height+"px";element.style.position="relative";element.style.height="0px";element.style.display="block";function setHeight(){inner.style.top=top-height+"px";element.style.height=top+"px";if(top<height){delay+=5;top+=15;window.setTimeout(setHeight,delay);}else{inner.style.top="0px";element.style.height=height+"px";element.setAttribute("Expanded",1);if(callback)callback();}}setHeight();},collapse:function(element,height,callback){var inner=sjcl.dom.firstChild(element);var top=height;var delay=0;inner.style.position="relative";inner.style.top="0px";element.style.position="relative";element.style.height=height+"px";element.style.display="block";function setHeight(){if(top>0){inner.style.top=-height+top+"px";element.style.height=top+"px";delay+=5;top-=15;window.setTimeout(setHeight,delay);}else{inner.style.top=-height+"px";element.style.height="0px";element.setAttribute("Expanded",0);if(callback)callback();}}setHeight();}};sjcl.effect.Rect.extend({contains:function(x,y){return(x>=this.left)&&(x<=this.right)&&(y>=this.top)&&(y<=this.bottom);}});sjcl.effect.RectAnimation.extend({play:function(){if(this.interval>0){var div=document.createElement("DIV");div.style.position="absolute";div.style.border="1px solid "+this.color;div.style.left=this.rect1.left+"px";div.style.top=this.rect1.top+"px";div.style.width=this.rect1.width+"px";div.style.height=this.rect1.height+"px";div.setAttribute("AnimationRect",true);document.body.appendChild(div);this.frame=div;this._deltaLeft=(this.rect2.left-this.rect1.left)/this.steps;this._deltaTop=(this.rect2.top-this.rect1.top)/this.steps;this._deltaWidth=(this.rect2.width-this.rect1.width)/this.steps;this._deltaHeight=(this.rect2.height-this.rect1.height)/this.steps;this._step=1;this._timerId=window.setInterval(this._animate.bind(this),this.interval);this.active=true;}else{if(this.callback)this.callback();}this.active=true;},cancel:function(){if(this._timerId){window.clearInterval(this._timerId);this._timerId=null;}if(this.frame){document.body.removeChild(this.frame);this.frame=null;}this.active=false;},_animate:function(){if(this._step>this.steps){this.cancel();if(this.callback)this.callback();return;}var e=this.frame;var left=parseInt(e.style.left)+this._deltaLeft;var top=parseInt(e.style.top)+this._deltaTop;var width=parseInt(e.style.width)+this._deltaWidth;var height=parseInt(e.style.height)+this._deltaHeight;if(this._step==this.steps){left=this.rect2.left;top=this.rect2.top;width=this.rect2.width;height=this.rect2.height;}e.style.left=left+"px";e.style.top=top+"px";e.style.width=width+"px";e.style.height=height+"px";this._step++;}});sjcl.effect.SlideDown.extend({_initialize:function(){var rc1=sjcl.dom.elementRect(this._outer);var rc2=sjcl.dom.elementRect(this._anchor);sjcl.effect.alignRect(rc1,rc2);this._outer.style.position="absolute";this._outer.style.left=rc1.left+"px";this._outer.style.top=rc1.top+"px";this._inner.style.position="relative";},_setInnerTop:function(top){this._inner.style.top=top+"px";},_setOuterHeight:function(height){this._outer.style.height=height+"px";},play:function(){var delay=0;var height=0;var top=-this._height;var incDelay=5;var incHeight=5;this._outer.style.visibility="visible";this._outer.style.display="block";this._inner.style.top=top+"px";while(top<0){setTimeout(this._setInnerTop.bind(this,top),delay);setTimeout(this._setOuterHeight.bind(this,height),delay);delay+=incDelay;top+=incHeight;height+=incHeight;}setTimeout(this._setInnerTop.bind(this,0),delay);setTimeout(this._setOuterHeight.bind(this,this._height),delay);if(this._callback)setTimeout(this._callback,delay);}});sjcl.effect.SlideUp.extend({_initialize:function(){var rc1=sjcl.dom.elementRect(this._outer);var rc2=sjcl.dom.elementRect(this._anchor);sjcl.effect.alignRect(rc1,rc2);this._outer.style.position="absolute";this._outer.style.left=rc1.left+"px";this._outer.style.top=rc1.top+"px";this._inner.style.position="relative";},_setInnerTop:function(top){this._inner.style.top=top+"px";},_setOuterHeight:function(height){this._outer.style.height=height+"px";},play:function(){var delay=0;var top=0;var height=this._height;var target=top-this._height;var incDelay=5;var incHeight=5;this._outer.style.visibility="visible";this._outer.style.display="block";this._inner.style.top=top+"px";while(top>target){setTimeout(this._setInnerTop.bind(this,top),delay);setTimeout(this._setOuterHeight.bind(this,height),delay);delay+=incDelay;top-=incHeight;height-=incHeight;}setTimeout(this._setOuterHeight.bind(this,0),delay);if(this._callback)setTimeout(this._callback,delay);}});
