//global variables
var FlashCookieName = "FlashEnabled"
var MusicCookieName = "MusicEnabled"

//ExpiresDays and Path are optional.
//ExipiresDays = the number of days this cookie should live for
//set ExipiresDays = 0 if you want it to expire after this session (the default)
//The default Path is "/"
function SetCookie(Name, Value, ExpiresDays, Path)
{
	var CookieString = new String(Name +"="+ Value + ";");
	if ((arguments.length >= 3) && 
		(ExpiresDays != 0))
	{	// add the expiresMS
		var ExpiresDate = new Date();
		ExpiresDate.setTime(ExpiresDate.getTime() + ExpiresDays * 24 * 60 * 60 * 1000);
		CookieString += "expires=" + ExpiresDate.toGMTString() + ";";
	}

	if (arguments.length >= 4)
	{	//set the path
		CookieString += "path=" + Path + ";";
	}
	else
	{	//the default path
		CookieString += "path=/;";
	}
	document.cookie = CookieString;
}

function GetCookie(Name)
{
	var CookieString = new String(document.cookie);
	var ReturnValue = "";
	var NameHeader = new String(Name +"=");
	
	var Start = CookieString.indexOf(NameHeader);
	
	if (Start != -1)
	{
		Start += NameHeader.length;
		var End = CookieString.indexOf(";", Start);
		if (End != -1)
		{
			ReturnValue = CookieString.substring(Start, End);
		}
		else
		{
			ReturnValue = CookieString.substr(Start);
		}
	}
	return ReturnValue;
}


//music functions
function SetMusicEnabled(Enabled){
	SetCookie(MusicCookieName, (Enabled)?"True":"False", 365);
}

function IsMusicEnabled(){
	return (GetCookie(MusicCookieName)=="True")?true:false;
}

function musicNavigate(sectionString,theURL){
	if (IsMusicEnabled()){
		window.location = theURL;
		parent.bottomnav.location.replace("bottomnav.asp?music=" + sectionString);
	}else{
		window.location = theURL;
	}
	return false;
}
//this function is to accommodate the dining subnavigation pages- its complicated.
function diningMusicNavigate(sectionString,theURL){
	if (IsMusicEnabled()){
		window.location = theURL;
		/*if the current page is the top level of the dining section-
		the music shouldn't be changed */
		var myWindow = self.location;
		myWindow = myWindow.toString();
		if ((myWindow.indexOf("din_bars.asp") != -1) || (myWindow.indexOf("din_main_flash.asp") != -1)){
			//buffet is the same as the main page for dining- weirdness
		}else{
			parent.bottomnav.location.replace("bottomnav.asp?music=" + sectionString);
		}
	}else{
		window.location = theURL;
	}
	return false;
}

function ToggleMusic(sectionString){
	if (IsMusicEnabled()){ //if music is on, turn it off
		parent.bottomnav.location.replace("bottomnav.asp?music=none");
		SetMusicEnabled(false);
	}else{ //or, turn it on
		if (confirm("Would you like to enable the Active Soundtrack? This feature allows music to play while you are viewing the site. It was created primarily for high-bandwidth users. Turning it on may slow the loading of graphic elements for modem connections.")){
			parent.bottomnav.location.replace("bottomnav.asp?music=" + sectionString);
			SetMusicEnabled(true);
		}
	}
	return false;
}

function RolloverMusic(imgOn, imgOff){
	if (IsMusicEnabled()){
		window.document.musicnotes.src = imgOff;
		MM_displayStatusMsg('Turn music off');
		return true;
	}else{
		window.document.musicnotes.src = imgOn;
		MM_displayStatusMsg('Turn music on');
		return true;
	}
}

function RolloverMusicOff(imgSrc){
		window.document.musicnotes.src = imgSrc;
		MM_displayStatusMsg('');
		return true;
}


function navigateFromPopup(url,sectionString){
	opener.document.location = url;
	if (IsMusicEnabled()){
		opener.parent.bottomnav.location.replace("bottomnav.asp?music=" + sectionString);
	}
	window.close();
}


//go to the FlashURL if Enabled
// otherwise goto the NonFlashURL
function FlashNavigate(FlashURL, NonFlashURL)
{
	if (IsFlashEnabled())
	{
		window.location = FlashURL;
	}
	else
	{
		window.location = NonFlashURL;
	}
	return false;
}

//Go to this url if flash is enabled.
//Returns false if it navigates (to cancel a <a> onclick event)
//or True if it doesn't
function GoIfFlash(FlashURL)
{
	if (IsFlashEnabled())
	{
		window.location = FlashURL;
		return false; //cancel the OnClick event
	}
	else
	{
		return true;
	}
}

function IsFlashEnabled()
{
	return (GetCookie(FlashCookieName)=="True")?true:false;
}

function FlashTest()
{
	var HasFlash = false;
	if (navigator.appName == "Netscape" && navigator.plugins) 
	{
		for (var i = 0; i < navigator.plugins.length; i++)
        {
        	var plugin = navigator.plugins[i];
			if (plugin.description.indexOf("Flash 4") != -1)               
			{
            	for (var j = 0; j < plugin.length; j++) 
                {
                   var mimetype = plugin[j];
                   if (mimetype)
                   {     
                      if (mimetype.enabledPlugin && (mimetype.suffixes.indexOf("swf") != -1))
                         HasFlash = true;
                      // Mac wierdness
                      if (navigator.mimeTypes["application/x-shockwave-flash"] == null)
                         HasFlash = false;
                   }
            	}
            }
         }                        
    }
	// MSIE browser for Win95/NT (ActiveX)
	else if (navigator.appName.indexOf('Microsoft') != -1 &&
	       navigator.appVersion.indexOf('Mac') == -1 &&
	       navigator.appVersion.indexOf('3.1') == -1)
	{
		HasFlash = true;
	}

	if (GetCookie(FlashCookieName) == "")
	{	//only set the cookie if it hasn't been set before
		SetFlashEnabled(HasFlash);		
	}
}

function SetFlashEnabled(Enabled)
{
	SetCookie(FlashCookieName, (Enabled)?"True":"False", 365);
}

function WriteFlashCheckBox()
{
	document.write('<input type="CheckBox" name="FlashEnabled" onClick="SetFlashEnabled(this.checked);" ')
	if (IsFlashEnabled())
	{
			document.write(' checked ');
	}
	document.write('>');	
}

//Disable flash and navigate to a URL
function DisableFlash(NonFlashURL)
{
	SetFlashEnabled(false);
	window.location = NonFlashURL;
	return false;
}

//Enable flash and navigate to a URL
function EnableFlash(FlashURL)
{
	SetFlashEnabled(true);
	window.location = FlashURL;
	return false;
}


function GoIfFlashBreakout(FlashURL)
{
	if (IsFlashEnabled())
	{
		top.location = FlashURL;
		return false; //cancel the OnClick event
	}
	else
	{
		return true;
	}
}





//macromedia functions
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
  window.status='';
  return true;
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function SetStatusbar(msg){
	window.status=msg;
	return true;
}

function MM_displayStatusMsg(msgStr) { //v1.0
  status=msgStr;
  document.MM_returnValue = true;
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
