var dragobject={z: 0, x: 0, y: 0, offsetx : null, offsety : null, targetobj : null, drag_now : 0,
 initialize:function(){document.onmousedown=this.dragjh;document.onmouseup=this.end;},
 dragjh:function(evt){      
    var evtobj=window.event? window.event : evt
    this.targetobj=window.event? event.srcElement : evt.target
    if (this.targetobj.className=="dragjh"){
        this.drag_now=1;
        if (isNaN(parseInt(this.targetobj.style.left))){this.targetobj.style.left=0}
        if (isNaN(parseInt(this.targetobj.style.top))){this.targetobj.style.top=0}
        this.offsetx=parseInt(this.targetobj.style.left)
        this.offsety=parseInt(this.targetobj.style.top)
        this.x=evtobj.clientX
        this.y=evtobj.clientY
        
        // aktuelles Objekt immer im vordergrund
        var cd = new Date(); 
        var d = " "+cd.valueOf();
        d = parseInt(d.substring(6,13));
        this.targetobj.style.zIndex = d;
                
        if (evtobj.preventDefault)
        evtobj.preventDefault()

        document.onmousemove=dragobject.moveit;
        document.onkeydown= dragobject.keyd;        
    }
 },
 moveit:function(evt){
    var evtobj=window.event? window.event : evt
    if (this.drag_now==1){
    this.targetobj.style.left=this.offsetx+evtobj.clientX-this.x+"px"
    this.targetobj.style.top=this.offsety+evtobj.clientY-this.y+"px"
    return false
    }
 },
 shrink:function(evt){
  this.targetobj.style.width= evtobj.clientX +"px";
 },
 keyd : function(evt){
   var evtobj=window.event? window.event : evt
   // Delete Objekt
   if ((window.event.keyCode == "46") && (this.targetobj != null)&& (this.targetobj.className=="dragjh"))
          this.targetobj.style.display="none";
   // Text  ausrichtung -1
   if ((window.event.keyCode == "37") && (this.targetobj != null)&& (this.targetobj.className=="dragjh"))        
          this.targetobj.style.textAlign="left"
   if ((window.event.keyCode == "39") && (this.targetobj != null)&& (this.targetobj.className=="dragjh"))
          this.targetobj.style.textAlign="right"
   if ((window.event.keyCode == "40") && (this.targetobj != null)&& (this.targetobj.className=="dragjh"))
          this.targetobj.style.textAlign="center"               
   //alert(window.event.keyCode);       
 },
 end : function(evt)
 {
  var evtobj=window.event? window.event : evt
  this.drag_now=0;
  document.onmousemove = null;
  this.targetobj=null;
 }   
}
dragobject.initialize();
