﻿// JScript File
var dragTarget=null;
var clickOffset={};
clickOffset.X=0;
clickOffset.Y=0;

function minTog(item)
{
    if(typeof(item)=="string"){item=document.getElementById(item)};
    var box=item;
    if(box.attributes["minimized"].nodeValue==true||box.attributes["minimized"].nodeValue=="true")
    {
        var node=1;
        for(var exit=false;exit==false;){if(box.childNodes[node-1].nodeType==3){node++}else{exit=true};}
        for(var exit=false;exit==false;){if(box.childNodes[node].nodeType==3){node++}else{exit=true};}
        box.childNodes[node].style.display="block";
        if(box.attributes["maximizedwidth"])box.style.width=box.attributes["maximizedwidth"].nodeValue;
        box.attributes["minimized"].nodeValue=false
    }else{
        var node=1;
        for(var exit=false;exit==false;){if(box.childNodes[node-1].nodeType==3){node++}else{exit=true};}
        for(var exit=false;exit==false;){if(box.childNodes[node].nodeType==3){node++}else{exit=true};}
        box.childNodes[node].style.display="none";
        if(box.attributes["minimizedwidth"])box.style.width=box.attributes["minimizedwidth"].nodeValue;
        box.attributes["minimized"].nodeValue=true
    }
};

function disableBubble(e)
{
    if(e==null)e=window.event;
    if (e.stopPropagation)
    {
	    e.stopPropagation();
	    e.preventDefault();
    }
    e.cancelBubble=true;
    return false
}

function Move(e,item)
{
    if(typeof(item)=="string"){item=document.getElementById(item)};
    dragTarget=item;
    clickOffset.X=e.offsetX||e.offsetX==0?e.offsetX:e.layerX;
    clickOffset.Y=e.offsetY||e.offsetY==0?e.offsetY:e.layerY;
    if(document.attachEvent)
    {
        document.attachEvent("onmousemove",dragElement);
        document.attachEvent("onmouseup",cleanUp);
    }else{
        document.addEventListener("mousemove",dragElement,false);
        document.addEventListener("mouseup",cleanUp,false);
    }
    disableBubble(e)
};

function dragElement(e)
{
    if(e==null)e=window.event;
    dragTarget.style.top=e.clientY+document.documentElement.scrollTop-Settings.MainDiv.offsetTop-clickOffset.Y+"px";
    dragTarget.style.left=e.clientX+document.documentElement.scrollLeft-Settings.MainDiv.offsetLeft-clickOffset.X+"px";
    disableBubble(e)
    return false;
};

function cleanUp()
{
    if(document.detachEvent)
    {
        document.detachEvent("onmousemove",dragElement);
        document.detachEvent("onmouseup",cleanUp);
    }else{
        document.removeEventListener("mousemove",dragElement,false);
        document.removeEventListener("mouseup",cleanUp,false);
    }
};

var lastClicked=null
function changeImgMouseOver(img, url)
{
    if(!img.clicked&&img.clicked!=true)img.src=url;
};

function changeImgMouseOut(img, url)
{
    if(!img.clicked&&img.clicked!=true)img.src=url;
};

function changeImgClick(img, url)
{
    if(lastClicked){lastClicked.clicked=false;lastClicked.onmouseout();}
    img.clicked=true;
    lastClicked=img;
    img.src=url;
};
