/* -----------------------------------------------------------------

	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(){

	// signin
		

	MochaUI.signinWindow = function(){
		new MochaUI.Window({
			id: 'signin',
			title: 'my.workspace log in',
			loadMethod: 'iframe',
			contentURL: 'butt.signin/main.php',
			width: 500,
			height: 250,
			resizeLimit: {'x': [500, 2500], 'y': [125, 2000]},
			
			onContentLoaded: function(windowEl){
				MochaUI.notification('log in window is loading.');
			},
			onCloseComplete: function(){
				MochaUI.notification('log in window is closed.');
			}

		});
	}
	if ($('signinLinkCheck')) {
		$('signinLinkCheck').addEvent('click', function(e){
		new Event(e).stop();
			MochaUI.signinWindow();
		});
	}
	
	
	// error
		

	MochaUI.errorWindow = function(){
		new MochaUI.Window({
			id: 'error',
			title: 'error - unauthorised access',
			loadMethod: 'iframe',
			contentURL: 'butt.error/main.html',
			width: 500,
			height: 170,
			resizeLimit: {'x': [500, 2500], 'y': [125, 2000]},
			
			onContentLoaded: function(windowEl){
				MochaUI.notification('error window is loading.');
			},
			onCloseComplete: function(){
				MochaUI.notification('error window is closed.');
			}

		});
	}
	if ($('errorLinkCheck')) {
		$('errorLinkCheck').addEvent('click', function(e){
		new Event(e).stop();
			MochaUI.errorWindow();
		});
	}
	
	// training
		

	MochaUI.trainingWindow = function(){
		new MochaUI.Window({
			id: 'training',
			title: 'training',
			loadMethod: 'iframe',
			contentURL: 'toolbar.training/intros',
			width: 600,
			height: 250,
			resizeLimit: {'x': [600, 2500], 'y': [125, 2000]},
			toolbar: true,
			toolbarURL: 'butt.training/tabs.html',
			onContentLoaded: function(windowEl){
				MochaUI.notification('training window is loading.');
			},
			onCloseComplete: function(){
				MochaUI.notification('training window is closed.');
			}

		});
	}
	if ($('trainingLinkCheck')) {
		$('trainingLinkCheck').addEvent('click', function(e){
		new Event(e).stop();
			MochaUI.trainingWindow();
		});
	}

	// network

	MochaUI.networkWindow = function(){
		new MochaUI.Window({
			id: 'network',
			title: 'network',
			loadMethod: 'iframe',
			contentURL: 'toolbar.network/name',
			width: 500,
			height: 250,
			resizeLimit: {'x': [500, 2500], 'y': [125, 2000]},
			toolbar: true,
			toolbarURL: 'butt.network/tabs.html',
			onContentLoaded: function(windowEl){
				MochaUI.notification('network window is loading.');
			},
			onCloseComplete: function(){
				MochaUI.notification('network window is closed.');
			}

		});
	}
	if ($('networkLinkCheck')) {
		$('networkLinkCheck').addEvent('click', function(e){
		new Event(e).stop();
			MochaUI.networkWindow();
		});
	}
	
	// projects
	
	MochaUI.projectsWindow = function(){
		new MochaUI.Window({
			id: 'projects',
			title: 'projects',
			loadMethod: 'iframe',
			contentURL: 'toolbar.projects/proposals',
			width: 500,
			height: 250,
			resizeLimit: {'x': [500, 2500], 'y': [125, 2000]},
			toolbar: true,
			toolbarURL: 'butt.projects/tabs.html',
			onContentLoaded: function(windowEl){
				MochaUI.notification('projects window is loading.');
			},
			onCloseComplete: function(){
				MochaUI.notification('projects window is closed.');
			}

		});
	}
	if ($('projectsLinkCheck')) {
		$('projectsLinkCheck').addEvent('click', function(e){
		new Event(e).stop();
			MochaUI.projectsWindow();
		});
	}
	
	// solutions
	
	MochaUI.solutionsWindow = function(){
		new MochaUI.Window({
			id: 'solutions',
			title: 'solutions store',
			loadMethod: 'iframe',
			contentURL: 'toolbar.solutions',
			width: 500,
			height: 250,
			resizeLimit: {'x': [500, 2500], 'y': [125, 2000]},
			onContentLoaded: function(windowEl){
				MochaUI.notification('solutions window is loading.');
			},
			onCloseComplete: function(){
				MochaUI.notification('solutions window is closed.');
			}

		});
	}
	if ($('solutionsLinkCheck')) {
		$('solutionsLinkCheck').addEvent('click', function(e){
		new Event(e).stop();
			MochaUI.solutionsWindow();
		});
	}
	
	// howto
	
	MochaUI.howtoWindow = function(){
		new MochaUI.Window({
			id: 'howto',
			title: 'how to..',
			loadMethod: 'iframe',
			contentURL: 'toolbar.howto/welcome',
			width: 570,
			height: 310,
			resizeLimit: {'x': [550, 2500], 'y': [125, 2000]},
			toolbar: true,
			toolbarURL: 'butt.howto/tabs.html',
			onContentLoaded: function(windowEl){
				MochaUI.notification('howto window is loading.');
			},
			onCloseComplete: function(){
				MochaUI.notification('howto window is closed.');
			}

		});
	}
	if ($('howtoLinkCheck')) {
		$('howtoLinkCheck').addEvent('click', function(e){
		new Event(e).stop();
			MochaUI.howtoWindow();
		});
	}
	
	
	// me
	
	MochaUI.meWindow = function(){
		new MochaUI.Window({
			id: 'me',
			title: 'me',
			loadMethod: 'iframe',
			contentURL: 'toolbar.me/myactions',
			width: 600,
			height: 250,
			resizeLimit: {'x': [600, 2500], 'y': [125, 2000]},
			toolbar: true,
			toolbarURL: 'butt.me/tabs.html',
			onContentLoaded: function(windowEl){
				MochaUI.notification('me window is loading.');
			},
			onCloseComplete: function(){
				MochaUI.notification('me window is closed.');
			}

		});
	}
	if ($('meLinkCheck')) {
		$('meLinkCheck').addEvent('click', function(e){
		new Event(e).stop();
			MochaUI.meWindow();
		});
	}
	
	// stats
	
	MochaUI.statsWindow = function(){
		new MochaUI.Window({
			id: 'stats',
			title: 'stats',
			loadMethod: 'iframe',
			contentURL: 'butt.stats',
			width: 500,
			height: 250,
			resizeLimit: {'x': [500, 2500], 'y': [125, 2000]},
			toolbar: true,
			toolbarURL: 'butt.stats/tabs.html',
			onContentLoaded: function(windowEl){
				MochaUI.notification('stats window is loading.');
			},
			onCloseComplete: function(){
				MochaUI.notification('stats window is closed.');
			}

		});
	}
	if ($('statsLinkCheck')) {
		$('statsLinkCheck').addEvent('click', function(e){
		new Event(e).stop();
			MochaUI.statsWindow();
		});
	}
	
	
	// badge
	
	MochaUI.badgeWindow = function(){
		new MochaUI.Window({
			id: 'badge',
			title: 'get a badge',
			loadMethod: 'iframe',
			contentURL: 'butt.badge/main.html',
			width: 500,
			height: 250,
			resizeLimit: {'x': [500, 2500], 'y': [125, 2000]},
			toolbar: true,
			toolbarURL: 'butt.badge/tabs.html',
			onContentLoaded: function(windowEl){
				MochaUI.notification('badge window is loading.');
			},
			onCloseComplete: function(){
				MochaUI.notification('badge window is closed.');
			}

		});
	}
	if ($('badgeLinkCheck')) {
		$('badgeLinkCheck').addEvent('click', function(e){
		new Event(e).stop();
			MochaUI.badgeWindow();
		});
	}
	
	// bugs
	
	MochaUI.bugsWindow = function(){
		new MochaUI.Window({
			id: 'bugs',
			title: 'bugs',
			loadMethod: 'iframe',
			contentURL: 'butt.bugs/main.html',
			width: 500,
			height: 250,
			resizeLimit: {'x': [500, 2500], 'y': [125, 2000]},
			toolbar: true,
			toolbarURL: 'butt.bugs/tabs.html',
			onContentLoaded: function(windowEl){
				MochaUI.notification('bugs window is loading.');
			},
			onCloseComplete: function(){
				MochaUI.notification('bugs window is closed.');
			}

		});
	}
	if ($('bugsLinkCheck')) {
		$('bugsLinkCheck').addEvent('click', function(e){
		new Event(e).stop();
			MochaUI.bugsWindow();
		});
	}
	
	//


	
	
	


	MochaUI.aboutWindow = function(){
		new MochaUI.Window({
			id: 'about',
			title: 'MochaUI',
			loadMethod: 'xhr',
			contentURL: 'pages/about.html',
			type: 'modal2',
			width: 350,
			height: 195,
			contentBgColor: '#e5e5e5 url(images/logo2.gif) left 3px no-repeat',
			padding: { top: 43, right: 12, bottom: 10, left: 12 },
			scrollbars:  false
		});
	}
	if ($('aboutLink')){
		$('aboutLink').addEvent('click', function(e){	
			new Event(e).stop();
			MochaUI.aboutWindow();
		});
	}

	// Deactivate menu header links
	$$('a.returnFalse').each(function(el){
		el.addEvent('click', function(e){
			new Event(e).stop();
		});
	});

	// Build windows onDomReady
	
	//edoooooooooooo
	MochaUI.howtoWindow();
	
}

// Initialize MochaUI when the DOM is ready
window.addEvent('domready', function(){
	MochaUI.Desktop = new MochaUI.Desktop();
	MochaUI.Dock = new MochaUI.Dock({
		dockPosition: 'bottom'
	});
	MochaUI.Modal = new MochaUI.Modal();
	
	MochaUI.Desktop.desktop.setStyles({
		'background': '#fff',
		'visibility': 'visible'
	});
	
	initializeWindows();
});

// This is just for the demo. Running it onload gives pngFix time to replace the pngs in IE6.
window.addEvent('load', function(){
	$$('.desktopIcon').addEvent('click', function(){
		//MochaUI.notification('working..');
	});
});	

// This runs when a person leaves your page.
window.addEvent('unload', function(){
	if (MochaUI) MochaUI.garbageCleanUp();
});
