/*
 * RaidsRUs
 * (c) 2006-2009 Rhyaehar
 * 
 * All rights explicitly reserved - unauthorized reproduction strictly prohibited
 */

// Site class - main active content wrapper
var Site = {
	start: function()
	{
		new SmoothScroll({duration:300, transition:Fx.Transitions.Expo.easeOut});
		this.externalLinks();
		
		if ($('raidplanner'))
			$('raidplanner').addEvent('click', function() { alert('Sorry, this doesn\'t work yet'); return false; });
		if ($('charactercrafting'))
			this.setupCraftingDisplay();
	},
	externalLinks: function()
	{
		$$('a').each(function(a) {
			if (a.get('href') != '' && a.get('rel') == 'external')
			a.set('target', '_blank');
		});
	},
	setupCraftingDisplay: function()
	{
		this.craftingDisplayTabs	= new Element('ol', {'id':'craftingdisplay'}).inject($('charactercrafting'), 'top');
		$('charactercrafting').getChildren('div.craftingprofession').each(function(c){
			var li	= new Element('li', {'id':c.get('id').replace('panel-','tab-')}).inject($('craftingdisplay'));
			var a	= new Element('a', {'id':c.get('id').replace('panel-',''), 'text':c.getFirst('h5').get('text')}).inject(li);
			a.addEvent('click', function() {
				$$('div.craftingprofession').each(function(p){
					p.setStyle('display','none');
					$(p.get('id').replace('panel-','tab-')).removeClass('active');
				}.bind(this));
				a.getParent().addClass('active');
				$('panel-'+a.get('id')).setStyle('display', '');
			}.bind(this));
			c.setStyle('display','none');
			$(c.get('id').replace('panel-', '')).removeClass('active');
		}.bind(this));
		var first	= this.craftingDisplayTabs.getFirst('li');
		first.setStyle('margin-left','4px');
		first.toggleClass('active');
		$(first.get('id').replace('tab-','panel-')).setStyle('display', '');
	}
};

// Set event to start running active content when DOM is loaded
window.addEvent('domready', function() { Site.start(); });
