// <script type="text/javascript" src="http://www.google.com/jsapi?key=ABQIAAAAPE0msCXAfcqzjiQQfBocGBT9hJcYGTWOvYf4UspFQYDhMOm3FRSDdVuNfqmXTNP4W4ihPcs0Mb6V5A"></script><script type="text/javascript">google.load("feeds", "1");</script>

onerror=handleErr;
function handleErr(msg,url,l)
{
debug.print(msg+", "+url+", line:"+l);
}

function widthChange(){
document.getElementById("apptitle1").style.width=document.body.clientWidth;
document.getElementById("apptitle2").style.width=document.body.clientWidth;
document.getElementById("dockback").style.width=document.body.clientWidth;
drawDock();
}

window.onresize = widthChange;

var appNumCount=0,sTop=50,zTop=300000,currentShortcut=0,currentWindow=0,winNumCount=0,killDock=false,dragObj={},skins=[],gecko=false,ie=false,opera=false,safari=false,outlineDrag=true,transitions=true;
var windows=[0];
var username="angry",topDock=true,pause=false,pauseTimeOut;

var desktop = document.getElementById("desktop");

skins["chocolate"] = {name:"chocolate",width:5,topHeight:29,bottomHeight:5,iconStyle:"left:5;top:5;",iconSize:24,minStyle:"right:35;top:8;",maxStyle:"right:20;top:8;",closeStyle:"right:5;top:8;",resizeStyle:"right:0;bottom:0;",titleStyle:"left:32;top:7;height:22;font-weight:bold;color:#333333;font-size:13px;"};
skins["xp"] = {name:"xp",width:6,topHeight:25,bottomHeight:6,iconStyle:"left:5;top:5;",iconSize:16,minStyle:"right:45;top:4;",maxStyle:"right:25;top:4;",closeStyle:"right:5;top:4;",resizeStyle:"right:0;bottom:0;",titleStyle:"left:25;top:4;font-weight:bold;color:#ffffff;font-size:13px;"};
skins["youos"] = {name:"youos",width:5,topHeight:28,bottomHeight:12,iconStyle:"left:7;top:7;",iconSize:16,minStyle:"right:43;top:6;",maxStyle:"right:24;top:6;",closeStyle:"right:5;top:6;",resizeStyle:"right:1;bottom:1;",resizeBottom:1,resizeRight:1,titleStyle:"left:25;top:1;height:22;font-weight:bold;color:#000000;font-size:13px;padding:3;"};
skins["98"] = {name:"98",width:6,topHeight:24,bottomHeight:24,iconStyle:"left:5;top:5;",iconSize:16,minStyle:"right:40;top:6;",maxStyle:"right:24;top:6;",closeStyle:"right:6;top:6;",resizeStyle:"right:1;bottom:1;",titleStyle:"left:25;top:4;height:20;font-weight:bold;color:#ffffff;font-size:13px;"};
skins["eyeos"] = {name:"eyeos",width:5,topHeight:23,bottomHeight:1,midWidth:1,bottomWidth:1,iconStyle:"left:4;top:4;",iconSize:16,minStyle:"right:35;top:3;",maxStyle:"right:20;top:3;",closeStyle:"right:5;top:3;",resizeStyle:"right:0;bottom:0;",titleStyle:"left:23;top:3;height:20;font-weight:bold;color:#ffffff;font-size:13px;"};
skins["osx"] = {name:"osx",width:6,topHeight:24,bottomHeight:1,midWidth:2,bottomWidth:1,iconStyle:"right:5;top:4;",iconSize:16,minStyle:"left:45;top:5;",maxStyle:"left:25;top:5;",closeStyle:"left:5;top:5;",resizeStyle:"right:0;bottom:0;",titleStyle:"left:0;top:3;height:20;font-weight:bold;color:#333333;font-size:14px;text-align:center;"};
skins["vista"] = {name:"vista",backColor:"#ffffff",width:8,topHeight:24,bottomHeight:8,midWidth:8,bottomWidth:8,iconStyle:"left:4;top:4;",iconSize:16,minStyle:"right:73;top:1;",maxStyle:"right:47;top:1;",closeStyle:"right:5;top:1;",resizeStyle:"right:0;bottom:0;",titleStyle:"left:25;top:3;height:21;font-weight:bold;color:#000000;font-size:13px;"};
skins["kde"] = {name:"kde",width:4,topHeight:25,bottomHeight:4,midWidth:4,bottomWidth:4,iconStyle:"left:6;top:5;",iconSize:16,minStyle:"right:46;top:3;",maxStyle:"right:26;top:3;",closeStyle:"right:6;top:3;",resizeStyle:"right:0;bottom:0;",titleStyle:"left:25;top:4;height:21;font-weight:bold;color:#ffffff;font-size:14px;"};
skins["gnome"] = {name:"gnome",backColor:"#ffffff",width:5,topHeight:24,bottomHeight:26,midWidth:5,bottomWidth:5,iconStyle:"left:6;top:4;",iconSize:16,minStyle:"right:44;top:3;",maxStyle:"right:24;top:3;",closeStyle:"right:4;top:3;",resizeStyle:"right:0;bottom:0;",titleStyle:"left:0;top:4;height:20;font-weight:bold;color:#ffffff;font-size:13px;text-align:center;"};
skins["desktop2"]={name:"desktop2",width:71,topHeight:22,bottomHeight:21,midWidth:1,bottomWidth:20,iconStyle:"left:5;top:5;",iconSize:0,minStyle:"right:49;top:2;",maxStyle:"right:27;top:2;",closeStyle:"right:5;top:2;",resizeStyle:"right:0;bottom:0;",titleStyle:"left:0;top:2;height:20;font-weight:bold;color:#333333;font-size:12px;text-align:center;"};
skins["google"]={name:"google",width:1,topHeight:22,bottomHeight:1,midWidth:1,bottomWidth:1,iconStyle:"left:5;top:5;",iconSize:0,minStyle:"right:36;top:5;",maxStyle:"right:21;top:5;",closeStyle:"right:6;top:5;",resizeStyle:"right:0;bottom:0;",titleStyle:"left:5;top:2;height:20;font-weight:bold;color:#7A66CC;font-size:14px;"};
skins["meebo"] = {name:"meebo",backColor:"#ffffff",width:8,topHeight:30,bottomHeight:26,midWidth:5,bottomWidth:5,iconStyle:"left:7;top:7;",iconSize:16,minStyle:"right:44;top:3;",maxStyle:"right:24;top:3;",closeStyle:"right:4;top:3;",resizeStyle:"right:0;bottom:0;",titleStyle:"left:26;top:5;height:20;font-weight:bold;color:#ffffff;font-size:13px;text-align:left;"};
skins["orange"] = {name:"orange",backColor:"#ffffff",width:1,topHeight:22,bottomHeight:1,midWidth:1,bottomWidth:1,iconStyle:"left:3;top:3;",iconSize:16,minStyle:"right:34;top:7;",maxStyle:"right:20;top:7;",closeStyle:"right:6;top:7;",resizeStyle:"right:0;bottom:0;",titleStyle:"left:21;top:3;height:20;font-weight:bold;color:#FFEDC8;font-size:12px;text-align:left;"};

