/*
 *
 * Copyright (c) 2004-2005 by Zapatec, Inc.
 * http://www.zapatec.com
 * 1700 MLK Way, Berkeley, California,
 * 94709, U.S.A.
 * All rights reserved.
 *
 *
 */


Zapatec.Array=function(arr){if(!Zapatec.isArray(arr)){var array=[];for(var i=0;i<arguments.length;++i){array.push(arguments[i]);}
arr=array;}
arr.clear=function(){Zapatec.Array.clear(this);};arr.compact=function(){var compact=Zapatec.Array.compact(this);return Zapatec.Array(compact);};arr.indexOf=function(value){return Zapatec.Array.indexOf(this,value);};arr.without=function(){var args=[].slice.call(arguments,0);args.unshift(this);var without=Zapatec.Array.without.apply(Zapatec.Array,args);return Zapatec.Array(without);};arr.remove=function(){var args=[].slice.call(arguments,0);args.unshift(this);var cut=Zapatec.Array.remove.apply(Zapatec.Array,args);return Zapatec.Array(cut);};arr.each=function(func,reverse){var result;for(var index=reverse?this.length-1:0;reverse?(index>=0):(index<this.length);reverse?--index:++index){if(typeof func=="function"){result=func(index,this[index],this);if(result=="break"){break;}}}
if(result=="break"){return false;}
return true;};arr.isZpArray=true;return arr;};Zapatec.Array.compact=function(arr){var newArr=[];for(var item=0;item<arr.length;++item){if(arr[item]!==null&&typeof arr[item]!="undefined"){newArr.push(arr[item]);}}
return newArr;};Zapatec.Array.clear=function(arr){arr.length=0;};Zapatec.Array.indexOf=function(arr,value){for(var item=0;item<arr.length;++item){if(arr[item]===value){return item;}}
return-1;};Zapatec.Array.without=function(arr){var newArr=[],without;for(var item=0;item<arr.length;++item){without=false;for(var value=1;value<arguments.length;++value){if(arr[item]===arguments[value]){without=true;break;}}
if(!without){newArr.push(arr[item]);}}
return newArr;};Zapatec.Array.remove=function(arr){var newArr=[],without,value,start=1;if(arguments[1]&&arguments[1].length&&typeof arguments[1]=="object"){args=arguments[1];start=0;}else{args=arguments;}
for(var item=0;item<arr.length;++item){without=false;for(value=start;value<args.length;++value){if(item===args[value]){without=true;break;}}
if(!without){newArr.push(arr[item]);}}
return newArr;};Zapatec.Hash=function(hash){if(!hash||typeof hash!="object"){hash={};}
hash.hashRemove=function(){var args=[].slice.call(arguments,0);args.unshift(this);var without=Zapatec.Hash.remove.apply(Zapatec.Hash,args);return Zapatec.Hash(without);};hash.hashEach=function(func){var result=null;for(var prop in this){if(prop=="hashRemove"||prop=="hashEach"||prop=="hashIsEmpty"||prop=="isZpHash"){continue;}
if(typeof Object.prototype[prop]!="undefined"){continue;}
result=func(prop,this[prop],this);if(result=="break"){break;}}
if(result=="break"){return false;}
return true;};hash.hashIsEmpty=function(){var empty=true;this.hashEach(function(){empty=false;return"break";});return empty;};hash.isZpHash=true;return hash;};Zapatec.Hash.remove=function(hash){var newHash={},without,value,start=1;if(arguments[1]&&arguments[1].length&&typeof arguments[1]=="object"){args=arguments[1];start=0;}else{args=arguments;}
for(var item in hash){without=false;for(value=start;value<args.length;++value){if(item===args[value]){without=true;break;}}
if(!without){newHash[item]=hash[item];}}
return newHash;};Zapatec.Hash.getByPath=function(hash,path){if(!path||typeof path!="string"){Zapatec.Log({description:"Not a path passed to Zapatec.Hash.getByPath function!",type:"warning"});return{result:false};}
var paths=path.split(".");if(!paths.length){Zapatec.Log({description:"Wrong path passed to Zapatec.Hash.getByPath function!",type:"warning"});return{result:false};}
var item=0;var value=hash;var name="";var scope=null;while(paths[item]){if(value===null||typeof value=="undefined"){Zapatec.Log({description:"Incorrect path passed to Zapatec.Hash.getByPath function!",type:"warning"});return{result:false};}
name=paths[item].replace(/(\(\)|\[[^\[\]]+\])+/,"");try{scope=value;value=value[name];}catch(e){Zapatec.Log({description:"Incorrect path passed to Zapatec.Hash.getByPath function!",type:"warning"});return{result:false};}
paths[item]=paths[item].replace(name,"");while(paths[item]!=""){name=paths[item].match(/(\(\)|\[[^\[\]]+\])/)[1];if(name&&/\(\)$/.test(name)){try{value=value.call(scope||value);scope=null;}catch(e){Zapatec.Log({description:"Incorrect path passed to Zapatec.Hash.getByPath function!",type:"warning"});return{result:false};}}else if(name&&/\[["']?[^\[\]"']+["']?\]$/.test(name)){try{value=value[name.match(/\[["']?([^\[\]"']+)["']?\]/)[1]];scope=null;}catch(e){Zapatec.Log({description:"Incorrect path passed to Zapatec.Hash.getByPath function!",type:"warning"});return{result:false};}}
paths[item]=paths[item].replace(name,"");}
++item;}
if(typeof value=="undefined"){Zapatec.Log({description:"Incorrect path passed to Zapatec.Hash.getByPath function!",type:"warning"});return{result:false};}
return{result:true,value:value};};Zapatec.Hash.setByPath=function(hash,path,val){if(!path||typeof path!="string"){Zapatec.Log({description:"Not a path passed to Zapatec.Hash.setByPath function!",type:"warning"});return false;}
var paths=path.split(".");if(!paths.length){Zapatec.Log({description:"Wrong path passed to Zapatec.Hash.setByPath function!",type:"warning"});return false;}
var lastItem=paths[paths.length-1];var obj=hash;var getPath=paths.slice(0,-1).join(".");var arrIndexReg=/\[[^\[\]]+\]$/;if(arrIndexReg.test(lastItem)){getPath+=(getPath==""?"":".")+lastItem.replace(arrIndexReg,"");lastItem=lastItem.match(/\[["']?([^\[\]"']+)["']?\]$/)[1];}
if(getPath!=""){var obj=Zapatec.Hash.getByPath(hash,getPath).value;}
try{obj[lastItem]=val;}catch(e){Zapatec.Log({description:"Incorrect path passed to Zapatec.Hash.setByPath function!",type:"warning"});return false;}
return true;};Zapatec.isHtmlElement=function(el){if(!el||el.nodeType!=1){return false;}
return true;};Zapatec.isSizableObj=function(obj){if(obj&&obj.hasInterface&&obj.hasInterface("Zapatec.Sizable")){return true;}
return false;};Zapatec.isMovableObj=function(obj){if(obj&&obj.hasInterface&&obj.hasInterface("Zapatec.Movable")){return true;}
return false;};Zapatec.isArray=function(arr){if(arr&&typeof arr=="object"&&arr.constructor==Array){return true;}
return false;};Zapatec.isDate=function(date){if(date&&typeof date=="object"&&date.constructor==Date){return true;}
return false;};Zapatec.SRProp=function(obj){this.obj=obj;this.savedProps=new Zapatec.Hash();Zapatec.Utils.createProperty(obj,"restorer",this);}
Zapatec.SRProp.prototype.getSavedProps=function(){return this.savedProps;};Zapatec.SRProp.prototype.getObject=function(){return this.obj;};Zapatec.SRProp.prototype.saveProp=function(propName){if(typeof propName!="string"){return false;}
var value=Zapatec.Hash.getByPath(this.getObject(),propName);if(value.result){if(typeof this.getProp(propName)!="undefined"){var prop=this.getSavedProps()[propName]=Zapatec.Array(this.getSavedProps()[propName]);prop.push(value.value);prop.combination=true;Zapatec.Log({description:"The property '"+propName+"' now contains more than one value!",type:"warning"});}else{this.getSavedProps()[propName]=value.value;}
return true;}else{return false;}}
Zapatec.SRProp.prototype.saveProps=function(){var result=[];for(var i=0;i<arguments.length;++i){if(this.saveProp(arguments[i])){result.push(arguments[i]);}}
return result;}
Zapatec.SRProp.prototype.restoreProp=function(propName){if(typeof propName!="string"||typeof this.getSavedProps()[propName]=="undefined"){return false;}
var prop=this.getSavedProps()[propName];var combination=false,nextSibling=null;if(Zapatec.isArray(prop)&&prop.combination){prop=prop[prop.length-1];combination=true;}
if(propName.match(/parentNode$/)!==null&&prop&&typeof prop=="object"&&prop.appendChild){nextSibling=this.getSavedProps()[propName.replace(/parentNode/,"nextSibling")]||null;if(nextSibling&&nextSibling.parentNode==prop){prop.insertBefore(this.getObject(),nextSibling);}else{prop.appendChild(this.getObject());}
this.savedProps=this.getSavedProps().hashRemove(propName.replace(/parentNode/,"nextSibling"));}else{if(!Zapatec.Hash.setByPath(this.getObject(),propName,prop)){return false;}}
if(!combination){this.savedProps=this.getSavedProps().hashRemove(propName);}else{prop=this.getSavedProps()[propName];this.getSavedProps()[propName]=Zapatec.Array.without(prop,prop.length-1);}
return true;}
Zapatec.SRProp.prototype.restoreProps=function(propName){var result=[];for(var i=0;i<arguments.length;++i){if(this.restoreProp(arguments[i])){result.push(arguments[i]);}}
return result;}
Zapatec.SRProp.prototype.restoreAll=function(){var self=this;this.getSavedProps().hashEach(function(i){self.restoreProp(i);});}
Zapatec.SRProp.prototype.getProp=function(propName){return this.getSavedProps()[propName];}
Zapatec.SRProp.prototype.isEmpty=function(){return this.getSavedProps().hashIsEmpty();};Zapatec.SRProp.prototype.destroy=function(){this.getObject().restorer=null;for(var iProp in this){this[iProp]=null;}
return null;};Zapatec.CommandEvent={};Zapatec.CommandEvent.fireEvent=function(strEvent){if(!this.events[strEvent]){return;}
var arrListeners=this.events[strEvent].listeners.slice();this._setReturnedValue(null);this._setEventPropagation(true);for(var iListener=0;iListener<arrListeners.length;iListener++){var arrArgs=[].slice.call(arguments,1);arrListeners[iListener].apply(this,arrArgs);var result=this._getReturnedValue();if(!this._getEventPropagation()){return result;}
if(result=="re-execute"){this.fireEvent(strEvent);break;}else if(result=="parent-re-execute"){return result;}}
return this._getReturnedValue();};Zapatec.CommandEvent.returnValue=function(val){this._setReturnedValue(val);};Zapatec.CommandEvent._setReturnedValue=function(val){this.returnedValue=val;};Zapatec.CommandEvent._getReturnedValue=function(){return this.returnedValue;};Zapatec.CommandEvent.stopPropagation=function(){this._setEventPropagation(false);};Zapatec.CommandEvent._setEventPropagation=function(on){this.eventPropagation=on;};Zapatec.CommandEvent._getEventPropagation=function(){return this.eventPropagation;};Zapatec.GlobalEvents=new Zapatec.EventDriven();Zapatec.implement(Zapatec.GlobalEvents,"Zapatec.CommandEvent");Zapatec.GlobalEvents.init();Zapatec.Utils.getWidth=function(el){if(!Zapatec.isHtmlElement(el)){return false;}
return el.offsetWidth};Zapatec.Utils.getHeight=function(el){if(!Zapatec.isHtmlElement(el)){return false;}
return el.offsetHeight};Zapatec.Utils.setWidth=function(el,width){width=Math.round(width);if(!Zapatec.isHtmlElement(el)||width<=0){return false;}
var oldWidth=el.style.width,newWidth;el.style.width=width+"px";if(Zapatec.Utils.getWidth(el)!=width){newWidth=width-(Zapatec.Utils.getWidth(el)-width);if(newWidth>0){el.style.width=newWidth+"px";if(Zapatec.Utils.getWidth(el)!=width){el.style.width=oldWidth;Zapatec.Log({description:"Can't set the width - "+width+"px!",type:"warning"});return false;}}else{el.style.width=oldWidth;Zapatec.Log({description:"Can't set the width - "+width+"px!",type:"warning"});return false;}}
return true;};Zapatec.Utils.setHeight=function(el,height){height=Math.round(height);if(!Zapatec.isHtmlElement(el)||height<=0){return false;}
var oldHeight=el.style.height,newHeight;el.style.height=height+"px";if(Zapatec.Utils.getHeight(el)!=height){newHeight=height-(Zapatec.Utils.getHeight(el)-height);if(newHeight>0){el.style.height=newHeight+"px";if(Zapatec.Utils.getHeight(el)!=height){el.style.height=oldHeight;Zapatec.Log({description:"Can't set the height - "+height+"px!",type:"warning"});return false;}}else{el.style.height=oldHeight;Zapatec.Log({description:"Can't set the height - "+height+"px!",type:"warning"});return false;}}
return true;};Zapatec.Utils.fixateWidth=function(el){return Zapatec.Utils.setWidth(el,Zapatec.Utils.getWidth(el));};Zapatec.Utils.fixateHeight=function(el){return Zapatec.Utils.setHeight(el,Zapatec.Utils.getHeight(el));};Zapatec.Utils.makeSafelySizable=function(el,restorer){if(el.sizable){return true;}
if(!Zapatec.isHtmlElement(el)){return false;}
if(!restorer){restorer=el.restorer;}
if(!restorer||!restorer.getObject||restorer.getObject()!=el){restorer=new Zapatec.SRProp(el);}
restorer.saveProps("style.width","style.height","style.overflow");Zapatec.Utils.fixateWidth(el);Zapatec.Utils.fixateHeight(el);var overflow=Zapatec.Utils.getStyleProperty(el,"overflow");if(overflow==""||overflow=="visible"){Zapatec.Log({description:"There is the chance that this element with overflow visible will not be sized correctly!",type:"warning"});}
el.sizable=true;return true;};Zapatec.Utils.restoreOfSizing=function(el){if(!el||!el.restorer||!el.sizable){return false;}
el.restorer.restoreProps("style.width","style.height","style.overflow");if(el.restorer.isEmpty()){el.restorer.destroy();}
el.sizable=false;return true;};Zapatec.Utils.makeSafelyMovable=function(el,within,restorer){if(!Zapatec.isHtmlElement(el)){return false;}
if(!within){within=document.body;}
if(el.within==within){return true;}
if(!restorer){restorer=el.restorer;}
if(!restorer||!restorer.getObject||restorer.getObject()!=el){restorer=new Zapatec.SRProp(el);}
el.within=within;if(within!=document.body&&within.style.position!="absolute"){restorer.saveProp("within.style.position");within.style.position="relative";}
if(within!=document.body){var pos1=Zapatec.Utils.getElementOffset(within);}else{var pos1={x:0,y:0};}
var pos2=Zapatec.Utils.getElementOffset(el);var x=pos2.x-pos1.x;var y=pos2.y-pos1.y;restorer.saveProps("style.left","style.top");el.style.left=x+"px";el.style.top=y+"px";if(el.style.position!="absolute"){restorer.saveProp("style.position");el.style.position="absolute";}
if(el.parentNode!=within){restorer.saveProps("parentNode","nextSibling");within.appendChild(el);}
restorer.saveProp("style.margin");el.style.margin="0px";return true;};Zapatec.Utils.moveTo=function(el,x,y){if(!Zapatec.isHtmlElement(el)){return false;}
var pos=null;if(Zapatec.FixateOnScreen.isRegistered(el)){pos=Zapatec.FixateOnScreen.correctCoordinates(x,y);if(Zapatec.is_ie&&!Zapatec.is_ie7){el.style.setExpression("left",pos.x);el.style.setExpression("top",pos.y);return true;}}else{pos={x:parseInt(x,10)+"px",y:parseInt(y,10)+"px"};}
if(x||x===0){el.style.left=pos.x;}
if(y||y===0){el.style.top=pos.y;}
return true;};Zapatec.Utils.getPos=function(el){if(!Zapatec.isHtmlElement(el)){return false;}
var pos=null;if(pos=Zapatec.FixateOnScreen.parseCoordinates(el)){return pos;}
return{x:el.offsetLeft,y:el.offsetTop}};Zapatec.Utils.moveFor=function(el,offsetX,offsetY){var oldPos=Zapatec.Utils.getPos(el);if(oldPos){return Zapatec.Utils.moveTo(el,oldPos.x+offsetX,oldPos.y+offsetY);}else{return false;}};Zapatec.Utils.restoreOfMove=function(el){if(!el.within)return false;el.restorer.restoreProps("style.position","parentNode","style.margin","nextSibling","within.style.position","style.left","style.top");if(el.restorer.isEmpty()){el.restorer.destroy();}
el.within=null;return true;};Zapatec.Utils.getElementsByAttribute=function(attribute,value,within,recursive,match){if(!attribute){return false;}
within=Zapatec.Widget.getElementById(within);within||(within=document.body);var element=within.firstChild;result=[];while(element){if(element[attribute]){if(typeof value=="undefined"||element[attribute]==value){result.push(element);}else if(match&&typeof element[attribute]=="string"&&element[attribute].indexOf(value)!=-1){result.push(element);}};if(recursive&&element.hasChildNodes()){result=result.concat(Zapatec.Utils.getElementsByAttribute(attribute,value,element,recursive,match));}
element=element.nextSibling};return Zapatec.Array(result);};Zapatec.Utils.applyToElements=function(constructor,elements,config,configOption){if(typeof constructor!="function"||!Zapatec.isArray(elements)){return false;}
elements=Zapatec.Array(elements);if(!configOption){configOption="container";}
if(!config||typeof config!="object"){config={};}
var result=Zapatec.Array();elements.each(function(index,element){config[configOption]=element;result.push(new constructor(config));});return result;};Zapatec.Utils.img2div=function(el){if(!Zapatec.isHtmlElement(el)){return null;}
if((/img/i).test(el.nodeName)){var div=document.createElement('div');var objImage=new Image();objImage.onload=function(){div.style.width=objImage.width+'px';div.style.height=objImage.height+'px';div.style.fontSize='0px';objImage.onload=null;};objImage.src=el.src;div.style.backgroundImage='url('+el.src+')';div.style.backgroundColor='transparent';var id=el.id;var className=el.className;el.parentNode.replaceChild(div,el);div.id=id;div.className=className;return div}else{return el}};Zapatec.Utils.getElementPath=function(element,parent){if(!Zapatec.isHtmlElement(element)||!Zapatec.isHtmlElement(parent)){return false;}
var res=[];var el=element;while(el&&el!=parent){var number=1;while(el.previousSibling){++number;el=el.previousSibling;}
res.unshift(number);el=el.parentNode;}
return res.join("-");};Zapatec.Utils.cover=Zapatec.Utils.createElement("div");Zapatec.Utils.cover.style.overflow="hidden";Zapatec.Utils.cover.style.backgroundImage="url("+Zapatec.zapatecPath+"zpempty.gif)";Zapatec.Utils.cover.style.display="none";Zapatec.Utils.cover.id="zpCoverControl";Zapatec.Utils.cover.show=function(zIndex,cursor,mouseMoveHandler,mouseUpHandler){if(!this.parentNode){document.body.appendChild(this);}
if(this.style.display!="none"){this.hide();}
this.style.display="block";Zapatec.Utils.makeSafelyMovable(this,null,document.body);var x=0;var y=0;y+=Zapatec.Utils.getPageScrollY();x+=Zapatec.Utils.getPageScrollX();Zapatec.Utils.moveTo(this,x,y);var dim=Zapatec.Utils.getWindowSize();this.style.width=dim.width+"px";this.style.height=dim.height+"px";Zapatec.FixateOnScreen.register(this);this.style.zIndex=zIndex;this.style.cursor=cursor;if(typeof mouseMoveHandler=="function"){Zapatec.Utils.addEvent(this,'mousemove',mouseMoveHandler);}
if(typeof mouseUpHandler=="function"){Zapatec.Utils.addEvent(this,'mouseup',mouseUpHandler);}
this.mouseMoveHandler=mouseMoveHandler;this.mouseUpHandler=mouseUpHandler;};Zapatec.Utils.cover.hide=function(){Zapatec.FixateOnScreen.unregister(this);if(typeof this.mouseMoveHandler=="function"){Zapatec.Utils.removeEvent(this,'mousemove',this.mouseMoveHandler);}
if(typeof this.mouseUpHandler=="function"){Zapatec.Utils.removeEvent(this,'mouseup',this.mouseUpHandler);}
this.mouseMoveHandler=null;this.mouseUpHandler=null;this.style.zIndex="";this.style.cursor="";this.style.display="none";};Zapatec.Movable={};Zapatec.Movable.setPosition=function(x,y){if(!this.isMovableSafely()){Zapatec.Log({description:"The object with ID '"+this.id+"' was not prepared for moving! Use obj.makeMovable() to do so!",type:"warning"});return false;}
var msgValue=null,moveConfig=this.getMoveConfig();if(x||x===0){msgValue=x;x=this._parseCoordinate(x,"x",moveConfig.moveLayer);if(!x&&x!==0){Zapatec.Log({description:"The X coordinate "+msgValue+" can not be set for object with ID '"+this.id+"'!",type:"warning"});return false;}}
if(y||y===0){msgValue=y;y=this._parseCoordinate(y,"y",moveConfig.moveLayer);if(!y&&y!==0){Zapatec.Log({description:"The Y coordinate "+msgValue+" can not be set for object with ID '"+this.id+"'!",type:"warning"});return false;}}
var elements=Zapatec.Array(this.getMovableElements());if(this.fireEvent("beforePositionChange",x,y)===false){return false;}
if(Zapatec.GlobalEvents.fireEvent("beforePositionChange",x,y,this)===false){return false;}
this._proceedElementsCoords(x,y,elements);if(this.isMoving()){this.fireEvent("onMove",x||this.getPosition().x,y||this.getPosition().y);Zapatec.GlobalEvents.fireEvent("onMove",x||this.getPosition().x,y||this.getPosition().y,this);}
this.fireEvent("onPositionChange",x||this.getPosition().x,y||this.getPosition().y);Zapatec.GlobalEvents.fireEvent("onPositionChange",x||this.getPosition().x,y||this.getPosition().y,this);return true;};Zapatec.Movable.setOrientedPosition=function(x,y){switch(this.getMoveConfig().orientation){case"vertical":{return this.setPosition(y,x);}
case"horizontal":{return this.setPosition(x,y);}}
return false;};Zapatec.Movable.setPagePosition=function(x,y){var moveConfig=this.getMoveConfig();if(moveConfig.moveLayer==document.body){return this.setPosition(x,y);}
var msgValue=null;if(x||x===0){msgValue=x;x=this._parseCoordinate(x,"x",document.body);if(!x&&x!==0){Zapatec.Log({description:"The X page coordinate "+msgValue+" can not be set for object with ID '"+this.id+"'!",type:"warning"});return false;}}
if(y||y===0){msgValue=y;y=this._parseCoordinate(y,"y",document.body);if(!y&&y!==0){Zapatec.Log({description:"The Y page coordinate "+msgValue+" can not be set for object with ID '"+this.id+"'!",type:"warning"});return false;}}
var pos=Zapatec.Utils.getElementOffset(moveConfig.moveLayer);return this.setPosition((x||x===0)?(x-pos.x):x,(y||y===0)?(y-pos.y):y);};Zapatec.Movable.setScreenPosition=function(x,y){var moveConfig=this.getMoveConfig();var msgValue=null;if(x||x===0){msgValue=x;x=this._parseCoordinate(x,"x",window);if(!x&&x!==0){Zapatec.Log({description:"The X screen coordinate "+msgValue+" can not be set for object with ID '"+this.id+"'!",type:"warning"});return false;}}
if(y||y===0){msgValue=y;y=this._parseCoordinate(y,"y",window);if(!y&&y!==0){Zapatec.Log({description:"The Y screen coordinate "+msgValue+" can not be set for object with ID '"+this.id+"'!",type:"warning"});return false;}}
if(moveConfig.moveLayer!=document.body){var pos=Zapatec.Utils.getElementOffset(moveConfig.moveLayer);}else{var pos={x:0,y:0};}
return this.setPosition((x||x===0)?(x-pos.x):x,(y||y===0)?(y-pos.y):y);};Zapatec.Movable.moveFor=function(offsetLeft,offsetTop){var pos=this.getPosition();return this.setPosition(offsetLeft==null?null:pos.x+offsetLeft,offsetTop==null?null:pos.y+offsetTop);};Zapatec.Movable.getPosition=function(){var el=this.getMovableMeasurement();if(Zapatec.isHtmlElement(el)||(el&&typeof el=="object"&&typeof el.x=="number"&&typeof el.y=="number")){return Zapatec.Utils.getPos(el)||el;}
Zapatec.Log({description:"Can't calculate position for object with ID '"+this.id+"'!",type:"warning"});return false;};Zapatec.Movable.getPagePosition=function(){var el=this.getMovableMeasurement();if(Zapatec.isHtmlElement(el)||(el&&typeof el=="object"&&typeof el.x=="number"&&typeof el.y=="number")){return Zapatec.Utils.getElementOffset(el)||el;}
Zapatec.Log({description:"Can't calculate screen position for object with ID '"+this.id+"'!",type:"warning"});return false;};Zapatec.Movable.getScreenPosition=function(){var pos=this.getPagePosition();pos.x-=Zapatec.Utils.getPageScrollX();pos.y-=Zapatec.Utils.getPageScrollY();return pos;};Zapatec.Movable.startMove=function(){if(!this.isMovableSafely()){Zapatec.Log({description:"The object with ID '"+this.id+"' was not prepared for moving! Use obj.makeMovable() to do so!",type:"warning"});return false;}
this.fireEvent("moveStart");Zapatec.GlobalEvents.fireEvent("moveStart",this);this._setMovingState(true);return true;};Zapatec.Movable.endMove=function(){if(!this.isMoving()){Zapatec.Log({description:"The moving for object with ID '"+this.id+"' was not started!",type:"warning"});return false;}
this.fireEvent("moveEnd");Zapatec.GlobalEvents.fireEvent("moveEnd",this);this._setMovingState(false);return true;};Zapatec.Movable.isMoving=function(){return this.movingState;};Zapatec.Movable._setMovingState=function(on){this.movingState=on;};Zapatec.Movable.isMovableSafely=function(){return this.safelyMovable;};Zapatec.Movable._setMovableSafely=function(on){this.safelyMovable=on;};Zapatec.Movable.makeMovable=function(){if(!this.requireInterface("Zapatec.CommandEvent")){return false;}
if(this.isMovableSafely()){return true;}
var elements=Zapatec.Array(this.getMovableElements()),self=this,moveConfig=this.getMoveConfig();success=elements.each(function(index,movable){if(Zapatec.isHtmlElement(movable)){if(moveConfig.preserveSizes&&!Zapatec.Utils.makeSafelySizable(movable)){return"break";}
if(!Zapatec.Utils.makeSafelyMovable(movable,moveConfig.moveLayer)){return"break";}
self.createProperty(movable,"moveObj",self);}else if(Zapatec.isMovableObj(movable)){if(!movable.makeMovable()){return"break";}}});if(!success){this.restoreOfMove();Zapatec.Log({description:"Can not make the object with ID '"+this.id+"' movable!"});return false;}
this._setMovableSafely(true);return true;};Zapatec.Movable.restoreOfMove=function(){if(!this.isMovableSafely()){return true;}
var elements=Zapatec.Array(this.getMovableElements());var self=this;elements.each(function(index,movable){if(Zapatec.isHtmlElement(movable)){Zapatec.Utils.restoreOfMove(movable);if(self.getMoveConfig().preserveSizes){Zapatec.Utils.restoreOfSizing(movable);}
movable.moveObj=null;}else if(Zapatec.isMovableObj(movable)){movable.restoreOfMove();}},true);this._setMovableSafely(false);return true;};Zapatec.Movable.getMovableMeasurement=function(){return this.getContainer();};Zapatec.Movable.getMoveConfig=function(){return this.getConfiguration();};Zapatec.Movable.setMoveConfig=function(config){this.reconfigure(config);};Zapatec.Movable.getMovableElements=function(){return this.getContainer();};Zapatec.Movable.getContainer=function(){return this.getMoveConfig().container;};Zapatec.Movable._parseCoordinate=function(coord,dimension,within){switch(true){case(typeof coord=="number"):{if(within==window){coord+=Zapatec.Utils["getPageScroll"+dimension.toUpperCase()]();}
break;}
case((/^\d+px$/).test(String(coord))):{coord=parseInt(coord,10);if(within==window){coord+=Zapatec.Utils["getPageScroll"+dimension.toUpperCase()]();}
break;}
case((/^(left|top|bottom|right|center)$/i).test(String(coord))):{coord=this._parseWordCoordinate(coord,dimension,within);break;}}
return this._canSetCoordinate(coord,dimension,within);};Zapatec.Movable._parseWordCoordinate=function(coord,dimension,within){if((/(left|right)/i).test(String(coord))&&dimension.toUpperCase()!="X"){return false;}
if((/(top|bottom)/i).test(String(coord))&&dimension.toUpperCase()!="Y"){return false;}
var dim=(dimension.toUpperCase()=="X")?"Left":"Top";var sizeDim=(dimension.toUpperCase()=="X")?"Width":"Height";var parsedCoord=0;var wSize=null;if(Zapatec.isHtmlElement(within)){parsedCoord=within["scroll"+dim];wSize=Zapatec.Utils["get"+sizeDim](within);}else if(within==window){parsedCoord=Zapatec.Utils["getPageScroll"+dimension.toUpperCase()]();wSize=Zapatec.Utils.getWindowSize()[sizeDim.toLowerCase()];}else if(within&&typeof within=="object"){parsedCoord+=within["scroll"+dim]||0;wSize=within[sizeDim.toLowerCase()];}else{return false;}
var measurement=this.getMovableMeasurement();var mSize=null;if(Zapatec.isHtmlElement(measurement)){mSize=Zapatec.Utils["get"+sizeDim](measurement);}else if(measurement&&typeof measurement=="object"){mSize=measurement[sizeDim.toLowerCase()];}
switch(coord){case"left":case"top":{break;}
case"LEFT":case"TOP":{parsedCoord-=mSize;break;}
case"right":case"bottom":{parsedCoord+=wSize-mSize;break;}
case"RIGHT":case"BOTTOM":{parsedCoord+=wSize;break;}
case"center":{parsedCoord+=Math.round((wSize-mSize)/2);break;}
case"CENTER":{parsedCoord+=Math.round(wSize/2);break;}
default:{parsedCoord=null;break;}}
if(!parsedCoord&&parsedCoord!==0){return false;}else{return parsedCoord;}};Zapatec.Movable._canSetCoordinate=function(coord,dimension,within){if(typeof coord!="number"){return false;}
var moveConfig=this.getMoveConfig();if(within!=moveConfig.moveLayer){return coord;}
var limitObj=moveConfig.limit;var dim=dimension.toUpperCase();var direction=moveConfig.direction.toLowerCase();var correction=this._getMovableShape();if(dim=="X"&&direction=="vertical"){return this._handleCoordOverflow(this.getPosition().x);}else if(dim=="Y"&&direction=="horizontal"){return this._handleCoordOverflow(this.getPosition().y);}
if((limitObj["min"+dim]||limitObj["min"+dim]===0)&&coord<limitObj["min"+dim]+correction["min"+dim]){return this._handleCoordOverflow(limitObj["min"+dim]+correction["min"+dim]);}
if((limitObj["max"+dim]||limitObj["max"+dim]===0)&&coord>limitObj["max"+dim]+correction["max"+dim]){return this._handleCoordOverflow(limitObj["max"+dim]+correction["max"+dim]);}
return coord;};Zapatec.Movable._handleCoordOverflow=function(limit,dimension){return false;};Zapatec.Movable._getMovableShape=function(){var measurement=this.getMovableMeasurement();var obj={minX:0,maxX:0,minY:0,maxY:0};switch(this.getMoveConfig().followShape){case(true):{if(!Zapatec.isHtmlElement(measurement)){return obj;}
obj.maxX=-Zapatec.Utils.getWidth(measurement);obj.maxY=-Zapatec.Utils.getHeight(measurement);return obj}
default:{return obj;}}};Zapatec.Movable.getMovingPoint=function(){return this.getScreenPosition();};Zapatec.Movable._proceedElementsCoords=function(x,y,elements){elements=Zapatec.Array(elements);var measurement=this.getMovableMeasurement();var pos=null;if(Zapatec.isHtmlElement(measurement)){pos=Zapatec.Utils.getPos(measurement);}else if(measurement&&typeof measurement=="object"){pos={x:(typeof measurement.x=="number")?measurement.x:null,y:(typeof measurement.y=="number")?measurement.y:null};if(!measurement.x||!measurement.y){pos=null;}}
elements.each(function(index,movable){var mX=x,mY=y;if(pos){var mPos=null;if(Zapatec.isHtmlElement(movable)){mPos=Zapatec.Utils.getPos(movable);}else if(Zapatec.isMovableObj(movable)){mPos=movable.getPosition();}else{return;}
if(x||x===0){mX=mPos.x+(x-pos.x);}
if(y||y===0){mY=mPos.y+(y-pos.y);}}
if(Zapatec.isHtmlElement(movable)){Zapatec.Utils.moveTo(movable,mX,mY);}else if(Zapatec.isMovableObj(movable)){movable.setPosition(mX,mY);}});};Zapatec.Movable.sortElementsByPath=function(elements){elements=Zapatec.Array(elements);elements.each(function(index,element){var path=Zapatec.Utils.getElementPath(element,document.body);if(!path){return;}
path=Zapatec.Array(path.split("-"));for(var i=index;i<elements.length;++i){var compPath=Zapatec.Utils.getElementPath(elements[i],document.body);if(!compPath){continue;}
compPath=Zapatec.Array(compPath.split("-"));path.each(function(k,pathPiece,whole){if(parseInt(pathPiece,10)>(parseInt(compPath[k],10)||0)){return"break";}else if(parseInt(pathPiece,10)<parseInt(compPath[k],10)){var el=elements[index]
elements[index]=elements[i];elements[i]=el;path=compPath;return"break";}});}});return true;};Zapatec.Utils.Movable=function(config){Zapatec.Utils.Movable.SUPERconstructor.call(this,config);};Zapatec.Utils.Movable.id="Zapatec.Utils.Movable";Zapatec.inherit(Zapatec.Utils.Movable,Zapatec.Widget);Zapatec.implement(Zapatec.Utils.Movable,"Zapatec.CommandEvent");Zapatec.implement(Zapatec.Utils.Movable,"Zapatec.Movable");Zapatec.Utils.Movable.prototype.init=function(config){Zapatec.Utils.Movable.SUPERclass.init.call(this,config);var self=this;var elements=null;if(this.getConfiguration().makeMovable){this.makeMovable();}else{elements=Zapatec.Array(this.getMovableElements());elements.each(function(index,movable){if(Zapatec.isHtmlElement(movable)){self.createProperty(movable,"moveObj",self);}});}};Zapatec.Utils.Movable.prototype.configure=function(config){this.defineConfigOption("synchronize",[]);this.defineConfigOption("container",null);this.defineConfigOption("limit",{minX:null,maxX:null,minY:null,maxY:null});this.defineConfigOption("direction","both");this.defineConfigOption("moveLayer",document.body);this.defineConfigOption("followShape","LT");this.defineConfigOption("preserveSizes",true);this.defineConfigOption("makeMovable",true);this.defineConfigOption("theme",null);Zapatec.Utils.Movable.SUPERclass.configure.call(this,config);config=this.getConfiguration();if(!config.limit||typeof config.limit!="object"){config.limit={minX:null,maxX:null,minY:null,maxY:null};}
var self=this;config.synchronize=Zapatec.Array(config.synchronize);config.synchronize.each(function(index,element){if(element===null){return;}
element=Zapatec.Widget.getElementById(element);element=Zapatec.Utils.img2div(element);if(!element){Zapatec.Log({description:"Wrong element in synchronize array for the movable object with ID '"+self.id+"'!"});}else{config.synchronize[index]=element;}});config.container=Zapatec.Widget.getElementById(config.container);config.container=Zapatec.Utils.img2div(config.container);if(!Zapatec.isHtmlElement(config.container)){Zapatec.Log({description:"Wrong element passed as container for the movable object with ID '"+self.id+"'!"});}
this.movableElements=Zapatec.Array(config.synchronize.concat(config.container));if(this.movableElements.length>1){this.sortElementsByPath(this.movableElements);}
if(!Zapatec.isHtmlElement(config.moveLayer=Zapatec.Widget.getElementById(config.moveLayer))){config.moveLayer=document.body;}};Zapatec.Utils.Movable.prototype.reconfigure=function(config){Zapatec.Utils.Movable.SUPERclass.reconfigure.call(this,config);};Zapatec.Utils.Movable.prototype.getMovableElements=function(){return this.movableElements;};Zapatec.Draggable={};Zapatec.Draggable.makeDraggable=function(){if(!this.requireInterface("Zapatec.Movable")){return false;}
if(!this.requireInterface("Zapatec.CommandEvent")){return false;}
var draggables=Zapatec.Array(this.getDraggableElements());var hooks=Zapatec.Array(this._getDraggableHooks());var self=this,result=false;var config=this.getDragConfig();if(config.method!="cut"){this.setDragConfig({eventCapture:false});}
var listenersObj=this._getRestorer().getSavedProps()["dragListeners"]={mousedown:function(ev){return self.dragStart(ev);},mousemove:function(ev){if(self.isDragging()){return self.dragMove(ev);}},mouseup:function(ev){if(self.isDragging()){return self.dragEnd(ev);}}};hooks.each(function(index,hook){if(!Zapatec.isHtmlElement(hook)){return;}
result=true;if(Zapatec.is_gecko){hook.style.setProperty("-moz-user-select","none","");}
Zapatec.Utils.addEvent(hook,'mousedown',listenersObj.mousedown);if(config.eventCapture){Zapatec.Utils.addEvent(hook,'mousemove',listenersObj.mousemove);Zapatec.Utils.addEvent(hook,'mouseup',listenersObj.mouseup);}});draggables.each(function(index,draggable){if(!Zapatec.isHtmlElement(draggable)){return;}
self.createProperty(draggable,"dragObj",self);});return result;};Zapatec.Draggable.dragStart=function(ev){if(!this.canDrag()){return true;}
ev=ev||window.event;var iButton=ev.button||ev.which;if(iButton>1){return false;}
var self=this;var config=this.getDragConfig();if(this.fireEvent("beforeDragInit",ev)===false){return true;}
if(Zapatec.GlobalEvents.fireEvent("beforeDragInit",ev,this)===false){return true;}
this._setDragging(true);if(config.eventCapture&&(config.method=="dummy"||config.method=="copy")){var draggables=Zapatec.Array(this.getDraggableElements());draggables.each(function(index,draggable){draggable.restorer.saveProp("style.zIndex");draggable.style.zIndex=2000001;});}
this._proceedDraggableElements("dragStart");var oPos=Zapatec.Utils.getMousePos(ev);var mouseX=oPos.pageX;var mouseY=oPos.pageY;this.makeMovable();this.startMove();var elements=Zapatec.Array(this.getMovableElements());elements.each(function(index,movable){if(Zapatec.isHtmlElement(movable)){movable.restorer.saveProp("style.zIndex");movable.style.zIndex=1000000+(parseInt(movable.style.zIndex,10)||0);self._proceedDragStyles(movable,"dragStart");if(config.eventCapture){movable.restorer.saveProp("style.cursor");movable.style.cursor="move";}}else if(Zapatec.isMovableObj(movable)){var elems=Zapatec.Array(movable.getMovableElements());elems.each(arguments.calee);}});Zapatec.Utils.cover.show(config.eventCapture?999999:2000000,"move",function(ev){return self.dragMove(ev);},function(ev){return self.dragEnd(ev);});this._setMovingPoint(mouseX,mouseY);this.fireEvent("onDragInit",ev);Zapatec.GlobalEvents.fireEvent("onDragInit",ev,this);if(config.stopEvent){return Zapatec.Utils.stopEvent(ev);}else{return true;}};Zapatec.Draggable.dragMove=function(ev){if(!this.isDragging()){return true;}
ev=ev||window.event;if(this.fireEvent("beforeDragMove",ev)===false){return true;}
if(Zapatec.GlobalEvents.fireEvent("beforeDragMove",ev,this)===false){return true;}
if(Zapatec.Utils.cover.style.zIndex!=2000000){var config=this.getDragConfig();if(config.eventCapture&&(config.method=="dummy"||config.method=="copy")){var draggables=Zapatec.Array(this.getDraggableElements());draggables.each(function(index,draggable){draggable.restorer.restoreProp("style.zIndex");});}
Zapatec.Utils.cover.style.zIndex=2000000;}
var oPos=Zapatec.Utils.getMousePos(ev);var mouseX=oPos.pageX;var mouseY=oPos.pageY;var movePoint=this.getMovingPoint();this.moveFor(mouseX-movePoint.x,mouseY-movePoint.y);this._setMovingPoint(mouseX,mouseY);this.fireEvent("onDragMove",ev);Zapatec.GlobalEvents.fireEvent("onDragMove",ev,this);return Zapatec.Utils.stopEvent(ev);};Zapatec.Draggable.dragEnd=function(ev){if(!this.isDragging()){return true;}
ev=ev||window.event;var self=this;if(this.fireEvent("beforeDragEnd",ev)===false){return true;}
if(Zapatec.GlobalEvents.fireEvent("beforeDragEnd",ev,this)===false){return true;}
var config=this.getDragConfig();if(config.eventCapture&&(config.method=="dummy"||config.method=="copy")){var draggables=Zapatec.Array(this.getDraggableElements());draggables.each(function(index,draggable){draggable.restorer.restoreProp("style.zIndex",true);});}
var elements=Zapatec.Array(this.getMovableElements());elements.each(function(index,movable){if(Zapatec.isHtmlElement(movable)){movable.restorer.restoreProp("style.zIndex");movable.restorer.restoreProp("style.cursor");self._proceedDragStyles(movable,"dragEnd");}else if(Zapatec.isMovableObj(movable)){var elems=Zapatec.Array(movable.getMovableElements());elems.each(arguments.calee);}});this._proceedDraggableElements("dragEnd");Zapatec.Utils.cover.hide();this._setMovingPoint(null,null);this._setDragging(false);this.endMove();this.fireEvent("onDragEnd",ev);Zapatec.GlobalEvents.fireEvent("onDragEnd",ev,this);return Zapatec.Utils.stopEvent(ev);};Zapatec.Draggable.restorePos=function(){this.restoreOfMove();};Zapatec.Draggable.restoreOfDrag=function(){var listenersObj=this._getRestorer().getSavedProps()["dragListeners"];if(!listenersObj){return false;}
this.restoreOfMove();var hooks=Zapatec.Array(this._getDraggableHooks());var draggables=Zapatec.Array(this.getDraggableElements());var self=this;var config=this.getDragConfig();hooks.each(function(index,hook){if(!Zapatec.isHtmlElement(hook)){return;}
if(Zapatec.is_gecko){hook.style.setProperty("-moz-user-select","","");}
Zapatec.Utils.removeEvent(hook,'mousedown',listenersObj.mousedown);if(config.eventCapture){Zapatec.Utils.removeEvent(hook,'mousemove',listenersObj.mousemove);Zapatec.Utils.removeEvent(hook,'mouseup',listenersObj.mouseup);}});draggables.each(function(index,draggable){if(!Zapatec.isHtmlElement(draggable)){return;}
draggable.dragObj=null;});return true;};Zapatec.Draggable.getDraggableElements=function(){return this.getContainer();};Zapatec.Draggable._getDraggableHooks=function(){return this.getContainer();};Zapatec.Draggable.getContainer=function(){return this.getDragConfig().container;};Zapatec.Draggable.isDragging=function(){return this.dragging;};Zapatec.Draggable.canDrag=function(){return this.canDrag;};Zapatec.Draggable._setCanDrag=function(on){this.canDrag=on;};Zapatec.Draggable.getDragConfig=function(){return this.getConfiguration();};Zapatec.Draggable.setDragConfig=function(config){this.reconfigure(config);};Zapatec.Draggable._setDragging=function(on){this.dragging=on;};Zapatec.Draggable._handleCoordOverflow=function(limit,dimension){if(!this.isDragging()){Zapatec.Movable._handleCoordOverflow.call(this,limit,dimension);}
return limit;};Zapatec.Draggable._getRestorer=function(){if(!this.restorer){this.restorer=new Zapatec.SRProp(this);}
return this.restorer;};Zapatec.Draggable._proceedDraggableElements=function(dragState){var config=this.getDragConfig(),restorer=this._getRestorer(),copies=null,measurement=null,self=this,listenersObj=restorer.getProp("dragListeners");function toggleEvents(action,hooks,listenersObj){hooks.each(function(index,hook){Zapatec.Utils[action+"Event"](hook,"mousedown",listenersObj.mousedown);if(config.eventCapture){Zapatec.Utils[action+"Event"](hook,'mousemove',listenersObj.mousemove);Zapatec.Utils[action+"Event"](hook,'mouseup',listenersObj.mouseup);}});}
switch(config.method){case"copy":case"dummy":{if(dragState=="dragStart"){var elements=Zapatec.Array(this.getDraggableElements());var hooks=Zapatec.Array(this._getDraggableHooks());copies=Zapatec.Array();toggleEvents("remove",hooks,listenersObj);elements.each(function(index,movable){if(Zapatec.isHtmlElement(movable)){var newNode=movable.cloneNode(config.copyChilds);newNode.dragObj=self;if(config.eventCapture){Zapatec.Utils.addEvent(newNode,'mousemove',listenersObj.mousemove);Zapatec.Utils.addEvent(newNode,'mouseup',listenersObj.mouseup);}
movable.parentNode.insertBefore(newNode,movable);newNode.style.visibility="visible";copies.push(newNode);if(movable==self.getMovableMeasurement()){measurement=newNode;}}else if(Zapatec.isMovableObj(movable)){var elems=Zapatec.Array(movable.getMovableElements());elems.each(arguments.calee);}});toggleEvents("add",hooks,listenersObj);if(!measurement){measurement=this.getMovableMeasurement();}
restorer.saveProp("getMovableElements");restorer.saveProp("isMovableSafely()");this._setMovableSafely(false);this.getMovableElements=function(resetArray){var arr=copies;copies=resetArray?null:copies;return arr;};restorer.saveProp("getMovableMeasurement");this.getMovableMeasurement=function(){return measurement;};}else if(dragState=="dragEnd"){var elements=Zapatec.Array(this.getMovableElements(true));elements.each(function(index,movable){if(config.method=="dummy"){movable.parentNode.removeChild(movable);}
movable.dragObj=null;if(config.eventCapture){Zapatec.Utils.removeEvent(movable,'mousemove',listenersObj.mousemove);Zapatec.Utils.removeEvent(movable,'mouseup',listenersObj.mouseup);}});this.restoreOfMove();restorer.restoreProp("getMovableElements");this._setMovableSafely(restorer.getProp("isMovableSafely()"));restorer.restoreProp("isMovableSafely()");restorer.restoreProp("getMovableMeasurement");}
break;}
default:{break;}}};Zapatec.Draggable._proceedDragStyles=function(movable,dragState){var config=this.getDragConfig();if(config.overwriteCSS){if(dragState=="dragStart"){movable.restorer.saveProp("className");movable.className=config.overwriteCSS;}else if(dragState=="dragEnd"){movable.restorer.restoreProp("className");}}
if(config.dragCSS){if(dragState=="dragStart"){Zapatec.Utils.addClass(movable,config.dragCSS);}else if(dragState=="dragEnd"){Zapatec.Utils.removeClass(movable,config.dragCSS);}}};Zapatec.Draggable._setMovingPoint=function(x,y){var movingPoint=this._getMovingPointObject();if(x===null||y===null){movingPoint.x=null;movingPoint.y=null;movingPoint.offsetX=null;movingPoint.offsetY=null;return;}
if(movingPoint.x===null||movingPoint.y===null){var pos=this.getPagePosition();movingPoint.x=x;movingPoint.y=y;movingPoint.offsetX=x-pos.x;movingPoint.offsetY=y-pos.y;}else{var pos=this.getPagePosition();movingPoint.x=pos.x+movingPoint.offsetX;movingPoint.y=pos.y+movingPoint.offsetY;}
return;};Zapatec.Draggable.getMovingPoint=function(){var movingPoint=this._getMovingPointObject();return{x:movingPoint.x,y:movingPoint.y};};Zapatec.Draggable._getMovingPointObject=function(){if(!this.movingPoint||typeof this.movingPoint!="object"){this.movingPoint={x:null,y:null,offsetX:null,offsetY:null};}
return this.movingPoint;};Zapatec.Utils.Draggable=function(config){if(arguments.length>1){var args=arguments[1];args.container=config;config=args;}
if(typeof config.left!="undefined"||typeof config.right!="undefined"||typeof config.top!="undefined"||typeof config.bottom!="undefined"){config.limit={minX:config.left,maxX:config.right,minY:config.top,maxY:config.bottom};}
if(config.dragLayer){config.moveLayer=config.dragLayer;}
if(!config.eventListeners){config.eventListeners={};}
if(config.beforeDragInit){config.eventListeners.beforeDragInit=config.beforeDragInit;}
if(config.beforeDragMove){config.eventListeners.beforeDragMove=config.beforeDragMove;}
if(config.beforeDragEnd){config.eventListeners.beforeDragEnd=config.beforeDragEnd;}
if(config.onDragInit){config.eventListeners.onDragInit=config.onDragInit;}
if(config.onDragMove){config.eventListeners.onDragMove=config.onDragMove;}
if(config.onDragEnd){config.eventListeners.onDragEnd=config.onDragEnd;}
if(config.stopEv){config.stopEvent=config.stopEv;}
config=Zapatec.Hash.remove(config,"left","top","right","bottom","dragLayer","beforeDragInit","beforeDragMove","beforeDragEnd","onDragInit","onDragMove","onDragEnd","stopEv");Zapatec.Utils.Draggable.SUPERconstructor.call(this,config);};Zapatec.Utils.Draggable.id="Zapatec.Utils.Draggable";Zapatec.inherit(Zapatec.Utils.Draggable,Zapatec.Utils.Movable);Zapatec.implement(Zapatec.Utils.Draggable,"Zapatec.Draggable");Zapatec.Utils.Draggable.prototype.init=function(config){Zapatec.Utils.Draggable.SUPERclass.init.call(this,config);this.makeDraggable();};Zapatec.Utils.Draggable.prototype.configure=function(config){this.defineConfigOption("method","cut");this.defineConfigOption("stopEvent",true);this.defineConfigOption("eventCapture",false);this.defineConfigOption("handler",null);this.defineConfigOption("dragCSS",null);this.defineConfigOption("overwriteCSS",null);this.defineConfigOption("copyChilds",true);this.defineConfigOption("makeMovable",false);Zapatec.Utils.Draggable.SUPERclass.configure.call(this,config);config=this.getConfiguration();if(Zapatec.is_opera){config.eventCapture=true;}
config.handler=Zapatec.Widget.getElementById(config.handler);config.handler=Zapatec.Utils.img2div(config.handler);if(!Zapatec.isHtmlElement(config.handler)){config.handler=config.container;}};Zapatec.Utils.Draggable.prototype.reconfigure=function(config){Zapatec.Utils.Draggable.SUPERclass.reconfigure.call(this,config);};Zapatec.Utils.Draggable.prototype.getDraggableElements=function(){return this.movableElements;};Zapatec.Utils.Draggable.prototype._getDraggableHooks=function(){return this.getConfiguration().handler;};Zapatec.Utils.initDragObjects=function(className,el,recursive,config){if(!className)return;var elements=Zapatec.Utils.getElementsByAttribute('className',className,el,recursive,true);return Zapatec.Utils.applyToElements(Zapatec.Utils.Draggable,elements,config);}
Zapatec.Utils.DropArea=function(config){if(arguments.length>1){config={container:config};config.dropName=arguments[1];config.eventListeners={onDrop:arguments[2],onDragInit:arguments[3],onDragOver:arguments[4],onDragOut:arguments[5],onDragEnd:arguments[6]}}
Zapatec.Utils.DropArea.SUPERconstructor.call(this,config);};Zapatec.Utils.DropArea.id="Zapatec.DropArea";Zapatec.inherit(Zapatec.Utils.DropArea,Zapatec.Widget);Zapatec.implement(Zapatec.Utils.DropArea,"Zapatec.CommandEvent");Zapatec.Utils.DropArea.prototype.init=function(config){Zapatec.Utils.DropArea.SUPERclass.init.call(this,config);this.dropArea=this.getConfiguration().container;this.elementOver=false;this.addListeners();};Zapatec.Utils.DropArea.prototype.configure=function(config){this.defineConfigOption("container",null);this.defineConfigOption("dropName",null);this.defineConfigOption("theme",null);Zapatec.Utils.DropArea.SUPERclass.configure.call(this,config);config=this.getConfiguration();config.container=Zapatec.Widget.getElementById(config.container);};Zapatec.Utils.DropArea.prototype.reconfigure=function(config){Zapatec.Utils.DropArea.SUPERclass.reconfigure.call(this,config);};Zapatec.Utils.DropArea.prototype.dragInit=function(ev,movable){this.mousePos=movingPoint=movable.getMovingPoint();var dropArea=Zapatec.Utils.getElementOffset(this.dropArea);var elems=Zapatec.Array(movable.getMovableElements());if(elems.length==1){elems=elems[0];}
if((movingPoint.x>dropArea.x)&&(movingPoint.x<dropArea.x+dropArea.width)&&(movingPoint.y>dropArea.y)&&(movingPoint.y<dropArea.y+dropArea.height)){this.elementOver=elems;}
if(this.fireEvent("onDragInit",elems,this)=="parent-re-execute"){return"re-execute";}
if(this.elementOver){if(this.fireEvent("onDragOver",elems,this)=="parent-re-execute"){return"re-execute";}}};Zapatec.Utils.DropArea.prototype.dragMove=function(ev,movable){this.mousePos=movingPoint=movable.getMovingPoint();var dropArea=Zapatec.Utils.getElementOffset(this.dropArea);var elems=Zapatec.Array(movable.getMovableElements());if(elems.length==1){elems=elems[0];}
if((movingPoint.x>dropArea.x)&&(movingPoint.x<dropArea.x+dropArea.width)&&(movingPoint.y>dropArea.y)&&(movingPoint.y<dropArea.y+dropArea.height)){if(!this.elementOver){if(this.fireEvent("onDragOver",elems,this)=="parent-re-execute"){return"re-execute";}}
this.elementOver=elems;}else{if(this.elementOver){if(this.fireEvent("onDragOut",elems,this)=="parent-re-execute"){return"re-execute";}}
this.elementOver=null;}};Zapatec.Utils.DropArea.prototype.dragEnd=function(ev,movable){var elems=Zapatec.Array(movable.getMovableElements());if(elems.length==1){elems=elems[0];}
if(this.elementOver){if(this.fireEvent("onDrop",elems,this)=="parent-re-execute"){return"re-execute";}}
if(this.fireEvent("onDragEnd",elems,this)=="parent-re-execute"){return"re-execute";}
this.movingPoint=null;this.elementOver=null;};Zapatec.Utils.DropArea.prototype.removeListeners=function(){Zapatec.GlobalEvents.removeEventListener("onDragInit",this.tmp.onDragInit);Zapatec.GlobalEvents.removeEventListener("onDragMove",this.tmp.onDragMove);Zapatec.GlobalEvents.removeEventListener("onDragEnd",this.tmp.onDragEnd);}
Zapatec.Utils.DropArea.prototype.addListeners=function(){var self=this;if(!this.tmp){this.tmp={};}
this.tmp.onDragInit=function(ev,movable){this.returnValue(self.dragInit(ev,movable));};this.tmp.onDragMove=function(ev,movable){this.returnValue(self.dragMove(ev,movable));};this.tmp.onDragEnd=function(ev,movable){this.returnValue(self.dragEnd(ev,movable));};Zapatec.GlobalEvents.addEventListener("onDragInit",this.tmp.onDragInit);Zapatec.GlobalEvents.addEventListener("onDragMove",this.tmp.onDragMove);Zapatec.GlobalEvents.addEventListener("onDragEnd",this.tmp.onDragEnd);}
Zapatec.Utils.DropArea.prototype.destroy=function(){this.dropArea=null;this.removeListeners();};
Zapatec.Utils.addEvent(window, 'load', Zapatec.Utils.checkActivation);
