/**
 * @author Rok
 */
var	nWhich = -1;

var nOpacity = 0;

var nStep = 5;
var nTopOff = 0;
var nLeftOff = 0;
var strPixDest = '';
var strTextBox = 'tbrw_Intro_Slide_Text';
var strWashBox = 'tbrw_Intro_Slide';
var strSlideBox = 'Box_HomeSlides_content';
var strBColor = '#87c1d8';

var nTimer = null;
var nTransition = null;
var aryPix = new Array();

function MoveIt()
{
	if (nTimer)
	{
		var objSlideText = document.getElementById(strTextBox);
		if (objSlideText)
		{
			var nTop = parseInt(objSlideText.style.top.replace('[^0-9]', ''));
			nTopOff = aryPix[nWhich].top - nTop;
			if (nTopOff)
			{
				if ((Math.abs(nTopOff)) > nStep)
					nTopOff = (nTopOff * nStep) / Math.abs(nTopOff);
				objSlideText.style.top = Math.floor(nTop += nTopOff) + 'px';
			}

			var nLeft = parseInt(objSlideText.style.left.replace('[^0-9]', ''));
			nLeftOff = aryPix[nWhich].left - nLeft;
			if (nLeftOff)
			{
				if ((Math.abs(nLeftOff)) > nStep)
					nLeftOff = (nLeftOff * nStep) / Math.abs(nLeftOff);
				objSlideText.style.left = Math.floor(nLeft += nLeftOff) + 'px';
			}
		}

		var objWash = document.getElementById(strWashBox);
		if (objWash)
		{
			if (nOpacity < 100)
			{
				nOpacity+=10;
				objWash.style.opacity = nOpacity/100;
				objWash.style.filter = 'alpha(opacity=' + nOpacity + ')';
				objWash.style.backgroundColor = strBColor;

				if (nOpacity >= 100)
				{
					var objSlidePicture = document.getElementById(strSlideBox);
					if (objSlidePicture)
						objSlidePicture.style.backgroundImage = aryPix[nWhich].file;
				}
			}else if (nOpacity < 200)
			{
				nOpacity+=10;
				objWash.style.opacity = (200 - nOpacity) /100;
				objWash.style.filter = 'alpha(opacity=' + (200 - nOpacity) + ')';
				if (nOpacity >= 145 && nOpacity >= 175) 
				{
					if (objSlideText) 
						objSlideText.innerHTML = aryPix[nWhich].text;
				}
				if (nOpacity >= 200)
				{
					objWash.style.backgroundColor = 'transparent';
					
				}
			}else if (nOpacity < 300)
			{
				nOpacity+=10;
				objWash.style.opacity = (nOpacity - 200) /100;
				objWash.style.filter = 'alpha(opacity=' + (nOpacity - 200) + ')';
			}

		}
		
		if (!(nTopOff || nLeftOff) && nOpacity >= 300)
		{
			clearInterval(nTimer);
			var objSlidePicture = document.getElementById(strSlideBox);

			if (objSlidePicture)
				objSlidePicture.style.backgroundImage = aryPix[nWhich].file;

			if (objSlideText)
				objSlideText.innerHTML = aryPix[nWhich].text;

			if (objWash) 
			{
				objWash.style.opacity = 100;
				objWash.style.filter = 'alpha(opacity=100)';
				objWash.style.backgroundColor = 'transparent';
			}
			nOpacity = 0;

		}			
	}
}

function Rotate()
{
	var objSlideText = document.getElementById(strTextBox);
	nWhich = ((nWhich + 1) % aryPix.length);
		
	if (nTimer)
	{
		clearInterval(nTimer);
		nTimer = null;	
	}
	
	if (objSlideText)
	{
		nOpacity = 0;
		nTimer = setInterval('MoveIt()', aryPix[nWhich].life);
	}
		
}

function StartSlideShow()
{
	if (aryPix.length > 1)
		setInterval('Rotate()', 8000);
}

function AddPix(p_strFile, p_nLife, p_nTop, p_nLeft, p_strText)
{
	aryPix.push({ file: p_strFile, life: p_nLife, top: p_nTop, left: p_nLeft, text: p_strText});
}