var skin={name:"chocolate",width:5,topHeight:29,bottomHeight:5,iconStyle:"left:5;top:5;",iconSize:24,minStyle:"right:35;top:8;",maxStyle:"right:20;top:8;",closeStyle:"right:5;top:8;",resizeStyle:"right:0;bottom:0;",titleStyle:"left:32;top:6;height:23;font-weight:bold;color:#333333;font-size:13px;"};

if ((BrowserDetect.browser=="Firefox") || (BrowserDetect.browser=="Netscape") || (BrowserDetect.browser=="Mozilla")){gecko=true;}
if (BrowserDetect.browser=="Konqueror"){safari=true;}
if (BrowserDetect.browser=="Explorer"){ie=true;}
if (BrowserDetect.browser=="Opera"){opera=true;}
if (BrowserDetect.browser=="Safari"){safari=true;}

//alert(BrowserDetect.browser);

var fix=0;if (!ie){fix=8;}

function setFocus(winId)
{
if ((windows[winId]) && (!windows[winId].focussed)){
windows[winId].getFocus();
}
}

function removeFocus(winId)
{
if ((windows[winId]) && (windows[winId].focussed)){
windows[winId].loseFocus();
}
}

function shieldsUp()
{

for (var i in windows){
if (document.getElementById("$$shield$$"+i)){
document.getElementById("$$shield$$"+i).style.zIndex=999998;
}
}

/*
if (document.getElementById("$$shield$$"+currentWindow)){
document.getElementById("$$shield$$"+currentWindow).style.zIndex=999998;
}
*/
}


