window.addEvent('domready', function(){
	
	if ($('hydroliccaravan'))
		new srpromotion($('hydroliccaravan'), $$('.promolist'));

	if (
		($('leftbg')) &&
		($('rightcontainer')) &&
		($('middlecontainer')) && 
		($('resizeright'))
	)
	{
		//we make sure the left and right column are of the right height:

		var i_left_size = $('leftbg').getSize().y;
		var i_right_size = $('rightcontainer').getSize().y;
		var i_middle_size = $('middlecontainer').getSize().y;

		//we set our size to the right container:
		if (i_middle_size > i_right_size)
		{
			var i_size = i_middle_size - i_right_size;
			i_size = i_size + $('resizeright').getSize().y;
			$('resizeright').setStyle('height', i_size);
		}

		if (i_middle_size > i_left_size)
		{
			var i_size = i_middle_size - i_left_size;
			i_size = i_size + $('leftbg').getSize().y;
			$('leftbg').setStyle('height', i_size);
		}
	}
});

var srpromotion = new Class(
{
	mobj_container: null,
	marr_obj: Array(),
	mi_index: 0,
	initialize: function(_obj_container, _arr_obj)
	{
		this.mobj_container = _obj_container;
		this.marr_obj = _arr_obj;

		//we then rotate:
		this.rotate();
		this.rotate.periodical(5000, this);
	},
	rotate: function()
	{
		//we fadeout our container:
		var obj_this = this;
		var fx = new Fx.Tween(this.mobj_container, {onComplete: function(){obj_this.change();}});
		fx.start('opacity', 1, 0);
	},
	change: function()
	{
		//we remove what we have in our container:
		this.mobj_container.empty();

		//we get our new data & insert it in our container:
		this.marr_obj[this.mi_index].getChildren().clone().inject(this.mobj_container);

		//we then take the bg image in our img tag and change our real div container with it:
		var arr_img = $$('#middlecontainer .bgelement');
		if (arr_img && arr_img[0])
		{
			//we then get our src:
			var s_src = arr_img[0].get('src');

			//we then modify our container background image with this one:
			this.mobj_container.setStyle('background-image',  'url("'+s_src+'")');
		}

		//we then fade in:
		var fx = new Fx.Tween(this.mobj_container);
		fx.start('opacity', 0, 1);

		//we then increase our index:
		if ((this.mi_index + 1) < this.marr_obj.length)
		{
			this.mi_index++;
			return;
		}

		//we reset our index:
		this.mi_index = 0;
	}
});
