if(typeof Zapatec == 'undefined'){Zapatec = {};} Zapatec.Utils = {}; Zapatec.Utils.addEvent = function(el, evname, func){if(el.attachEvent){el.attachEvent("on" + evname, func);}else if(el.addEventListener){el.addEventListener(evname, func, false);}else{el["on" + evname] = func;}}; Zapatec.Utils.removeEvent = function(el, evname, func){if(el.detachEvent){el.detachEvent("on" + evname, func);}else if(el.removeEventListener){el.removeEventListener(evname, func, false);}else{el["on" + evname] = null;}}; var ErrorTimer=0; Zapatec.defaultSlideTime=500; Zapatec.defaultSlideSteps=30; Zapatec.Utils.initDragObjects=function(className,el,recursive,attribObject){ if(!className) return; el=Zapatec.Utils.idOrObject(el); var changeArray=Zapatec.Utils.getElementsByAttribute('className',className,el,recursive); for(var a in changeArray) { if(typeof(changeArray[a])=='function'){continue;} a=new Zapatec.Utils.Draggable(changeArray[a],attribObject) }; } Zapatec.Utils.img2div=function(el){ if(el.nodeName.match(/img/i)){ var div=document.createElement('div'); var objImage = new Image(); objImage.onload = function() { div.style.width = this.width + 'px'; div.style.height = this.height + 'px'; div.style.fontSize = '0px'; this.onload = null; }; objImage.src = el.src; div.style.backgroundImage = 'url(' + el.src + ')'; div.style.backgroundColor = 'transparent'; var id=el.id; el.parentNode.replaceChild(div,el); div.id=id; return div }else{ return el } }; Zapatec.Utils.eventPosition=function(ev){ ev||(ev=window.event); var ret={}; ret.X = ev.pageX || ev.clientX + document.documentElement.scrollLeft || 0; ret.Y = ev.pageY || ev.clientY + document.documentElement.scrollTop || 0; //window.status=ret.X+" - "+ret.Y+" - ev.pageY='"+ev.clientY+"'"; return ret; }; Zapatec.Utils.idOrObject=function(el,errorMessage,errorAction){ if(typeof(el)=='string'){el=document.getElementById(el)||el}; if(typeof(el)!='object'){ if(errorAction)errorAction(); return false }else{ return el } }; Zapatec.Utils.getElementsByAttribute=function(attr, val, el, recursive){ if(!attr) return false; try{el=Zapatec.Utils.idOrObject(el);}catch(e){} el||(el=window.document.body); var a=el.firstChild;retArray=[] while(a){ if(a[attr]){ if(val){ if(a[attr]==val) retArray=retArray.concat([a]) }else{ retArray=retArray.concat([a]) } }; if(recursive&&a.hasChildNodes()){ try{ //retArray=retArray.concat(Zapatec.Utils.getElementsByAttribute(attr, val, a, recursive)) } catch(e){} }; a=a.nextSibling }; return retArray }; Zapatec.Utils.Draggable=function(el,left,top,right,bottom,direction,followShape,handler,dragCSS,dragLayer,method,dropName){ el=Zapatec.Utils.idOrObject(el); if(!el) return; el=Zapatec.Utils.img2div(el); if(typeof(left)=='object'){ el.Atr=left }else{ var Atr={}; if(left)Atr.left=left; if(top)Atr.top=top; if(right)Atr.right=right; if(bottom)Atr.bottom=bottom; if(direction)Atr[direction]=true; if(followShape)Atr.followShape=true; if(handler)Atr.handler=handler; if(dragCSS)Atr.dragCSS=dragCSS; if(dragLayer)Atr.dragLayer=dragLayer; if(method)Atr.method=method; if(dropName)Atr.dropName=dropName; el.Atr=Atr }; if(el.Atr.followShape){ setTimeout(function() { if (el.Atr.right) { el.Atr.right -= el.offsetWidth; } if (el.Atr.bottom) { el.Atr.bottom -= el.offsetHeight; } }, 0); }; if(el.Atr.handler){ el.Atr.handler=Zapatec.Utils.idOrObject(el.Atr.handler,'cannot find the handlerobject:'+el.Atr.handler) } if(el.Atr.handler){ el.Atr.handler=Zapatec.Utils.img2div(el.Atr.handler) }; el.Atr.dragLayer=Zapatec.Utils.idOrObject(el.Atr.dragLayer,'cannot find the dragLayer:'+el.Atr.dragLayer)||(el.Atr.horizontal||el.Atr.vertical)?0:window.document.body; Zapatec.Utils.addEvent(el.Atr.handler||el, "mousedown", function(ev){ if(!el.cState){ el.cState='mouseDown'; el.mouseStart=Zapatec.Utils.eventPosition(ev); Zapatec.Utils.addEvent(window.document, "mousemove", el.mouseMoveEv); Zapatec.Utils.addEvent(window.document, "mouseup", el.mouseUpEv);} }); el.dragStartEv=function(ev){ document.getElementsByTagName("BODY")[0].onselectstart=new Function("return false"); el.Atr.Start={}; el.Atr.Start.X=el.offsetLeft; el.Atr.Start.Y=el.offsetTop; if(el.Atr.dragLayer){ el.Atr.Start=Zapatec.Utils.getRelativePos(el,el.Atr.dragLayer); }; el.Atr.beforeDrag=Zapatec.Utils.changeAttributes(el,{ className:el.Atr.dragCSS||'', /*parentNode:el.Atr.dragLayer,*/ nextSibling:null, offsetLeft:el.Atr.Start.X,offsetTop:el.Atr.Start.Y,style:{ display:'block',position:'absolute' } }); var initObjects=Zapatec.Utils.getElementsByAttribute('onDragInit',0, el.Atr.dragLayer, true); if (initObjects.length){ for(var a in initObjects){if(typeof(initObjects[a])=='function'){continue;} if(initObjects[a]!=el)initObjects[a].onDragInit(ev); } } } el.mouseMoveEv=function(ev){ if(el.cState=='mouseDown'){ el.cState='dragStart'; el.dragStartEv(ev) el.cState='drag'; }; var mouse=Zapatec.Utils.eventPosition(ev); if(!el.Atr.vertical){ var X=el.Atr.Start.X+mouse.X-el.mouseStart.X; if(Xel.Atr.right)X=el.Atr.right}; X=X+((typeof(ActiveXObject)!='undefined')?document.documentElement.scrollLeft:0); el.style.left=X+'px'}; if(!el.Atr.horizontal){ var Y=el.Atr.Start.Y+mouse.Y-el.mouseStart.Y; if(Yel.Atr.bottom)Y=el.Atr.bottom}; Y=Y+((typeof(ActiveXObject)!='undefined')?document.documentElement.scrollTop:0); el.style.top=Y+'px'}; var overel=Zapatec.Utils.getTopElementByPos(el.Atr.dragLayer,mouse.X,mouse.Y,el,true,'dropName') if((overel!=el.Atr.overEl)){ if(el.Atr.overEl&&el.Atr.overEl.onDragOut)el.Atr.overEl.onDragOut(el); el.Atr.overEl=overel; if(overel.onDragOver)overel.onDragOver(el) } }; el.mouseUpEv=function(ev){ document.getElementsByTagName("BODY")[0].onselectstart=new Function("_ill=1;"); if(el.cState=='drag'){ if(el.Atr.overEl&&el.Atr.overEl.onDrop){ var returnToOldPos=!(el.Atr.overEl.onDrop(el)); if(returnToOldPos){ Zapatec.Utils.Slide(el,el.Atr.Start.X,el.Atr.Start.Y); } } Zapatec.Utils.removeEvent(window.document, "mousemove", el.mouseMoveEv); Zapatec.Utils.removeEvent(window.document, "mouseup", el.mouseUpEv); el.cState=''; var uninit=Zapatec.Utils.getElementsByAttribute('onDragEnd',0,0,1); for(var a in uninit){if(typeof(uninit[a])=='function'){continue;} if(uninit[a]){uninit[a].onDragEnd(el, ev);}} }; }; }; Zapatec.Utils.Arrange=function(el){ }; Zapatec.Utils.Slide=function(el,toX,toY,time,steps){ time || (time=Zapatec.defaultSlideTime); steps || (steps=Zapatec.defaultSlideSteps); Zapatec.Glide={ob:el,X:toX,Y:toY}; Zapatec.Utils.Slide.step=function(el,x,y){ var eX=el.offsetLeft||parseInt(el.style.left)||0; var eY=el.offsetTop||parseInt(el.style.top)||0; var cX=el.offsetLeft+(x-eX)/el.Atr.slideSteps; var cY=el.offsetTop+(y-eY)/el.Atr.slideSteps--; if (!el.Atr.slideSteps){ delete(el.Atr.slideSteps); cX=x; cX=y; clearInterval(el.Atr.sliding); Zapatec.Utils.changeAttributes(el,el.Atr.beforeDrag); el.Atr.beforeDrag=''; delete(el.Atr.beforeDrag); return }; el.style.left=cX+'px'; el.style.top=cY+'px' } el.Atr.slideSteps=steps; el.Atr.sliding=setInterval('Zapatec.Utils.Slide.step(Zapatec.Glide.ob,Zapatec.Glide.X,Zapatec.Glide.Y)',Math.round(time/steps)); }; Zapatec.Utils.getTopElementByPos=function(con,X,Y,ignoreElement,recursive,stopAttr,stopAttrValue){ if(!(con=Zapatec.Utils.idOrObject(con)))return; var a=con.firstChild,ret=false; while(a){ if(a.offsetLeftX && (a.offsetTop+a.offsetHeight)>Y && a.style.display!='none' && a!=ignoreElement){ if(!ret||a.style.zIndex>=ret.style.zIndex)ret=a; }; a=a.nextSibling }; if (recursive&&ret&&ret.hasChildNodes()&&!ret[stopAttr]){ ret=Zapatec.Utils.getTopElementByPos(ret,X-ret.offsetLeft,Y-ret.offsetTop,ignoreElement,recursive,stopAttr)||ret }; return ret } Zapatec.Utils.getRelativePos=function(el,con){ if(!(el=Zapatec.Utils.idOrObject(el,'relativePos - no object:'+el)))return; con=Zapatec.Utils.idOrObject(con,'relativePos - no container:'+con); var SL = 0, ST = 0; if (el.scrollLeft)SL = el.scrollLeft; if (el.scrollTop)ST = el.scrollTop; var r = { X: el.offsetLeft - SL, Y: el.offsetTop - ST }; if (el.offsetParent&&el.offsetParent!=con) { var tmp = Zapatec.Utils.getRelativePos(el.offsetParent,con); r.X += tmp.X; r.Y += tmp.Y; } return r; }; Zapatec.Utils.changeAttributes=function(el,newValues,dontSet){ if(!(el=Zapatec.Utils.idOrObject(el))||!newValues)return; var ret={}; for(var a in newValues){if(typeof(newValues[a])=='function'){continue;} var b=newValues[a]; if(b&&typeof(b)=='object'&&!b.nodeName){ ret[a]=Zapatec.Utils.changeAttributes(el[a],b,false) }else{ ret[a]=el[a]||''; if(a=='nextSibling'){ if(ret[a]==null)ret.parentNode=el.parentNode } } } if(!dontSet){ if(newValues.parentNode&&newValues.nextSibling){ delete(newValues.parentNode); }; for(var a in newValues){if(typeof(newValues[a])=='function'){continue;} var b=newValues[a]; if(b&&typeof(b)=='object'&&!b.nodeName){ if(!el[a])el[a]={}; ret[a]=Zapatec.Utils.changeAttributes(el[a],b) }else{ if(/^offset/.test(a)){ el.style[a.replace(/^offset(.*)$/,'$1').toLowerCase()]=(b||0)+'px' }else if(a=='parentNode'){ if(b&&b.nodeType==1)b.appendChild(el) }else if(a=='nextSibling'){ if(b)b.parentNode.insertBefore(el,b); }else{ try{el[a]=b}catch(e){} } } } }; return ret }