get = function (id)
{
	return document.getElementById(id) || false;
}

opacityUp = function (i, block)
{
	window.animation.movies[i].counter += 1;

	var value = window.animation.movies[i].counter / 100;
	if (i !== 1)
	{
		get('mover' + i).style.left = parseFloat(get('mover' + i).style.left) + 0.25 + '%';
	}
	if (value < 1)
	{
		window.animation.setOpacity(window.animation.movies[i].target, value);
	}
	else
	{
		if (i !== 1)
		{
			get('mover' + i).style.left = '0%';
			get('timeline' + i).className = get('timeline' + i).className.replace('iwork', 'iready');
			get('animationbutton' + i).className = get('animationbutton' + i).className.replace(' stop', '');
		}
		clearInterval(window.animation.movies[i].timer);
		window.animation.movies[i].target = null;
		window.animation.movies[i].reseted = window.animation.movies[i].block = window.animation.movies[i].reset;
		if (window.animation.movies[i].after && window.animation.movies[i].reseted && !block) window.animation.movies[i].after();
		get('animation' + i + '_' + '1').style.display = get('animation' + i + '_' + '2').style.display = get('animation' + i + '_' + '3').style.display = get('animation' + i + '_' + '4').style.display = '';
		window.animation.setOpacity(get('animation' + i + '_' + '1'), 1);
		window.animation.setOpacity(get('animation' + i + '_' + '2'), 1);
		window.animation.setOpacity(get('animation' + i + '_' + '3'), 1);
		window.animation.setOpacity(get('animation' + i + '_' + '4'), 1);
		
		window.animation.movies[i].reset = true;
		window.animation.movies[i].reseted = true;

		if (i == 1)
		{
			//eval(window.animation.movies[i].next);
			func = createHandlerOver(i);
			func();
		}
	}
}

opacityDown = function (i)
{
	window.animation.movies[i].counter -= 1;
	if (i !== 1)
	{
		get('mover' + i).style.left = parseFloat(get('mover' + i).style.left) + 0.25 + '%';
	}
	var value = window.animation.movies[i].counter / 100;
	
	if (value > 0)
	{
		window.animation.setOpacity(window.animation.movies[i].target, value);
	}
	else
	{
		clearInterval(window.animation.movies[i].timer);
		window.animation.movies[i].target.style.display = 'none';
		window.animation.movies[i].target = null;
		window.animation.movies[i].block = false;
		eval(window.animation.movies[i].next);
	}
}

window.onload = function ()
{
	window.animation = Array();
	if (!window.opera && !navigator.product)
	{
		window.animation.setOpacity = function (target, value)
		{
			if (target)
			{
				if (target.style)
				{
					value *= 100;
					target.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + value + ')';
					return true;
				}
			}
		}
	}
	else
	{
		window.animation.setOpacity = function (target, value)
		{
			if (target)
			{
				if (target.style)
				{
					target.style.opacity = value;
					return true;
				}
			}
		}
	}

	step = function (from, to, i, count, last)
	{
		if (i !== 'undefined')
		{
			clearTimeout(window.animation.movies[i].timer2);
			window.animation.movies[i].timer2 = false;
			if (!window.animation.movies[i].block)
			{
				window.animation.movies[i].block = true;
				window.animation.movies[i].targetFrom = get('animation' + i + '_' + from);
				window.animation.movies[i].targetTo = get('animation' + i + '_' + to);
				
				if (window.animation.movies[i].targetFrom.style && window.animation.movies[i].targetTo.style)
				{
					if (to < count)
					{
						window.animation.movies[i].next = 'window.animation.timer2 = setTimeout("step(' + to + ', ' + (to+1) + ', ' + i + ', ' + count + ', false)", 100);';
					}
					else
					{
						window.animation.movies[i].next = 'window.animation.timer2 = setTimeout("step(' + count + ', 1, ' + i + ', ' + count + ', true)", 100);';
					}
					if (!last)
					{
						window.animation.movies[i].counter = 100;
						window.animation.setOpacity(window.animation.movies[i].targetFrom, 1);
						window.animation.setOpacity(window.animation.movies[i].targetTo, 1);

						window.animation.movies[i].targetFrom.style.display = '';
						window.animation.movies[i].targetTo.style.display = '';
						
						window.animation.movies[i].target = window.animation.movies[i].targetFrom;
						window.animation.movies[i].timer = setInterval("opacityDown(" + i + ")", 1);
					}
					else
					{
						window.animation.movies[i].counter = 0;
						window.animation.setOpacity(window.animation.movies[i].targetFrom, 1);
						window.animation.setOpacity(window.animation.movies[i].targetTo, 0);

						window.animation.movies[i].targetFrom.style.display = '';
						window.animation.movies[i].targetTo.style.display = '';
						
						
						window.animation.movies[i].target = window.animation.movies[i].targetTo;
						window.animation.movies[i].timer = setInterval("opacityUp(" + i + ")", 1);
					}
				}
			}
		}
	}
	
	createHandlerOver = function (key)
	{
		return function ()
		{
			window.animation.movies[key].reset = false;
			if (window.animation.movies[key].reseted) 
			{
				if (key !== 1)
				{
					get('animationbutton' + key).className += ' stop';
					get('timeline' + key).className = get('timeline' + key).className.replace('iready', 'iwork');
					get('mover' + key).style.left = '0%';
				}				
				window.animation.movies[key].block = false;
				window.animation.movies[key].reseted = false;
				var func = "step(1, 2, " + key + ", " + window.animation.movies[key].count + ")";
				window.animation.movies[key].timer2 = setTimeout(func, 40);
			}
		}
	}
	
	createHandlerOut = function (key)
	{
		return function ()
		{
			window.animation.movies[key].reset = true;
			window.animation.movies[key].reseted = false;
		}
	}
	
	window.animation.movies = Array();
	var j = 0;
	while (get('animation' + j + '_1'))
	{
		window.animation.movies[j] = Array();
		window.animation.movies[j].count = 4;
		window.animation.movies[j].reseted = true;
		get('animationbutton' + j).onclick = createHandlerOver(j);
		
		if (j == 1)
		{
			func = createHandlerOver(j);
			func();
		}
		//get('animationbutton' + j + '_1').onclick = createHandlerOut(j);
		j += 2;
	}
}
