
///////////////////// mainControl ///////////////

function mainControl(){}

var _this = mainControl.prototype = new Object();

_this.constructor	= mainControl;

// class objects
_this.swfAudioControl;
_this.swfVideoControl;
_this.galleryControl;
_this.montageControl;
_this.aVideoControlVars;
_this.aAudioControlVars;
_this.aGalleryVars;

// holders for HTML variables
_this.cMediaFolder;
_this.cImageFolder;
_this.cImageHolderID;
_this.aSoundTracks;
_this.nInitialTrack;
_this.cVideoName;
_this.aImages;
_this.aMontages;
_this.cMontageHolderID;
_this.cSectionName;
_this.nSlideShowWidth;
_this.nSlideShowHeight;

// other variables
_this.lVideoOn;
_this.lAudioOn;


_this.init = function (	aVars ) {

	// passed from HTML
	this.cMediaFolder			= aVars[0];
	this.cImageFolder			= aVars[1];
	this.cImageHolderID		= aVars[2];
	this.aSoundTracks			= aVars[3];
	this.nInitialTrack		= aVars[4];
	this.cVideoName			= aVars[5];
	this.aImages				= aVars[6];
	this.aMontages				= aVars[7];
	this.cMontageHolderID	= aVars[8];
	this.cSectionName   	= aVars[9];
	this.nSlideShowWidth    = aVars[10];
	this.nSlideShowHeight   = aVars[11];
	
 	
	this.lVideo = false;
	this.lAudioOn = false;
	


	switch ( this.cSectionName )
	{
		case "Portfolio":
    		if ( this.aImages.length > 1 )
			{
			    this.galleryControl = new galleryControl();
			    this.galleryControl.parent = this;
                // aps modified 19th April 2007
			    this.aGalleryControlVars = [this.aImages, this.cMediaFolder, this.cImageHolderID, this.nSlideShowWidth, this.nSlideShowHeight];
			    //this.aGalleryControlVars = [this.aImages, this.cMediaFolder, this.cImageHolderID];
			    this.galleryControl.init(this.aGalleryControlVars, false); 
			}
			break;
		case "Product":
			if ( this.aImages.length > 1 )
			{
				this.galleryControl = new galleryControl();
				this.galleryControl.parent = this;
				this.aGalleryControlVars = [this.aImages, this.cMediaFolder, this.cImageHolderID];
				this.galleryControl.init(this.aGalleryControlVars, true); 
			}
			else
			{
				document.getElementById("SingleImage").style.marginLeft = (document.getElementById("SingleImage").width/2)*(-1) + "px";
			}

			this.swfVideoControl = new videoControl();
			this.aVideoControlVars = ["videoPlayer"];
			this.swfVideoControl.init(this.aVideoControlVars); 

			this.swfAudioControl = new audioControl();
			this.swfAudioControl.parent = this;
			this.aAudioControlVars = ["audioPlayer", this.cMediaFolder, this.aSoundTracks, this.nInitialTrack];
			this.swfAudioControl.init(this.aAudioControlVars); 
			break;

		case "Video":

			this.swfVideoControl = new videoControl();
			this.aVideoControlVars = ["videoPlayer"];
			this.swfVideoControl.init(this.aVideoControlVars); 
		

			break;

			
		default:
    		if ( this.aImages.length > 1 )
			{
			    this.galleryControl = new galleryControl();
			    this.galleryControl.parent = this;
                // aps modified 19th April 2007
			    this.aGalleryControlVars = [this.aImages, this.cMediaFolder, this.cImageHolderID, this.nSlideShowWidth, this.nSlideShowHeight];
			    //this.aGalleryControlVars = [this.aImages, this.cMediaFolder, this.cImageHolderID];
			    this.galleryControl.init(this.aGalleryControlVars, false); 
			}
			break;
	}

	this.montageControl = new montageControl();
	this.montageControl.parent = this;
	this.aMontageControlVars = [this.aMontages, this.cImageFolder, this.cMontageHolderID];
	this.montageControl.init(this.aMontageControlVars);


} ;

