	// some variables to save
	var currentPosition;
	var currentVolume;
	var currentItem;

	// these functions are caught by the JavascriptView object of the player.
	function sendEvent(typ,prm) { thisMovie("_flvplayer").sendEvent(typ,prm); };
	function getUpdate(typ,pr1,pr2,pid) {
		if(typ == "time") { currentPosition = pr1; }
		else if(typ == "volume") { currentVolume = pr1; }
		else if(typ == "item") { currentItem = pr1; setTimeout("getItemData(currentItem)",100); }
		var id = document.getElementById(typ);
		id.innerHTML = typ+ ": "+Math.round(pr1);
		pr2 == undefined ? null: id.innerHTML += ", "+Math.round(pr2);
		if(pid != "null") {
			document.getElementById("pid").innerHTML = "(received from the player with id <i>"+pid+"</i>)";
		}
	};

	// These functions are caught by the feeder object of the player.
	function loadFile(obj) { thisMovie("_flvplayer").loadFile(obj); };
	function addItem(obj,idx) { thisMovie("_flvplayer").addItem(obj,idx); }
	function removeItem(idx) { thisMovie("_flvplayer").removeItem(idx); }
	function getItemData(idx) {
		/*
		var obj = thisMovie("_flvplayer").itemData(idx);
		var nodes = "";
		for(var i in obj) { 
			nodes += "<li>"+i+": "+obj[i]+"</li>"; 
		}
		document.getElementById("data").innerHTML = nodes;
		*/
	};

	// This is a javascript handler for the player and is always needed.
	function thisMovie(movieName) {
	    if(navigator.appName.indexOf("Microsoft") != -1) {
			return window[movieName];
		} else {
			return document[movieName];
		}
	};
	
	function trim(str){
		return str.replace(/^\s+|\s+$/g, '') ;
	}

    function cbaUpdateElement(element, html_src)
	{
		$("#" + element).load(html_src);
	}
	
	function renderThumbs(init)
		{
			
			start = (offset-1)*8;
			end = offset*8;
			if (end > videoIDs.length) 
				end = videoIDs.length;
				
			for (i = start; i<end; i++)
				document.getElementById('img-' + i).src = videoDir + videoIDs[i] + "_thumb1.jpg"; 			
			
		}
	
	function moveRight(){
		offset++;
		renderThumbs(false);
		document.getElementById("thumbs").scrollLeft += 150;
	}
	function moveLeft(){
		document.getElementById("thumbs").scrollLeft -= 150;
	}
	
	function loadVideo(videoID){
		currentVideo = videoID;
		cbaUpdateElement('videoTitle','ajax_interface.php?type=videoTitle&videoID=' + currentVideo);
		cbaUpdateElement('seeAlsoList','ajax_interface.php?type=seeAlsoList&videoID=' + currentVideo);		
		loadFile({file: videoDir + currentVideo + '.flv', image: videoDir + currentVideo + '_thumb1.jpg'});
		if (document.getElementById("descriptionIcon").src.indexOf('minus.gif') > 0)
			cbaUpdateElement('videoDescription','ajax_interface.php?type=videoDescription&videoID=' + currentVideo);		
	}

	function showHideDescription(){
		
		if (document.getElementById("descriptionIcon").src.indexOf('plus.gif') > 0)
		{
			document.getElementById("descriptionIcon").src = 'minus.gif';
			document.getElementById("videoDescription").style.overflow = "visible";
			document.getElementById("videoDescription").style.visibility = "visible";
			cbaUpdateElement('videoDescription','ajax_interface.php?type=videoDescription&videoID=' + currentVideo);		
		}
		else {
			document.getElementById("descriptionIcon").src = 'plus.gif';
			document.getElementById("videoDescription").style.overflow = "hidden";
			document.getElementById("videoDescription").style.visibility = "hidden";
			document.getElementById("videoDescription").innerHTML = "";
		}
		
	}
$(document).ready(function(){


	
	$("DIV#thumbs IMG").click(function() { loadVideo($(this).attr('alt')) } );
	
	renderThumbs(true);
	
	var timerID = window.setTimeout("loadVideo(" + videoIDs[0] +");", 1000);

});
	
		