// ****************************


function dragInit(event, id)
{

if ((windows[id]) && (windows[id].maximized)){return;}

var x;
var y;

//fireEvent("onLoseFocus"+currentWindow);

killStart();
killDock=true;
setFocus(id); // call this b4 currentWindow is changed :S
dragObj.winId=id;
//currentWindow=id;
shieldsUp();



if (outlineDrag)
{
dragObj.element = document.getElementById("resizediv");
dragObj.element.style.left = document.getElementById("$$frame$$"+id).style.left;
dragObj.element.style.top = document.getElementById("$$frame$$"+id).style.top;
dragObj.element.style.height = (parseInt(document.getElementById("$$frame$$"+id).style.height,10)-fix);
dragObj.element.style.width = (parseInt(document.getElementById("$$frame$$"+id).style.width)-fix);
dragObj.element.style.display="block";
}
else
{
dragObj.element = document.getElementById("$$frame$$"+id);
}

if (gecko)
{
x = event.clientX;
if (topDock){y = event.clientY+50;}else{y = event.clientY;}
}
else
{
x = window.event.clientX;
if (topDock){y = window.event.clientY+50;}else{y = window.event.clientY;}
}

dragObj.cursorInitX = x;
dragObj.cursorInitY = y;
dragObj.elInitLeft = parseInt(dragObj.element.style.left);
dragObj.elInitTop = parseInt(dragObj.element.style.top);

if (ie) {
document.attachEvent("onmousemove", dragDo);
document.attachEvent("onmouseup", dragStop);
window.event.cancelBubble = true;
window.event.returnValue = false;
}
else {
document.addEventListener("mousemove", dragDo, true);
document.addEventListener("mouseup", dragStop, true);
event.preventDefault();
}
removeFocus(dragObj.winId);
}

// ****************************

function dragDo(event)
{


var x, y;

if (gecko)
{
x = event.clientX;
if (topDock){y = event.clientY+50;}else{y = event.clientY;}
}
else
{
x = window.event.clientX;
if (topDock){y = window.event.clientY+50;}else{y = window.event.clientY;}
}
temp = (dragObj.elInitTop  + y - dragObj.cursorInitY);
if (temp>document.body.clientHeight-skin.topHeight){temp=document.body.clientHeight-skin.topHeight;}
if (topDock){if (temp<50){temp=50;}}else{if (temp<0){temp=0;}}

if (outlineDrag)
{
document.getElementById("resizediv").style.left = dragObj.elInitLeft + x - dragObj.cursorInitX;
document.getElementById("resizediv").style.top = temp;
}
else
{
windows[dragObj.winId].move((dragObj.elInitLeft + x - dragObj.cursorInitX),temp-50);
}

if (gecko)
{
event.preventDefault();
}
else
{
window.event.cancelBubble = true;
window.event.returnValue = false;
}

}

// ****************************

function dragStop(event)
{
if (ie)
{
document.detachEvent("onmousemove", dragDo);
document.detachEvent("onmouseup", dragStop);
}
else
{
document.removeEventListener("mousemove", dragDo, true);
document.removeEventListener("mouseup", dragStop, true);
}
killDock=false;

setFocus(dragObj.winId);

if (outlineDrag)
{
windows[dragObj.winId].move(parseInt(dragObj.element.style.left),parseInt(dragObj.element.style.top)-50);
document.getElementById("resizediv").style.display="none";
}
fireEvent("onMove"+dragObj.winId);
}

