/* -----------------------------------------------------------------

	In this file:
	
	1. Define windows
	
		var myWindow = function(){ 
			new MochaUI.Window({
				id: 'mywindow',
				title: 'My Window',
				loadMethod: 'xhr',
				contentURL: 'pages/lipsum.html',
				width: 340,
				height: 150
			});
		}	
	
	2. Build windows on onDomReady
	
		myWindow();
	
	3. Add link events to build future windows
	
		if ($('myWindowLink')){
			$('myWindowLink').addEvent('click', function(e) {
				new Event(e).stop();
				jsonWindows();			
			});
		}	
		
		Note: If your link is in the top menu, it opens only a single window, and you would
		like a check mark next to it when it's window is open, format the link name as follows:
		
		window.id + LinkCheck, e.g., mywindowLinkCheck
		
		Otherwise it is suggested you just use mywindowLink
	
	Associated HTML for link event above:
	
		<a id="myWindowLink" href="pages/lipsum.html">My Window</a>	

	
	Notes:
		If you need to add link events to links within windows you are creating, do
		it in the onContentLoaded function of the new window.


   ----------------------------------------------------------------- */

initializeWindows = function(){

	var windowWidth = getClientWidth();
	var windowHeight = getClientHeight();

	// Corporate Overview
	MochaUI.corporateOverviewWindow = function(){ 
		new MochaUI.Window({
			id: 'corporateOverviewPage',
			title: 'Universal Curve LLC Corporate Overview',
			loadMethod: 'xhr',
			contentURL: 'pages/overview.html',
			width: 640,
			height: 480
		});
	}	
	if ($('corporateOverview')){ 
		$('corporateOverview').addEvent('click', function(e){	
			new Event(e).stop();
			MochaUI.corporateOverviewWindow();
		});
	}

	// Sepulveda Systems
	MochaUI.sepulvedaSystemsWindow = function(){ 
		new MochaUI.Window({
			id: 'sepulvedaSystemsPage',
			title: 'Sepulveda Systems &#8480;',
			loadMethod: 'xhr',
			contentURL: 'pages/sepulvedasystems.html',
			width: 640,
			height: 480
		});
	}	
	if ($('sepulvedaSystems')){ 
		$('sepulvedaSystems').addEvent('click', function(e){	
			new Event(e).stop();
			MochaUI.sepulvedaSystemsWindow();
		});
	}	

	// Vizible
	MochaUI.vizibleWindow = function(){ 
		new MochaUI.Window({
			id: 'viziblePopup',
			title: 'Vizible &#8480;',
			loadMethod: 'xhr',
			contentURL: 'pages/vizible.html',
			width: 640,
			height: 480
		});
	}	
	if ($('vizible')){ 
		$('vizible').addEvent('click', function(e){	
			new Event(e).stop();
			MochaUI.vizibleWindow();
		});
	}	

	// Basecamp client login
	MochaUI.basecampLoginWindow = function() {
		new MochaUI.Window({
			id: 'basecampPopup',
			title: 'Universal Curve: Project Management',
			loadMethod: 'iframe',
			contentURL: 'http://universalcurve.basecamphq.com',
			width: 1024,
			height: 768,
		});
	}
	if ($('basecampLogin')){
		$('basecampLogin').addEvent('click', function(e){
		new Event(e).stop();
			MochaUI.basecampLoginWindow();
		});
	}

	// Relevant Searches
	MochaUI.relevantSearchesWindow = function(){
		new MochaUI.Window({
			id: 'relevantSearchesFrame',
			title: 'Relevant Searches',
			loadMethod: 'iframe',
			contentURL: 'http://www.relevantsearches.com/',
			width: 1000,
			height: 480			
		});
	}
	if ($('relevantSearches')) {
		$('relevantSearches').addEvent('click', function(e){
		new Event(e).stop();
			MochaUI.relevantSearchesWindow();
		});
	}	

	// Booyah
	MochaUI.booyahNetworksWindow = function(){
		new MochaUI.Window({
			id: 'booyahNetworksFrame',
			title: 'Booyah Networks',
			loadMethod: 'iframe',
			contentURL: 'http://www.booyahnetworks.com/',
			width: 800,
			height: 480			
		});
	}
	if ($('booyahNetworks')) {
		$('booyahNetworks').addEvent('click', function(e){
		new Event(e).stop();
			MochaUI.booyahNetworksWindow();
		});
	}	

	// PSI
	MochaUI.programmedScientificWindow = function(){
		new MochaUI.Window({
			id: 'programmedScientificFrame',
			title: 'Programmed Scientific Instruments',
			loadMethod: 'iframe',
			contentURL: 'http://www.programmedscientific.com/',
			width: 500,
			height: 300			
		});
	}
	if ($('programmedScientific')) {
		$('programmedScientific').addEvent('click', function(e){
		new Event(e).stop();
			MochaUI.programmedScientificWindow();
		});
	}	

	// Escom
	MochaUI.escomWindow = function(){
		new MochaUI.Window({
			id: 'escomFrame',
			title: 'Escom',
			loadMethod: 'iframe',
			contentURL: 'http://www.escomllc.com/',
			width: 400,
			height: 250			
		});
	}
	if ($('escom')) {
		$('escom').addEvent('click', function(e){
		new Event(e).stop();
			MochaUI.escomWindow();
		});
	}	

	// Fluidesign
	MochaUI.fluidesignWindow = function(){
		new MochaUI.Window({
			id: 'fluidesignFrame',
			title: 'fluidesign',
			loadMethod: 'iframe',
			contentURL: 'http://www.fluidesign.com/',
			width: 800,
			height: 600			
		});
	}
	if ($('fluidesign')) {
		$('fluidesign').addEvent('click', function(e){
		new Event(e).stop();
			MochaUI.fluidesignWindow();
		});
	}	

	// Long Now
	MochaUI.longNowWindow = function(){
		new MochaUI.Window({
			id: 'longNowFrame',
			title: 'The Long Now Foundation',
			loadMethod: 'iframe',
			contentURL: 'http://www.longnow.org/',
			width: 800,
			height: 480			
		});
	}
	if ($('longNow')) {
		$('longNow').addEvent('click', function(e){
		new Event(e).stop();
			MochaUI.longNowWindow();
		});
	}	

	// GEC Media
	MochaUI.gecMediaWindow = function(){
		new MochaUI.Window({
			id: 'gecMediaFrame',
			title: 'GEC Media',
			loadMethod: 'iframe',
			contentURL: 'http://www.gecmedia.com/',
			width: 900,
			height: 480			
		});
	}
	if ($('gecMedia')) {
		$('gecMedia').addEvent('click', function(e){
		new Event(e).stop();
			MochaUI.gecMediaWindow();
		});
	}	

	// CarrierConnect
	MochaUI.carrierConnectWindow = function(){
		new MochaUI.Window({
			id: 'carrierConnectFrame',
			title: 'CarrierConnect',
			loadMethod: 'iframe',
			contentURL: 'http://www.carrierconnect.com/',
			width: 1024,
			height: 480			
		});
	}
	if ($('carrierConnect')) {
		$('carrierConnect').addEvent('click', function(e){
		new Event(e).stop();
			MochaUI.carrierConnectWindow();
		});
	}	

	MochaUI.clockWindow = function(){	
		new MochaUI.Window({
			id: 'clock',
			title: 'Canvas Clock',
			addClass: 'transparent',			
			loadMethod: 'xhr',
			contentURL: 'plugins/coolclock/index.html?t=' + new Date().getTime(),
			onContentLoaded: function(){				
				if ( !MochaUI.clockScript == true ){
					new Request({
						url: 'plugins/coolclock/scripts/coolclock.js?t=' + new Date().getTime(),
						method: 'get',
						onSuccess: function() {							
							if (Browser.Engine.trident) {	
								myClockInit = function(){
									CoolClock.findAndCreateClocks();
								};
								window.addEvent('domready', function(){
									myClockInit.delay(10); // Delay is for IE
								});
								MochaUI.clockScript = true;
							}
							else {
								CoolClock.findAndCreateClocks();
							}						
						}.bind(this)							
					}).send();					
				}
				else {							
					if (Browser.Engine.trident) {	
						myClockInit = function(){
							CoolClock.findAndCreateClocks();
						};
						window.addEvent('domready', function(){
							myClockInit.delay(10); // Delay is for IE
						});
						MochaUI.clockScript = true;
					}
					else {
						CoolClock.findAndCreateClocks();
					}
				}				
			},
			shape: 'gauge',
			headerHeight: 30,			
			width: 160,
			height: 160,
			x: 1024,
			y: 75,
			padding: { top: 0, right: 0, bottom: 0, left: 0 },
			bodyBgColor: [250,250,250]
		});	
	}

	// View
	if ($('sidebarLinkCheck')){
		$('sidebarLinkCheck').addEvent('click', function(e){	
			new Event(e).stop();
			MochaUI.Desktop.sidebarToggle();
		});
	}
	
	if ($('cascadeLink')){
		$('cascadeLink').addEvent('click', function(e){	
			new Event(e).stop();
			MochaUI.arrangeCascade();
		});
	}
	
	if ($('tileLink')){
		$('tileLink').addEvent('click', function(e){	
			new Event(e).stop();
			MochaUI.arrangeTile();
		});
	}	
	
	if ($('closeLink')){
		$('closeLink').addEvent('click', function(e){	
			new Event(e).stop();
			MochaUI.closeAll();
		});
	}
	
	if ($('minimizeLink')){
		$('minimizeLink').addEvent('click', function(e){	
			new Event(e).stop();
			MochaUI.minimizeAll();
		});
	}	
	
	// Help

	MochaUI.docsWindow = function(){
			new MochaUI.Window({
				id: 'docs',
				title: 'Documentation',
				loadMethod: 'xhr',
				contentURL: 'pages/docs.html',
				width: 750,
				height: 350,
				padding: [10,10,10,10,10]
			});
	}
	if ($('docsLinkCheck')){
		$('docsLinkCheck').addEvent('click', function(e){	
			new Event(e).stop();
			MochaUI.docsWindow();
		});
	}	
	
	MochaUI.resourcesWindow = function(){
			new MochaUI.Window({
				id: 'resources',
				title: 'Resources',
				loadMethod: 'xhr',
				contentURL: 'pages/resources.html',
				width: 300,
				height: 275,
				x: 20,
				y: 70
			});
	}
	if ($('resourcesLinkCheck')){
		$('resourcesLinkCheck').addEvent('click', function(e){	
			new Event(e).stop();
			MochaUI.resourcesWindow();
		});
	}	

	MochaUI.helpWindow = function(){
			new MochaUI.Window({
				id: 'help',
				title: 'Support',
				loadMethod: 'xhr',
				contentURL: 'pages/support.html',
				width: 320,
				height: 320,
				x: 20,
				y: 70
			});
	}
	if ($('helpLinkCheck')){
		$('helpLinkCheck').addEvent('click', function(e){	
			new Event(e).stop();
			MochaUI.helpWindow();
		});
	}	

	MochaUI.aboutWindow = function(){
		new MochaUI.Window({
			id: 'about',
			title: '&copy; Universal Curve LLC, 2006-2009',
			loadMethod: 'xhr',
			contentURL: 'pages/about.html',
			type: 'modal',
			minimizable: false,
			width: 300,
			height: 150
		});
	}
	if ($('aboutUs')){
		$('aboutUs').addEvent('click', function(e){	
			new Event(e).stop();
			MochaUI.aboutWindow();
		});
	}

	/*
	Privacy
	*/
	MochaUI.privacyWindow = function(){
		new MochaUI.Window({
			id: 'privacyPopup',
			title: '&copy; Universal Curve LLC, 2006-2009',
			loadMethod: 'xhr',
			contentURL: 'pages/privacy.html',
			type: 'modal',
			minimizable: false,
			width: 600,
			height: 450
		});
	}
	if ($('privacy')){
		$('privacy').addEvent('click', function(e){	
			new Event(e).stop();
			MochaUI.privacyWindow();
		});
	}

	/*
	Returns
	*/
	MochaUI.returnsWindow = function(){
		new MochaUI.Window({
			id: 'returnsPopup',
			title: '&copy; Universal Curve LLC, 2006-2009',
			loadMethod: 'xhr',
			contentURL: 'pages/returns.html',
			type: 'modal',
			minimizable: false,
			width: 600,
			height: 450
		});
	}
	if ($('returns')){
		$('returns').addEvent('click', function(e){	
			new Event(e).stop();
			MochaUI.returnsWindow();
		});
	}

	/*
	Terms of Service
	*/
	MochaUI.tosWindow = function(){
		new MochaUI.Window({
			id: 'tosPopup',
			title: '&copy; Universal Curve LLC, 2006-2009',
			loadMethod: 'xhr',
			contentURL: 'pages/tos.html',
			type: 'modal',
			minimizable: false,
			width: 600,
			height: 450
		});
	}
	if ($('tos')){
		$('tos').addEvent('click', function(e){	
			new Event(e).stop();
			MochaUI.tosWindow();
		});
	}

	/*
	Copyright Disputes
	*/
	MochaUI.copyrightDisputesWindow = function(){
		new MochaUI.Window({
			id: 'copyrightDiputesPopup',
			title: '&copy; Universal Curve LLC, 2006-2009',
			loadMethod: 'xhr',
			contentURL: 'pages/copyright_disputes.html',
			type: 'modal',
			minimizable: false,
			width: 600,
			height: 450
		});
	}
	if ($('copyrightDisputes')){
		$('copyrightDisputes').addEvent('click', function(e){	
			new Event(e).stop();
			MochaUI.copyrightDisputesWindow();
		});
	}

	/*
	Acceptable Use Policy
	*/
	MochaUI.aupWindow = function(){
		new MochaUI.Window({
			id: 'aupPopup',
			title: '&copy; Universal Curve LLC, 2006-2009',
			loadMethod: 'xhr',
			contentURL: 'pages/aup.html',
			type: 'modal',
			minimizable: false,
			width: 600,
			height: 450
		});
	}
	if ($('aup')){
		$('aup').addEvent('click', function(e){	
			new Event(e).stop();
			MochaUI.aupWindow();
		});
	}

	MochaUI.etymologyWindow = function(){
		new MochaUI.Window({
			id: 'etymology',
			title: 'Universal Curve: Etymology of the name',
			loadMethod: 'xhr',
			contentURL: 'pages/etymology.html',
			width: 320,
			height: 200
		});
	}
	if ($('nameEtymology')){
		$('nameEtymology').addEvent('click', function(e){	
			new Event(e).stop();
			MochaUI.etymologyWindow();
		});
	}
	
	// Deactivate menu header links
	$$('a.returnFalse').each(function(el){
		el.addEvent('click', function(e){
			new Event(e).stop();
		});
	});

	MochaUI.contactWindow = function(){
		new MochaUI.Window({
			id: 'contact',
			title: 'Contact Universal Curve',
			loadMethod: 'iframe',
			contentURL: 'pages/contact.php',
			type: 'modal',
			minimizable: false,
			width: 640,
			height: 480
		});
	}
	if ($('contactUs')){
		$('contactUs').addEvent('click', function(e){	
			new Event(e).stop();
			MochaUI.contactWindow();
		});
	}
	
	// Deactivate menu header links
	$$('a.returnFalse').each(function(el){
		el.addEvent('click', function(e){
			new Event(e).stop();
		});
	});
	
	// Build windows onDomReady
	//MochaUI.clockWindow();
	
}

// Initialize MochaUI when the DOM is ready
window.addEvent('domready', function(){									 
	MochaUI.Desktop = new MochaUI.Desktop();									 
	MochaUI.Dock = new MochaUI.Dock();	
	MochaUI.Modal = new MochaUI.Modal();
	initializeWindows();
});


// This runs when a person leaves your page.
window.addEvent('unload', function(){
	if (MochaUI) MochaUI.garbageCleanUp();
});

function getClientWidth() {
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}

function getClientHeight() {
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}
