currentSpinInd = currentSpinThumb = currentStillThumb = currentLayout = null;

slideShowInterval = 5500; //5.5 sec.
slideShowStarted = false;


function getSWF(movieName)
{
	if (navigator.appName.indexOf('Microsoft') != -1) return window[movieName];
	
	return document[movieName];
}


function showSpin(ind)
{
	slideShowStop();
	markSpinThumb(ind);
	setLayout('spins');	
	getSWF('SpinPlayer').showSpinByImageIndex(ind);
	window.scroll(0, 0);
	currentSpinInd = ind;
}


function showStill(ind)
{
	markStillThumb(ind);
	
	var img = document.getElementById('stillImg');
	img.src = getStillFile(ind-1).url;
	img.srcFull = getStillFile(ind-1, true).url;
	img.onclick = function(){ window.open(this.srcFull) };
	img.style.cursor = 'pointer';
	img.alt = img.title = 'Click to View at full size...'
	
	document.getElementById('stillTitle').innerHTML = getStillFile(ind-1).title;
	
	if (totalStills > 1) document.getElementById('stillStatus').innerHTML = 'Photo '+ ind +' of '+ totalStills;
	
	setLayout('stills');
	window.scroll(0, 0);
}

function showStillFull(url)
{
	
}


function showByDirection(direction)
{
	var ind = currentStillThumb == null ? 0 : currentStillThumb.ind;

	ind += direction;
	if (ind > totalStills) ind = 1;
	else if (ind < 1) ind = totalStills;

	showStill(ind);
}



function markSpinThumb(ind)
{
	if (currentSpinThumb) currentSpinThumb.className = 'thumb';
	currentSpinThumb = document.getElementById('spinThumb'+ind);
	currentSpinThumb.className = 'currentThumb';
}

function markStillThumb(ind)
{
	if (currentStillThumb) currentStillThumb.className = 'thumb';
	currentStillThumb = document.getElementById('stillThumb'+ind);
	currentStillThumb.ind = ind;
	currentStillThumb.className = 'currentThumb';
}



function setLayout(type)
{
	if (currentLayout != undefined && currentLayout == type) return;
	
	currentLayout = type;

	var stills = document.getElementById('stills');
	var content = document.getElementById('content');
	var contentWrap = document.getElementById('contentWrap');
	
	var spinViewer = document.getElementById('spinViewer');
	var stillHolder = document.getElementById('stillHolder');
	
	if (type == 'spins')
	{
		var swf = getSWF('SpinPlayer');
		if (swf) swf.width = 650;
		
		spinViewer.style.width = '650px';
		spinViewer.style.visibility = 'visible';
		
		stills.style.top = '362px';
		stillHolder.style.visibility = 'hidden';
	}
	else if (type == 'stills')
	{
		var swf = getSWF('SpinPlayer');
		if (swf)
		{
			swf.stopSpin();
			swf.width = 410;
		}
			

		spinViewer.style.width = '410px';
		spinViewer.style.visibility = 'hidden';
		
		stills.style.top = 0;
		stillHolder.style.visibility = 'visible';
	}

	contentWrap.style.height = Math.max(stills.offsetTop + stills.clientHeight, contentWrap.offsetTop + content.clientHeight) -contentWrap.offsetTop + 0 +'px';
}


function tourViewInit()
{
	if (totalSpins > 0) document.getElementById('spinViewer').style.display = 'block';
	
	if (totalStills > 0)
	{
		document.getElementById('stillHolder').style.display = 'block';
		document.getElementById('stills').style.visibility = 'visible';
	}
	
	if (totalSpins == 0 && totalStills == 0)
	{
		var contentWrap = document.getElementById('contentWrap');
		contentWrap.style.position = 'absolute';
		contentWrap.style.top = 0;
	}
	
	if (totalSpins > 0)
	{
		setLayout('spins');
		currentSpinInd = 1;
	}
	else if (totalStills > 0)
	{
		var i = 0;
		while( getStillFile(i++) == false );

		showStill(i);
	}
}


function slideShowStart()
{	
	if (slideShowStarted) return;

	slideShowTimer = setInterval( 'showByDirection(1)', slideShowInterval );
	showByDirection(1);
	slideShowStarted = true;
}	

function slideShowStop()
{	
	if (!slideShowStarted) return;
	
	clearInterval(slideShowTimer);
	slideShowStarted = false;
}


function openMegaTour()
{
//	getSWF('SpinPlayer').stopSpin();
	window.open(megaTourUrl, '', 'width=800, height=700, scrollbars=1, resizable=1');
}


currentOnLoad = window.onload;
window.onload = function()
{
	currentOnLoad();
	tourViewInit();
}