// ****************************

function shortcutDragInit(event, id)
{
var x, y;
killStart();
killDock=true;

resetSomeStuff();
currentShortcut=id;

dragObj.element = document.getElementById("$$shortcut$$"+id);

document.getElementById("caption"+id).style.height="";
document.getElementById("caption"+id).style.background="gray";

if (gecko)
{
x = event.clientX;
y = event.clientY;
}
else
{
x = window.event.clientX;
y = window.event.clientY;
}
dragObj.cursorInitX = x;
dragObj.cursorInitY = y;
dragObj.elInitLeft = parseInt(dragObj.element.style.left);
dragObj.elInitTop = parseInt(dragObj.element.style.top);
dragObj.element.style.zIndex=999999;

if (ie)
{
document.attachEvent("onmousemove", shortcutDragDo);
document.attachEvent("onmouseup", shortcutDragStop);
window.event.cancelBubble = true;
window.event.returnValue = false;
}
else
{
document.addEventListener("mousemove", shortcutDragDo,   true);
document.addEventListener("mouseup", shortcutDragStop, true);
event.preventDefault();
}
shieldsUp();
//fireEvent("onLoseFocus"+currentWindow);
removeFocus(currentWindow);
}

// ****************************

function shortcutDragDo(event)
{
var x, y;

dragObj.element.style.MozOpacity=0.5;
dragObj.element.style.opacity=0.5;
dragObj.element.style.KhtmlOpacity=0.5;
//dragObj.element.style.filter="alpha(opacity=50)";
    
if (gecko)
{
x = event.clientX;
y = event.clientY;
}
else
{
x = window.event.clientX;
y = window.event.clientY;
}
dragObj.element.style.left=dragObj.elInitLeft + x - dragObj.cursorInitX;
dragObj.element.style.top=dragObj.elInitTop + y - dragObj.cursorInitY;
if (gecko)
{
event.preventDefault();
}
else
{
window.event.cancelBubble = true;
window.event.returnValue = false;
}
}

// ****************************

function shortcutDragStop(event)
{
//setFocus(currentWindow);

if (ie)
{
document.detachEvent("onmousemove", shortcutDragDo);
document.detachEvent("onmouseup", shortcutDragStop);
}
else
{
document.removeEventListener("mousemove", shortcutDragDo, true);
document.removeEventListener("mouseup",  shortcutDragStop, true);
}
killDock=false;

dragObj.element.style.MozOpacity=1;
dragObj.element.style.opacity=1;
dragObj.element.style.KhtmlOpacity=1;
//dragObj.element.style.filter="alpha(opacity=100)";

dragObj.element.style.zIndex=sTop;
sTop++;
if (ie) {
document.attachEvent("onmousedown", resetSomeStuff);
}
else {
document.addEventListener("mousedown", resetSomeStuff, true);
}

if ((dragObj.elInitLeft!=parseInt(dragObj.element.style.left)) || (dragObj.elInitTop!=parseInt(dragObj.element.style.top)))
{
//localRequest('php/updateshortcut.php?id='+currentShortcut+'&x='+parseInt(dragObj.element.style.left)+'&y='+parseInt(dragObj.element.style.top)+'&sid=' + new Date().getTime(),function(){});

updateShortcut(function(){},username, new Date().getTime(), currentShortcut, parseInt(dragObj.element.style.left), parseInt(dragObj.element.style.top));

//setFocus(currentWindow);
//currentWindow=0;
}
}

// ****************************

