var browserName=navigator.appName;

function sendEvent(swf,typ,prm) 
{ 
  thisMovie(swf).sendEvent(typ,prm); 
}

function getUpdate(typ,pr1,pr2,swf) {}

function thisMovie(swf) {
  if(navigator.appName.indexOf("Microsoft") != -1) {
    return window[swf];
  } else {
    return document[swf];
  }
}

function getUpdate(typ,pr1,pr2,swf) 
	{ 
 		 
		  if(typ == 'time')
  		 {
    		var currentElapsed = pr1;
    	  	var currentRemaining = pr2;
			//alert("elapsed : "+currentElapsed+" remain : "+currentRemaining);
			
			if(currentRemaining == 1)
			{
				stop();
			}
			
			if(currentElapsed == 1)
			{
				start();
			}
  		 }
		 
		 if(typ == 'state') 
		 { 
		 		
			if(pr1 == 2)
			{
				document.getElementById('play').className = 'hidden';
				document.getElementById('pause').className = 'unhidden';
			}
			
			if (pr1 == 3)
			{
				document.getElementById('play').className = 'unhidden';
				document.getElementById('pause').className = 'hidden';
			}

		 }
	}

	function start()
	{
		 	
			document.getElementById("neuro-linguistics").StopPlay();
			
			if (BrowserDetect.browser == 'Firefox') 
			{
				document.getElementById("living-in-formation-movie").StopPlay();
				
			}
			else
			{
				document.getElementById("living-in-formation").StopPlay();
			}
			
				//sound fade
				var millisec = 500;
				var speed = Math.round(millisec/100);
				var timer = 0;
			
				for (i=100; i>=0; i--)
				{
					setTimeout("soundManager.setVolume('mySound',"+i+")",(timer * speed));
					timer++;		
				}
			setTimeout("soundManager.unload('mySound')",500);		
				
			//Hide music button
			document.getElementById("music_pause").className = 'hidden';
			document.getElementById("music_play").className = 'hidden';
			
		
	}
	
	function stop()
	{
			//Display music button			
			document.getElementById("music_pause").className = 'unhidden';
			document.getElementById("music_play").className = 'hidden';
				
			document.getElementById("neuro-linguistics").Play();
			
			if (BrowserDetect.browser == 'Firefox') 
			{
				document.getElementById("living-in-formation-movie").Play();
				
			}
			else
			{
				document.getElementById("living-in-formation").Play();
			}
			
			soundManager.createSound('mySound','mp3/grand_central.mp3');	
			soundManager.play('mySound');
			//soundManager.resume('mySound');
			//sound swell
			var millisec = 2000;
			var speed = Math.round(millisec/100);
			var timer = 0;
			
			for (i=0; i<=100; i++)
			{
				setTimeout("soundManager.setVolume('mySound',"+i+")",(timer * speed));
				timer++;
			}
		
	}

function pause()
{
	document.getElementById('play').className = 'unhidden';
	document.getElementById('pause').className = 'hidden';
}

