var ImpactList = new Class({
	Implements: [Events, Options],
	options: 
	{
		requestOptions: {},
		onComplete: $empty,
		timer:0,
		bheight:250,
		sheight:50,
		expand:1
	},
	initialize: function(boxes, options) 
	{
		this.setOptions(options);
		this.rightdivs = $$(boxes);
		this.showlist();
		this.showorange();
		if($('back')) $('back').setStyle('opacity', 0);
	},

	showlist: function() 
	{
		var thisc = this;
		timer = this.options.timer;
		bheight = this.options.bheight;
		sheight = this.options.sheight;
		expand = this.options.expand;
		rightdivs = this.rightdivs;
		rightdivs.each(function(item, i) 
		{
			item.setStyles({'cursor':'pointer', 'opacity':0, 'display':'block', 'min-height':sheight});
			item.store('text', item.getElement('div').get('html'));
			item.store('expand', 0);
			item.addEvents({
				'mouseover': function() 
				{
					this.addClass('itemhover');
					this.setStyle('background-color', '#f1f1f1'); 
				},
				'mouseout': function()
				{
					this.removeClass('itemhover');
					this.setStyle('background-color', '#ffffff'); 
				},
				'click': function(e) 
				{
					if(e.target.tagName == 'A' && e.target.parentNode.tagName == 'P') {
						window.open(e.target.href, 'newwindow');
					} 
					
					if(expand == 1) 
					{
						if($('back')) $('back').setStyle('opacity', 1);
						e.stop();
						if(this.retrieve('expand') == 0) 
						{
							this.store('expand', 1);
							var href = this.getElement('h2').getElement('a').get('href');
							new Request.HTML({
								url:href+'&amp;_='+$time(),
								update:this.getElement('div'),
								method:'get',
								onComplete:function() 
								{
									try {
										pageTracker._trackPageview('/'+href);
									} catch(err) {}
								}
							}).send();
						
							this.set('morph', {
								duration:500
							}).morph({'min-height':bheight});
							
							rightdivs.each(function(hide)
							{
								if(hide.retrieve('expand') == 0) 
								{
									hide.set('morph', {
										duration: 1000,
										fps: 25
									}).morph({'opacity':0, 'padding':0});
								}
							});
						} else {
							if($('back')) $('back').setStyle('opacity', 0);
							this.store('expand', 0);
							this.getElement('div').set('html', this.retrieve('text'));
							this.set('morph', {
								duration:500
							}).morph({'min-height':sheight});
							
							rightdivs.each(function(hide) 
							{
							
								hide.set('morph', {
									duration: 1000,
									fps: 25
								}).morph({'opacity':1, 'min-height':sheight, 'padding':'10px'});
			 				});
						}
					} else {
						if($chk(this.getElement('a'))) window.location = this.getElement('a').get('href');
					}
				}
			});

			(function() 
			{
				item.set('morph', {
					duration: 1000,
					fps: 25
				}).morph({'opacity': [0, 1], 'background-color':['#cccccc', '#ffffff']});
			}).delay(timer);
			timer += 250;
		});
	},
	
	showorange:function() 
	{
		var shiftOrange = new Fx.Morph('orange', {duration:'long', transition: Fx.Transitions.Sine.easeOut});
		
		(function() 
		{
			shiftOrange.start({
				'left':[-300, 280]
			});
		}).delay(this.options.timer+450);
	}
});

if($('back')) 
{
	$('back').addEvent('click', function(e) 
	{
		e.stop();
		$$('#rightbox div.item').each(function(item) 
		{
			item.store('expand', 0);
			item.getElement('div').set('html', item.retrieve('text'));
			item.set('morph', {
				duration:500
			}).morph({'min-height':sheight});
			
			rightdivs.each(function(hide) 
			{
				hide.set('morph', {
					duration: 1000,
					fps: 25
				}).morph({'opacity':1, 'min-height':sheight, 'padding':'10px'});
			});
		});
		this.setStyle('opacity', 0);
	});
}

