window.onresize = function() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
myWidth = myWidth - windowleft - 25;
myHeight = myHeight - windowtop - 70;

 // shift desktop buttons if not in view
 if (myHeight>700) {
	 if (myHeight<760) {
	  document.getElementById("root8").style.top = "10px";
	  document.getElementById("root8").style.left = "145px";
	  windowleft = 280;
	  if (win[0]) win[0].left = windowleft;
	  if (win[1]) win[1].left = windowleft;
	  if (win[2]) win[2].left = windowleft;
	  if (win[3]) win[3].left = windowleft;
	  if (win[4]) win[4].left = windowleft;
	  if (win[5]) win[5].left = windowleft;
	  if (win[6]) win[6].left = windowleft;
	  if (win[7]) win[7].left = windowleft;
	  if (win[8]) win[8].left = windowleft;
	 }
	 else {
	  windowleft = 150;
	  if (win[0]) win[0].left = windowleft;
	  if (win[1]) win[1].left = windowleft;
	  if (win[2]) win[2].left = windowleft;
	  if (win[3]) win[3].left = windowleft;
	  if (win[4]) win[4].left = windowleft;
	  if (win[5]) win[5].left = windowleft;
	  if (win[6]) win[6].left = windowleft;
	  if (win[7]) win[7].left = windowleft;
	  if (win[8]) win[8].left = windowleft;
	  document.getElementById("root8").style.top = "710px";
	  document.getElementById("root8").style.left = "10px";
	  document.getElementById("root6").style.top = "610px";
	  document.getElementById("root6").style.left = "10px";
	  document.getElementById("root5").style.top = "510px";
	  document.getElementById("root5").style.left = "10px";
	  document.getElementById("root4").style.top = "410px";
	  document.getElementById("root4").style.left = "10px";
	 }
 }
 else if (myHeight>600) {
	 if (myHeight<660) {
	  document.getElementById("root6").style.top = "110px";
	  document.getElementById("root6").style.left = "145px";
	  windowleft = 280;
	  if (win[0]) win[0].left = windowleft;
	  if (win[1]) win[1].left = windowleft;
	  if (win[2]) win[2].left = windowleft;
	  if (win[3]) win[3].left = windowleft;
	  if (win[4]) win[4].left = windowleft;
	  if (win[5]) win[5].left = windowleft;
	  if (win[6]) win[6].left = windowleft;
	  if (win[7]) win[7].left = windowleft;
	  if (win[8]) win[8].left = windowleft;
	 }
	 else {
	  document.getElementById("root6").style.top = "610px";
	  document.getElementById("root6").style.left = "10px";
	  document.getElementById("root5").style.top = "510px";
	  document.getElementById("root5").style.left = "10px";
	  document.getElementById("root4").style.top = "410px";
	  document.getElementById("root4").style.left = "10px";
	 }
 }
 else if (myHeight>500) {
	 if (myHeight<560) {
	  windowleft = 280;
	  if (win[0]) win[0].left = windowleft;
	  if (win[1]) win[1].left = windowleft;
	  if (win[2]) win[2].left = windowleft;
	  if (win[3]) win[3].left = windowleft;
	  if (win[4]) win[4].left = windowleft;
	  if (win[5]) win[5].left = windowleft;
	  if (win[6]) win[6].left = windowleft;
	  if (win[7]) win[7].left = windowleft;
	  if (win[8]) win[8].left = windowleft;
	  document.getElementById("root8").style.top = "10px";
	  document.getElementById("root8").style.left = "145px";
	  document.getElementById("root6").style.top = "110px";
	  document.getElementById("root6").style.left = "145px";
	  document.getElementById("root5").style.top = "210px";
	  document.getElementById("root5").style.left = "145px";
	 }
	 else {
	  document.getElementById("root5").style.top = "510px";
	  document.getElementById("root5").style.left = "10px";
	  document.getElementById("root4").style.top = "410px";
	  document.getElementById("root4").style.left = "10px";
	 }
 }
 else if (myHeight>400) {
	 if (myHeight<460) {
	  windowleft = 280;
	  if (win[0]) win[0].left = windowleft;
	  if (win[1]) win[1].left = windowleft;
	  if (win[2]) win[2].left = windowleft;
	  if (win[3]) win[3].left = windowleft;
	  if (win[4]) win[4].left = windowleft;
	  if (win[5]) win[5].left = windowleft;
	  if (win[6]) win[6].left = windowleft;
	  if (win[7]) win[7].left = windowleft;
	  if (win[8]) win[8].left = windowleft;
	  document.getElementById("root8").style.top = "10px";
	  document.getElementById("root8").style.left = "145px";
	  document.getElementById("root6").style.top = "110px";
	  document.getElementById("root6").style.left = "145px";
	  document.getElementById("root5").style.top = "210px";
	  document.getElementById("root5").style.left = "145px";
	  document.getElementById("root4").style.top = "310px";
	  document.getElementById("root4").style.left = "145px";
	 }
	 else {
	  document.getElementById("root4").style.top = "410px";
	  document.getElementById("root4").style.left = "10px";
	 }
 }
 else if (myHeight<401) {
	  windowleft = 280;
	  if (win[0]) win[0].left = windowleft;
	  if (win[1]) win[1].left = windowleft;
	  if (win[2]) win[2].left = windowleft;
	  if (win[3]) win[3].left = windowleft;
	  if (win[4]) win[4].left = windowleft;
	  if (win[5]) win[5].left = windowleft;
	  if (win[6]) win[6].left = windowleft;
	  if (win[7]) win[7].left = windowleft;
	  document.getElementById("root8").style.top = "10px";
	  document.getElementById("root8").style.left = "145px";
	  document.getElementById("root6").style.top = "110px";
	  document.getElementById("root6").style.left = "145px";
	  document.getElementById("root5").style.top = "210px";
	  document.getElementById("root5").style.left = "145px";
	  document.getElementById("root4").style.top = "310px";
	  document.getElementById("root4").style.left = "145px";
 }

  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
