function wmxAutoScrollingSpecial()
{
	//Private variables
	var _actualHeight = '';
	var _actualWidth = '';
	var _element0 = null;
	var _element1 = null;
	var _element2 = null;
	var _initialized = false;
	var _moveEffect0 = null;
	var _xDuration = 50;
	var _timeLeft = _xDuration;

	// speeds are set in px/s
	var _xSpeedVerySlow = 20;
	var _xSpeedSlow = 45;
	var _xSpeedMedium = 70;
	var _xSpeedFast = 95;
	var _xSpeedVeryFast = 115;
	
	//Public properties
	this.content = '';
	this.height = '';
	this.name = '';
	this.gridHeight = 195;
	this.photoType = /\.jpg/i;
	this.gridWidth = 215;
	this.specialId = 0;
	this.speed = 1;
	this.width = '';

	//Public functions
	this.initialize = function()
	{
		var imageArray = this.content.split(this.photoType);
		var count = imageArray.length - 1;
		
		var code = "<table><tr><td>";
		code += "<div id='" + this.name + "_Special' class='ScrollingSpecialContainer' style='position:relative;overflow:hidden'>";
		code += "<div id='" + this.name + "_Element0' class='ScrollingSpecialElement' style='left:0;position:absolute;top:0;width:100%;z-index:3'>";
		code += "<div id='" + this.name + "_Element1' class='ScrollingSpecialElement' style='left:0;z-index:2;overflow:hidden;position:absolute;'></div>";
		code += "<div id='" + this.name + "_Element2' class='ScrollingSpecialElement' style='left:0;z-index:1;overflow:hidden;position:absolute;'></div>";
		code += "</div></div>";
		code += "</td></tr></table>";
		$('Scrolling_' + this.specialId).innerHTML = code;

		_element0 = $(this.name + "_Element0");
		_element1 = $(this.name + "_Element1");
		_element2 = $(this.name + "_Element2");

		var containerHeight = 0;
		var containerWidth = 0;

		_actualHeight = this.gridHeight;
		_actualWidth = (this.gridWidth * count) - 5;
		containerHeight = this.gridHeight;
		this.content = "<nobr>" + this.content + "</nobr>";
		_element2.style.left = _actualWidth + "px";
		
		Special = $(this.name + "_Special");
		Special.style.height = (this.height != '' ? this.height : containerHeight != 0 ? containerHeight : this.gridHeight) + "px";
		Special.style.width = this.width != '' ? this.width + "px" : containerWidth != 0 ? containerWidth + "px" : "100%";

		_element1.innerHTML = _element2.innerHTML = this.content;

		if(Prototype.Browser.IE)
		{
			_element0.observe('mouseenter', function(e){this.stop();}.bind(this));
			_element0.observe('mouseleave', function(e){this.resume();}.bind(this));
		}
		else
		{
			_element0.observe('mouseover', function(e){this.stop();}.bind(this));
			_element0.observe('mouseout', function(e){this.resume();}.bind(this));
		}
	};

	this.move = function(target)
	{
		_moveEffect0 = new Effect.Move(target, {
			x:-_actualWidth, y:0, duration: _xDuration, mode: 'absolute',
			transition:Effect.Transitions.linear,
			afterFinish:this.resetMove.bind(this, target),
			queue: {scope: this.name + '_WmxScrollingSpecial'}
		});
	};

	this.resumeMove = function(target, iDuration)
	{
		_moveEffect0 = new Effect.Move(target, {
			x:-_actualWidth, y:0, duration: iDuration, mode: 'absolute',
			transition:Effect.Transitions.linear,
			afterFinish:this.resetMove.bind(this, target),
			queue: {scope: this.name + '_WmxScrollingSpecial'}
		});
	};

	this.resetMove = function(target)
	{
		$(target).setStyle({left: 0 + 'px'});
		this.move(target);
	};

	this.speedSwitch = function()
	{
		switch (this.speed)
		{
			case 1: //very slow
				_xDuration = _actualWidth / _xSpeedVerySlow;
				break;
			case 2: //slow
				_xDuration = _actualWidth / _xSpeedSlow;
				break;
			case 4: //fast
				_xDuration = _actualWidth / _xSpeedFast;
				break;
			case 5://very fast
				_xDuration = _actualWidth / _xSpeedVeryFast;
				break;
			case 6: //stopped
				_xDuration = 0;
			default: //medium
				_xDuration = _actualWidth / _xSpeedMedium;
		}
	};

	this.scroll = function(resume)
	{
		if(resume)
	{
			this.resumeMove(_moveEffect0.element.id, _timeLeft);
		}
		else
		{			
			this.move(_element0.id);
		}
	};

	this.start = function()
	{
		if (!_initialized)
		{
			this.initialize();
			_initialized = true;
			if (this.speed != 0)
			{
				this.speedSwitch();
				this.scroll(false);
		}
		}
	};

	this.resume = function()
	{
		this.scroll(true);
	};

	this.stop = function()
	{
		var currentTime = new Date();
		var timeFinish  = _moveEffect0.finishOn;
		_timeLeft 		 = (timeFinish - currentTime)/1000;
		_moveEffect0.cancel();
	};
}