_this.htmlStartVideo = function () {
	
	if (this.lAudioOn ) { clearTimeout(this.swfAudioControl.hDelay); }

	this.lVideoOn = true;

	this.swfAudioControl.stop();
	this.swfAudioControl.disable();			
	
	 var oListenText1 = document.getElementById("ListenText1");
	 var oListenText2 = document.getElementById("ListenText2");
     var oListenText3 = document.getElementById("ListenText3");
                
    if ( oListenText1 && document.getElementById("ListenText1").innerHTML == "Stop Track 1" ) { document.getElementById("ListenText1").innerHTML = "Listen to Track 1"; }
    if ( oListenText2 && document.getElementById("ListenText2").innerHTML == "Stop Track 2" ) { document.getElementById("ListenText2").innerHTML = "Listen to Track 2"; }
    if ( oListenText3 && document.getElementById("ListenText3").innerHTML == "Stop Track 3" ) { document.getElementById("ListenText3").innerHTML = "Listen to Track 3"; }
	

	document.getElementById("Gallery").style.display   = "none";
	document.getElementById("VideoArea").style.display = "block";
	
	if ( this.aImages.length > 1 ) { this.galleryControl.pause(); }

	this.swfVideoControl.play(this.cMediaFolder + this.cVideoName, 2); // delay is in seconds	

	document.getElementById("WatchText").innerHTML  = "Stop Video";
	var oListenDiv = document.getElementById("ListenText");
	if ( oListenDiv ) { oListenDiv.innerHTML = "Listen"; }
}

_this.htmlStopVideo = function () {

	clearTimeout(this.swfVideoControl.hDelay);
	
	this.lVideoOn     = false;
	
	this.swfVideoControl.stop();
	this.swfAudioControl.enable();				
		
	document.getElementById("Gallery").style.display   = "block";
	document.getElementById("VideoArea").style.display = "none";
	
	if ( this.aImages.length > 1 ) { this.galleryControl.resume(); }

	document.getElementById("WatchText").innerHTML  = "Watch a Video";
	var oListenDiv = document.getElementById("ListenText");
	if ( oListenDiv ) { oListenDiv.innerHTML = "Listen"; }
}

_this.htmlPlayVideo = function() {

	if ( document.getElementById("WatchText").innerHTML == "Watch a Video" ) {
		this.htmlStartVideo();
	} else {
		this.htmlStopVideo();
	} ;
} 

_this.htmlStopVideoNoAudio = function () {

	clearTimeout(this.swfVideoControl.hDelay);
	
	this.lVideoOn     = false;
	
	this.swfVideoControl.stop();

	document.getElementById("WatchText").innerHTML  = "Watch Video";
}

_this.htmlPlayVideoNoAudio = function() {

    if ( document.getElementById("WatchText").innerHTML == "Watch Video" ) {
		this.htmlStartVideoNoAudio();
	} else {
		this.htmlStopVideoNoAudio();
	} ;
} 

_this.htmlStartVideoNoAudio = function () {
	
	this.lVideoOn = true;
	
//alert(this.cMediaFolder + this.cVideoName);
	

	this.swfVideoControl.play(this.cMediaFolder + this.cVideoName, 2); // delay is in seconds	

	document.getElementById("WatchText").innerHTML  = "Stop Video";
}