function sound(state,id,play,pause)
{
	if(state == 'off')
	{
		var millisec = 500;
		var speed = Math.round(millisec/100);
		var timer = 0;
			
		for (i=100; i>=0; i--)
		{
			setTimeout("soundManager.setVolume('"+id+"',"+i+")",(timer * speed));
			timer++;		
		}
		setTimeout("soundManager.togglePause('"+id+"')",500);
		document.getElementById(play).className = 'unhidden';
		document.getElementById(pause).className = 'hidden';
	}
	
	if(state == 'on')
	{
		soundManager.togglePause(id);
		
		var millisec = 1000;
		var speed = Math.round(millisec/100);
		var timer = 0;
			
		for (i=0; i<=100; i++)
			{
				setTimeout("soundManager.setVolume('"+id+"',"+i+")",(timer * speed));
				timer++;
			}
		
		document.getElementById(pause).className = 'unhidden';
		document.getElementById(play).className = 'hidden';
	}
	
}

 /*function updateHTML(elmId, value) {
          document.getElementById(elmId).innerHTML = value;
		  
        }

        function setytplayerState(newState) {
		  
          //when movie plays, pause slide show
		  if(newState == 3)
		  {
		  	document.getElementById("neuro-linguistics").StopPlay();
			document.getElementById("living-in-formation").StopPlay();
			//sound fade
			var millisec = 2000;
			var speed = Math.round(millisec/100);
			var timer = 0;
			
			for (i=100; i>=0; i--)
			{
				setTimeout("soundManager.setVolume('mySound',"+i+")",(timer * speed));
				timer++;		
			}
			setTimeout("soundManager.pause('mySound')",2000);
		  }
		  
		  //when movie done, restart slide show and recue movie
		  if(newState == 0)
		  {
		  	document.getElementById("neuro-linguistics").Play();
			document.getElementById("living-in-formation").Play();
			//soundManager.createSound('mySound','mp3/grand_central.mp3');	
			//soundManager.play('mySound');
			soundManager.resume('mySound');
			//sound swell
			var millisec = 2000;
			var speed = Math.round(millisec/100);
			var timer = 0;
			
			for (i=0; i<=100; i++)
			{
				setTimeout("soundManager.setVolume('mySound',"+i+")",(timer * speed));
				timer++;
			}
			auto();
		  }
		   
		   updateHTML("playerstate", newState);
	   	}
	
        function onYouTubePlayerReady(playerId) {			
          ytplayer = document.getElementById("myytplayer");
          setInterval(updateytplayerInfo, 250);
          updateytplayerInfo();
          ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
		  //Call function auto to set initial cue and volume
		  auto();
        }

		function auto() 
		{ if (ytplayer) {
			//Auto Cue & Initial Volumne
			var id = 'HvYrJJbe498';
			var startSeconds = 0;
			ytplayer.cueVideoById(id, startSeconds);
			ytplayer.setVolume(100);
			}
		}

        function onytplayerStateChange(newState) {
          setytplayerState(newState);
        }

        function updateytplayerInfo() {
         // updateHTML("bytesloaded", getBytesLoaded());
          //updateHTML("bytestotal", getBytesTotal());
         // updateHTML("videoduration", getDuration());
         // updateHTML("videotime", getCurrentTime());
         // updateHTML("startbytes", getStartBytes());
         // updateHTML("volume", getVolume());
        }

        // functions for the api calls
        function loadNewVideo(id, startSeconds) {
          if (ytplayer) {
            ytplayer.loadVideoById(id, startSeconds);
          }
        }

        function cueNewVideo(id, startSeconds) {
          if (ytplayer) {
            ytplayer.cueVideoById(id, startSeconds);
          }
        }

        function play() {
          if (ytplayer) {
		  	//document.getElementById("neuro-linguistics").StopPlay();
            ytplayer.playVideo();
          }
        }

        function pause() {
          if (ytplayer) {
            ytplayer.pauseVideo();
          }
        }

        function stop() {
          if (ytplayer) {
            ytplayer.stopVideo();
          }
        }

        function getPlayerState() {
          if (ytplayer) {
            return ytplayer.getState();
          }
        }

        function seekTo(seconds) {
          if (ytplayer) {
            ytplayer.seekTo(seconds, true);
          }
        }

        function getBytesLoaded() {
          if (ytplayer) {
            return ytplayer.getVideoBytesLoaded();
          }
        }

        function getBytesTotal() {
          if (ytplayer) {
            return ytplayer.getVideoBytesTotal();
          }
        }

        function getCurrentTime() {
          if (ytplayer) {
            return ytplayer.getCurrentTime();
          }
        }

        function getDuration() {
          if (ytplayer) {
            return ytplayer.getDuration();
          }
        }

        function getStartBytes() {
          if (ytplayer) {
            return ytplayer.getVideoStartBytes();
          }
        }

        function mute() {
          if (ytplayer) {
            ytplayer.mute();
          }
        }

        function unMute() {
          if (ytplayer) {
            ytplayer.unMute();
          }
        }
        
        function getEmbedCode() {
          alert(ytplayer.getVideoEmbedCode());
        }

        function getVideoUrl() {
          alert(ytplayer.getVideoUrl());
        }

        function setVolume(newVolume) {
          if (ytplayer) {
            ytplayer.setVolume(newVolume);
          }
        }

        function getVolume() {
          if (ytplayer) {
            return ytplayer.getVolume();
          }
        }

        function clearVideo() {
          if (ytplayer) {
            ytplayer.clearVideo();
          }
        }*/