/**
 * @author 3dvista
 */
var EMBED_CODE_PRESENTATION_MOVIE = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="647" height="360" id="presentationhq" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="' + ROOT + 'swfs/presentationhq.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><embed src="' + ROOT + 'swfs/presentationhq.swf" quality="high" bgcolor="#ffffff" width="647" height="360" name="presentationhq" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';
var EMBED_CODE_VT_PANORAMAS = '<iframe src="http://files.net-fs.com/2080/show/16/publish/__index.htm" width="680" height="400" frameborder="0" scrolling="no"></iframe>';
var EMBED_CODE_VT_OBJECTS = '<iframe src="http://files.net-fs.com/2080/show/17/publish/__index.htm" width="680" height="400" frameborder="0" scrolling="no"></iframe>';

var hash = "#invalid";
var status = STATUS_NONE;

var STATUS_NONE = 0;		
var STATUS_INIT = 1;
var STATUS_PRESENTATION = 2;
var STATUS_VT_PANORAMAS = 3;
var STATUS_VT_OBJECTS = 4;

function getStatusForHash(value)
{
	value = value.toLowerCase();	
	switch (value)
	{
		case ("#vt_panoramas"):
			return STATUS_VT_PANORAMAS;
		case ("#vt_objects"):				
			return STATUS_VT_OBJECTS;
		case ("#presentation"):
			return STATUS_PRESENTATION;				
		case ("#init"):
			return STATUS_INIT;							
		default:
			return STATUS_NONE;
	}	
}

function checkURLHash()
{
	if (window.location.hash != hash)
	{
		hash = window.location.hash;
		var newStatus = getStatusForHash(hash);
		if (newStatus != STATUS_NONE)
			setStatus(newStatus);
	}
}		

function setStatus(value)
{
	if (status != value) 
	{
		status = value;
		setContentItemSelected("#init", (status == STATUS_INIT));
		setContentItemSelected("#presentation", (status == STATUS_PRESENTATION), "#containerPresentationVideo", EMBED_CODE_PRESENTATION_MOVIE);
		setContentItemSelected("#vt_panoramas", (status == STATUS_VT_PANORAMAS), "#containerVTPanoramas", EMBED_CODE_VT_PANORAMAS);		
		setContentItemSelected("#vt_objects", (status == STATUS_VT_OBJECTS), "#containerVTObjects", EMBED_CODE_VT_OBJECTS);		
	}
}

function setContentItemSelected(id, value, containerId, embedCode)
{
	var contentItem = $(id);
	if (contentItem.is(":hidden") == value) 
	{
		if (value) 
			contentItem.fadeIn(500, 
				function()
				{
					if (containerId != null)
						$(containerId).html(embedCode);
				}
			);
		else 
			contentItem.fadeOut(300, 
				function ()
				{
					if (containerId != null)
						$(containerId).html('');					
				}
			);
	}
}

function presentationVideoFinished()
{
	setStatus(STATUS_VT_PANORAMAS);
}

$(document).ready(function()
{
	var visited = $.cookie('visited');			
	$.cookie('visited', 'true', { expires: 90 });		
		
	if (visited == null) 
	{
		setStatus(STATUS_PRESENTATION);
	}
	else 
	{
		var newStatus = getStatusForHash(window.location.hash);
		if (newStatus == STATUS_NONE) 
			setStatus(STATUS_INIT);
		else 
			setStatus(newStatus);
	}
	
	setInterval("checkURLHash()", 200);		
});