
///////////////////// 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;

// other variables
_this.lVideoOn;
_this.lAudioOn;
_this.lVideoPaused;
_this.nVideoStartDelay;
_this.nShowcaseButtonDelay;

// new 2008 variables
_this.name;

_this.test = "";

_this.swfBasicControl;

_this.init = function (cName, 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.lVideoOn = false;
	this.lAudioOn = false;
	
	this.name = cName;

	switch ( this.cSectionName ){
		
		case "Portfolio":
			this.galleryControl = new galleryControl();
			this.galleryControl.parent = this;
			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
			{
			    var oTest = document.getElementById("SingleImage");
			    if ( oTest != null ) { 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 "Product2008":
		 			
		   if ( this.aImages.length > 1 ) {
				this.switchToGallery();
				this.galleryControl = new galleryControl();
				this.galleryControl.parent = this;
				this.aGalleryControlVars = [this.aImages, this.cMediaFolder, this.cImageHolderID];
				this.galleryControl.init(this.aGalleryControlVars, true); 
				if (document.getElementById("SlideShow")) {
					document.getElementById("SlideShow").innerHTML  = "Photos";			  		           
				}
			} else {
			    var oTest = document.getElementById("SingleImage");
			    if ( oTest != null ) { 
			    	document.getElementById("SingleImage").style.marginLeft = (document.getElementById("SingleImage").width/2)*(-1) + "px"; 
					document.getElementById("SingleImage").style.visibility = "visible";
			    }
			}
					 	   
			if ( cIsVideo ) {
				this.switchToVideo();				
		 		document.getElementById("WatchText").innerHTML  = "Loading";
			   this.swfVideoControl = new videoControl();
      	   this.swfVideoControl.parent = this;
         	this.swfVideoControl.init("swfVideoControl", aPlayer_1, aSpinner_1, aOverlay_1, aBackground_1);	
         	this.switchToGallery()
			} 
			
			if (cIsAudio) {
				
				document.getElementById("ListenText").innerHTML  = "Loading";
	      	this.swfAudioControl = new audioControl();
        		this.swfAudioControl.parent = this;
	      	this.swfAudioControl.init("swfAudioControl", aPlayer_3, aAudioTracks, nInitialAudioTrack, cAudioFolder, nAudioFadeTime);	
        		// this.swfAudioControl.playInitialTrack();
	      }
				       
	      break;
    
		case "Showcase2008":
		
			this.lVideoPaused = false;
			document.getElementById("play2008").innerHTML  = "Loading";
			document.getElementById("play2009").innerHTML  = "";
			document.getElementById("pausebutton").style.visibility = "visible";
			this.swfVideoControl = new videoControl();
	      this.swfVideoControl.parent = this;
	      this.swfVideoControl.init("swfVideoControl", aPlayer_1, aSpinner_1, aOverlay_1, aBackground_1);	  
		   break;

	}

	this.montageControl = new montageControl();
	this.montageControl.parent = this;
	this.aMontageControlVars = [this.aMontages, this.cImageFolder, this.cMontageHolderID];
	this.montageControl.init(this.aMontageControlVars);

} ;


_this.htmlPlayVideo = function(cFlv) {
	var self = this;
	
	switch ( this.cSectionName ) {
		
		case "Product2008":
	
			switch (document.getElementById("WatchText").innerHTML) {
				case "Watch":
					this.switchToVideo();
					this.nVideoStartDelay = setInterval( function () {self.delayedVideoPlay(cFlv)}, 400); 
		   	   // this.swfVideoControl.play(cFlv);
		   	   if (cIsAudio) {
						this.swfAudioControl.stop();
					}
		   	   break;
				case "Stop":
					this.swfVideoControl.stop();		
					this.switchToGallery();
					this.galleryControl.restart();
					break;
			}
			break;

		case "Showcase2008":
			switch (document.getElementById("play2008").innerHTML) {
				case "Play Showcase 2008":
					this.nVideoStartDelay = setInterval( function () {self.delayedVideoPlay(cFlv)}, 400); 
		   	   // this.swfVideoControl.play(cFlv);
					break;								
				case "Stop Showcase Video":
					this.swfVideoControl.stop();		
					break;
			}		

			break;
			
	}

} ;

_this.delayedVideoPlay = function(cFlv) {
	// need to wait for the page elements to be reset
	clearInterval(this.nVideoStartDelay);
	this.swfVideoControl.play(cFlv);	
}

_this.delayedShowcaseButtons = function() {
	// need to wait for the page elements to be reset
	clearInterval(this.nShowcaseButtonDelay);
	document.getElementById("play2008").innerHTML  = "Play Showcase 2008";
	document.getElementById("play2009").innerHTML  = "Play Showcase 2009";
}

_this.htmlPlayAudio = function (nIndex) {
	
	switch ( this.cSectionName ) {
		
		case "Product2008":
	
			switch ( document.getElementById("ListenText").innerHTML) {
				case "Listen":
					if ( this.lVideoOn ) { 
						this.swfVideoControl.stop();
					}
					this.switchToGallery();
					this.swfAudioControl.play(nIndex);
					if ( this.aImages.length > 1 ) {
						this.galleryControl.restart();
					}
					break;
				case "Stop":
					this.swfAudioControl.stop();		
					break;
			}
			break;
		
		case "Showcase2008":
		
			break;
			
	}
} ;


_this.htmlStartSlideShow = function (nIndex) {
	
	switch ( this.cSectionName ) {
		
		case "Product2008":
	
			if ( this.lVideoOn ) { 		
				this.swfVideoControl.stop();
			}
			this.switchToGallery();
			this.galleryControl.restart();
			break;

		case "Showcase2008":
		
			break;
	}
}

_this.switchToVideo = function () {
   document.getElementById("VideoArea").style.visibility = "visible";
   document.getElementById("VideoArea").style.display = "block";
   document.getElementById("Gallery").style.display = "none";
   document.getElementById("Gallery").style.visibility = "hidden";
}

_this.switchToGallery  = function () {
 	document.getElementById("Gallery").style.visibility = "visible";
   document.getElementById("Gallery").style.display = "block";
   document.getElementById("VideoArea").style.display = "none";
   document.getElementById("VideoArea").style.visibility = "hidden";
}

_this.htmlPauseResumeVideo = function() {

	switch ( this.cSectionName ) {	
		case "Product2008":
			break;
		case "Showcase2008":					
			if ( this.lVideoOn ) { 
				this.swfVideoControl.pauseResume();				
			}	
			break;
	}

}

/*

		// <div class='Listen' onclick='startPlayTrack()'>
		<div class='Listen' onclick='PlayTrack(1)'>
							
		// <div class='Watch' onclick='startProductVideo("http://www.asandl.co.uk/media/V0013100002.FLV");'>
		<div class='Watch' onclick='PlayVideo("http://www.asandl.co.uk/media/V0013100002.FLV");'>		
		
		// <div class='SlideShow' onclick='startSlideShow()'><span id='SlideShow'>Photos</span></div>	
		<div class='SlideShow' onclick='StartSlideShow()'><span id='SlideShow'>Photos</span></div>


function PlayVideo(cFlv) 			{ main ? main.htmlPlayVideo(cFlv) 						: false; }
function PlayTrack(nIndex) 	   { main ? main.htmlPlayAudio(nIndex) 					: false; }
function StartSlideShow() 	    	{ main ? main.htmlStartSlideShow() 						: false; }

*/



_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();
}

// new video methods 5.6.2008

/*

_this.htmlPlay = function (cFlv) {
	this.swfVideoControl.play(cFlv);
}

_this.htmlStop = function () {
	this.swfVideoControl.stop();
}

_this.htmlPlayPause	= function () {
	this.swfVideoControl.pauseResume();
}

_this.htmlMute = function () {
	this.swfVideoControl.mute();
}

_this.htmlVolume = function (nVol) {
	this.swfVideoControl.volume(nVol);
}	

_this.htmlHideReveal = function () {
	this.swfVideoControl.hideReveal();	
}

*/

_this.swfStatus = function(cSwfName, cStatus) {
	switch (cSwfName) {
		case "swfVideoControl":	
			this.swfVideoStatus(cStatus);
			break;
		case "swfAudioControl":	
			this.swfAudioStatus(cStatus);
			break;			
	}
}			
						
_this.swfVideoStatus = function(cStatus) {	
	var self = this;	
	switch(cStatus) {
		case "Movie:Loaded":
			break;
		case "SwfFormFixed":
			switch ( this.cSectionName ) {
				case "Product2008":
					document.getElementById("WatchText").innerHTML  = "Watch";	
					break;
				case "Showcase2008":
					this.nShowcaseButtonDelay = setInterval( function () {self.delayedShowcaseButtons()}, 4000); 
					break;
			}
			break;
		case "Muted:Off":
			break;
		case "Muted:On":
			break;
		case "Paused:Off":
			this.lVideoPaused = false;
			switch ( this.cSectionName ) {
				case "Product2008":
					break;
				case "Showcase2008":
					document.getElementById("pausebutton").innerHTML  = "Pause";									
					break;
			}
			break;
		case "Paused:On":
			this.lVideoPaused = true;
			switch ( this.cSectionName ) {
				case "Product2008":
					break;
				case "Showcase2008":
					document.getElementById("pausebutton").innerHTML  = "Resume";									
					break;
			}
			break;
		case "Flv:Started":
			this.lVideoOn = true;
			switch ( this.cSectionName ) {
				case "Product2008":
					document.getElementById("WatchText").innerHTML  = "Stop";	
					break;
				case "Showcase2008":
					document.getElementById("play2008").innerHTML  = "";
					document.getElementById("play2009").innerHTML  = "Stop Showcase Video";
					document.getElementById("pausebutton").innerHTML  = "Pause";									
					break;
			}
			break;
		case "Flv:Stopped":
			this.lVideoOn = false;
			switch ( this.cSectionName ) {
				case "Product2008":
					document.getElementById("WatchText").innerHTML  = "Watch";	
					break;
				case "Showcase2008":
					document.getElementById("play2008").innerHTML  = "Play Showcase 2008";
					document.getElementById("play2009").innerHTML  = "Play Showcase 2009";
					document.getElementById("pausebutton").innerHTML  = "";									
					break;
			}
			break;
		case "Flv:Finished":
			this.lVideoOn = false;
			switch ( this.cSectionName ) {
				case "Product2008":
					document.getElementById("WatchText").innerHTML  = "Watch";	
					break;
				case "Showcase2008":
					document.getElementById("play2008").innerHTML  = "Play Showcase 2008";
					document.getElementById("play2009").innerHTML  = "Play Showcase 2009";
					document.getElementById("pausebutton").innerHTML  = "";									
					break;
			}
			this.switchToGallery();
			break;
		default:
			break;
	}		
}

// Audio Controls

/*

_this.htmlPlayAudio = function (cTrack) {
	this.swfAudioControl.play(cTrack + 1);
}

_this.htmlStopAudio = function () {
	this.swfAudioControl.stop();
}

_this.htmlPlayPauseAudio	= function () {
	this.swfAudioControl.pauseResume();
}

_this.htmlMuteAudio = function () {
	this.swfAudioControl.mute();
}

_this.htmlVolumeAudio = function (nVol) {
	this.swfAudioControl.volume(nVol);
}

*/

_this.swfAudioStatus = function(cStatus) {
	switch(cStatus) {
		case "Player:Loaded":
			break;
		case "SwfFormFixed":
			document.getElementById("ListenText").innerHTML = "Listen";
			break;
		case "Muted:Off":
			break;
		case "Muted:On":
			break;
		case "Paused:Off":
			break;
		case "Paused:On":
			break;
		case "Play:Started":
			this.lAudioOn = true;
			document.getElementById("ListenText").innerHTML = "Stop";
			break;
		case "Play:Stopped":
			this.lAudioOn = false;
			document.getElementById("ListenText").innerHTML = "Listen";
			break;
		case "Play:Finished":
			this.lAudioOn = false;
			document.getElementById("ListenText").innerHTML = "Listen";
			break;
		default:
			break;
	}
}

/////////////////////// 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;

// 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.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.slideShowControl.init(this.aSlideShowControlVars, lOffset); 

	this.slideShowControl.start();
	
}

_this.start = function () {
	this.slideShowControl.start();
} ;

// EMS Added 14/3/08
_this.restart = function () {
	this.slideShowControl.restart();
} ;

_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 /////////////////////////