myWidth = myWidth - windowleft - 25;
myHeight = myHeight - windowtop - 70;

  var windowWidth = 0, windowHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    windowWidth = window.innerWidth;
    windowHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    windowWidth = document.documentElement.clientWidth;
    windowHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    windowWidth = document.body.clientWidth;
    windowHeight = document.body.clientHeight;
  }
  if (myHeight+windowtop>windowHeight-70) myHeight = windowHeight-windowtop;
  if (myWidth+windowleft>windowWidth-25) myWidth = windowWidth-windowleft-25;

  if (win[0]) {
   if (win[0].visible && myWidth>0 && myHeight>0) {
     new Effect.ResizeWindow(win[0], win[0].top, win[0].left, myWidth, myHeight, {duration: Window.resizeEffectDuration});
   }
  }
  if (win[1]) {
   if (win[1].visible && myWidth>0 && myHeight>0) {
     new Effect.ResizeWindow(win[1], win[1].top, win[1].left, myWidth, myHeight, {duration: Window.resizeEffectDuration});
   }
  }
  if (win[2]) {
   if (win[2].visible && myWidth>0 && myHeight>0) {
     new Effect.ResizeWindow(win[2], win[2].top, win[2].left, myWidth, myHeight, {duration: Window.resizeEffectDuration});
   }
  }
  if (win[3]) {
   if (win[3].visible && myWidth>0 && myHeight>0) {
     new Effect.ResizeWindow(win[3], win[3].top, win[3].left, myWidth, myHeight, {duration: Window.resizeEffectDuration});
   }
  }
  if (win[4]) {
   if (win[4].visible && myWidth>0 && myHeight>0) {
     new Effect.ResizeWindow(win[4], win[4].top, win[4].left, myWidth, myHeight, {duration: Window.resizeEffectDuration});
   }
  }
  if (win[5]) {
   if (win[5].visible && myWidth>0 && myHeight>0) {
     new Effect.ResizeWindow(win[5], win[5].top, win[5].left, myWidth, myHeight, {duration: Window.resizeEffectDuration});
   }
  }
  if (win[6]) {
   if (win[6].visible && myWidth>0 && myHeight>0) {
     new Effect.ResizeWindow(win[6], win[6].top, win[6].left, myWidth, myHeight, {duration: Window.resizeEffectDuration});
   }
  }
  if (win[7]) {
   if (win[7].visible && myWidth>0 && myHeight>0) {
     new Effect.ResizeWindow(win[7], win[7].top, win[7].left, myWidth, myHeight, {duration: Window.resizeEffectDuration});
   }
  }
  if (win[8]) {
   if (win[8].visible && myWidth>0 && myHeight>0) {
     new Effect.ResizeWindow(win[8], win[8].top, win[8].left, myWidth, myHeight, {duration: Window.resizeEffectDuration});
   }
  }

 if (win[0]) {
  if (win[0].visible) {
   setTimeout("win[0].toFront()",500);
   setTimeout("Windows.focus(win[0].getId())",1000);
  }
 }
 if (win[1]) {
  if (win[1].visible) {
   setTimeout("win[1].toFront()",500);
   setTimeout("Windows.focus(win[1].getId())",1000);
  }
 }
 if (win[2]) {
  if (win[2].visible) {
   setTimeout("win[2].toFront()",500);
   setTimeout("Windows.focus(win[2].getId())",1000);
  }
 }
 if (win[3]) {
  if (win[3].visible) {
   setTimeout("win[3].toFront()",500);
   setTimeout("Windows.focus(win[3].getId())",1000);
  }
 }
 if (win[4]) {
  if (win[4].visible) {
   setTimeout("win[4].toFront()",500);
   setTimeout("Windows.focus(win[4].getId())",1000);
  }
 }
 if (win[5]) {
  if (win[5].visible) {
   setTimeout("win[5].toFront()",500);
   setTimeout("Windows.focus(win[5].getId())",1000);
  }
 }
 if (win[6]) {
  if (win[6].visible) {
   setTimeout("win[6].toFront()",500);
   setTimeout("Windows.focus(win[6].getId())",1000);
  }
 }
 if (win[7]) {
  if (win[7].visible) {
   setTimeout("win[7].toFront()",500);
   setTimeout("Windows.focus(win[7].getId())",1000);
  }
 }
 if (win[8]) {
  if (win[8].visible) {
   setTimeout("win[8].toFront()",500);
   setTimeout("Windows.focus(win[8].getId())",1000);
  }
 }

} 

