
/////////////////////////// functions called by HTML ///////////////////

// These functions represent the external interface to the HTML page.

function PreludeStopVideo() 				{main ? main.htmlStopVideo() 				: false;}
function PreludeStopTrack() 				{main ? main.htmlStopTrack() 				: false;}
function TextReveal() 							{main ? main.htmlTextReveal() 			: false;}
function TextHide() 								{main ? main.htmlTextHide()		 			: false;}
function ShowMask() 								{main ? main.htmlShowMask()		 			: false;}
function HideMask()	 								{main ? main.htmlHideMask()		 			: false;}
function StopMedia() 								{main ? main.htmlStopMedia() 				: false;}
function BypassFlashUpdate()				{main ? main.swfBypassUpdate() 			: false;}

/////////////////////////// end //////////////////////////////////


///////////////////////// main /////////////////////////////////

var main;

function init(){

	main = new mainControl();
    main.bHomePage = bHomePage;
	main.init("main");

    window.onunload = function(){StopMedia();}
    
}

/////////////////////////// end //////////////////////////////////


//////////////////////// main control ////////////////////////////


function mainControl(){}

var _this = mainControl.prototype = new Object();

_this.constructor	= mainControl;

_this.className = "mainControl";

_this.name;

_this.swfInstall;
_this.swfLetterP;
_this.swfPreludeB;
_this.swfPreludeC;
_this.swfPreludeD;
_this.swfPreludeF;
_this.swfPreludeI;
_this.swfPreludeL;
_this.swfPreludeS;
_this.swfPreludeV;

_this.swfInstalled;

_this.pFinished; 
_this.browser;

_this.init = function (cName) {
	// passed from HTML
	this.name = cName;
	
	this.swfInstalled = false;

	if (navigator.appName.indexOf("Microsoft") != -1) {
		// IE
		this.browser = "IE";
	} else {
		// FireFox
		this.browser = "FF";
	}	
	
	if (cPageType == "I") {	
		this.swfInstall = new InstallSwf();
		this.swfInstall.parent = this;
		this.swfInstall.init(this.name + ".swfInstall", aInstallSwf);	
		if (this.swfInstall.loaded()) {
			this.swfInit();		
		}
	} else {
		this.swfInit();
	}
	
}

_this.swfBypassUpdate = function () {
	this.swfInstall.hide();	
	this.swfInit();
}

_this.swfInit = function () {
	
	this.swfInstalled = true;
	this.pFinished = false;
	this.swfLetterP = new LetterP();
	this.swfLetterP.parent = this;
	this.swfLetterP.init(this.name + ".swfLetterP", aLetterP, cPageType);	

	if (cPageType == "B" || cPageType == "C" || cPageType == "D" || cPageType == "N" || cPageType == "T") { 
		if (this.browser == "IE") {	
			this.swfPreludeF = new PreludeClassF();
			this.swfPreludeF.parent = this;
			this.swfPreludeF.init(this.name + ".swfPreludeF", aPageClassF, cXmlData, cXmlClassF);
		}
	}

	// cPageType = "Z";
	
	switch (cPageType) {
		case "B":
			this.swfPreludeB = new PreludeClassB();
			this.swfPreludeB.parent = this;
			this.swfPreludeB.init(this.name + ".swfPreludeB", aPageClassB, cXmlData, cXmlContent);	
			this.swfPreludeS = new PreludeClassS();
			this.swfPreludeS.parent = this;
			this.swfPreludeS.init(this.name + ".swfPreludeS", aPageClassS, cXmlData, cXmlContent);				
			if (this.homePage()) {
				this.swfPreludeL = new PreludeClassL();
				this.swfPreludeL.parent = this;
				this.swfPreludeL.init(this.name + ".swfPreludeL", aPageClassL, cXmlData, cXmlContent);					
			}
			break;	
		case "C":
			if(bIE()){
				this.swfPreludeC = new PreludeClassC();
				this.swfPreludeC.parent = this;
				this.swfPreludeC.init(this.name + ".swfPreludeC", aPageClassC, cXmlData, cXmlContent);	
			}
			break;
		case "D":
		    this.swfPreludeD = new PreludeClassD();
              this.swfPreludeD.parent = this;
              this.swfPreludeD.init(this.name + ".swfPreludeD", aPageClassD, cXmlData, cXmlContent);
              this.swfPreludeT = new PreludeClassT();
              this.swfPreludeT.parent = this;
              this.swfPreludeT.init(this.name + ".swfPreludeT", aPageClassT, cXmlData, cXmlContent);
			break;		
		case "F":
			if (this.browser == "IE") {	
				this.swfPreludeF = new PreludeClassF();
				this.swfPreludeF.parent = this;
				this.swfPreludeF.init(this.name + ".swfPreludeF", aPageClassF, cXmlData, cXmlContent);	
			}
			break;
		case "I":
			this.swfPreludeI = new PreludeClassI();
			this.swfPreludeI.parent = this;
			this.swfPreludeI.init(this.name + ".swfPreludeI", aPageClassI, cXmlData, cXmlContent);	
			break;
		case "V":
			this.swfPreludeV = new PreludeClassV();
			this.swfPreludeV.parent = this;
			this.swfPreludeV.init(this.name + ".swfPreludeV", aPageClassV, cXmlData, cXmlContent);	
			break;			
		default:
			break;
	}
	
}

