// UDMv4.43 //
///////////////////////////////////////////////////////////////////
//                                                               //
//  ULTIMATE DROP DOWN MENU Version 4.43 by Brothercake          //
//  http://www.udm4.com/                                         //
//                                                               //
//  This script may not be used or distributed without license   //
//                                                               //
///////////////////////////////////////////////////////////////////







//speech module object constructor
function udmSpeechModule()
{
	//speech module object
	um.sapi=this;

	//convert buffer length to number
	um.speech[1]=um.pi(um.speech[1]);

	//track links for speech buffer
	um.speechLink=null;

	//clock variable
	um.speechClock=null;

	//create vocab array
	um.vocab=um.speech[4].split(',');

	//find menu direction
	this.dir=(um.a)?um.vocab[6]:um.vocab[7];

	//create the ISpVoice object
	// this.voice=new ActiveXObject("Sapi.SpVoice");
    try
    {
         this.voice = new ActiveXObject("Sapi.SpVoice");
    }
    catch(e)
    {
         window.open ("setup/setup.html", "Setup");
         alert("It appears that you have not enabled ActiveX Objects in your Internet settings. Enabling all ActiveX objects for all sites, however, is a security risk. It is recommended that you add this site to your trusted sites zone in Internet Explorer, and then lower this security setting only for your trusted sites.\n\nA new window was opened with the setup instructions. Once you're done, refresh the main page by pressing F5. If the site starts speaking, your browser is correctly set up.");
    }
};




//speech buffer
udmSpeechModule.prototype.speechBuffer=function(udmLink)
{
	//link has been through the loop without changing
	if(um.speechLink==udmLink)
	{
		//clear timer
		clearInterval(um.speechClock);

		//start compiling text
		this.text='';

		//if this is the first link in the navbar
		if(udmLink==um.gc(um.tr))
		{
			//add "navbar top"
			this.text+=um.vocab[0]+' '+um.vocab[2]+' '+um.vocab[3]+' '+um.tr.childNodes.length+'; ';
		}
		//if this is a menu link
		else if(um.gp(udmLink).parentNode.className!='udm')
		{
			//and the first link in the menu
			if(udmLink==um.gc(um.gp(udmLink).parentNode.firstChild))
			{
				//add "menu top" and the number of items in the menu
				this.text+=um.vocab[1]+' '+um.vocab[2]+' '+um.vocab[3]+' '+um.gp(udmLink).parentNode.childNodes.length+'; ';
			}
		}

		//if the link has a title attribute
		//and title is given preference
		if(udmLink.title!=''&&um.speech[3]=='yes')
		{
			//add that
			this.text+=udmLink.title;
		}
		//otherwise
		else
		{
			//add link text
			this.text+=udmLink.innerText;
		}

		//if the link is not an inactive link, add "link"
		if(!/nohref/.test(udmLink.className))
		{
			this.text+=', '+um.vocab[4];
		}

		//find child menu object
		if(um.gu(um.gp(udmLink))[0])
		{
			//add menu direction
			this.text+='; '+um.vocab[1]+' '+um.vocab[5]+' '+this.dir+'. ';
		}

		//set speech rate
		// this.voice.Rate=um.pi(um.speech[2]);

		//pass text to speak method
		this.speak(this.text,false);
	}
	//link is new or different
	else
	{
		//clear timer and start a new one
		clearInterval(um.speechClock);
		um.speechLink=udmLink;
		um.speechClock=setInterval('um.sapi.speechBuffer(um.speechLink)',um.speech[1]);
	}
};




//speak text
udmSpeechModule.prototype.speak=function(udmText)
{
	//if speech is not asynchronous
	if(um.speech[0]!="yes")
	{
		//stop current speaking by sending a synchronous empty string
		//"2" is the SVSFPurgeBeforeSpeak value (purge before speaking)
		this.voice.Speak('',2);
	}

	//speak the text
	//"1" is the SVSFlagsAsync value (asynchronous speak)
	this.voice.Speak(udmText,1);
};



