/////////////////////////// functions called by HTML ///////////////////

// These functions represent the external interface to the HTML page.

function slideshowGoto(nImg) 						{main ? main.htmlSlideshowGoto(nImg) 				: false;}
function slideshowStart() 							{main ? main.htmlSlideshowStart() 					: false;}
function slideshowStop() 								{main ? main.htmlSlideshowStop() 						: false;}
function slideshowPauseResume() 				{main ? main.htmlSlideshowPauseResume() 		: false;}
function slideshowPrevious() 						{main ? main.htmlSlideshowPrevious() 				: false;}
function slideshowNext() 								{main ? main.htmlSlideshowNext() 						: false;}
function BypassFlashUpdate()						{main ? main.swfBypassUpdate() 							: false;}

function audioMute() 										{main ? main.htmlAudioMute() 								: false;}
function audioPauseResume() 						{main ? main.htmlAudioPauseResume() 				: false;}
function audioPlay(nTrack) 							{main ? main.htmlAudioPlay(nTrack) 					: false;}
function audioStop() 										{main ? main.htmlAudioStop() 								: false;}
function audioVolume(nVol)	 						{main ? main.htmlAudioVolume(nVol) 					: false;}

function audioPlayStop()		 								{main ? main.htmlAudioPlayStop() 								: false;}


function videoMute() 										{main ? main.htmlVideoMute() 								: false;}
function videoPauseResume() 						{main ? main.htmlVideoPauseResume() 				: false;}
function videoPlay()		 								{main ? main.htmlVideoPlay() 								: false;}
function videoStop() 										{main ? main.htmlVideoStop() 								: false;}
function videoVolume(nVol)	 						{main ? main.htmlVideoVolume(nVol) 					: false;}

function videoPlayStop()		 								{main ? main.htmlVideoPlayStop() 								: false;}


function stopMedia() 										{main ? main.htmlStopMedia() 								: false;}

/////////////////////////// end //////////////////////////////////


///////////////////////// main /////////////////////////////////

var main;

window.onload = function() {

	main = new mainControl();
	main.init("main");

}

// aps added 7.10.2008
window.onunload = function() {
   stopMedia();
}

/////////////////////////// end //////////////////////////////////


//////////////////////// main control ////////////////////////////


function mainControl(){}

var _this = mainControl.prototype = new Object();

_this.constructor	= mainControl;

_this.className = "mainControl";

_this.name;

this.swfVideoControl;
_this.swfSlideshowControl;
_this.swfAudioControl;

_this.init = function (cName) {

	// passed from HTML
	this.name = cName;
	
    if ( Boolean(typeof aVideoPlayer != 'undefined' && aVideoPlayer) || Boolean(typeof aSlideshowPlayer != 'undefined' && aSlideshowPlayer) || Boolean(typeof aAudioPlayer != 'undefined' && aAudioPlayer) )
    {
	    this.swfInstall = new InstallSwf();
	    this.swfInstall.parent = this;
	    this.swfInstall.init(this.name + ".swfInstall", aInstallSwf);	
    	
	    if (this.swfInstall.loaded()) {
		    this.swfInit();	
	    }
    }
}

_this.swfBypassUpdate = function () {
	this.swfInstall.hide();	
	this.swfInit();
}

_this.swfInit = function () {
	
    if ( Boolean(typeof aVideoPlayer     != 'undefined' && aVideoPlayer) )  {
        this.swfVideoControl = new videoControl();
	    this.swfVideoControl.parent = this;
	    this.swfVideoControl.init(this.name + ".swfVideoControl", aVideoPlayer, cXmlGenericContent, cXmlVideoContent);	
	}
    
	if ( Boolean(typeof aSlideshowPlayer != 'undefined' && aSlideshowPlayer) ) {
	    this.swfSlideshowControl = new slideshowControl();
	    this.swfSlideshowControl.parent = this;
	    this.swfSlideshowControl.init(this.name + ".swfSlideshowControl", aSlideshowPlayer, cXmlGenericContent, cXmlSlideshowContent);	
	    this.swfSlideshowControl.swfStart();
	}
	
	if ( Boolean(typeof aAudioPlayer     != 'undefined' && aAudioPlayer) )   {
        this.swfAudioControl = new audioControl();
	    this.swfAudioControl.parent = this;
	    this.swfAudioControl.init(this.name + ".swfAudioControl", aAudioPlayer, cXmlGenericContent, cXmlAudioContent);		
    }	
}

