/*############################################################################
This script is made by bratta from www.bratta.com and can be used freely
as long as this msg is intact. Visit www.bratta.com for more great scripts.
############################################################################*/

//## BrowserCheck and setting variables #####################################
	var n = (document.layers) ? 1:0;
	var ie = (document.all) ? 1:0;
	var layer=(n)?'layer':'div'
	var oDrag;

//## The dragObject contructor and it's method's/functions and porperties ##
function dragObj(obj,nest){
	nest=(!nest) ? '':'document.'+nest+'.'										
    this.css=(n) ? eval(nest+'document.'+obj):eval('document.all.'+obj+'.style')		
    this.evnt=(n)? eval(nest+'document.'+obj):eval(obj);
	this.getLeft=b_getLeft;
	this.getTop=b_getTop;
	this.moveIt=b_moveIt;
	this.name=obj				
	return this
}
function b_moveIt(x,y){
	this.css.left=x
	this.css.top=y
}
function b_getLeft(){
  	x=(n)? this.css.left:this.css.pixelLeft
	return x
}
function b_getTop(){
  	y=(n)? this.css.top:this.css.pixelTop
	return y
}
//## Capturing events #######################################################
function dragInit(){
	if(n) document.captureEvents(Event.MOUSEMOVE | Event.MOUSEDOWN | Event.MOUSEUP)
	document.onmousedown=mdown
	document.onmouseup=mup
	document.onmousemove=mmove;
}
function mmover(num){
	oDrag[num].isOver=true
}
function mmout(num){
	oDrag[num].isOver=false
}
function mup(){
	for(var i=0; i<oDrag.length;i++){
		if(oDrag[i].isOver) {
			oDrag[i].drag=false
		}	
	}
}
function mdown(num){
	x=(n)?num.pageX:event.x
    y=(n)?num.pageY:event.y
	for(var i=0; i<oDrag.length;i++){
		if(oDrag[i].isOver) {
			oDrag[i].drag=true
			oDrag[i].clickedX=x-oDrag[i].getLeft()
			oDrag[i].clickedY=y-oDrag[i].getTop()
			cZIndex++
			oDrag[i].css.zIndex=cZIndex
		}
	}
}
function mmove(e){
	x=(n)?e.pageX:event.x
    y=(n)?e.pageY:event.y
	for(var i=0; i<oDrag.length;i++){
	if(oDrag[i].drag)
		oDrag[i].moveIt(x-oDrag[i].clickedX,y-oDrag[i].clickedY)
	}
}

/*################################################################################
Init, here's where you set how many draggable layers you want.
Make one more "Drag[3]=new dragObj('divDrag3')" and as i did here, ++ the number
to add draggable layers. You also have to add them in the stylesheet (in the <style></style>)
To make another one that's sized 100*200 and with a background-color of red add this:
#divDrag3{position:absolute; height:100; width:200; clip:rect(0,200,100,0); background-color:red; layer-background-color:red}
Get the picture?
There's one more thing you have to do to add layers, look further down for explanation.
##############################################################################*/
function init(divTag){
	dragInit();
	oDrag=new Array();
	oDrag[0]=new dragObj(divTag);

	//oDrag[1]=new dragObj('divDrag1')
	//oDrag[2]=new dragObj('divDrag2')
}

/*################################################################################
// This is a variant of init that takes 2 parameters and manages divs appropriately
// TLP 8/17/2006
/*################################################################################
Init, here's where you set how many draggable layers you want.
Make one more "Drag[3]=new dragObj('divDrag3')" and as i did here, ++ the number
to add draggable layers. You also have to add them in the stylesheet (in the <style></style>)
To make another one that's sized 100*200 and with a background-color of red add this:
#divDrag3{position:absolute; height:100; width:200; clip:rect(0,200,100,0); background-color:red; layer-background-color:red}
Get the picture?
There's one more thing you have to do to add layers, look further down for explanation.
##############################################################################*/
function init2(divTag1,divTag2){
	dragInit();
	oDrag=new Array();
	oDrag[0]=new dragObj(divTag1);
	oDrag[1]=new dragObj(divTag2);
	
	//Note: mmover(num) & mmover(num) references on the mouseover and mouseout events 
	//      must line up with the indexes above to work correctly.  
	// Example:  mmover(1) & mmover(1) should be used to work with the second divTag parameter.

	//oDrag[1]=new dragObj('divDrag1')
	//oDrag[2]=new dragObj('divDrag2')
}


/*################################################################################
Set this variable to the zIndex you want it to start at, (if you have several
layers and want it to start on the top, change to somthing higher then the uppermost layer*/
cZIndex=10
//################################################################################
