/*
Author: Brendan Phillips [brendan.p.phillips@gmail.com]

All contents copyright 2009 by Brendan Phillips.
All rights reserved.
No part of this code or the related files may be reproduced or transmitted in any form, by any means without the prior written permission of the owner.

The code provided herein is provided "as is."
Brendan Phillips has used his best efforts in preparing this code, and makes no representation or warranties with respect to its accuracy or completeness and specifically disclaims any implied warranties of merchantability or fitness for any particular purpose.
In no event shall he be liable for any loss of profit or any other commercial damage, including but not limited to special, incidental, consequential, or other damages.

Steppin' Razor [steppin-razor.com] has recieved permission from Brendan Phillips to use this code.
*/

function initDragging(){
	try{
		dragableImage=$("expandableImgDiv");
		dragableImage.onmousedown=startDrag;
		if(dragableImage.captureEvents)element.captureEvents(Event.MouseDown);
		if(isNaN(parseInt(dragableImage.style.left)))dragableImage.style.left="0px";
		if(isNaN(parseInt(dragableImage.style.top)))dragableImage.style.top="0px";
	}catch(e){}
}
function getEvent(e){try{return(typeof(e)=='undefined')?window.event:e;}catch(e){}}
function startDrag(e){
	try{
		if(!stillExpanding){
			e=getEvent(e);
			oldMouseX=e.clientX;
			oldMouseY=e.clientY;
			dragableImage.style.cursor="move";
			minLocX=oldMouseX-parseInt(dragableImage.style.left);
			minLocY=oldMouseY-parseInt(dragableImage.style.top);
			maxLocX=minLocX+windowWidth-parseInt(expandableImg.style.width);
			maxLocY=minLocY+windowHeight-parseInt(expandableImg.style.height);
			document.onmousemove=DragIt;
			document.onmouseup=endDrag;
			if(document.captureEvents)document.captureEvents(Event.MouseUp|Event.MouseMove);
		}
		return false;
	}catch(e){}
}
function DragIt(e){
	try{
		e=getEvent(e);
		eventX=Math.min(Math.max(e.clientX,minLocX),maxLocX);
		eventY=Math.min(Math.max(e.clientY,minLocY),maxLocY);
		dragableImage.style.left=parseInt(dragableImage.style.left)+Math.floor(eventX-oldMouseX)+"px";
		dragableImage.style.top =parseInt(dragableImage.style.top) +Math.floor(eventY-oldMouseY)+"px";
		oldMouseX=eventX;
		oldMouseY=eventY;
		return false;
	}catch(e){}
}
function endDrag(){
	try{
		if(document.captureEvents)document.releaseEvents(Event.MouseUp|Event.MouseMove);
		document.onmouseup=document.onmousemove=null;
		dragableImage.style.cursor="auto";
		return false;
	}catch(e){}
}