// Overide WindowUtilities getPageSize to remove dock height (for maximized windows)
WindowUtilities._oldGetPageSize = WindowUtilities.getPageSize;
WindowUtilities.getPageSize = function() {
  var size = WindowUtilities._oldGetPageSize();
  var dockHeight = $('dock').getHeight();
  
  size.pageHeight -= dockHeight;
  size.windowHeight -= dockHeight;
  return size;
};    


// Overide Windows minimize to move window inside dock  
Object.extend(Windows, {
  // Overide close function
  close: function(id, event) {
    var win = this.getWindow(id);
    if (win) {
	var title=win.getTitle();
	var updatetitle=title;
	var pattern=/Welcome/gi;
	if (title.match(pattern)) {
		updatetitle = titlecode2[0];
		windows[0] = 0;
		if (elements[0]) new Effect.Fade(elements[0], {afterFinish: function() {elements[0].remove()}});
		document.getElementById("td0").className='';
	}
	var pattern=/Shoutcast/gi;
	if (title.match(pattern)) {
		updatetitle = titlecode2[1];
		windows[1] = 0;
		if (elements[1]) new Effect.Fade(elements[1], {afterFinish: function() {elements[1].remove()}});
		document.getElementById("td1").className='';
	}
	var pattern=/Icecast/gi;
	if (title.match(pattern)) {
		updatetitle = titlecode2[2];
		windows[2] = 0;
		if (elements[2]) new Effect.Fade(elements[2], {afterFinish: function() {elements[2].remove()}});
		document.getElementById("td2").className='';
	}
	var pattern=/Teamspeak 3/gi;
	if (title.match(pattern)) {
		updatetitle = titlecode2[3];
		windows[3] = 0;
		if (elements[3]) new Effect.Fade(elements[3], {afterFinish: function() {elements[3].remove()}});
		document.getElementById("td3").className='';
	}
	var pattern=/Teamspeak 2/gi;
	if (title.match(pattern)) {
		updatetitle = titlecode2[4];
		windows[4] = 0;
		if (elements[4]) new Effect.Fade(elements[4], {afterFinish: function() {elements[4].remove()}});
		document.getElementById("td4").className='';
	}
	var pattern=/Flash/gi;
	if (title.match(pattern)) {
		updatetitle = titlecode2[5];
		windows[5] = 0;
		if (elements[5]) new Effect.Fade(elements[5], {afterFinish: function() {elements[5].remove()}});
		document.getElementById("td5").className='';
	}
	var pattern=/Webhosting/gi;
	if (title.match(pattern)) {
		updatetitle = titlecode2[6];
		windows[6] = 0;
		if (elements[6]) new Effect.Fade(elements[6], {afterFinish: function() {elements[6].remove()}});
		document.getElementById("td6").className='';
	}
	var pattern=/Contact/gi;
	if (title.match(pattern)) {
		updatetitle = titlecode2[7];
		windows[7] = 0;
		if (elements[7]) new Effect.Fade(elements[7], {afterFinish: function() {elements[7].remove()}});
	}
	var pattern=/Reseller/gi;
	if (title.match(pattern)) {
		updatetitle = titlecode2[8];
		windows[8] = 0;
		if (elements[8]) new Effect.Fade(elements[8], {afterFinish: function() {elements[8].remove()}});
	}
      win.close();
    }
    if (event)
      Event.stop(event);
  },

  minimize: function(id, event) {
    var win = this.getWindow(id)
    if (win && win.visible) {
      // Hide current window
      win.hide();            
    }
    Event.stop(event);
  },                 
  
  // Restore function
  restore: function(event) { 
   // minimize all other background windows

    var elem = Event.element(event);
    if (elem.win) {
     // Show window
	var title=elem.win.getTitle();
	var updatetitle=title;
	var pattern=/Welcome/gi;
	if (title.match(pattern)) {
		updatetitle = titlecode2[0];
		windows[0] = 1;

		// highlight button selection
		document.getElementById("td0").className='buttonover';
		// turn off other buttons
		document.getElementById("td1").className='';
		document.getElementById("td2").className='';
		document.getElementById("td3").className='';
		document.getElementById("td4").className='';
		document.getElementById("td5").className='';
		document.getElementById("td6").className='';
		document.getElementById("td8").className='';
		buttonselected = 0;

		   if (win[1]) win[1].hide();
		   if (win[2]) win[2].hide();
		   if (win[3]) win[3].hide();
		   if (win[4]) win[4].hide();
		   if (win[5]) win[5].hide();
		   if (win[6]) win[6].hide();
		   if (win[7]) win[7].hide();
		   if (win[8]) win[8].hide();
	}
	var pattern=/Shoutcast/gi;
	if (title.match(pattern)) {
		updatetitle = titlecode2[1];
		windows[1] = 1;

		// highlight button selection
		document.getElementById("td1").className='buttonover';
		// turn off other buttons
		document.getElementById("td0").className='';
		document.getElementById("td2").className='';
		document.getElementById("td3").className='';
		document.getElementById("td4").className='';
		document.getElementById("td5").className='';
		document.getElementById("td6").className='';
		document.getElementById("td8").className='';
		buttonselected = 1;

		   if (win[0]) win[0].hide();
		   if (win[2]) win[2].hide();
		   if (win[3]) win[3].hide();
		   if (win[4]) win[4].hide();
		   if (win[5]) win[5].hide();
		   if (win[6]) win[6].hide();
		   if (win[7]) win[7].hide();
		   if (win[8]) win[8].hide();
	}
	var pattern=/Icecast/gi;
	if (title.match(pattern)) {
		updatetitle = titlecode2[2];
		windows[2] = 1;

		// highlight button selection
		document.getElementById("td2").className='buttonover';
		// turn off other buttons
		document.getElementById("td0").className='';
		document.getElementById("td1").className='';
		document.getElementById("td3").className='';
		document.getElementById("td4").className='';
		document.getElementById("td5").className='';
		document.getElementById("td6").className='';
		document.getElementById("td8").className='';
		buttonselected = 2;

		   if (win[0]) win[0].hide();
		   if (win[1]) win[1].hide();
		   if (win[3]) win[3].hide();
		   if (win[4]) win[4].hide();
		   if (win[5]) win[5].hide();
		   if (win[6]) win[6].hide();
		   if (win[7]) win[7].hide();
		   if (win[8]) win[8].hide();
	}
	var pattern=/Teamspeak 3/gi;
	if (title.match(pattern)) {
		updatetitle = titlecode2[3];
		windows[3] = 1;

		// highlight button selection
		document.getElementById("td3").className='buttonover';
		// turn off other buttons
		document.getElementById("td0").className='';
		document.getElementById("td1").className='';
		document.getElementById("td2").className='';
		document.getElementById("td4").className='';
		document.getElementById("td5").className='';
		document.getElementById("td6").className='';
		document.getElementById("td8").className='';
		buttonselected = 3;

		   if (win[0]) win[0].hide();
		   if (win[1]) win[1].hide();
		   if (win[2]) win[2].hide();
		   if (win[4]) win[4].hide();
		   if (win[5]) win[5].hide();
		   if (win[6]) win[6].hide();
		   if (win[7]) win[7].hide();
		   if (win[8]) win[8].hide();
	}
	var pattern=/Teamspeak 2/gi;
	if (title.match(pattern)) {
		updatetitle = titlecode2[4];
		windows[4] = 1;

		// highlight button selection
		document.getElementById("td4").className='buttonover';
		// turn off other buttons
		document.getElementById("td0").className='';
		document.getElementById("td1").className='';
		document.getElementById("td2").className='';
		document.getElementById("td3").className='';
		document.getElementById("td5").className='';
		document.getElementById("td6").className='';
		document.getElementById("td8").className='';
		buttonselected = 4;

		   if (win[0]) win[0].hide();
		   if (win[1]) win[1].hide();
		   if (win[2]) win[2].hide();
		   if (win[3]) win[3].hide();
		   if (win[5]) win[5].hide();
		   if (win[6]) win[6].hide();
		   if (win[7]) win[7].hide();
		   if (win[8]) win[8].hide();
	}
	var pattern=/Flash/gi;
	if (title.match(pattern)) {
		updatetitle = titlecode2[5];
		windows[5] = 1;

		// highlight button selection
		document.getElementById("td5").className='buttonover';
		// turn off other buttons
		document.getElementById("td0").className='';
		document.getElementById("td1").className='';
		document.getElementById("td2").className='';
		document.getElementById("td3").className='';
		document.getElementById("td4").className='';
		document.getElementById("td6").className='';
		document.getElementById("td8").className='';
		buttonselected = 5;

		   if (win[0]) win[0].hide();
		   if (win[1]) win[1].hide();
		   if (win[2]) win[2].hide();
		   if (win[3]) win[3].hide();
		   if (win[4]) win[4].hide();
		   if (win[6]) win[6].hide();
		   if (win[7]) win[7].hide();
		   if (win[8]) win[8].hide();
	}
	var pattern=/Webhosting/gi;
	if (title.match(pattern)) {
		updatetitle = titlecode2[6];
		windows[6] = 1;

		// highlight button selection
		document.getElementById("td6").className='buttonover';
		// turn off other buttons
		document.getElementById("td0").className='';
		document.getElementById("td1").className='';
		document.getElementById("td2").className='';
		document.getElementById("td3").className='';
		document.getElementById("td4").className='';
		document.getElementById("td5").className='';
		document.getElementById("td8").className='';
		buttonselected = 6;

		   if (win[0]) win[0].hide();
		   if (win[1]) win[1].hide();
		   if (win[2]) win[2].hide();
		   if (win[3]) win[3].hide();
		   if (win[4]) win[4].hide();
		   if (win[5]) win[5].hide();
		   if (win[7]) win[7].hide();
		   if (win[8]) win[8].hide();
	}
	var pattern=/Contact/gi;
	if (title.match(pattern)) {
		updatetitle = titlecode2[7];
		windows[7] = 1;

		// highlight button selection
		// turn off other buttons
		document.getElementById("td0").className='';
		document.getElementById("td1").className='';
		document.getElementById("td2").className='';
		document.getElementById("td3").className='';
		document.getElementById("td4").className='';
		document.getElementById("td5").className='';
		document.getElementById("td6").className='';
		document.getElementById("td8").className='';
		buttonselected = 7;

		   if (win[0]) win[0].hide();
		   if (win[1]) win[1].hide();
		   if (win[2]) win[2].hide();
		   if (win[3]) win[3].hide();
		   if (win[4]) win[4].hide();
		   if (win[5]) win[5].hide();
		   if (win[6]) win[6].hide();
		   if (win[8]) win[8].hide();
	}
	var pattern=/Reseller/gi;
	if (title.match(pattern)) {
		updatetitle = titlecode2[8];
		windows[8] = 1;

		// highlight button selection
		document.getElementById("td8").className='buttonover';
		// turn off other buttons
		document.getElementById("td0").className='';
		document.getElementById("td1").className='';
		document.getElementById("td2").className='';
		document.getElementById("td3").className='';
		document.getElementById("td4").className='';
		document.getElementById("td5").className='';
		document.getElementById("td6").className='';
		buttonselected = 8;

		   /*if (win[0]) win[0].hide();
		   if (win[1]) win[1].hide();
		   if (win[2]) win[2].hide();
		   if (win[3]) win[3].hide();
		   if (win[4]) win[4].hide();
		   if (win[5]) win[5].hide();
		   if (win[6]) win[6].hide();
		   if (win[7]) win[7].hide();*/
	}
  if (elements[0]) elements[0].className = "dock_icon";
  if (elements[1]) elements[1].className = "dock_icon";
  if (elements[2]) elements[2].className = "dock_icon";
  if (elements[3]) elements[3].className = "dock_icon";
  if (elements[4]) elements[4].className = "dock_icon";
  if (elements[5]) elements[5].className = "dock_icon";
  if (elements[6]) elements[6].className = "dock_icon";
  if (elements[7]) elements[7].className = "dock_icon";
  if (elements[8]) elements[8].className = "dock_icon";
  if (elem) elem.className = "dock_iconover";

     elem.win.show();
     //Windows.focus(elem.win.getId());                    
     elem.win.toFront();
     // Fade and destroy icon
     // new Effect.Fade(elem, {afterFinish: function() {elem.remove()}})
    }
  }
})

