var Reflections = Class.create(
{
	initialize: function()
	{
		this.name = "Reflections";
		
		$('controlUl').observe('click', this.controlUlClick.bindAsEventListener(this));
		Event.observe(window, 'resize', this.resize.bindAsEventListener(this));
		document.observe('dom:loaded', this.resize.bindAsEventListener(this));
		document.observe('dom:loaded', this.loadContent.bindAsEventListener(this));
	},
	
	controlUlClick: function(event)
	{
		var element = event.element();
		var content = element.readAttribute('content');
		
		if (content == 'gallery')
		{
			window.location.assign('http://reflectionsbyeddie.smugmug.com/');
		}
		else if (content == 'blog')
		{
			window.location.assign('http://reflectionsbyeddie.blogspot.com/');
		}
		else
		{
			this.redirectContent(content);
		}
	},
				
	
	resize: function(event)
	{
		var picFrameDiv = $('picFrameDiv');
		var headerDiv = $('headerDiv');
		var contentDiv = $('contentDiv');
		
		var h = picFrameDiv.getHeight();
		h  = h  - headerDiv.getHeight();
		
		h = h - 4; //4 = picFrameDiv border width
		h = h - 15; // content div padding
		h = h - 15; //copyright
		
		contentDiv.setStyle(
		{
			height: h + 'px'
		});
	},
	
	loadContent: function(event)
	{
		$('controlUl').select('li').invoke('removeClassName', 'selected');
		
		var content = $('contentTypeHidden').value;		
		switch (content)
		{
			case 'about':
			case 'suggestions':
			case 'contact':
			case 'faq':
				break;
			default:
				content = 'home';
		}
		
		this.redirectContent(content);
	},
	
	redirectContent: function(content)
	{
		$('contentTypeHidden').value = content;
		
		$('controlUl').select('li').invoke('removeClassName', 'selected');
		$('controlUl').down('li[content="' + content + '"]').addClassName('selected');
		var url = 'content/' + content + '.html';
			
		new Ajax.Request(url, 
		{
			method: 'get',
			onSuccess: function(transport) 
			{
				new Effect.Fade($('contentDiv'),
				{
					duration: 0.3,
					queue: 
					{
						position: 'front',
						scope: 'contentDivScope'
					},
					afterFinish: function()
					{
						$('contentDiv').update(transport.responseText);
					},
					from: 1,
					to: 0
				});				
				new Effect.Appear($('contentDiv'), 
				{
					duration: 0.3,
					queue: 
					{
						position: 'end',
						scope: 'contentDivScope'
					},
					from: 0,
					to: 1,
					afterFinish: function()
					{
						$('contentDiv').show();
						$('copyrightDiv').show();
					}
				});
				
			}
		});
	}
	
});

