/* -----------------------------------------------------------------

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

	ventana = function(x,y,u){ 
		new MochaUI.Window({
			id: x,
			title: y,
			loadMethod: 'iframe',
			contentURL: u,
			width: 640,
			height: 480
		});
	}
	subventana = function(x,y,u){	
		new MochaUI.Window({
			id: x,
			title: y,
			loadMethod: 'xhr',
			contentURL: u,
			width: 750,
			height: 400

		});
	}
if($('programas'))
{
	$('programas').addEvent('click', function(e)
	{	
		new Event(e).stop();
		subventana('index_programas','programas','./mostrar.php?tabla=programas');
	});
};
if($('juegos'))
{
	$('juegos').addEvent('click', function(e)
	{	
		new Event(e).stop();
		subventana('index_juegos','juegos','./mostrar.php?tabla=juegos');
	});
};
if($('abandonware'))
{
	$('abandonware').addEvent('click', function(e)
	{	
		new Event(e).stop();
		subventana('index_abandonware','abandonware','./mostrar.php?tabla=abandonware');
	});
};
if($('series'))
{
	$('series').addEvent('click', function(e)
	{	
		new Event(e).stop();
		subventana('index_series','series','./mostrar.php?tabla=series');
	});
};
if($('peliculas'))
{
	$('peliculas').addEvent('click', function(e)
	{	
		new Event(e).stop();
		subventana('index_peliculas','peliculas','./mostrar.php?tabla=peliculas');
	});
};
if($('nes'))
{
	$('nes').addEvent('click', function(e)
	{	
		new Event(e).stop();
		subventana('index_nes','nes','./mostrar.php?tabla=nes');
	});
};
if($('musica'))
{
	$('musica').addEvent('click', function(e)
	{	
		new Event(e).stop();
		ventana('index_musica','Musica','http://spool.fm/');
	});
};
if($('msn'))
{
	$('msn').addEvent('click', function(e)
	{	
		new Event(e).stop();
		ventana('index_msn','msn','http://istanbul.ebuddy.com/vo7.4.8/start.html');
	});
};
if($('chat'))
{
	$('chat').addEvent('click', function(e)
	{	
		new Event(e).stop();
		ventana('index_chat','chat','aplicaciones/chat/');
	});
};	
		
	
	
	
	

	
	

	MochaUI.parametricsWindow = function(){	
		new MochaUI.Window({
			id: 'parametrics',
			title: 'Intro',
			loadMethod: 'xhr',
			contentURL: 'intro.html',
			onContentLoaded: function(){
				if ( !MochaUI.parametricsScript == true ){
					new Request({
						url: 'plugins/parametrics/scripts/parametrics.js',
						method: 'get',
						onSuccess: function() {
							MochaUI.addRadiusSlider.delay(10); // Delay is for IE6
							MochaUI.addShadowSlider.delay(10); // Delay is for IE6
							MochaUI.parametricsScript = false;
						}.bind(this)
					}).send();
				}
				else {
					MochaUI.addRadiusSlider.delay(10); // Delay is for IE6
					MochaUI.addShadowSlider.delay(10); // Delay is for IE6
				}
			},
			width: 305,
			height: 110,
			x: 230,
			y: 180,
			padding: { top: 12, right: 12, bottom: 10, left: 12 },
			resizable: false,
			maximizable: false,
			contentBgColor: '#fff'
		});
	}

	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: 570,
			y: 152,
			padding: { top: 0, right: 0, bottom: 0, left: 0 },
			bodyBgColor: [250,250,250]
		});	
	}
	if ($('clockLinkCheck')){
		$('clockLinkCheck').addEvent('click', function(e){
			new Event(e).stop();
			MochaUI.clockWindow();
		});
	}

	

	// Deactivate menu header links
	$$('a.returnFalse').each(function(el){
		el.addEvent('click', function(e){
			new Event(e).stop();
		});
	});

	// Build windows onDomReady
	MochaUI.parametricsWindow();
	if (!Browser.Engine.trident) {
		MochaUI.clockWindow();
	}
	else {
		MochaUI.clockWindow.delay(500);	
	}
	
}

// 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('Do Something');
	});
});	

// This runs when a person leaves your page.
window.addEvent('unload', function(){
	if (MochaUI) MochaUI.garbageCleanUp();
});
