Ext.onReady(function() 
{
	var links_window;
	var links_text = Ext.get('links-text');
	var links_image = Ext.get('links-image');
	
	var side_project_window;
	var side_project_text = Ext.get('side-project-text');
	var side_project_image = Ext.get('side-project-image');
	
	var resume_window;
	var resume_text = Ext.get('resume-text');
	var credits_window;
	var credits_text = Ext.get('credits-text');
	var terms_window;
	var terms_text = Ext.get('terms-text');		
	
	// TODO: since all these windows are almost the same we should be able to parameterize the creation of the function
	// for now we just brute force it
	var links_window_function = function()
	{
		// create the window on the first click and reuse on subsequent clicks
		if(!links_window)
		{
			links_window = new Ext.Window
			(
				{
					el:'links-window',
					layout:'fit',
					width:420,
					height:220,
					closeAction:'hide',
					plain: true,
					/*verticalScroll:true, nothing - autoScroll:true is both*/
					items: new Ext.Panel
					(
						{
							el: 'links-panel',
							autoTabs:true,
							activeTab:0,
							deferredRender:false,
							border:false
						}
					),							
					buttons: [{ text: 'Close', handler: function(){ links_window.hide();}}]
				}
			);
		}
		links_window.show(this);
	}
	
	var side_project_window_function = function()
	{
		// create the window on the first click and reuse on subsequent clicks
		if(!side_project_window)
		{
			side_project_window = new Ext.Window
			(
				{
					el:'side-project-window',
					layout:'fit',
					width:420,
					height:220,
					closeAction:'hide',
					plain: true,
					/*verticalScroll:true, nothing - autoScroll:true is both*/
					items: new Ext.Panel
					(
						{
							el: 'side-project-panel',
							autoTabs:true,
							activeTab:0,
							deferredRender:false,
							border:false
						}
					),							
					buttons: [{ text: 'Close', handler: function(){ side_project_window.hide();}}]
				}
			);
		}
		side_project_window.show(this);
	}		
	
	var resume_window_function = function()
	{
		// create the window on the first click and reuse on subsequent clicks
		if(!resume_window)
		{
			resume_window = new Ext.Window
			(
				{
					el:'resume-window',
					layout:'fit',
					width:420,
					height:220,
					closeAction:'hide',
					plain: true,
					/*verticalScroll:true, nothing - autoScroll:true is both*/
					items: new Ext.Panel
					(
						{
							el: 'resume-panel',
							autoTabs:true,
							activeTab:0,
							deferredRender:false,
							border:false
						}
					),							
					buttons: [{ text: 'Close', handler: function(){ resume_window.hide();}}]
				}
			);
		}
		resume_window.show(this);
	}	

	var credits_window_function = function()
	{
		// create the window on the first click and reuse on subsequent clicks
		if(!credits_window)
		{
			credits_window = new Ext.Window
			(
				{
					el:'credits-window',
					layout:'fit',
					width:420,
					height:220,
					closeAction:'hide',
					plain: true,
					autoScroll:true,
					items: new Ext.Panel
					(
						{
							el: 'credits-panel',
							autoTabs:true,
							activeTab:0,
							deferredRender:false,
							border:false
						}
					),							
					buttons: [{ text: 'Close', handler: function(){ credits_window.hide();}}]
				}
			);
		}
		credits_window.show(this);
	}			
	
	var terms_window_function = function()
	{
		// create the window on the first click and reuse on subsequent clicks
		if(!terms_window)
		{
			terms_window = new Ext.Window
			(
				{
					el:'terms-window',
					layout:'fit',
					width:420,
					height:220,
					closeAction:'hide',
					plain: true,
					autoScroll:true,
					items: new Ext.Panel
					(
						{
							el: 'terms-panel',
							autoTabs:true,
							activeTab:0,
							deferredRender:false,
							border:false
						}
					),							
					buttons: [{ text: 'Close', handler: function(){ terms_window.hide();}}]
				}
			);
		}
		terms_window.show(this);
	}			
		
	// wire up the onclick for the links window
	links_text.on('click', links_window_function);	
	links_image.on('click', links_window_function);	
	
	// wire up the onclick for the side projects
	side_project_text.on('click', side_project_window_function);
	side_project_image.on('click', side_project_window_function);
	
	// wire up
	resume_text.on('click', resume_window_function);	
	credits_text.on('click', credits_window_function);	
	terms_text.on('click', terms_window_function);	
});	