//flexTPS - flexible TelePresense System
//Copyright (c) 2003-2005  Christopher Stanton
//
//Visit: http://flextps.org
//
//This program is free software; you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation; either version 2 of the License, or
//(at your option) any later version.
//
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with this program; if not, write to the Free Software
//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA

var ie=document.all
var ns6=document.getElementById&&!document.all

var obj,objX,objY,oldMouseX,oldMouseY,objDivShim
var drag=false

function getElementStyle(elem, IEStyleProp, CSSStyleProp) {
    if (elem.currentStyle) {
        return elem.currentStyle[IEStyleProp]
    } else if (window.getComputedStyle) {
        var compStyle = window.getComputedStyle(elem, "")
        return compStyle.getPropertyValue(CSSStyleProp)
    }
    return ""
}

function move(e){
	if (drag){
		obj.style.left=ns6? objX+e.clientX-oldMouseX: objX+event.clientX-oldMouseX
		obj.style.top=ns6? objY+e.clientY-oldMouseY : objY+event.clientY-oldMouseY
			
		if ( ie ) {
			objDivShim.style.left = obj.style.left;
			objDivShim.style.top = obj.style.top;
		}

		return false
	}
}

function dragStart(e){
	if (!ie&&!ns6)
		return
	var topelement=ns6? "HTML" : "BODY"
	obj=ns6? e.target : event.srcElement

	if (obj.className=="header"){
		obj=ns6? obj.parentNode : obj.parentElement

		if (obj.className == "container"){
			obj.style.zIndex = ++topzindex
			if ( ie ) {
				objDivShim = document.getElementById("div_shim-" + obj.id.substring(10,obj.id.length) );
				obj.style.zIndex = ++topzindex
			}
			updateVideoBoxZIndexs();

			objX=parseInt(getElementStyle(obj, "left", "left")+0)
			objY=parseInt(getElementStyle(obj, "top", "top")+0)
			oldMouseX=ns6? e.clientX: event.clientX
			oldMouseY=ns6? e.clientY: event.clientY

			drag=true
			document.onmousemove=move
			return false
		}
	}
}

function dragStop(e) {
	drag=false

	if (obj.className == "container"){
		updateVideoBoxPositions();
	}
}

document.onmousedown=dragStart
document.onmouseup=dragStop