// Video Controls

_this.htmlVideoStopMedia	= function () {
	if(this.swfVideoControl) {
		this.swfVideoControl.swfDeletePlayer();
		delete this.swfVideoControl;
	}
}

_this.htmlVideoPlay = function () {
	this.swfVideoControl.swfStart();
}

_this.htmlVideoStop = function () {
	this.swfVideoControl.swfStop();
}

_this.htmlVideoPauseResume	= function () {
	this.swfVideoControl.swfPauseResume();
}

_this.htmlVideoMute = function () {
	this.swfVideoControl.swfMute();
}

_this.htmlVideoVolume = function (nVol) {
	this.swfVideoControl.swfVolume(nVol);
}	

_this.htmlVideoPlayStop = function () {

    switch (document.getElementById("PlayVideoButton").innerHTML)
    {
        case "Start Video":
            document.getElementById("PlayVideoButton").innerHTML = "Stop Video";
        	this.swfVideoControl.swfStart();
            break;
        case "Stop Video":
            document.getElementById("PlayVideoButton").innerHTML = "Start Video";
        	this.swfVideoControl.swfStop();
            break;
    } 
}


// Slide Show Controls

_this.htmlSlideshowStopMedia	= function () {
	if(this.swfSlideshowControl) {
		this.swfSlideshowControl.swfDeletePlayer();
		delete this.swfSlideshowControl;
	}
}

_this.htmlSlideshowGoto = function (nImg) {
	this.swfSlideshowControl.swfGotoImage(nImg);
}

_this.htmlSlideshowPauseResume	= function () {
	this.swfSlideshowControl.swfPauseResume();
}

_this.htmlSlideshowStart	= function () {
	this.swfSlideshowControl.swfStart();
}

_this.htmlSlideshowStop	= function () {
	this.swfSlideshowControl.swfStop();
}

_this.htmlSlideshowPrevious	= function () {
	this.swfSlideshowControl.swfPreviousImage();
}

_this.htmlSlideshowNext	= function () {
	this.swfSlideshowControl.swfNextImage();
}

// Audio Controls

_this.htmlAudioStopMedia	= function () {
	this.swfAudioControl.swfDeletePlayer();
	delete this.swfAudioControl;
}

_this.htmlAudioPlay = function (nTrack) {
	this.swfAudioControl.swfStart(nTrack);
	//document.getElementById("PlayAudioButton").innerHTML = "stop";
}

_this.htmlAudioStop = function () {
	this.swfAudioControl.swfStop();
}

_this.htmlAudioPauseResume	= function () {
	this.swfAudioControl.swfPauseResume();
}

_this.htmlAudioMute = function () {
	this.swfAudioControl.swfMute();
}

_this.htmlAudioVolume = function (nVol) {
	this.swfAudioControl.swfVolume(nVol);
}


_this.htmlAudioPlayStop = function () {

    switch (document.getElementById("PlayAudioButton").innerHTML)
    {
        case "listen":
            document.getElementById("PlayAudioButton").innerHTML = "stop";
        	this.swfAudioControl.swfStart(1);
            break;
        case "stop":
            document.getElementById("PlayAudioButton").innerHTML = "listen";
        	this.swfAudioControl.swfStop();
            break;
    } 
}

// Common functions


_this.htmlStopMedia	= function () {

    if ( Boolean(typeof aVideoPlayer     != 'undefined' && aVideoPlayer) )    { this.htmlVideoStopMedia(); }
	if ( Boolean(typeof aSlideshowPlayer != 'undefined' && aSlideshowPlayer) ) { this.htmlSlideshowStopMedia();}
	if ( Boolean(typeof aAudioPlayer     != 'undefined' && aAudioPlayer) )   { this.htmlAudioStopMedia(); }		
}

_this.showMovieStatus = function(cStatus) {
	document.getElementById("movieStatus").value = document.getElementById("movieStatus").value + cStatus + "\r\n"; 	
}

_this.swfStatus = function(cName, cStatus) {
	switch (cName) {
		case "main.swfVideoControl":	
			this.showMovieStatus(cName + " " + cStatus);
			break;		
		case "main.swfSlideshowControl":	
			this.showMovieStatus(cName + " " + cStatus);
			break;		
		case "main.swfAudioControl":	
			this.showMovieStatus(cName + " " + cStatus);
			break;	
	}
}			


/////////////////////////// end //////////////////////////////////