// blur focused window if click on document
Event.observe(document, "click", function(event) {   
  var e = Event.element(event);
  var win = e.up(".dialog");
  var dock = e == $('dock') || e.up("#dock"); 
  if (!win && !dock && Windows.focusedWindow) {
    Windows.blur(Windows.focusedWindow.getId());                    
  }
})               

// Chnage theme callback
var currentTheme = 1;
var currentThemeName = "bluelighting";
var currentBlurThemeName = "greylighting";
function changeTheme(event) {
  var index = Event.element(event).selectedIndex;
  if (index == currentTheme)
    return;

  var theme, blurTheme;
  switch (index) {
    case 0:
      theme = "mac_os_x";
      blurTheme = "blur_os_x";
      currentThemeName = theme;
      currentBlurThemeName = blurTheme;
      break;
    case 1:
      theme = "bluelighting";
      blurTheme = "greylighting";
      currentThemeName = theme;
      currentBlurThemeName = blurTheme;
      break;
    case 2:
      theme = "greenlighting";
      blurTheme = "greylighting";
      currentThemeName = theme;
      currentBlurThemeName = blurTheme;
      break;
    case 3:
      theme = "nuncio";
      blurTheme = "greylighting";
      currentThemeName = theme;
      currentBlurThemeName = blurTheme;
      break;
    case 4:
      theme = "darkX";
      blurTheme = "greylighting";
      currentThemeName = theme;
      currentBlurThemeName = blurTheme;
      break;
    case 5:
      theme = "spread";
      blurTheme = "greylighting";
      currentThemeName = theme;
      currentBlurThemeName = blurTheme;
      break;
    case 6:
      theme = "alphacube";
      blurTheme = "greylighting";
      currentThemeName = theme;
      currentBlurThemeName = blurTheme;
      break;
  }
  Windows.windows.each(function(win) {
    win.options.focusClassName = theme; 
    win.options.blurClassName = blurTheme;
    win.changeClassName(blurTheme)
  });
  if (Windows.focusedWindow) Windows.focusedWindow.changeClassName(theme);
  currentTheme = index;
}