_this.htmlPlayTrack = function (nIndex) {
    switch ( nIndex )
    {
        case 0:
            if ( document.getElementById("ListenText1").innerHTML == "Listen to Track 1" )
            {
                if ( this.lVideoOn ) { this.htmlStopVideo(); } ;
                
                var oListenText2 = document.getElementById("ListenText2");
                var oListenText3 = document.getElementById("ListenText3");
                
                if ( oListenText2 && document.getElementById("ListenText2").innerHTML == "Stop Track 2" ) { this.swfAudioControl.stop(); document.getElementById("ListenText2").innerHTML = "Listen to Track 2"; }
                if ( oListenText3 && document.getElementById("ListenText3").innerHTML == "Stop Track 3" ) { this.swfAudioControl.stop(); document.getElementById("ListenText3").innerHTML = "Listen to Track 3"; }
                
		        this.lAudioOn = true;
		        this.swfAudioControl.play(nIndex, 1); // delay is in seconds
		        document.getElementById("ListenText1").innerHTML = "Stop Track 1";	
		        
            }
            else
            {
            	this.lAudioOn = false;
		        this.swfAudioControl.stop(); // delay is in seconds
		        document.getElementById("ListenText1").innerHTML = "Listen to Track 1";
            }
            break;
        case 1:
            if ( document.getElementById("ListenText2").innerHTML == "Listen to Track 2" )
            {
                if ( this.lVideoOn ) { this.htmlStopVideo(); } ;

                var oListenText1 = document.getElementById("ListenText1");
                var oListenText3 = document.getElementById("ListenText3");
                
                if ( oListenText1 && document.getElementById("ListenText1").innerHTML == "Stop Track 1" ) { this.swfAudioControl.stop(); document.getElementById("ListenText1").innerHTML = "Listen to Track 1"; }
                if ( oListenText3 && document.getElementById("ListenText3").innerHTML == "Stop Track 3" ) { this.swfAudioControl.stop(); document.getElementById("ListenText3").innerHTML = "Listen to Track 3"; }
                
		        this.lAudioOn = true;
		        this.swfAudioControl.play(nIndex, 1); // delay is in seconds
		        document.getElementById("ListenText2").innerHTML = "Stop Track 2";	
		        
            }
            else
            {
            	this.lAudioOn = false;
		        this.swfAudioControl.stop(); // delay is in seconds
		        document.getElementById("ListenText2").innerHTML = "Listen to Track 2";
            }
        
            break;
        case 2:
            if ( document.getElementById("ListenText3").innerHTML == "Listen to Track 3" )
            {
                if ( this.lVideoOn ) { this.htmlStopVideo(); } ;
                
                var oListenText1 = document.getElementById("ListenText1");
                var oListenText2 = document.getElementById("ListenText2");
                
                if ( oListenText1 && document.getElementById("ListenText1").innerHTML == "Stop Track 1" ) { this.swfAudioControl.stop(); document.getElementById("ListenText1").innerHTML = "Listen to Track 1";}
                if ( oListenText2 && document.getElementById("ListenText2").innerHTML == "Stop Track 2" ) { this.swfAudioControl.stop(); document.getElementById("ListenText2").innerHTML = "Listen to Track 2"; }
                
		        this.lAudioOn = true;
		        this.swfAudioControl.play(nIndex, 1); // delay is in seconds
		        document.getElementById("ListenText3").innerHTML = "Stop Track 3";	
		        
            }
            else
            {
            	this.lAudioOn = false;
		        this.swfAudioControl.stop(); // delay is in seconds
		        document.getElementById("ListenText3").innerHTML = "Listen to Track 3";
            }

            break;
    }
} ;

_this.htmlPauseResumeSlideShow = function() {
	if ( document.getElementById("SlideShowPauseResume").innerHTML == "pause" )
	{
		this.galleryControl.pause();
		document.getElementById("SlideShowPauseResume").innerHTML = "resume slideshow";
	}
	else
	{
		this.galleryControl.resume();
		document.getElementById("SlideShowPauseResume").innerHTML = "pause";
	}
}

_this.htmlPrevSlide = function() {
	if ( document.getElementById("SlideShowPauseResume").innerHTML == "pause" )
	{
		this.galleryControl.pause();
		document.getElementById("SlideShowPauseResume").innerHTML = "resume slideshow";
	}
	this.galleryControl.previous();
}