function resizeInit(event, id)
{

if ((windows[id]) && (windows[id].maximized)){return;}

var x;
var y;

killStart();
killDock=true;
setFocus(id);  // call this b4 currentWindow is changed
dragObj.element = document.getElementById("$$frame$$"+id);
dragObj.winId=id;
currentWindow=id;
shieldsUp();

removeFocus(id);

if (gecko)
{
x = event.clientX;
y = event.clientY;
}
else
{
x = window.event.clientX;
y = window.event.clientY;
}

document.getElementById("resizediv").style.left = dragObj.element.style.left;
document.getElementById("resizediv").style.top = dragObj.element.style.top;
document.getElementById("resizediv").style.height = (parseInt(dragObj.element.style.height)-fix);
document.getElementById("resizediv").style.width = (parseInt(dragObj.element.style.width)-fix);
document.getElementById("resizediv").style.display="block";

dragObj.cursorInitX = x;
dragObj.cursorInitY = y;
dragObj.elInitLeft = parseInt(dragObj.element.style.left);
dragObj.elInitTop = parseInt(dragObj.element.style.top);

if (ie)
{
document.attachEvent("onmousemove",resizeDo);
document.attachEvent("onmouseup",resizeStop);
window.event.cancelBubble = true;
window.event.returnValue = false;
}
else
{
document.addEventListener("mousemove", resizeDo, true);
document.addEventListener("mouseup", resizeStop, true);
event.preventDefault();
}
}

// ****************************

function resizeDo(event)
{
var x, y;
if (gecko)
{
x = event.clientX;
y = event.clientY;
}
else
{
x = window.event.clientX;
y = window.event.clientY;
}

th=(parseInt(dragObj.element.style.height)-fix)+(y-dragObj.cursorInitY);
tw=(parseInt(dragObj.element.style.width)-fix)+(x-dragObj.cursorInitX);

if (th<windows[dragObj.winId].minHeight){th=windows[dragObj.winId].minHeight;}
if (tw<windows[dragObj.winId].minWidth){tw=windows[dragObj.winId].minWidth;}


document.getElementById("resizediv").style.height = th;

document.getElementById("resizediv").style.width = tw;

if (gecko)
{
event.preventDefault();
}
else
{
window.event.cancelBubble = true;
window.event.returnValue = false;
}
}

// ****************************

function resizeStop(event)
{
if (ie)
{
document.detachEvent("onmousemove", resizeDo);
document.detachEvent("onmouseup", resizeStop);
}
else
{
document.removeEventListener("mousemove", resizeDo, true);
document.removeEventListener("mouseup", resizeStop, true);
}
document.getElementById("resizediv").style.display="none";

killDock=false;
setFocus(dragObj.winId);

windows[dragObj.winId].resize((parseInt(document.getElementById("resizediv").style.width)+fix)-(skin.midWidth*2),(parseInt(document.getElementById("resizediv").style.height)+fix)-skin.bottomHeight-skin.topHeight);
}

// ************************

function resetSomeStuff()
{

if (document.getElementById("caption"+currentShortcut))
{
document.getElementById("caption"+currentShortcut).style.background="transparent";
if (safari){document.getElementById("caption"+currentShortcut).style.height="24px";}
else{document.getElementById("caption"+currentShortcut).style.height="28px";}
}

if (ie)
{
document.detachEvent("onmousedown", resetSomeStuff);
}
else
{
document.removeEventListener("mousedown", resetSomeStuff, true);
}
killStart();
}



function loadApp(appid,parameters)
{
if (pause){return false;}
pause=true;
pauseTimeOut=setTimeout(function(){pause=false;},500);

appNumCount++;ap=appNumCount;
localRequest("php/loadapp.php?appid="+appid,function(txt){executeApp(txt,parameters,ap);});
testtt=document.createElement("DIV");
testtt.innerHTML="<img src='icons/icon.png' id=app"+ap+" style=\"position:absolute;-moz-user-select:none;left:0px;top:0px;width:48px;height:48px;\">";
dockbar.appendChild(testtt);
drawDock();
}

