﻿// version: 2009.09.16.2

dragsw = false;
startdrag = function(t, e) {
    var browser = navigator.appName;
    if (e.button == (1 ? (browser == "Microsoft Internet Explorer") : 0)) {
        if ( e.preventDefault == undefined )
			e.returnValue = false;
		else
		{
            var obj = e.srcElement ? e.srcElement : e.target;
			if (navigator.userAgent.toLowerCase().indexOf('safari') < 0)  // not Safari case
			{
				if ( e.cancelable ){
					e.preventDefault();
                }
                
                // workaround onmouseup issue in firefox on Mac
                if (obj.tagName.toUpperCase() == "EMBED") {
                    if (obj.id.toLowerCase().indexOf('previewobj') >= 0){
                        obj.onmouseup = stopdragup;
                    }
                }
			}
			else
			{
                if (obj.tagName.toUpperCase() == "IMG") {
                    e.preventDefault();
                }
			}
		}
        
        window.document.onmousemoveOld = window.document.onmousemove;
        window.document.onmouseupOld = window.document.onmouseup;
        var nInitLeft = isNaN(parseInt(t.offsetLeft)) ? "0" : t.offsetLeft;
        var nInitTop = isNaN(parseInt(t.offsetTop)) ? "0" : t.offsetTop;
        
        t.style.left = isNaN(parseInt(t.style.left)) ? (nInitLeft + "px") : t.style.left;
        t.style.top = isNaN(parseInt(t.style.top )) ? (nInitTop + "px") : t.style.top;
        
        window.document.draged = t;
        dragsw = true;
		window.document.onmousemove = dodrag;
        window.document.onmouseup = stopdragup;
        t.dragX = e.clientX;
        t.dragY = e.clientY;
    }
    else {
        dragsw = false;
    }
    return false;
}
dodrag = function(e) {
    if (!e) e = event;
    if (dragsw) {
        t = window.document.draged;
        t.style.left = (parseInt(t.style.left) + e.clientX - t.dragX) + "px";
        t.style.top = (parseInt(t.style.top) + e.clientY - t.dragY) + "px";
        t.dragX = e.clientX;
        t.dragY = e.clientY;
        t.style.cursor = 'move';
    }
    return false;
}
stopdragup = function() {
    window.document.onmousemove = window.document.onmousemoveOld;
    window.document.onmouseup = window.document.onmouseupOld;
    t = window.document.draged;
    t.style.cursor = 'auto';
    dragsw = false;
    return true;
}
stopdrag = function() {
     stopdragup();
}
resumedrag = function() {
     dragsw = true;
}

setLayer = function( strId )
{
	var obj = document.getElementById(strId);
	obj.style.display='none';
}