if (tkGallo_container==null) var tkGallo_container = "container";
if (tkGallo_labelContainer==null) var tkGallo_labelContainer = "labelContainer";

function tkVGallo() {
	this.videos = new Array();
	this.container = document.getElementById(tkGallo_container);
	this.labelContainer = document.getElementById(tkGallo_labelContainer);
	this.currentIndex = 0;
	this.add = function (element) {
	 	if (element.isVGalloElement==true) {
	 	 	this.videos.push(element); return true;
		} else {return false;}
	}
	this.shuffle = function() {
		for (var j, x, i = this.videos.length; i; j = parseInt(Math.random() * i), x = this.videos[--i], this.videos[i] = this.videos[j], this.videos[j] = x);
	}

	this.next = function() {
		this.currentIndex +=1;
		if (this.currentIndex>=this.videos.length) this.currentIndex = 0;
		this.refreshVideo();
	}
	this.previous = function() {
		this.currentIndex -=1;
		if (this.currentIndex<0) this.currentIndex = (this.videos.length-1);
		this.refreshVideo();
	}
	this.refreshVideo= function() {
		var so = new FlashObject("/repository/video/videoPlayer.swf?tick=<?= $tick ?>", "videoPlayer", "489", "325", "8", "#f0f0f0", true);
	    so.addParam("menu", "false");
	    so.addParam("base", "/repository/video/");
	    so.addParam("allowScriptAccess", "always");
	    so.addParam("flashVars","video="+this.videos[this.currentIndex].video);
	    so.addParam("allowFullScreen", "false");
	    so.addParam("wmode","transparent");
	    so.write(this.container.id);
		this.labelContainer.innerHTML = this.videos[this.currentIndex].didascalia;
		return true;
	}
}

function tkVGalloElement(videoUrl,didascalia) {
 	this.video = videoUrl;
 	this.didascalia = didascalia;
 	this.isVGalloElement = true;
}