// Entertainments Controls

_this.htmlStopMedia	= function () {

	if (this.swfInstalled) {	
	    
    hideElement("PageText");
		this.swfLetterP.swfDeletePlayer();  delete this.swfLetterP;	
		if (cPageType == "B" || cPageType == "C" || cPageType == "D" || cPageType == "N" || cPageType == "T") { 
			if (this.browser == "IE") {	
				this.swfPreludeF.swfDeletePlayer(); delete this.swfPreludeF;  
			}
		}
		
		// cPageType = "Z";
		
		switch (cPageType) {
		    case "B":   this.swfPreludeB.swfDeletePlayer(); delete this.swfPreludeB;  
		    		    		this.swfPreludeS.swfDeletePlayer(); delete this.swfPreludeS;
								    if (this.homePage()) {
								    	this.swfPreludeL.swfDeletePlayer(); delete this.swfPreludeL;
								    }		    
		      					break;	
		    case "C":   this.swfPreludeC.swfDeletePlayer(); delete this.swfPreludeC;  break;
		    case "D":   this.swfPreludeD.swfDeletePlayer(); delete this.swfPreludeD;  break;	
		    case "I":   this.swfPreludeI.swfDeletePlayer(); delete this.swfPreludeI;  break;
		    case "V":   this.swfPreludeV.swfDeletePlayer(); delete this.swfPreludeV;  break;			
	    }
	}
}

_this.htmlStopTrack = function () {
	if (cPageType == "C") {
		this.swfPreludeC.swfStopTrack();
	}
}

_this.htmlStopVideo = function () {
	if (cPageType == "V") {
		this.swfPreludeV.swfStopVideo();
	}
}

_this.htmlTextReveal = function () {
	if (this.browser == "IE") {	
  	this.swfPreludeF.swfStart();
  }
}

_this.htmlTextHide = function () {
	if (this.browser == "IE") {	
    this.swfPreludeF.swfStop();
	}
}

_this.htmlShowMask = function () {
	if (this.browser == "IE") {	
		this.swfPreludeF.swfShow();
	}
}

_this.htmlHideMask = function () {
	if (this.browser == "IE") {	
		this.swfPreludeF.swfHide();
	}
}

_this.swfPreludeStatus = function(cStatus) {
	document.getElementById("PreludeStatus").value = document.getElementById("PreludeStatus").value + cStatus + "\r\n";
}

_this.swfStatus = function(cSwfName, cStatus) {
	if (cStatus == "LetterP:Finished") {
			this.pFinished = true;		
			this.swfPreludeStatus(cStatus)
			if( cPageType == "T" || cPageType == "N" ) {
			    this.showMenu(); 
			}
			if(!bIE() && (cPageType == "C")) {
				this.swfPreludeC = new PreludeClassC();
				this.swfPreludeC.parent = this;
				this.swfPreludeC.init(this.name + ".swfPreludeC", aPageClassC, cXmlData, cXmlContent);	
			}	
	} else {
		switch (cSwfName) {
			case "main.swfPreludeB":	
				this.swfPreludeStatus(cStatus);
				break;
			case "main.swfPreludeC":	

				this.swfPreludeStatus(cStatus);
			
		    if( cStatus.split(":")[0] == "Video" ){
		        if( cStatus.split(":")[1] == "None"){
		            this.hideVideoCtrls(); 
		        }else{
		            this.showVideoCtrls(cStatus.split(":")[1]); 
		        }
		    }
		    
		    if( cStatus.split(":")[0] == "Audio" ){
		        if( cStatus.split(":")[1] == "None"){
		            this.hideAudioCtrls(); 
		        }else{
		            this.showAudioCtrls(); 
		        }
		    }

		    if( cStatus.split(":")[0] == "WatchVideo" ){
		    	var cVideoURL = document.getElementById("playVideo" + cStatus.split(":")[1]).href;
					location.href = cVideoURL;
				}
				
		    if( cStatus.split(":")[0] == "StopAudio" ){
					this.swfPreludeC.swfStopTrack();		    	
		    }			
				break;
			case "main.swfPreludeD":	
				this.swfPreludeStatus(cStatus);
				break;
			case "main.swfPreludeF":
			   // alert( cStatus );
				this.swfPreludeStatus(cStatus);
				break;
			case "main.swfPreludeI":	
				if (cStatus == "Movie:Finished") {
					//this.showMenu();
					location.href = "/EntertainmentIdeas?action=intro";
				}
				this.swfPreludeStatus(cStatus);
				break;
			case "main.swfPreludeL":	
				if (cStatus == "Logo:Finished") {
				    showElement("NormLogo");
				}
				this.swfPreludeStatus(cStatus);
				break;
			case "main.swfPreludeS":	
				this.swfPreludeStatus(cStatus);
				break;
			case "main.swfPreludeV":	
				this.swfPreludeStatus(cStatus);
				break;
			case "main.swfLetterP":	
				this.swfPreludeStatus(cStatus);
				break;				
		}
	}
	
	if( cStatus == "Movie:Started" ){
		if( cPageType != "I" && cSwfName != "main.swfPreludeF" && cSwfName != "main.swfPreludeD" ){
			this.showMenu();
        }else if( cSwfName == "main.swfPreludeF" ){
            HideMask();
        }
	}
}			

