var Section = Class.create({
	// Elements
	section: null,
	title: null,
	content: null,
	arrow: null,
	
	// Properties
	opened: null,
	locked: false,
	
	initialize: function(element, opened)
	{
		this.section = $(element);
		this.opened = ( opened != undefined ) ? opened : true;
		
		this.title = this.section.down('div.section-title');
		this.content = this.section.down('div.section-content');
		
		this.arrow = this.title.down('a.section-arrow img');
		
		this.title.down('a.section-arrow').observe('click', this.click.bind(this));
		this.title.down('a.section-open-close').observe('click', this.click.bind(this));
		
		// Temporary mod
		this.title.down('a.section-open-close').hide();
		
		if ( this.opened )
		{
			this.makeOpen();
		}
		else
		{
			this.makeClosed();
			
			this.content.setStyle({
				display: 'none'
			});
		}
	},
	
	click: function()
	{
		if ( this.locked )
		{
			return;
		}
		
		this.locked = true;
		this.toggle();
	},
	
	toggle: function()
	{
		if ( this.opened )
		{
			
			this.makeClosed();
			this.arrow.fire('section:closing');
			
			new Effect.BlindUp(this.content, {
				afterFinish: this.effectsComplete.bind(this),
				duration: 1.5,
				transition: Effect.Transitions.slowstop
			});
		}
		else
		{
			this.makeOpen();
			this.arrow.fire('section:opening');
			
			new Effect.BlindDown(this.content, {
				afterFinish: this.effectsComplete.bind(this),
				duration: 1.5,
				transition: Effect.Transitions.slowstop
			});
		}
	},
	
	effectsComplete: function()
	{
		this.arrow.fire(( this.opened ) ? 'section:opened' : 'section:closed');
		this.locked = false;
	},
	
	makeOpen: function()
	{
		// Change the section
		this.section.removeClassName('section-closed');
		this.section.addClassName('section-open');
		
		// Change the arrow
		this.arrow.src = "http://us-cdn.creamermedia.co.za/template/mw/section_arrow_open.png";
		Images.fix(this.arrow);
		
		// Change the content styling
		this.content.setStyle({marginBottom: '1px'});
		
		this.opened = true;
	},
	
	makeClosed: function()
	{
		// Change the section
		this.section.removeClassName('section-open');
		this.section.addClassName('section-closed');
		
		// Change the arrow
		this.arrow.src = "http://us-cdn.creamermedia.co.za/template/mw/section_arrow_closed.png";
		Images.fix(this.arrow);
		
		// Change the content styling
		this.content.setStyle({marginBottom: ''});
		
		this.opened = false;
	}
});