function executeApp(appSource,parameters,appId)
{
var ifram = document.createElement("iframe");
ifram.id="ifrm"+appId;
ifram.name="ifrm"+appId;
ifram.style.display = "none";
document.getElementById("junk").appendChild(ifram);

window.frames["ifrm"+appId].document.open();
appSource = appSource.replace(/\$APPID\$/gi,appId+"");
appSource = appSource.replace(/api.addWin\(\{/g,"api.addWin({appId:"+appId+",");
appSource = appSource.replace(/api.addWin\(\)/g,"api.addWin({appId:"+appId+"})");
window.frames["ifrm"+appId].document.write("<script>var api=this.parent;var appId="+appId+";parameters='"+parameters+"';<\/script>"+appSource);
window.frames["ifrm"+appId].document.close();
window.frames["ifrm"+appId].open();
}


// move this function.....
function winToggle(winId)
{
if (parseInt(document.getElementById("$$frame$$"+winId).style.top)>1900)
{
windows[winId].ready=false;
windows[winId].display="none";
anim.winId=winId;
setFocus(anim.winId);
if (windows[winId].width>windows[winId].height){wid=windows[winId].height;y=windows[winId].y;x=windows[winId].x+((windows[winId].width-wid)/2);}
else{wid=windows[winId].width;x=windows[winId].x;y=windows[winId].y+((windows[winId].height-wid)/2);}
anim.x1=parseInt(document.getElementById(winId+"dockIcon").style.left)+parseInt(dockbar.style.left)+parseInt(document.getElementById(winId+"dockIcon").style.width)/2-24;
anim.y1=25;
anim.w1=48;
anim.h1=48;
anim.x2=x;
anim.y2=y+50;
anim.w2=wid;
anim.h2=wid;
box.style.zIndex=windows[winId].z;
box.src=windows[winId].icon;
newAnim();
}
else
{
if (currentWindow==winId)
{
winMinimize(winId);
//nextWin();
}
else
{
setFocus(winId);
}
}
}

// move this function.....
function winMinimize(winId)
{
if (windows[winId].width>windows[winId].height){wid=windows[winId].height;y=windows[winId].y;x=windows[winId].x+((windows[winId].width-wid)/2);}
else{wid=windows[winId].width;x=windows[winId].x;y=windows[winId].y+((windows[winId].height-wid)/2);}
anim.x2=parseInt(document.getElementById(winId+"dockIcon").style.left)+parseInt(dockbar.style.left)+parseInt(document.getElementById(winId+"dockIcon").style.width)/2-24;
anim.y2=25;
anim.w2=48;
anim.h2=48;
anim.x1=x;
anim.y1=y+50;
anim.w1=wid;
anim.h1=wid;
box.style.zIndex=999997;
box.src=windows[winId].icon;
newAnim();

document.getElementById("$$frame$$"+winId).style.top=parseInt(document.getElementById("$$frame$$"+winId).style.top)+2000;
removeFocus(winId);
document.getElementById("$$frame$$"+winId).style.zIndex=0;
windows[winId].z=0;
nextWin();
}
function getElement(elem)
{
return(document.getElementById(elem));
}
function appCall(elem)
{
return(window.frames["ifrm"+elem]);
}


// move this function.....
function winClose(temp)
{
if ((temp) && (window.frames["ifrm"+windows[temp].appId].close)){
window.frames["ifrm"+windows[temp].appId].close();}
windowClose(temp);
}

function windowClose(winId)
{
desktop.removeChild(document.getElementById("$$frame$$"+winId));
document.getElementById("dockbar").removeChild(document.getElementById(winId+"dockIcon").parentNode);
drawDock();
document.getElementById("junk").removeChild(document.getElementById("ifrm"+windows[winId].appId));
//windows.splice(winId,1);

if (windows[winId].width>windows[winId].height){wid=windows[winId].height;y=windows[winId].y;x=windows[winId].x+((windows[winId].width-wid)/2);}
else{wid=windows[winId].width;x=windows[winId].x;y=windows[winId].y+((windows[winId].height-wid)/2);}
anim.x2=x+(wid/2);
anim.y2=y+(wid/2)+50;
anim.w2=0;
anim.h2=0;
anim.x1=x;
anim.y1=y+50;
anim.w1=wid;
anim.h1=wid;
box.style.zIndex=999997;
box.src=windows[winId].icon;
newAnim();

windows[winId]=null;

debug.print("deleted "+winId);

nextWin();
}

function nextWin()
{
// find the next highest window and set focus..
var hiZ=0,id=0;
for (var i in windows)
{
if ((windows[i]) && (windows[i].z>hiZ))
{
hiZ=windows[i].z;id=i;
}
}
setFocus(id);
}


function toggleStart()
{
if (document.getElementById("startMenu"))
{
desktop.removeChild(document.getElementById("startMenu"));
if (ie)
{
document.detachEvent("onmouseup", toggleStart);
}
else
{
document.removeEventListener("mouseup", toggleStart, true);
}
setFocus(currentWindow);
}
else
{
shieldsUp();
removeFocus(currentWindow);
testtt=document.createElement("DIV");

var menu=[];
menu[0,0]={title:"browser",icon:"icons/WhereWolf.png",link:"loadApp(\"browser\");"};
menu[0,1]={title:"test",icon:"icons/ed49.gif",link:"loadApp(\"test\");"};
menu[0,2]={title:"yaplet",icon:"icons/icon20.png",link:"loadApp(\"yaplet\");"};
menu[0,3]={title:"ballsorting",icon:"http://s3.amazonaws.com/youos_staticfsprod/angryfrommanchester/staticfs/cb2.png/",link:"loadApp(\"ballsorting\");"};
menu[0,4]={title:"preferences",icon:"icons/prefs.gif",link:"loadApp(\"prefs\");"};
menu[0,5]={title:"ladybugs",icon:"http://s3.amazonaws.com/youos_staticfsprod/angryfrommanchester/staticfs/ladybugs.gif/",link:"loadApp(\"ladybugs\");"};
menu[0,6]={title:"paperthrowing",icon:"http://s3.amazonaws.com/youos_staticfsprod/angryfrommanchester/staticfs/paper.png/",link:"loadApp(\"paper\");"};
menu[0,7]={title:"games",icon:"icons/folder.png",link:"",subMenu:1};
menu[0,8]={title:"clock",icon:"icons/clock.jpg",link:"loadApp(\"clock\");"};
menu[0,9]={title:"c64 emulator",icon:"icons/c64.jpg",link:"loadApp(\"c64\");"};

temp="<table cellpadding=0 cellspacing=0 style=\"cursor:pointer;-moz-user-select:none;border-width:1px;border-color:#555;border-style:solid;width:200px;background-color:#fff\">";
for (var i in menu)
{
temp+="<tr height=20 valign=middle onmouseover=\"this.style.backgroundColor='#ddd';\" onmousedown='"+menu[0,i].link+"' onmouseout=\"this.style.backgroundColor='#fff';\"><td width=30 align=center><img src=\""+menu[0,i].icon+"\" width=16 height=16></td><td>"+menu[0,i].title+"</td>";
if (menu[0,i].subMenu){temp+="<td><img src='icons/submenu.png'></td>";}else{temp+="<td></td>";}
}
temp+="</table>";


testtt.innerHTML=temp;
testtt.id="startMenu";
testtt.style.position="absolute";
testtt.style.left="0px";
testtt.style.top="49px";

testtt.style.zIndex=999999;
desktop.appendChild(testtt);

if (ie) {
document.attachEvent("onmouseup", toggleStart);
}
else {
document.addEventListener("mouseup", toggleStart, true);
}


}
}

function killStart()
{
if (document.getElementById("startMenu"))
{
desktop.removeChild(document.getElementById("startMenu"));
if (ie)
{
document.detachEvent("onmouseup", toggleStart);
}
else
{
document.removeEventListener("mouseup", toggleStart, true);
}
}
}

debug =
{txt:"",
print:function(temp)
{
this.txt+=temp+"<br>";
fireEvent("debug",this.txt);
},

clear:function()
{
this.txt="";
this.print("");
}
}

function changeSkin(temp)
{
skin=temp;
document.getElementById("dockback").style.width=document.body.clientWidth;
document.getElementById("dockback").style.backgroundImage="url(skins/"+skin.name+"/bar.png)";
document.getElementById("apptitle1").style.width=document.body.clientWidth;
document.getElementById("apptitle2").style.width=document.body.clientWidth;
for (var i in windows)
{
if (windows[i]){windows[i].redraw()}
}
}