// Init webOS, create 1 welcome window
  function initWebOS() {         
   //$$("#theme select").first().selectedIndex = currentTheme;
   //Event.observe($$("#theme select").first(), "change", changeTheme); 
  }

  var myWidth = 0, myHeight = 0;

  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
myWidth = myWidth - windowleft - 25;
myHeight = myHeight - windowtop - 75;

var startingpositionx = 0;
var startingpositiony = 0;
var endingpositionx = 0;
var endingpositiony = 0;
var coord1x, coord1y, coord1x2, coord1y2;
var coord2x, coord2y, coord2x2, coord2y2;
var coord3x, coord3y, coord3x2, coord3y2;
var coord4x, coord4y, coord4x2, coord4y2;
var coord5x, coord5y, coord5x2, coord5y2;
var coord6x, coord6y, coord6x2, coord6y2;
var coord7x, coord7y, coord7x2, coord7y2;
var coord8x, coord8y, coord8x2, coord8y2;
var coord9x, coord9y, coord9x2, coord9y2;
var coord10x, coord10y, coord10x2, coord10y2;
var coord11x, coord11y, coord11x2, coord11y2;

var nextwindowid = -1;
var win = new Array();
var coordx = new Array();
var coordy = new Array();
var coordx2 = new Array();
var coordy2 = new Array();
var titlecode = new Array();
var titlecode2 = new Array();
titlecode[0] = "<img src=images/mavos64wide.png height=14>&nbsp;&nbsp;Welcome to MakeAVoice";
titlecode2[0] = "<img src=images/mavos64wide.png height=14>&nbsp;&nbsp;Welcome";
titlecode[1] = "<img src=images/shoutcast64wide.png height=14>&nbsp;&nbsp;Shoutcast Servers by MakeAVoice";
titlecode2[1] = "<img src=images/shoutcast64wide.png height=14>&nbsp;&nbsp;Shoutcast";
titlecode[2] = "<img src=images/icecast64wide.png height=14>&nbsp;&nbsp;Icecast  Servers by MakeAVoice";
titlecode2[2] = "<img src=images/icecast64wide.png height=14>&nbsp;&nbsp;Icecast";
titlecode[3] = "<img src=images/teamspeak364wide.png height=14>&nbsp;&nbsp;Teamspeak 3 Servers by MakeAVoice";
titlecode2[3] = "<img src=images/teamspeak364wide.png height=14>&nbsp;&nbsp;TS3";
titlecode[4] = "<img src=images/teamspeak264wide.png height=14>&nbsp;&nbsp;Teamspeak 2 Servers by MakeAVoice";
titlecode2[4] = "<img src=images/teamspeak264wide.png height=14>&nbsp;&nbsp;TS2";
titlecode[5] = "<img src=images/fmsicon64wide.png height=14>&nbsp;&nbsp;Flash Media Servers by MakeAVoice";
titlecode2[5] = "<img src=images/fmsicon64wide.png height=14>&nbsp;&nbsp;Flash";
titlecode[6] = "<img src=images/webhosting64wide.png height=14>&nbsp;&nbsp;Webhosting Accounts by MakeAVoice";
titlecode2[6] = "<img src=images/webhosting64wide.png height=14>&nbsp;&nbsp;Webhost";
titlecode[7] = "<img src=images/contacts64wide.png height=14>&nbsp;&nbsp;Contacts for MakeAVoice";
titlecode2[7] = "<img src=images/contacts64wide.png height=14>&nbsp;&nbsp;Contacts";
titlecode[8] = "<img src=images/teamspeak364wide.png height=14>&nbsp;&nbsp;TS3 Reseller";
titlecode2[8] = "<img src=images/teamspeak364wide.png height=14>&nbsp;&nbsp;Reseller";