function wmxClickScrollingSpecial()
{
	//Private variables
	var _count = 0;
	var _Left = null;
	var _element = null;
	var _Right = null;
	var _initialized = false;
	var _page = 1;
	
	//Public properties
	this.content = '';
	this.height = '';
	this.name = '';
	this.gridHeight = 195;
	this.photoType = /\.jpg/i;
	this.gridWidth = 215;
	this.specialId = 0;
	this.width = '';

	//Public functions
	this.initialize = function()
	{
		var imageArray = this.content.split(this.photoType);
		_count = imageArray.length - 1;
		
		var specialWidth = 0;
		specialWidth = $('Special_' + this.specialId).getWidth();
		specialWidth = specialWidth - 45;
		
		var code = "<table><tr><td>";
		code += "<div id='" + this.name + "_Special' class='ScrollingSpecialContainer' style='position:relative;overflow:hidden'>";
		code += "<div id='" + this.name + "_Left' class='ScrollingSpecialLeft' style='z-index:2;'></div>";
		code += "<div id='" + this.name + "_Wrapper' class='ScrollingSpecialWrapper' style='width:" + specialWidth + "px;'>";
		code += "<div id='" + this.name + "_Element' class='ScrollingSpecialElement' style='z-index:1'></div></div>";
		code += "<div id='" + this.name + "_Right' class='ScrollingSpecialRight' style='z-index:2;'></div>";
		code += "</div>";
		code += "</td></tr></table>";
		$('Scrolling_' + this.specialId).innerHTML = code;

		with (document)
		{
			write("<script type='text/javascript'>");
			write("$('" + this.name + "_Left').observe('click', function(event){");
			write(this.name + ".previous();");
			write("event.stop();");
			write("});");
			write("$('" + this.name + "_Right').observe('click', function(event){");
			write(this.name + ".next();");
			write("event.stop();");
			write("});");
			write("</script>");
		}		

		_element = new cmxElement();
		_element.setId(this.name + "_Element");

		var containerHeight = 0;
		var containerWidth = 0;
		containerHeight = this.gridHeight;

		Special = new cmxElement();
		Special.setId(this.name + "_Special");
		Special.style.height = (this.height != '' ? this.height : containerHeight != 0 ? containerHeight : this.gridHeight) + "px";
		Special.style.width = this.width != '' ? this.width + "px" : containerWidth != 0 ? containerWidth + "px" : "100%";
		
		this.changePage();
	};
	
	this.next = function()
	{
		if (_page < _count)
		{
			_page++;
		}
		else
		{
			_page = 1;
		}
		this.changePage();
	};
	
	this.previous = function()
	{
		if (_page > 1)
		{
			_page--;
		}
		else
		{
			_page = _count;
		}
		this.changePage();
	};
	
	this.addContent = function(firstItem, index)
	{
		if (firstItem == false)
		{
			this.content += '<div class="ScrollingDivider"></div>';
		}
		$('Special_' + this.specialId + '_' + index).addClassName("ClickItem");
		
		if (typeof ($('Special_' + this.specialId + '_' + index).outerHTML) != 'undefined')
		{
			this.content += $('Special_' + this.specialId + '_' + index).outerHTML;
		}
		else
		{
			this.content += new XMLSerializer().serializeToString($('Special_' + this.specialId + '_' + index));
		}
	};
	
	this.changePage = function()
	{
		this.content = '<div class="ScrollingSpecial">';
		var firstItem = true;
		
		for (var index = _page; index <= _count; ++index) 
		{
			this.addContent(firstItem, index);
			firstItem = false;
		}
		for (var index = 1; index < _page; ++index) 
		{
			this.addContent(firstItem, index);
		}
		this.content += '</div>';
		_element.element.innerHTML = this.content;
	};
}

