maybe this can help you out:
its not coded so well but could be tweek for better performance
it seems like something that could be of assistance
<html>
<head runat=“server”>
<title>window interface</title>
<script type=“text/javascript”>
var global_obj;
var global_obj_width;
var global_obj_height;
var global_obj_top;
var global_obj_left;
var global_obj_right;
var global_obj_bottom;
var clickcounter = 0;
var gloabl_obj_name;
var global_objnameAJT = new Array();
global_objnameAJT[0] = "main";
global_objnameAJT[1] = "options";
var global_zIndexAJT = new Array();
global_zIndexAJT[0] = "1000";
global_zIndexAJT[1] = "999";
//======================================================
function setGlobalVariables(temp_obj, temp_obj_width, temp_obj_height, temp_obj_top, temp_obj_left, temp_obj_right, temp_obj_bottom, obj_name) {
global_obj = temp_obj;
global_obj_width = temp_obj_width;
global_obj_height = temp_obj_height;
global_obj_top = temp_obj_top;
global_obj_left = temp_obj_left;
global_obj_right = temp_obj_right;
global_obj_bottom = temp_obj_bottom;
gloabl_obj_name = obj_name;
}
//============MOVING THE DIV WITH THE MOUSE=============
function moveDIV(obj_name, _x, _y) {
var obj = document.getElementById(obj_name + 'DIV');
var obj_width = parseInt(obj.style.width);
var obj_height = parseInt(obj.style.height);
var obj_top = parseInt(obj.style.top);
var obj_left = parseInt(obj.style.left);
var obj_right = obj_left + obj_width;
var obj_bottom = obj_top + obj_height;
obj.style.top = (_y - 15) + 'px';
obj.style.left = (_x - (obj_width / 2)) + 'px';
} //end function moveDIV(obj_name, _x, _y)
//this function captures the div
//and basically prepares it for being dragged/moved
function onmousedown_captureDIV(obj_name) {
clickcounter = 1;
var obj = document.getElementById(obj_name + 'DIV');
var obj_width = parseInt(obj.style.width);
var obj_height = parseInt(obj.style.height);
var obj_top = parseInt(obj.style.top);
var obj_left = parseInt(obj.style.left);
var obj_right = obj_left + obj_width;
var obj_bottom = obj_top + obj_height;
setGlobalVariables(obj, obj_width, obj_height, obj_top, obj_left, obj_right, obj_bottom, obj_name);
set_movingDIV_style(obj_name);
reArrangeWindowOrder(obj_name);
}
//this function stops the move
function onmouseup_releaseDIV(obj_name) {
clickcounter = 0;
set_stationaryDIV_style(obj_name);
}
//changes the divs style to the movingn style
function set_movingDIV_style(obj_name) {
var mainobj = document.getElementById(obj_name + 'DIV');
var obj_titlebar = document.getElementById(obj_name + '_titlebarDIV');
var obj_content = document.getElementById(obj_name + '_contentDIV');
obj_titlebar.style.display = "none";
obj_content.style.display = "none";
mainobj.style.backgroundColor = "Transparent";
mainobj.style.border = "1pt dashed black";
mainobj.style.cursor = "move";
}
//changes the divs style to stationary style
function set_stationaryDIV_style(obj_name) {
var mainobj = document.getElementById(obj_name + 'DIV');
var obj_titlebar = document.getElementById(obj_name + '_titlebarDIV');
var obj_content = document.getElementById(obj_name + '_contentDIV');
obj_titlebar.style.display = "block";
if (mainobj.style.height == "30px") {
}
else {
obj_content.style.display = "block";
}
mainobj.style.backgroundColor = "White";
mainobj.style.border = "1pt solid black";
mainobj.style.cursor = "default";
}
function reArrangeWindowOrder(obj_name) {
// alert(obj_name);
//-----------------------------------------------------------
//store the windows/divs names in a temporary array
var temp1 = new Array(global_objnameAJT.length);
for (var i = 0; i < global_objnameAJT.length; i++) {
temp1[i] = global_objnameAJT[i];
}
//------------------------------------------------------------
//--------------------------------------------------------------------------------
//set the selected object as the first in array, or on top in order of z-index
global_objnameAJT[0] = obj_name;
//----------------------------------------------------------------------------------
//--------------------------------------------------------------------------------
//re order the array
var counter = 1;
for (var i = 0; i < temp1.length; i++) {
if (temp1[i] != obj_name) {
global_objnameAJT[counter] = temp1[i];
counter++;
}
else {
}
}
//------------------------------------------------------------------------------------
//---------------------------------------------------------------------------
//set the divs zindex to 1234
for (var i = 0; i < global_objnameAJT.length; i++) {
var tempobj = document.getElementById(global_objnameAJT[i] + 'DIV');
tempobj.style.zIndex = global_zIndexAJT[i];
//alert(global_zIndexAJT[i]);
}
//-------------------------------------------------------------------------------
}
//=====================================================
//==================WINDOW/DIV FUNCTIONS===================================
//minimize the div, make only the titlebar visible
function minimize_maximizeDIV(obj_name) {
var mainobj = document.getElementById(obj_name + 'DIV');
var obj_titlebar = document.getElementById(obj_name + '_titlebarDIV');
var obj_content = document.getElementById(obj_name + '_contentDIV');
if (mainobj.style.height == "30px") {
//maximize
obj_titlebar.style.display = "block";
obj_content.style.display = "block";
var obj_titlebar_height = parseInt(obj_titlebar.style.height);
var obj_content_height = parseInt(obj_content.style.height);
document.getElementById('minmax_' + obj_name).innerHTML = "_";
document.getElementById('minmax_' + obj_name).title = "Minimize";
var winW = 630, winH = 460;
if (document.body && document.body.offsetWidth) {
winW = document.body.offsetWidth;
winH = document.body.offsetHeight;
}
if (document.compatMode == 'CSS1Compat' && document.documentElement && document.documentElement.offsetWidth) {
winW = document.documentElement.offsetWidth;
winH = document.documentElement.offsetHeight;
}
if (window.innerWidth && window.innerHeight) {
winW = window.innerWidth;
winH = window.innerHeight;
}
var page_height = winH;
var page_width = winW;
if ((parseInt(mainobj.style.top) + parseInt(mainobj.style.height)) >= (parseInt(page_height) - 100)) {
mainobj.style.top = (parseInt(page_height) - (obj_titlebar_height + obj_content_height)) + 'px';
}
mainobj.style.height = (obj_titlebar_height + obj_content_height) + 'px';
}
else {
//minimize
obj_titlebar.style.display = "block";
obj_content.style.display = "none";
document.getElementById('minmax_' + obj_name).innerHTML = "+";
document.getElementById('minmax_' + obj_name).title = "Maximize";
var winW = 630, winH = 460;
if (document.body && document.body.offsetWidth) {
winW = document.body.offsetWidth;
winH = document.body.offsetHeight;
}
if (document.compatMode == 'CSS1Compat' && document.documentElement && document.documentElement.offsetWidth) {
winW = document.documentElement.offsetWidth;
winH = document.documentElement.offsetHeight;
}
if (window.innerWidth && window.innerHeight) {
winW = window.innerWidth;
winH = window.innerHeight;
}
var page_height = winH;
var page_width = winW;
if ((parseInt(mainobj.style.top) + parseInt(mainobj.style.height)) >= (parseInt(page_height) - 100)) {
mainobj.style.top = (parseInt(page_height) - 40) + 'px';
}
mainobj.style.height = "30px";
}
reArrangeWindowOrder(obj_name);
}
//=========================================================================
//==============MOUSE CAPTURE==========================
var IE = document.all ? true : false;
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;
var tempX = 0;
var tempY = 0;
function getMouseXY(e) {
if (IE) { // grab the x-y pos.s if browser is IE
tempX = event.clientX + document.body.scrollLeft;
tempY = event.clientY + document.body.scrollTop;
}
else { // grab the x-y pos.s if browser is NS
tempX = e.pageX;
tempY = e.pageY;
}
if (tempX < 0) { tempX = 0; }
if (tempY < 0) { tempY = 0; }
//------------------------------------------------------------
//now it works in FireFox, Chrome, and Internet Explorer
if (clickcounter == 1) {
moveDIV(gloabl_obj_name, tempX, tempY);
}
//------------------------------------------------------------
return true;
}
//=====================================================
//===============Setting up the layout=========================
function set_newPosition() {
var new_obj = document.getElementById('newDIV');
var new_obj_width = parseInt(new_obj.style.width);
var new_obj_height = parseInt(new_obj.style.height);
var new_obj_top = parseInt(new_obj.style.top);
var new_obj_left = parseInt(new_obj.style.left);
var new_obj_right = new_obj_left + new_obj_width;
var new_obj_bottom = new_obj_top + new_obj_height;
var winW = 630, winH = 460;
if (document.body && document.body.offsetWidth) {
winW = document.body.offsetWidth;
winH = document.body.offsetHeight;
}
if (document.compatMode == 'CSS1Compat' && document.documentElement && document.documentElement.offsetWidth) {
winW = document.documentElement.offsetWidth;
winH = document.documentElement.offsetHeight;
}
if (window.innerWidth && window.innerHeight) {
winW = window.innerWidth;
winH = window.innerHeight;
}
var page_height = winH;
var page_width = winW;
new_obj.style.top = (page_height - new_obj_height) + 'px';
} //end function set_newPosition()
var newwindowcounter = 0;
function CreateNewWindow() {
newwindowcounter++;
/*
This method deals with creating a new window object.
there is an erro here with the userMe and userYou variables
their values keep/ sometimes coming back as undefined, but other times they work just fine
*/
var id = "newwindow" + newwindowcounter.toString();
//alert(id);
var width = "250px";
var height = "300px";
var left = "100px";
var top = "100px";
var newdiv = document.createElement("div"); //creates the element
//--------------------------------------------Sets attributes and properties of the div element
newdiv.setAttribute('id', id + "DIV");
newdiv.style.width = width;
newdiv.style.height = height;
newdiv.style.position = "absolute";
newdiv.style.left = left;
newdiv.style.top = top;
newdiv.style.background = "orange"; //should be random colors, or no two boxes have the same color
newdiv.style.border = "1pt solid black";
var htmlstring = "<div id='" + id + "_titlebarDIV' style='border: 1pt solid black; width:250px; height: 30px; background-color:White; position: absolute; top:0px; left: 0px;' onmouseup='onmouseup_releaseDIV('" + id + "');'>" +
"<table height='30px' width='100%' cellpadding='0' cellspacing='0'>"+
"<tr>"+
"<td id='title_" + id + "' align='left' style='width:220px; cursor:move;' onmousedown='onmousedown_captureDIV('" + id + "');'>" +
"New Window : " + id +
"</td>"+
"<td id='minmax_" + id + "' align='center' style='width:30px; cursor:pointer;' title='Minimize' onclick='minimize_maximizeDIV('" + id + "')'>" +
" _"+
"</td>"+
"</tr>"+
"</table>"+
"</div>"+
"<div id='" + id + "_contentDIV' style='border: 1pt solid black; width:250px; height: 270px; background-color:Silver; position: absolute; top:30px; left: 0px;'>" +
"<table border='1' cellspacing='0' cellpadding='0'>" +
"<tr>" +
"<td colspan='2' align='center' style='border-bottom: 1pt solid black;'>" +
"<u>A NEW WINDOW</u>" +
"</td>" +
"</tr>" +
"<tr>" +
"<td valign='top' align='left' style='border-right: 3pt solid gray; border-bottom: 1pt solid black;'>" +
"Something here"
"</td>" +
"</tr>" +
"</table>" +
"</div>";
newdiv.innerHTML = htmlstring;
newdiv.onmouseup = function() { onmouseup_releaseDIV(id); }; //onmouseup="onmouseup_releaseDIV('games');"
newdiv.onclick = function() { reArrangeWindowOrder(id); };//re arranges the windows
//--------------------------------------------------------------------------------------------
document.body.appendChild(newdiv); //adds the element to the body
global_objnameAJT[global_objnameAJT.length] = id;
global_zIndexAJT[global_zIndexAJT.length] = global_zIndexAJT[global_zIndexAJT.length - 1] - 1;
reArrangeWindowOrder(id);
} //function CreateNewObject()
//=================================
</script>
</head>
<body>
<form id=“form1” runat=“server”>
<div id=“optionsDIV” style=“border: 1pt solid black; width:400px; height: 200px; background-color:White; position: absolute; top:0px; left: 0px;” onclick=“reArrangeWindowOrder(‘options’);” onmouseup=“onmouseup_releaseDIV(‘options’);”>
<div id=“options_titlebarDIV” style=“border: 1pt solid black; width:400px; height: 30px; background-color:White; position: absolute; top:0px; left: 0px;” onmouseup=“onmouseup_releaseDIV(‘options’);”>
<table height=“30px” width=“100%” cellpadding=“0” cellspacing=“0”>
<tr>
<td id=“title_options” align=“left” style=“width:370px; cursor:move;” onmousedown=“onmousedown_captureDIV(‘options’);”>
OPTIONS
</td>
<td id=“minmax_options” align=“center” style=“width:30px; cursor:pointer;” title=“Minimize” onclick=“minimize_maximizeDIV(‘options’)”>
_
</td>
</tr>
</table>
</div>
<div id=“options_contentDIV” style=“border: 1pt solid black; width:400px; height: 170px; background-color:Silver; position: absolute; top:30px; left: 0px;”>
the options:
<br />
more tabs,
<br />
more windows;
<br />
<a href=“javascript:CreateNewWindow();”>create new window</a>
</div>
</div>
<div id="mainDIV" style="border: 1pt solid black; width:600px; height: 800px; background-color:White; position: absolute; top:80px; left: 250px;" onclick="reArrangeWindowOrder('main');" onmouseup="onmouseup_releaseDIV('main');">
<div id="main_titlebarDIV" style="border: 1pt solid black; width:600px; height: 30px; background-color:White; position: absolute; top:0px; left: 0px;" onmouseup="onmouseup_releaseDIV('main');">
<table height="30px" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td id="title_main" align="left" style="width:570px; cursor:move;" onmousedown="onmousedown_captureDIV('main');">
MAIN
</td>
<td id="minmax_main" align="center" style="width:30px; cursor:pointer;" title="Minimize" onclick="minimize_maximizeDIV('main')">
_
</td>
</tr>
</table>
</div>
<div id="main_contentDIV" style="border: 1pt solid black; width:600px; height: 770px; background-color:Silver; position: absolute; top:30px; left: 0px;">
here the main content will go
</div>
</div>
</form>
</body>
</html>