var dragapproved=false; 
var chosen=false; 
var z,x,y;  
 

  

function imagehandler(evt){
	if ((evt.which == 1)&&(evt.target.className=="drag"))
	{	//chosen for resize ; not chosen for drag
	
	    if (chosen) resizeimage(evt);
		else  drags(evt);
	}
	
}

function setchosen(evt)
{	
	if ((evt.which == 192))
	{
		if (chosen == true) chosen = false;
		else chosen = true;
	}
}

function resizeimage(evt)
{
	if (evt.target.className=="drag")
	{	
		if (evt.which == 1) 
		{
			z=evt.target;   
			temp1=parseInt(z.width);  
			temp2=parseInt(z.height);  
			
			x=evt.pageX;   
			y=evt.pageY;   
			document.onmousemove=resize; 
		}
	}
}

function drags(evt){   

//alert(evt.target);
if (evt.target.className=="drag")
{   
dragapproved=true;

z=evt.target;   
temp1=parseInt(z.style.left);  
temp2=parseInt(z.style.top);  
x=evt.pageX;   
y=evt.pageY;   
document.onmousemove=move;   
}   
}

function resize(evt)
{
if ((evt.which == 1)&&(chosen))
{
	//alert(evt.which);
	z.width=temp1+evt.pageX-x;   
	z.height=temp2+evt.pageY-y;
	return false;
}
} 

function move(evt){   
	
if ((evt.which == 1)&&(dragapproved))
{
z.style.left=temp1+evt.pageX-x;   
z.style.top=temp2+evt.pageY-y;
return false;
}   

} 
   
document.onmousedown=imagehandler;  
document.onmouseup=new Function("dragapproved=false; chosen=false;");   
document.onkeydown=setchosen;





