﻿// © 2006 - Copyright 2006 PK Multimedia Australia

window.document.getElementById( "ADTEXMedia" ).style.display = "BLOCK";
var UAFlashSupport = false, UAMPEGSupport = false, UAGecko = window.navigator.userAgent.indexOf( "Gecko/" ) > 0;

if ( window.navigator.userAgent.indexOf( "Windows" ) )
    if ( UAGecko || window.navigator.mimeTypes.length ) {
        for( var MIMEIdx = 0; MIMEIdx < window.navigator.mimeTypes.length; MIMEIdx++ )
            switch( window.navigator.mimeTypes[MIMEIdx].description ) {
                case "Shockwave Flash": UAFlashSupport = true; break;
                case "MPEG media file": UAMPEGSupport = true;
            }
    } else {
        try {
            var FlashSupport = new ActiveXObject( "ShockwaveFlash.ShockwaveFlash" )
            if ( FlashSupport != null && FlashSupport.FlashVersion() >= 524288 ) UAFlashSupport = true;
            FlashSupport = null;

            var WMPSupport = new ActiveXObject( "MediaPlayer.MediaPlayer" );
            if ( WMPSupport != null ) UAMPEGSupport = true;
            WMPSupport = null;

        } catch( PlayersTestFail ) { ; }
    }

if ( !UAFlashSupport && !UAMPEGSupport ) {
    var PlayerNOTSupported = window.document.createElement( "DIV" );

    var Paragraph = window.document.createElement( "P" );
    Paragraph.className = "Title";
    Paragraph.appendChild( window.document.createTextNode( "Unable to play the AD-TEX TV Commerical." ) );
    PlayerNOTSupported.appendChild( Paragraph );

    Paragraph = window.document.createElement( "P" );
    Paragraph.className = "Title";
    Paragraph.appendChild( window.document.createTextNode( "A Flash Player or Media Player needs to be installed or upgraded on a Windows OS." ) );
    PlayerNOTSupported.appendChild( Paragraph );

    Paragraph = window.document.createElement( "P" );
    Paragraph.className = "Title";
    Paragraph.appendChild( window.document.createTextNode( "Install or Upgrade the relevant Player and reload this page in Internet Explorer on MS Windows." ) );
    PlayerNOTSupported.appendChild( Paragraph );

    window.document.getElementById( "ADTEXMedia" ).parentNode.replaceChild( PlayerNOTSupported, window.document.getElementById( "ADTEXMedia" ) );
} else {
    if ( !UAFlashSupport ) {
        window.document.getElementById( "ADTEXMedia" ).rows.item( 0 ).cells.item( 0 ).style.display = "NONE";
        window.document.getElementById( "ADTEXMedia" ).rows.item( 1 ).cells.item( 0 ).style.display = "NONE"
        window.document.getElementById( "ADTEXMedia" ).rows.item( 2 ).cells.item( 0 ).style.display = "NONE"
    } else if ( !UAMPEGSupport ) {
        window.document.getElementById( "ADTEXMedia" ).rows.item( 0 ).cells.item( 1 ).style.display = "NONE"
        window.document.getElementById( "ADTEXMedia" ).rows.item( 1 ).cells.item( 1 ).style.display = "NONE"
    } else if ( UAGecko ) {
        window.document.getElementById( "ADTEXMedia" ).rows.item( 0 ).cells.item( 1 ).style.paddingLeft = "50px";
        window.document.getElementById( "ADTEXMedia" ).rows.item( 1 ).cells.item( 1 ).style.paddingLeft = "50px";
    }
}

function PlayADTEXAD( CommericalNo ) {
    if ( !UAFlashSupport && !UAMPEGSupport ) return;
    try {
        for( var CurrentPlayer = window.document.getElementById( "ADPlayers" ).childNodes, NodesLen = window.document.getElementById( "ADPlayers" ).childNodes.length, Idx = 0; Idx < NodesLen; Idx++ )
            if ( CurrentPlayer.item( Idx ) != null ) {
                if ( CurrentPlayer.item( Idx ).nodeName == "OBJECT" )
                    try { CurrentPlayer.item( Idx ).Stop(); } catch( CantStop ) { ; }
                CurrentPlayer.item( Idx ).style.display = "NONE";
            }

        var CommericalFilePath = "";
        switch( CommericalNo ) {
            case 0: CommericalFilePath = "./App_Video/ADTEXMultimediaSlideshow.swf"; break;
            case 1: CommericalFilePath = "./App_Video/ADTEX-65-15.swf"; break;
            case 2: CommericalFilePath = "./App_Video/ADTEX-65-30.swf"; break;
            case 3: CommericalFilePath = "./App_Video/ADTEX-100-15.swf"; break;
            case 4: CommericalFilePath = "./App_Video/ADTEX-100-30.swf"; break;

            case 5: CommericalFilePath = "./App_Video/ADTEX-65-15.mpg"; break;
            case 6: CommericalFilePath = "./App_Video/ADTEX-65-30.mpg"; break;
            case 7: CommericalFilePath = "./App_Video/ADTEX-100-15.mpg"; break;
            case 8: CommericalFilePath = "./App_Video/ADTEX-100-30.mpg"; break;
        }

        if ( CommericalNo < 5 ) {
            if ( UAGecko || window.navigator.mimeTypes.length ) {
                window.document.getElementById( "ADTEXVideoPlayerPISWF" ).style.display = "BLOCK";
                window.document.getElementById( "ADTEXVideoPlayerPISWF" ).src = CommericalFilePath;
            } else {                
                window.document.getElementById( "ADTEXVideoPlayerSWF" ).style.display = "BLOCK";
                window.document.getElementById( "ADTEXVideoPlayerSWF" ).LoadMovie( 0, CommericalFilePath );
                window.document.getElementById( "ADTEXVideoPlayerSWF" ).Play();
            }
        }
        else {
            if ( UAGecko || window.navigator.mimeTypes.length ) {
                window.document.getElementById( "ADTEXVideoPlayerPIMPG" ).style.display = "BLOCK";
                window.document.getElementById( "ADTEXVideoPlayerPIMPG" ).src = CommericalFilePath;
            } else {
                window.document.getElementById( "ADTEXVideoPlayerWMP" ).style.display = "BLOCK";
                try { // Microsoft Windows Media Player
                    window.document.getElementById( "ADTEXVideoPlayerWMP" ).AutoStart = true;
                    window.document.getElementById( "ADTEXVideoPlayerWMP" ).AutoRewind = true; 
                    window.document.getElementById( "ADTEXVideoPlayerWMP" ).EnableContextMenu = false;
                    window.document.getElementById( "ADTEXVideoPlayerWMP" ).ShowStatusBar = true;
                } catch( WMPlayerNot ) { ; }
                window.document.getElementById( "ADTEXVideoPlayerWMP" ).Open( CommericalFilePath );
            }        
        }
        window.document.getElementById( "ADPlayers" ).scrollIntoView( false );
    } catch( PlayerAPINotSupported ) { ; }
}