var req;

var windows = new Array();
var elements = new Array();
var buttonselected = 0;
function changeClass(typenumber) {
 if (buttonselected==typenumber) {}
 else {
  document.getElementById("td"+typenumber).className='';
 }
}
function MavOS(typenumber,pagename) {
 // minimize all other background windows
 if (win[0] && typenumber!=0) win[0].hide();
 if (win[1] && typenumber!=1) win[1].hide();
 if (win[2] && typenumber!=2) win[2].hide();
 if (win[3] && typenumber!=3) win[3].hide();
 if (win[4] && typenumber!=4) win[4].hide();
 if (win[5] && typenumber!=5) win[5].hide();
 if (win[6] && typenumber!=6) win[6].hide();
 if (win[7] && typenumber!=7) win[7].hide();
 if (win[8] && typenumber!=8) win[8].hide();

 // highlight button selection
 if (typenumber!=7) document.getElementById("td"+typenumber).className='buttonover';
 // turn off other buttons
 if (typenumber==0) {
  document.getElementById("td1").className='';
  document.getElementById("td2").className='';
  document.getElementById("td3").className='';
  document.getElementById("td4").className='';
  document.getElementById("td5").className='';
  document.getElementById("td6").className='';
  document.getElementById("td8").className='';
 }
 else if (typenumber==1) {
  document.getElementById("td0").className='';
  document.getElementById("td2").className='';
  document.getElementById("td3").className='';
  document.getElementById("td4").className='';
  document.getElementById("td5").className='';
  document.getElementById("td6").className='';
  document.getElementById("td8").className='';
 }
 else if (typenumber==2) {
  document.getElementById("td0").className='';
  document.getElementById("td1").className='';
  document.getElementById("td3").className='';
  document.getElementById("td4").className='';
  document.getElementById("td5").className='';
  document.getElementById("td6").className='';
  document.getElementById("td8").className='';
 }
 else if (typenumber==3) {
  document.getElementById("td0").className='';
  document.getElementById("td2").className='';
  document.getElementById("td1").className='';
  document.getElementById("td4").className='';
  document.getElementById("td5").className='';
  document.getElementById("td6").className='';
  document.getElementById("td8").className='';
 }
 else if (typenumber==4) {
  document.getElementById("td0").className='';
  document.getElementById("td2").className='';
  document.getElementById("td3").className='';
  document.getElementById("td1").className='';
  document.getElementById("td5").className='';
  document.getElementById("td6").className='';
  document.getElementById("td8").className='';
 }
 else if (typenumber==5) {
  document.getElementById("td0").className='';
  document.getElementById("td2").className='';
  document.getElementById("td3").className='';
  document.getElementById("td4").className='';
  document.getElementById("td1").className='';
  document.getElementById("td6").className='';
  document.getElementById("td8").className='';
 }
 else if (typenumber==6) {
  document.getElementById("td0").className='';
  document.getElementById("td2").className='';
  document.getElementById("td3").className='';
  document.getElementById("td4").className='';
  document.getElementById("td5").className='';
  document.getElementById("td1").className='';
  document.getElementById("td8").className='';
 }
 else if (typenumber==7) {
  document.getElementById("td0").className='';
  document.getElementById("td1").className='';
  document.getElementById("td2").className='';
  document.getElementById("td3").className='';
  document.getElementById("td4").className='';
  document.getElementById("td5").className='';
  document.getElementById("td6").className='';
  document.getElementById("td8").className='';
 }
 else if (typenumber==8) {
  document.getElementById("td0").className='';
  document.getElementById("td1").className='';
  document.getElementById("td2").className='';
  document.getElementById("td3").className='';
  document.getElementById("td4").className='';
  document.getElementById("td5").className='';
  document.getElementById("td6").className='';
 }
 buttonselected = typenumber;
 if (windows[typenumber]==1) {
  win[typenumber].show();
  win[typenumber].toFront();
  Windows.focus(win[typenumber].getId());                    
  win[typenumber].show();
  win[typenumber].toFront();
  if (elements[0]) elements[0].className = "dock_icon";
  if (elements[1]) elements[1].className = "dock_icon";
  if (elements[2]) elements[2].className = "dock_icon";
  if (elements[3]) elements[3].className = "dock_icon";
  if (elements[4]) elements[4].className = "dock_icon";
  if (elements[5]) elements[5].className = "dock_icon";
  if (elements[6]) elements[6].className = "dock_icon";
  if (elements[7]) elements[7].className = "dock_icon";
  if (elements[8]) elements[8].className = "dock_icon";
  if (elements[typenumber]) elements[typenumber].className = "dock_iconover";
 }
 else {
  newWindow(typenumber,pagename);
 }
}
function newWindow(typenumber,pagename) {
 windows[typenumber]=1;

  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
myWidth = myWidth - windowleft - 25;
myHeight = myHeight - windowtop - 75;

 // dont open if dragging to new spot
 if (coordx[typenumber] != coordx2[typenumber] || coordy[typenumber] != coordy2[typenumber]) {}
 else if (startingpositionx != endingpositionx || startingpositiony != endingpositiony) {}
 else {
  // Show window if already opened
  // Create window
  nextwindowid = typenumber;
  var windowWidth = 0, windowHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    windowWidth = window.innerWidth;
    windowHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    windowWidth = document.documentElement.clientWidth;
    windowHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    windowWidth = document.body.clientWidth;
    windowHeight = document.body.clientHeight;
  }

  if (myHeight+windowtop>windowHeight-70) myHeight = windowHeight-windowtop;
  if (myWidth+windowleft>windowWidth-25) myWidth = windowWidth-windowleft-25;
  var zindexnumber = 10+typenumber;
  win[nextwindowid] = new Window({destroyOnClose: true, className: currentThemeName, blurClassName: currentBlurThemeName, title: titlecode[typenumber], width: myWidth, height: myHeight, top: windowtop, left: windowleft, zIndex: zindexnumber });

    win[nextwindowid].show();

   // update window content
		req = null;
                if (window.XMLHttpRequest) {
                        req = new XMLHttpRequest();
		}
                else if (window.ActiveXObject) {
                        req = new ActiveXObject("Microsoft.XMLHTTP");
		}

                req.onreadystatechange = function()
                {
                        if(req.readyState == 4)
                        {
                                if(req.status == 200)
                                {
					win[nextwindowid].getContent().update(req.responseText);
                                }
                        }
                };
                req.open("GET", "window"+typenumber+"Ajax.php?&windowidnum="+nextwindowid+"&pagename="+pagename+"&"+(new Date().getTime()), true);
                req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
                req.send(null);

      // Create a dock element
      elements[nextwindowid] = document.createElement("span");

      if (elements[0]) elements[0].className = "dock_icon";
      if (elements[1]) elements[1].className = "dock_icon";
      if (elements[2]) elements[2].className = "dock_icon";
      if (elements[3]) elements[3].className = "dock_icon";
      if (elements[4]) elements[4].className = "dock_icon";
      if (elements[5]) elements[5].className = "dock_icon";
      if (elements[6]) elements[6].className = "dock_icon";
      if (elements[7]) elements[7].className = "dock_icon";
      if (elements[8]) elements[8].className = "dock_icon";

      elements[nextwindowid].className = "dock_iconover";
      elements[nextwindowid].style.display = "none";
      elements[nextwindowid].win = win[nextwindowid];

      if ($('dock')) {
       $('dock').appendChild(elements[nextwindowid]);
       Event.observe(elements[nextwindowid], "mouseup", Windows.restore);
       if (win[nextwindowid]) {
        var title=win[nextwindowid].getTitle();
        var updatetitle=title;
        var pattern=/Welcome/gi;
        if (title.match(pattern)) updatetitle = titlecode2[0];
        var pattern=/Shoutcast/gi;
        if (title.match(pattern)) updatetitle = titlecode2[1];
        var pattern=/Icecast/gi;
        if (title.match(pattern)) updatetitle = titlecode2[2];
        var pattern=/Teamspeak 3/gi;
        if (title.match(pattern)) updatetitle = titlecode2[3];
        var pattern=/Teamspeak 2/gi;
        if (title.match(pattern)) updatetitle = titlecode2[4];
        var pattern=/Flash/gi;
        if (title.match(pattern)) updatetitle = titlecode2[5];
        var pattern=/Webhosting/gi;
        if (title.match(pattern)) updatetitle = titlecode2[6];
        var pattern=/Contact/gi;
        if (title.match(pattern)) updatetitle = titlecode2[7];
        var pattern=/Reseller/gi;
        if (title.match(pattern)) updatetitle = titlecode2[8];
        $(elements[nextwindowid]).update(updatetitle);
       }
       new Effect.Appear(elements[nextwindowid]);
      }

   // show window to front
   win[nextwindowid].toFront();
   // focus on it
   Windows.focus(win[nextwindowid].getId());                    
 }
}

Event.observe(window, "load", initWebOS)

