/********************************
*  Initialize and set videos	*
********************************/

// Store video buttons
var numVideos = 0;
var navName = "";
var videoName = "";
var videoTarget = "";


// Initialize video references
function initVideo(_numVideos, _navName, _videoName, _videoTarget)
{
	numVideos = _numVideos;
	navName = _navName;
	videoName = _videoName;
	videoTarget = _videoTarget;
}

// Clear all buttons
function clearButtons()
{
	// Store a reference to the navigation
	navroot = document.getElementById(navName)
	// Loop though all LI elements
	for (i = 0; i < navroot.childNodes.length; i++)
	{
		// Store current node
		currentnode = navroot.childNodes[i];
		if (currentnode.nodeName == "LI")
			currentnode.firstChild.className.replace(" selected", "");
	}
}

// Return correct path to Flash Movie
function thisMovie(movieName) 
{
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName]
	}
	else {
		return document[movieName]
	}
}

// Play New Video (Video number, Duration)
function playVideo(num, dur) 
{
	// Store LI tags
	var liarray = new Array();
	for (i = 0; i < document.getElementById(navName).childNodes.length; i++)
	{
		if (document.getElementById(navName).childNodes[i].nodeName == "LI")
			liarray.push(document.getElementById(navName).childNodes[i]);
	}
	// Clear all buttons
	for (i = 0; i < liarray.length; i++)
	{
		if (liarray[i].firstChild.className.length > 6)
		{
			liarray[i].firstChild.className = liarray[i].firstChild.className.substring(0, 6);
		}
	}
	liarray[num].firstChild.className += " selected";
	thisMovie(videoName).playvid("video/" + (videoName + num) + ".flv", "video/" + (videoName + num) + ".jpg", dur);
	//document.getElementById("gallery").innerHTML = '<a href="images/page' + (num + 1) + '.jpg"><img src="images/page' + (num + 1) + '-thumb.png?"' + Math.random() + ' alt="" border="0">Enlarge Sample Page</a>';
	
	setTimeout( function() {
		var a = document.createElement('a');
		a.setAttribute('href', 'images/page' + (num + 1) + '.jpg');
		var img = document.createElement('img');
		img.setAttribute('src', 'images/page' + (num + 1) + '-thumb.png');
		img.setAttribute('border', '0');
		a.appendChild(img);
		var txt = document.createElement('span');
		txt.innerHTML = 'Enlarge Sample Page';
		a.appendChild(txt);
		document.getElementById("gallery").innerHTML = '';
		document.getElementById("gallery").appendChild(a);
		// Reselect this images
		$(function() 
		{
			$('#gallery a').lightBox(); // Select all links in object with gallery ID
		});
	}, 500 );
}



