// 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 - 64;
  return size;
};    


// Overide Windows minimize to move window inside dock  
Object.extend(Windows, {
  // Overide minimize function
  minimize: function(id, event) {
    var win = this.getWindow(id)
    if (win && win.visible) {
      // Hide current window
      win.hide();            
    
      // Create a dock element
      var element = document.createElement("span");
      element.className = "dock_icon"; 
      element.style.display = "none";
      element.win = win;
      $('dock').appendChild(element);
      Event.observe(element, "mouseup", Windows.restore);
      $(element).update(win.getTitle());
    
      new Effect.Appear(element)
    }
    Event.stop(event);
  },                 
  
  // Restore function
  restore: function(event) { 
    var element = Event.element(event);
    // Show window
    element.win.show();
    //Windows.focus(element.win.getId());                    
    element.win.toFront();
    // Fade and destroy icon
    new Effect.Fade(element, {afterFinish: function() {element.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 = 0;
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";
      break;
    case 1:
      theme = "bluelighting";
      blurTheme = "greylighting";
      break;
    case 2:
      theme = "greenlighting";
      blurTheme = "greylighting";
      break;
  }
  Windows.windows.each(function(win) {
    win.options.focusClassName = theme; 
    win.options.blurClassName = blurTheme;
    win.changeClassName(blurTheme)
  });
  Windows.focusedWindow.changeClassName(theme);
  currentTheme = index;
}

WinW = window.innerWidth;
WinH = window.innerHeight;

function wellcome() {         
    var win = new Window({
		className: 			"mac_os_x",
		blurClassName: 		"mac_os_x",
		title: 				"Bem vindo!",
		closable:       	false,
		minimizable:       	false,
        maximizable:      	false,
		width:				640,
		height:				430
		}); 
    win.setURL("wellcome.asp")
    win.showCenter(); 
}

function autorama() {
if (!$("autorama")) {	
	var win = new Window({
		id:					"autorama",
		className: 			"mac_os_x",
		blurClassName: 		"mac_os_x",
		title: 				"AUTORAMA",
		closable:       	true,
		minimizable:       	true,
		maximizable:       	false,
		resizable:      	false,
		width:				600,
		height:				300,
		});
    win.setURL("autorama.asp?a=1")
    win.showCenter(); 
	}
}

function empire() {
if (!$("empire")) {	
	var win = new Window({
		id:					"empire",
		className: 			"mac_os_x",
		blurClassName: 		"mac_os_x",
		title: 				"EMPIRE",
		closable:       	true,
		minimizable:       	true,
		maximizable:       	false,
		resizable:      	false,
		width:				600,
		height:				300,
		});
    win.setURL("empire.asp?a=1")
    win.showCenter(); 
	}
}

function rss() {
if (!$("rss")) {	
	var win = new Window({
		id:					"rss",
		className: 			"mac_os_x",
		blurClassName: 		"mac_os_x",
		title: 				"RSS",
		closable:       	true,
		minimizable:       	true,
		maximizable:       	false,
		resizable:      	false,
		width:				WinW - 100,
		height:				WinH - 220,
		});
    win.setURL("rss_home.asp?w=" + (WinW-168) + "&h=" + (WinH-430));
    win.showCenter(); 
	}
}

function calendario() {
if (!$("calendario")) {	
	var win = new Window({
		id:					"calendario",
		className: 			"mac_os_x",
		blurClassName: 		"mac_os_x",
		title: 				"CALEND&Aacute;RIO",
		closable:       	true,
		minimizable:       	true,
		maximizable:       	true,
		resizable:      	true,
		width:				WinW - 140,
		height:				WinH - 220,
		});
    win.setURL("http://www.codeorama.com/sazonal")
    win.showCenter(); 
	}
}

function viewrss(pag) {
if (!$("viewrss")) {	
	var win = new Window({
		id:					"viewrss",
		className: 			"mac_os_x",
		blurClassName: 		"mac_os_x",
		title: 				"RSS",
		closable:       	true,
		minimizable:       	true,
		maximizable:       	true,
		resizable:      	true,
		width:				700,
		height:				450,
		});
    win.setURL(pag)
    win.showCenter();
	}
}

function config() {
if (!$("config")) {	
	var win = new Window({
		id:					"config",
		className: 			"mac_os_x",
		blurClassName: 		"mac_os_x",
		title: 				"CONFIGURA&Ccedil;&Atilde;O",
		closable:       	true,
		minimizable:       	false,
		maximizable:       	false,
		resizable:      	false,
		width:				500,
		height:				320,
		});
    win.setURL("config_home.asp")
    win.showCenter(); 
	}
}

function termo() {         
if (!$("termo")) {	
	var win = new Window({
		id:					"termo",
		className: 			"mac_os_x",
		blurClassName: 		"mac_os_x",
		title: 				"TERMO DE USO",
		closable:       	true,
		minimizable:       	false,
		maximizable:       	false,
		width:				500,
		height:				400,
		top:				64
		});
    win.setURL("termo.asp")
    win.show(); 
	}
}

function privacidade() {         
if (!$("privacidade")) {	
	var win = new Window({
		id:					"privacidade",
		className: 			"mac_os_x",
		blurClassName: 		"mac_os_x",
		title: 				"PRIVACIDADE",
		closable:       	true,
		minimizable:       	false,
		maximizable:       	false,
		width:				500,
		height:				400,
		top:				64
		});
    win.setURL("privacidade.asp")
    win.show(); 
	}
}

function adm() {
if (!$("adm")) {	
    var win = new Window({
		id:					"adm",
		className: 			"mac_os_x",
		blurClassName: 		"mac_os_x",
		title: 				"ADM",
		url:				"adm_home.asp",
		closable:       	true,
		minimizable:       	true,
		maximizable:       	true,
		width:				WinW - 140,
		height:				WinH - 220,
		top:				64
		}); 
    win.showCenter();
	}
}

function banco() {
if (!$("banco")) {	
    var win = new Window({
		id:					"banco",
		className: 			"mac_os_x",
		blurClassName: 		"mac_os_x",
		title: 				"BANCO",
		url:				"adm/default.asp",
		closable:       	true,
		minimizable:       	true,
		maximizable:       	true,
		width:				WinW - 140,
		height:				WinH - 220,
		top:				64
		}); 
    win.showCenter();
	}
}

function banco2() {
if (!$("banco2")) {	
    var win = new Window({
		id:					"banco2",
		className: 			"mac_os_x",
		blurClassName: 		"mac_os_x",
		title: 				"BANCO 2",
		url:				"adm_noticias/default.asp",
		closable:       	true,
		minimizable:       	true,
		maximizable:       	true,
		width:				WinW - 140,
		height:				WinH - 220,
		top:				64
		}); 
    win.showCenter();
	}
}

function oauth() {
if (!$("oauth")) {	
    var win = new Window({
		id:					"oauth",
		className: 			"mac_os_x",
		blurClassName: 		"mac_os_x",
		title: 				"oAuth",
		url:				"oauth.asp",
		closable:       	true,
		minimizable:       	true,
		maximizable:       	true,
		width:				500,
		height:				400,
		top:				64
		}); 
    win.showCenter();
	}
}
