/**
*	@package		Classical BRITs
*	@subpackage		Models
*	@author			Ben Sekulowicz-Barclay
*	@copyright		Copyright 2008, Outside Line.
*	@version		0.1
*
************************************************************************************************************************ **/

var hellocharlie = Class.create({
	
	onLoad: 0,
	
	/* ****************************************************************************************************************** */
	
	initialize: function() {
		// When the page loads, look for the 'nominations' list element
		document.observe('dom:loaded', function(e) {
						
			// Set-up shadowbox
			Shadowbox.init({ 
				animSequence: 'sync',
				flvPlayer: base_url + 'assets/swf/player.swf',
				loadingImage: base_url + 'assets/img/sbLoading.gif',
				overlayBgImage: base_url + 'assets/img/sbOverlay-85.png'
			});
			
			// Set-up the expanding triggers
			$$('ol#content > li > h2').each(function(h2) {
				// Add class
				h2.addClassName('closed');

				// Add event observer
				Event.observe(h2, 'click', this.onClickTrigger.bindAsEventListener(this));
			}.bind(this));

			// Set up the expanding list
			$$('ol#content > li > div.expanded').invoke('hide');

			// Check the URL and make sure we don't need to do anything
			this.testUrl();			
		}.bindAsEventListener(this));
	},
	
	/* ****************************************************************************************************************** */
	
	onClickTrigger: function(e) {
		// Get the ID
		var id = Event.findElement(e, 'h2').up('li').getAttribute('id')
		
		// Run the SetUrl functionality to show/hide the list
		this.setUrl(id);
	},	
	
	/* ****************************************************************************************************************** */
	
	testUrl: function() {
		var u = this.getUrl();
		
		if (u != '') {
			document.location.href = '#/';
			this.setUrl(u);
		}
	},
	
	/* ****************************************************************************************************************** */
	
	setUrl: function(u) {
		// Get the current URL
		var x = this.getUrl();
		
		// If we have an ID to close ...
		if ((x) && (x != '')) {
			// Hide the list and update the URL
			Effect.BlindUp($(x).down('div.expanded'), {duration: 0.8 });
			document.location.href = '#/';
			
			// Modify the title class
			$(x).down('h2').removeClassName('open');
			$(x).down('h2').addClassName('closed');
		}
		
		// if we have an ID to open ...
		if ((u) && (u != x) && (u != '')) {
			// Show the list and update the URL
			Effect.BlindDown($(u).down('div.expanded'), {duration: 0.8 });
			
			document.location.href = '#/' + u;
			
			// Modify the title class
			$(u).down('h2').removeClassName('closed');
			$(u).down('h2').addClassName('open');
		}
	},
	
	/* ****************************************************************************************************************** */
	
	getUrl: function() {
		// break the URL on the #
		var href = document.location.href.split('#');
		
		// If we have an extra part,
		if ((href.size() == 2) && ($(href[1].sub('/', '')))) { return(href[1].sub('/', '')); }
		
		return '';
	}
});
