var status;
var browser;

function getActiveXObject()
{
    if (window.ActiveXObject) {
        try {
            var obj = new ActiveXObject("WickedNet.Duocast");
			browser = 'IE';
            if ( obj == null ) status = 0;
            return obj;
        }catch(e){  status = 0; }
        
    }
    else if (window.GeckoActiveXObject) {
        try {
            var obj = new GeckoActiveXObject("WickedNet.Duocast");
			browser = 'FF';			
            if ( obj == null )  status = 0;
            return obj;
        }catch(e){ status = 0; }
    }
    //return null;
}

try{
    var obj = getActiveXObject();
    if ( obj != null )
    {
        var ver = obj.getVersion();
        //if ( ver >= "1.0.1.9" )
        //{
			//LoadChannel();
			//checkCache();
			status = 1;
        //}
        //else
        //{
        //    status = 2;
        //}
    }     
}catch(e){ alert(e.message);}

function checkCache()
{
 
 res = obj.currentData();
 
 if ( res < 1 ) 
 {
	setTimeout( "checkCache()", 1000 );
 }else{
 	playStream();
	setTimeout( "getLog()", 600000 );
 }
}

function getLog()
{
	obj.sendLog('http://119.110.96.72/log/plog.php')
	setTimeout( "getLog()", 600000 );
}

function playStream()
{
	//stream = obj.getPlayedURL();
	//stream = stream.split(":");
	streamURL = "rtsp://127.0.0.1:555/live";
	
	if ( browser == 'IE'){
	//WindowsMediaPlayer1.uiMode = "mini";
	WindowsMediaPlayer1.URL = streamURL;
	WindowsMediaPlayer1.controls.stop();
	WindowsMediaPlayer1.controls.play();
	}
	
	if ( browser == 'FF'){
	//document.WindowsMediaPlayer1.uiMode = "mini";	
	document.WindowsMediaPlayer1.URL = streamURL;		
	document.WindowsMediaPlayer1.controls.stop();
	document.WindowsMediaPlayer1.controls.play();
	}	
	
	setTimeout( "obj.sendLog('http://119.110.96.72/log/play.php')", 10000 );
}

function ClosePlugin()
{
	//res = obj.stop( obj.curMediaID );
	delete obj;
}

function LoadChannel()
{
	//obj.playURL( "duocast://119.110.96.71:80/DEA314A03F1CBDF58CD2483ED12DF66C" );	
}

//status = 3;
status = 1;
if (status == 1){ 
document.write('<object id="WindowsMediaPlayer1"'); 
if(-1 != navigator.userAgent.indexOf("MSIE")) { 
document.write(' classid="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6"'); 
} else if(-1 != navigator.userAgent.indexOf("Firefox")) { document.write(' type="application/x-ms-wmp"'); 
} document.write(' width=405 height=364>');
document.write('<param name="URL" value="http://119.110.96.68/bernama-webtv">');
document.write('<param name="autoStart" value="1">');
document.write('<param name="volume" value="50">');
document.write('<param name="uiMode" value="mini">');
document.write('<param name="stretchToFit" value="-1">');
document.write('<param name="windowlessVideo" value="false">');
document.write('<param name="enableContextMenu" value="-1">');
document.write('<param name="fullScreen" value="0">');
document.write('</object>');
}else if(status == 3){	
document.write('<a href="http://www.wickednetworks.tv/Duocast_Setup.exe"><img src="images/maintenance.jpg" width="405" height="360" border="0"></a>');
delete obj;
}else if(status == 2){	
document.write('<a href="http://www.wickednetworks.tv/Duocast_Setup.exe"><img src="images/incompatible.jpg" width="405" height="364" border="0"></a>');
delete obj;
}else{
document.write('<a href="http://www.wickednetworks.tv/Duocast_Setup.exe"><img src="images/no_plugin.jpg" width="405" height="364" border="0"></a>');
}