var base="http://pictures.a2zpattaya.com/music/";
var namex;
var namey;
function detectWMP()
{
	var wmpInfo={installed:false,scriptable:false,type:null,versionInfo:null};
	var wmp64="MediaPlayer.MediaPlayer.1";
	var wmp7="WMPlayer.OCX.7";
	if((window.ActiveXObject&&navigator.userAgent.indexOf('Windows')!=-1)||window.GeckoActiveXObject)
	{
		wmpInfo.type="ActiveX";
//		wmpInfo.type=null; //Enable this line for No Active X installed
		var player=createActiveXObject(wmp7);
		if(player)
		{
			wmpInfo.installed=true;
			wmpInfo.scriptable=true;
			wmpInfo.versionInfo=player.versionInfo;
			return wmpInfo;
		}
		else
		{
			player=createActiveXObject(wmp64);
			if(player)
			{
				wmpInfo.installed=true;
				wmpInfo.scriptable=true;
				wmpInfo.versionInfo="6.4";
				return wmpInfo;
			}
			else
			{
				wmpInfo.versionInfo="none";
				return wmpInfo;
			}
		}
	}
	else if(navigator.mimeTypes)
	{
		wmpInfo.type="NetscapePlugin";
		var player=navigator.mimeTypes['application/x-mplayer2'].enabledPlugin;
		if(player)
		{
			wmpInfo.installed=true;
			wmpInfo.scriptable=true;
//			wmpInfo.scriptable=false;
			wmpInfo.versionInfo="PluginVersion";
		}
		return wmpInfo;
	}
}
function createActiveXObject(id)
{
	var error;
	var control=null;
	try
	{
		if(window.ActiveXObject) control=new ActiveXObject(id);
		else if(window.GeckoActiveXObject) control=new GeckoActiveXObject(id);
	}
	catch(error)
	{
		;
	}
	return control;
}
function printResults()
{
	var detectionResults=detectWMP();
	document.write("Browser architecture supports: "+detectionResults.type+"<br>\n");
	document.write("Windows Media Player Installed: "+detectionResults.installed+"<br>\n");
	if(detectionResults.installed)
	{
		document.write("Windows Media Scriptable: "+detectionResults.scriptable+"<br>\n");
		document.write("Windows Media Version: "+detectionResults.versionInfo+"<br>\n");
	}
}
function createObject()
{
	var detectionResults=detectWMP();
	if(detectionResults.type=="ActiveX"&&detectionResults.installed&&detectionResults.scriptable)
	{
		x=detectionResults.versionInfo.substring(0,1);
//		x=6; //Enable this line to test Media Player 6.4
		if(x>=7)
		{
			document.writeln('<object id="MediaPlayer" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" width="0" height="0" type="application/x-oleobject">');
			document.writeln('\t<param name="autoStart" value="0">');
			document.writeln('\t<param name="balance" value="0">');
			document.writeln('\t<param name="SAMIFileName" value="null">');
			document.writeln('\t<param name="uiMode" value="invisible">');
			document.writeln('\t<param name="volume" value="100">');
			document.writeln('<\/object>');
			document.writeln('\<script for="MediaPlayer" event="PlayStateChange(NewState)" language="JavaScript" type="text/javascript">');
			document.writeln('\<!--');
			document.writeln('switch(NewState)');
			document.writeln('{');
			document.writeln('\tcase 0:');
			document.writeln('\tnamez.value="Buffering";');
			document.writeln('\tnamez.style.backgroundColor="yellow";');
			document.writeln('\tbreak;');
			document.writeln('\tcase 1:');
			document.writeln('\tnamez.value="Play";');
			document.writeln('\tnamez.style.backgroundColor="green";');
			document.writeln('\tbreak;');
			document.writeln('\tcase 2:');
			document.writeln('\tbreak;');
			document.writeln('\tcase 3:');
			document.writeln('\tnamez.value="Stop";');
			document.writeln('\tnamez.style.backgroundColor="red";');
			document.writeln('\tbreak;');
			document.writeln('\tcase 4:');
			document.writeln('\tbreak;');
			document.writeln('\tcase 5:');
			document.writeln('\tbreak;');
			document.writeln('\tcase 6:');
			document.writeln('\tnamez.value="Buffering";');
			document.writeln('\tnamez.style.backgroundColor="yellow";');
			document.writeln('\tbreak;');
			document.writeln('\tcase 7:');
			document.writeln('\tnamez.value="Waiting";');
			document.writeln('\tnamez.style.backgroundColor="yellow";');
			document.writeln('\tbreak;');
			document.writeln('\tcase 8:');
			document.writeln('\tnamez.value="Play";');
			document.writeln('\tnamez.style.backgroundColor="green";');
			document.writeln('\tbreak;');
			document.writeln('\tcase 9:');
			document.writeln('\tnamez.value="Buffering";');
			document.writeln('\tnamez.style.backgroundColor="yellow";');
			document.writeln('\tbreak;');
			document.writeln('\tcase 10:');
			document.writeln('\tnamez.value="Stop";');
			document.writeln('\tnamez.style.backgroundColor="red";');
			document.writeln('\tbreak;');
			document.writeln('\tcase 11:');
			document.writeln('\tnamez.value="Reconnecting";');
			document.writeln('\tnamez.style.backgroundColor="yellow";');
			document.writeln('\tbreak;');
			document.writeln('}');
			document.writeln('\// -->');
			document.writeln('\<\/script\>');
		}
		else
		{
			document.writeln('<object id="MediaPlayer" classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112" width="0" height="0" standby="Loading Microsoft® Windows® Media Player components..." type="application/x-oleobject">');
			document.writeln('\t<param name="AnimationatStart" value="0">');
			document.writeln('\t<param name="AutoRewind" value="1">');
			document.writeln('\t<param name="AutoSize" value="1">');
			document.writeln('\t<param name="AutoStart" value="1">');
			document.writeln('\t<param name="Balance" value="0">');
			document.writeln('\t<param name="DisplaySize" value="0">');
			document.writeln('\t<param name="SAMIFileName" value="null">');
			document.writeln('\t<param name="ShowCaptioning" value="0">');
			document.writeln('\t<param name="ShowControls" value="1">');
			document.writeln('\t<param name="ShowDisplay" value="0">');
			document.writeln('\t<param name="ShowStatusBar" value="0">');
			document.writeln('\t<param name="ShowTracker" value="1">');
			document.writeln('\t<param name="TransparentAtStart" value="1">');
			document.writeln('\t<param name="Volume" value="0">');
			document.writeln('<\/object>');
			document.writeln('\<script for="MediaPlayer" event="PlayStateChange(lOldState,lNewState)" language="JavaScript" type="text/javascript">');
			document.writeln('\<!--');
			document.writeln('switch(lNewState)');
			document.writeln('{');
			document.writeln('\tcase 0:');
			document.writeln('\tnamez.value="Play";');
			document.writeln('\tnamez.style.backgroundColor="green";');
			document.writeln('\tbreak;');
			document.writeln('\tcase 1:');
			document.writeln('\tbreak;');
			document.writeln('\tcase 2:');
			document.writeln('\tnamez.value="Stop";');
			document.writeln('\tnamez.style.backgroundColor="red";');
			document.writeln('\tbreak;');
			document.writeln('\tcase 3:');
			document.writeln('\tnamez.value="Waiting";');
			document.writeln('\tnamez.style.backgroundColor="yellow";');
			document.writeln('\tbreak;');
			document.writeln('\tcase 4:');
			document.writeln('\tbreak;');
			document.writeln('\tcase 5:');
			document.writeln('\tbreak;');
			document.writeln('\tcase 6:');
			document.writeln('\tbreak;');
			document.writeln('\tcase 7:');
			document.writeln('\tbreak;');
			document.writeln('\tcase 8:');
			document.writeln('\tbreak;');
			document.writeln('}');
			document.writeln('\// -->');
			document.writeln('\<\/script\>');
			document.writeln('\<script for="MediaPlayer" event="Buffering(bStart)" language="JavaScript" text="text/javascript">');
			document.writeln('\<!--');
			document.writeln('switch(bStart)');
			document.writeln('{');
			document.writeln('\tcase 0:');
			document.writeln('\tnamez.value="Stop";');
			document.writeln('\tnamez.style.backgroundColor="red";');
			document.writeln('\tbreak;');
			document.writeln('\tcase 1:');
			document.writeln('\tnamez.value="Buffering";');
			document.writeln('\tnamez.style.backgroundColor="yellow";');
			document.writeln('\tbreak;');
			document.writeln('}');
			document.writeln('\// -->');
			document.write('\<\/script\>');
		}
	}
	else if(detectionResults.type=="NetscapePlugin"&&detectionResults.installed&&detectionResults.scriptable)
	{
		document.writeln('<embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" name="MediaPlayer" width="0" height="0" src="" AutoRewind="1" AutoStart="0" Balance="0" SAMIFileName="" ShowCaptioning="0" ShowControls="0" ShowStatusBar="0" Volume="0"></embed>');
	}
	else
	{
		document.writeln("Your browser does not support the ActiveX Windows Media Player.<br>");
		document.writeln("We have disabled the Play/Stop buttons.");
	}
}
function interact(namew,ext,namex)
{
	namez=namex;
	var detectionResults=detectWMP();
	if(namex.value=="Play")
	{
		coll=document.getElementsByTagName("input");
		if(coll!=null)
		{
			for(i=0;i<coll.length;i++)
			{
				if(coll.item(i).value!="Play")
				{
					with(coll.item(i))
					{
						value="Play";
						style.backgroundColor="green";
					}
				}
			}
		}
	}
	if(detectionResults.type=="ActiveX"&&detectionResults.installed&&detectionResults.scriptable)
	{
		if(namex.value=="Play")
		{
			if(x>=7)
			{
				document.MediaPlayer.URL=base+namew+"."+ext;
				document.MediaPlayer.controls.play();
			}
			else
			{
				document.MediaPlayer.FileName=base+namew+"."+ext;
				document.MediaPlayer.Play();
			}
			namex.value="Stop";
			namex.style.backgroundColor="red";
		}
		else
		{
			if(x>=7) document.MediaPlayer.controls.stop();
			else document.MediaPlayer.Stop();
			namex.value="Play";
			namex.style.backgroundColor="green";
		}
	}
	else if(detectionResults.type=="NetscapePlugin"&&detectionResults.installed&&detectionResults.scriptable)
	{
		namey=namex;
		if(namex.value=="Play")
		{
			document.MediaPlayer.Open(base+namew+"."+ext);
			playerReadyStatus=document.MediaPlayer.GetReadyState();
			while(playerReadyStatus<4)
			{
				namex.value="Buffering";
				namex.style.backgroundColor="yellow";
				playerReadyStatus=document.MediaPlayer.GetReadyState();
			}
			document.MediaPlayer.Play();
			timerID=setInterval('PlayState()',250);
			namex.value="Stop";
			namex.style.backgroundColor="red";
		}
		else
		{
			document.MediaPlayer.Stop();
			document.MediaPlayer.Open(base+namew+"."+ext);
			namex.value="Play";
			namex.style.backgroundColor="green";
		}
	}
}
function disable_buttons()
{
	var detectionResults=detectWMP();
	if(detectionResults.type!=null||detectionResults.installed)
	{
		coll=document.getElementsByTagName("input");
		if(coll!=null)
		{
			for(i=0;i<coll.length;i++)
			{
				coll.item(i).value="Play";
				coll.item(i).style.backgroundColor="green";
				coll.item(i).disabled=0;
			}
		}
	}
}
function PlayState()
{
	playerStatus=document.MediaPlayer.GetPlayState();
	if(playerStatus==0)
	{
		clearInterval(timerID);
		namey.value="Play";
		namey.style.backgroundColor="green";
	}
}