_this.letterPFinished = function () {
	return this.pFinished;
}

_this.homePage = function() {
	return this.bHomePage;	
}

_this.showVideoCtrls = function(cID){
	this.hideVideoCtrls();
  showElement("playVideo" + cID);
  this.cCurrentVideoId = cID;
}

_this.showAudioCtrls = function(cID){
	showElement("stopAudio");
}

_this.hideVideoCtrls = function(cID){
	if( this.cCurrentVideoId ){
  	hideElement("playVideo" + this.cCurrentVideoId);
	}
}

_this.hideAudioCtrls = function(cID){
    hideElement("stopAudio");
}



_this.showMenu = function(){

    ShowMask(); 
    
    setTimeout(function(){
               
	        if( cPageType != "V" ){
                showElement("PageText");
            }
	        if( cPageType == "N" ){
                showElement("AltHeader");
            }
            showElement("ContactForm");
	        if( cPageType != "D" ){
                showElement("ClassBButtons");
                if( document.getElementById( "QuoteList" ) ) { document.getElementById("QuoteList").scrollAmount = 4; }
                showElement("QuoteListLeft");
                showElement("QuoteListRight");
                showElement("QuoteList");
               TextReveal();
            }else{
                showElement("GenLeft");
                showElement("GenTop");
                showElement("GenBottom");
                showElement("Quotes");
                showElement("ClientList");
                showElement("AltHeadClient");
                showElement("AltHeadVenue");
               // cycleQuotes();
               TextReveal();
            }
        }, 250 
    ); 
}

function posMenus(){
    hideElement("SubMenu");
    if( document.getElementById("SubMenu") ){
        
        /* Position next to Item */
        var aItems = getElementsByClassName( document.getElementById("MainMenu"), "selected" );
        var nOffSet = bIE() ? 90 : 50;
        
        if( aItems.length > 0 ){ 
            if( aItems[0].innerHTML != "Shows"/*.offsetLeft + document.getElementById("SubMenu").offsetWidth + nOffSet) < 970*/ ){
                document.getElementById("SubMenu").style.left = nOffSet + aItems[0].offsetLeft + "px"; 
            }else /*if( aItems[0].offsetLeft + aItems[0].offsetWidth > document.getElementById("SubMenu").offsetWidth )*/ {
                document.getElementById("SubMenu").style.left = nOffSet + aItems[0].offsetLeft - 150 + "px"; 
            } 
        }
    }
    showElement("SubMenu");
}

function cycleQuotes(){ 

    /* Store refs in theTol Global Scope */
    top.nIndex = 0; 
    top.cRef = "";
    swapQuote(); 
    setInterval( swapQuote, 5000);
    
}

function swapQuote(){ 
    
    /* If one is already visiable, hide it. */
    if( top.cRef != "" ){
        hideElement(  "Quote"   + top.cRef );
        hideElement(  "QuoteBy" + top.cRef );
    }
    
    /* Reference the Ref */
    top.cRef = aQuotes[top.nIndex];
    
    /* Display the New Ref */
    fadeElement( "Quote"    + top.cRef );
    fadeElement( "QuoteBy"  + top.cRef );

    /* Step on the Indexer */
    top.nIndex++; 
    
    if( top.nIndex >= aQuotes.length ){ top.nIndex = 0; }
}

function showElement(cID) { var eRef = document.getElementById(cID); if( eRef ){ eRef.style.display = "block"; } }
function hideElement(cID) { var eRef = document.getElementById(cID); if( eRef ){ eRef.style.display = "none";  } }

function bIE(){ if( navigator.userAgent.indexOf("MSIE") > -1) return true; else return false;}

function fadeElement(cID){

    var elRef = document.getElementById(cID); 
    if( !elRef ){ return; }
    elRef.style.filter = "alpha(opacity=0)";
    elRef.style.display = "block";
    elRef.nCurOpacity = 0;
    elRef.cHandle = "hFade" + cID;
    
    var fnFade = function(){
        elRef.nCurOpacity += 10;
        if( elRef.nCurOpacity >= 100 ){
            elRef.style.filter = "";     
            clearInterval( top[elRef.cHandle] );
        }else{
            elRef.style.filter = "alpha(opacity=" + elRef.nCurOpacity + ")";     
        }
    }
    
    top[elRef.cHandle] = setInterval( fnFade, 100 ); 

}