_this.htmlNextSlide = function() {
	if ( document.getElementById("SlideShowPauseResume").innerHTML == "pause" )
	{
		this.galleryControl.pause();
		document.getElementById("SlideShowPauseResume").innerHTML = "resume slideshow";
	}
	this.galleryControl.next();
}

_this.htmlGetState = function(){
   return this.galleryControl.getState();
}


/////////////////////// end /////////////////////////


///////////////////// galleryControl ///////////////

function galleryControl(){}

var _this = galleryControl.prototype = new Object();

_this.constructor	= galleryControl;

// class objects
_this.slideShowControl;

// containers for HTML variables
_this.aImages;
_this.cMediaFolder;
_this.cImageHolderID;
_this.nSlideShowWidth;
_this.nSlideShowHeight;

// other variables
_this.aSlideShowControlVars;
_this.aUrls;
_this.aDesc;

_this.init = function ( aVars, lOffset ) {
	
	
	this.aImages			= aVars[0];	
	this.cMediaFolder 	    = aVars[1]; //  "/Media/"
	this.cImageHolderID 	= aVars[2]; // "Gallery"
	this.nSlideShowWidth    = aVars[3];
	this.nSlideShowHeight   = aVars[4];

	this.aUrls = [];
	this.aDesc = [];
	
	for( var nIndex = 0; nIndex < aImages.length; nIndex = nIndex + 1 ) { 
		this.aUrls[this.aUrls.length] = this.aImages[nIndex].src; 
		this.aDesc[this.aDesc.length] = this.aImages[nIndex].desc; 
	}

	this.slideShowControl = new slideShowControl();
	this.slideShowControl.parent = this;
	this.aSlideShowControlVars = [this.aUrls, this.cMediaFolder, document.getElementById(this.cImageHolderID), this.aDesc, this.nSlideShowWidth, this.nSlideShowHeight];
	this.slideShowControl.init(this.aSlideShowControlVars, lOffset); 

	this.slideShowControl.start();
	
}

_this.getState = function () {
	return this.slideShowControl.lPause;
} ;

_this.start = function () {
	this.slideShowControl.start();
} ;

_this.pause = function () {
	this.slideShowControl.pause();
} ;

_this.resume = function () {
	this.slideShowControl.resume();
} ;

_this.next = function () {
	this.slideShowControl.next();
}	

_this.previous = function () {
	this.slideShowControl.previous();
}	

/////////////////////// end /////////////////////////


///////////////////// montageControl ///////////////

function montageControl(){}

var _this = montageControl.prototype = new Object();

_this.constructor	= montageControl;

// class objects
_this.slideShowControl;

// containers for HTML variables
_this.aImages;
_this.cMediaFolder;
_this.cImageHolderID;

// other variables
_this.aSlideShowControlVars;
_this.aUrls;
_this.aDesc;

_this.init = function ( aVars ) {
	
	
	this.aImages			= aVars[0];	
	this.cMediaFolder 	= aVars[1]; //  "/Media/"
	this.cImageHolderID 	= aVars[2]; // "Montage"

	this.aUrls = [];
	this.aDesc = [];
	
	for( var nIndex = 0; nIndex < this.aImages.length; nIndex = nIndex + 1 ) { 
		this.aUrls[this.aUrls.length] = this.aImages[nIndex].src; 
		this.aDesc[this.aDesc.length] = this.aImages[nIndex].desc; 
	}

	this.slideShowControl = new slideShowControlII();
	this.slideShowControl.parent = this;
	this.aSlideShowControlVars = [this.aUrls, this.cMediaFolder, document.getElementById(this.cImageHolderID), this.aDesc];
	this.slideShowControl.init(this.aSlideShowControlVars); 

	this.slideShowControl.start();

}

_this.start = function () {
	this.slideShowControl.start();
} ;

_this.resume = function () {
	this.slideShowControl.resume();
} ;
	

/////////////////////// end /////////////////////////
