// Filename: shared.js
// SWF version

// Generate
lessonText=new Array
(
"Title",
"Getting around Garden Composer", 
"Rulers, grid and creating View settings", 
"First steps", 
"Placing plants from the Encyclopaedia (general)", 
"Using the Encyclopaedia (Main and Care tabs)", 
"Using the Encyclopaedia in-depth (World map, Plan notes, Collage, Diseases, Scientific and User tabs)", 
"Placing objects on your Plan", 
"Surface objects", 
"Curvature", 
"Green hedges and sheared plants", 
"Customized structures", 
"Composite structures", 
"Landscaping", 
"Landscaping (using surfaces)", 
"Photo designer", 
"Print and Export", 
"Useful features", 
"Plant Editor (Editing a plant)", 
"Plant Editor (Textures, New fences, User fields and updating from the Web)"
);
var startLesson=1;
var endLesson=19;

var titleText="Garden Composer Tutorial";
var currentLesson=0; // current lesson (if 0 then title)

// Image for table of contents
var contentImage="<img src='images/lesson.gif' width='16' height='16'>";
var contentInited=false;

var textFolder="text/";
var textFilePrefix="text";
var topicFolder="video/";
var topicFilePrefix="topic";
var contentFile="content.htm";
var titleFile="title.htm";
var switchFile="sw.htm";

// Contents
function initContents()
{
	var i = 0;
	var count = endLesson - startLesson + 1;
	
	if (contentInited == true)	
		return;
		
	var table="<table>";
	for (i = 0; i <= count; i++)
	{
		var topicText="<a href='javascript:onLesson("+i+")'>"+lessonText[i]+"</a>";
		var topic="<tr><td>"+contentImage+"</td><td>"+topicText+"</td></tr>";
		table=table+topic;
	}
	//window.alert("initContents(): "+table+"</table>");
	document.all.Contents.innerHTML=document.all.Contents.innerHTML + table + "</table>";
	contentInited = true;
}

function _onChangeLesson() // change lesson helper
{
	if (currentLesson == 0) // title case
	{
		parent.frmTopic.location=titleFile;
		parent.frmContent.location=contentFile;	
		parent.document.title=titleText;
	}
	else
	{
		parent.frmTopic.location=topicFolder + topicFilePrefix + currentLesson + ".htm";
		parent.frmContent.location=textFolder + textFilePrefix + currentLesson + ".htm";
		parent.document.title=lessonText[currentLesson];
	}
}

function onLesson(lsn) // move to selected lesson
{
	if (lsn > endLesson)
		return;
	if (lsn < startLesson && lsn != 0)
		return;
	currentLesson = lsn;
	parent.frmContentSwitch.location=switchFile + "?" + currentLesson;
	_onChangeLesson()
}

function onNextLesson()
{
	var lsn = parseInt(currentLesson) + 1;
	UpdateState(lsn);
	if (lsn > endLesson)
		return;
	currentLesson = lsn;
	_onChangeLesson();
}

function onPrevLesson()
{
	var lsn = parseInt(currentLesson) - 1;
	UpdateState(lsn);
	if (lsn < startLesson)
		return;
	currentLesson = lsn;
	_onChangeLesson();
}

// Switch
var switchState="Text";

function initSwitch()
{
	//window.alert("initSwitch() loc search:" + location.search);
	var lesson="0";
	if (location.search != "" && location.search.length > 0) // try to read current lesson from URL
	{
		var l = "0";
		l=parseInt(location.search.substring(1));
		if (l == l) // test NaN
			lesson = l;
	}
		
	if (lesson == 0) // title case
		switchState="Text";
	else
		switchState="Content";
		
	currentLesson=lesson;
	onSwitch();
	UpdateState(currentLesson);
}

function UpdateState(lsn) // update buttons state
{
	if (lsn == 0) // title case
		document.all.btnSwitch.style.visibility="hidden";	
		
	if (switchState != "Text")
		return;
		
	if (lsn == startLesson + 1)
		document.all.btnPrev.style.visibility="visible";	
	if (lsn >= endLesson)
		document.all.btnNext.style.visibility="hidden";	
	if (lsn == endLesson - 1)
		document.all.btnNext.style.visibility="visible";	
	if (lsn <= startLesson)
		document.all.btnPrev.style.visibility="hidden";	
}

function onSwitch() // switch between Table of contents and Topic's text modes
{
	if (switchState == "Content") // move to Topic's text mode
	{
		switchState = "Text"; 
		parent.frmContent.location=textFolder + textFilePrefix + currentLesson + ".htm";
		document.all.btnSwitch.src="images/content.gif";	
		document.all.btnPrev.style.visibility="visible";
		document.all.btnNext.style.visibility="visible";
		if (currentLesson > 0)
			parent.frmTopic.location=topicFolder + topicFilePrefix + currentLesson + ".htm";
	}
	else // move to Table of contents mode
	{
		switchState = "Content";
		parent.frmContent.location=contentFile;
		parent.frmTopic.location=titleFile;
		document.all.btnSwitch.src="images/lesson.gif";	
		document.all.btnPrev.style.visibility="hidden";
		document.all.btnNext.style.visibility="hidden";
	}
}

// Topic with video
function closeTopic()
{
	videoStop();
}

function videoPlay()
{
	if (!TopicVideo.IsPlaying())
		TopicVideo.Play();
}

function videoStop()
{
	if (TopicVideo.IsPlaying())
	{
		TopicVideo.StopPlay();
		TopicVideo.Rewind();
	}
}

function videoPause()
{
	if (TopicVideo.IsPlaying())
		TopicVideo.StopPlay();
}
