﻿//===================================My Functions==================================
function normalized(hex) {
    var str = '';
    for (var i = 0; i < hex.length; i += 2)
        str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
    return str;
} 

function showHideAnswer(id)
{
    if(document.getElementById("faq"+id) != null)
    {
        if(document.getElementById("faq"+id).style.display == '')
        {
            document.getElementById("faq"+id).style.display = 'none';
        }
        else
        {
            document.getElementById("faq"+id).style.display = '';
        }
    }
}
function reload() {
    document.location.href = document.location.href;
}
function uncheckPlayAll() {
    if (document.getElementById("chkAllTracks").checked) {
        document.getElementById("chkAllTracks").checked = false;
    }
}

function fullScreen() {
    var player = document.getElementById("Player");
    if (player.playState == 3) {
        player.fullScreen = true;
    } else {
        alert("Please click full screen mode when the movie is playing.\nOr double click on the player window when movie is playing..");
    }
}
function onSilverlightError() {
    //alert("Silverlight error occured!");
}
//=================================================================================
var server1Url = "http://208.85.243.4/";
var server2Url = "http://208.100.25.76/";
var server4Url = "http://208.100.15.164/";
var dynamicList = "/tempplists/";

var pwidth = "690";
var pheight = "360";

function showContainer(server, fileName, audio, isHttpStream) {
    var medialink = "";
    var isIOS = false;
    var isSafari = false;
    var fullScr = document.getElementById("imgFullScr");
    if (fullScr != null) {
        fullScr.style.display = "none"; 
    }

    if(navigator.appVersion.indexOf("Win") == -1 && navigator.userAgent.toLowerCase().match(/safari/i)) {
        isSafari = true;
    }
    if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i)) || (navigator.userAgent.match(/Android/i)))
    {
        isIOS = true;
    }
    fileName = normalized(fileName);
    if (server != null) {
        switch (server) {
            case "server2":                
                medialink = (isIOS || (isSafari && isHttpStream) ? "http://server2.bollypod.com/" + fileName : server2Url + "autowsx/" + fileName);
                break;
            case "server4":
                medialink = (isIOS || (isSafari && isHttpStream) ? "http://server3.bollypod.com/" + fileName : server4Url + "autowsx/" + fileName);
                break;
            case "playlist":
                medialink = dynamicList + fileName;
                break;
            default:
                medialink = (isIOS || (isSafari && isHttpStream) ? "http://server1.bollypod.com/" + fileName : server1Url + "autowsx/" + fileName);
                break;
        }
        if (fileName.indexOf("sample") > -1) {
            medialink = medialink.replace("autowsx/", "");
        }
    } else {
        medialink = fileName;
    }
    if (audio != null && audio) {
        pwidth = "240";
        pheight = "247";
    }
    if (navigator.appVersion.indexOf("Win") != -1) {//Windows OS
        if (navigator.userAgent.toLowerCase().indexOf("msie") > -1) {
            loadWindowsMediaPlayer(medialink,audio);
        } else {
            if (audio) {
                loadWSXPlayer(medialink);
            } else {
                loadSLPlayer(medialink);
            }
        }
    } else {//Mac OSx or iOS or Android Unix
        if (!isHttpStream) {
            loadWSXPlayer(medialink);
        } else {
            if(!isIOS) {
                if (navigator.userAgent.toLowerCase().indexOf("safari") > -1) {
                    if (audio) {
                        loadWSXPlayer(medialink);
                    } else {
                        document.write("<center><video width=\"690px\" height=\"360px\" autoplay=\"true\" controls=\"true\" src=\"" + medialink.replace(" ", "%20") + "\">Player not supported</video></center>");
                    }
                } else {
                    loadSLPlayer(medialink);
                }
            } else {
	            document.write("<center><video width=\"100%\" height=\"220px\" autoplay=\"true\" controls=\"true\" src=\"" + medialink.replace(" ", "%20") + "\">Player not supported</video></center>");
            }
        }
    }
	if (!audio && !isIOS) {
        if (navigator.appVersion.indexOf("Win") != -1 && navigator.userAgent.toLowerCase().indexOf("msie") > -1) {
            document.write("<ul style=\"font-size: 12px;color: #ffffff\"><li>Please install Windows Media Player version 11 or newer for best performance</li><li>Please double click on the video screen when video starts playing for full screen view</li>");
        } else {
            if(isSafari) {
                document.write("<ul style=\"font-size: 12px;color: #ffffff\"><li>Please wait a few seconds for the player to load the movie</li><li>Please click on the play button once the movie loads in the player</li><li>Please click on the 'toggle full screen' button on bottom right to switch to full screen</li>");
            } else {
                document.write("<ul style=\"font-size: 12px;color: #ffffff\"><li>Please wait a few seconds for the player to load the movie</li><li>Please install the latest version of Silverlight for " + (navigator.appVersion.indexOf("Win") != -1 ? "Windows" : "Mac OSx") + "</li><li>Please click on the 'toggle full screen' button on bottom right to switch to full screen</li>");
            }
        }
        document.write("<li>Press the Esc button on the keyboard to exit full screen mode</li></ul><br /><br />");
    }
}

function loadWindowsMediaPlayer(medialink, audio) {
    var fullScr = document.getElementById("imgFullScr");
    if (fullScr != null) {
        fullScr.style.display = "";
    }
    document.write("<center><object ID=\"Player\" CLASSID=\"CLSID:6BF52A52-394A-11D3-B153-00C04F79FAA6\" standby=\"Loading Microsoft Windows Media Player components...\" type=\"application/x-oleobject\" width=\"" + pwidth + "\" height=\"" + pheight + "\" VIEWASTEXT>");
    document.write("\<param name=\"url\" value=\"" + medialink + "\">");
    document.write("<param name=\"AutoStart\" value=\"true\">");
    document.write("<param name=\"ShowTracker\" value=\"true\">");
    document.write("<param name=\"ShowControls\" value=\"true\">");
    document.write("<param name=\"ShowGotoBar\" value=\"false\">");
    document.write("<param name=\"ShowStatusBar\" value=\"false\">");
    document.write("<param name=\"AutoSize\" value=\"true\">");
    document.write("<param name=\"AnimationAtStart\" value=\"true\">");
    document.write("<param name=\"AutoRewind\" value=\"false\">");
    document.write("<param name=\"Balance\" value=\"0\">");
    document.write("<param name=\"EnableFullScreenControls\" value=\"1\">");
    if (audio != null && !audio) {
        document.write("<param name=\"FullScreen\" value=\"2\">");
    }
    document.write("<param name=\"BufferingTime\" value=\"5\">");
    document.write("<param name=\"Enabled\" value=\"true\">");
    document.write("<param name=\"enableContextMenu\" value=\"false\">");
    document.write("<param name=\"uiMode\" value=\"full\">");
    document.write("<param name=\"EnableTracker\" value=\"true\">");
    document.write("<param name=\"InvokeURLs\" value=\"true\">");
    document.write("<param name=\"VideoBorderWidth\" value=\"0\">");
    document.write("<param name=\"VideoBorderColor\" value=\"0\">");
    document.write("<param name=\"Volume\" value=\"100\">");
    document.write("<param name=\"WindowlessVideo\" value=\"false\">");
    document.write("<embed name=\"Player\" id=\"Player\" type=\"application/x-mplayer2\" uiMode=\"full\" width=\"" + pwidth + "\" height=\"" + pheight + "\" src=\"" + medialink + "\" pluginspage=\"http://www.microsoft.com/windows/mediaplayer/\" AutoStart=\"true\" ShowTracker=\"true\" " + ((audio != null && !audio) ? "FullScreen=\"true\" " : "") + "ShowControls=\"true\" ShowGotoBar=\"false\" ShowDisplay=\"false\" ShowStatusBar=\"false\" AutoSize=\"true\"  AudioStream=\"-1\" AnimationAtStart=\"true\" AllowScan=\"true\" Balance=\"0\" BufferingTime=\"5\" ClickToPlay=\"true\" CursorType=\"0\" CurrentMarker=\"0\" DisplayMode=\"0\" DisplaySize=\"0\" Enabled=\"true\" EnableContextMenu=\"0\" EnableFullScreenControls=\"0\" EnablePositionControls=\"true\" EnableTracker=\"true\" InvokeURLs=\"false\" Mute=\"false\" PlayCount=\"1\" SendPlayStateChangeEvents=\"true\" ShowCaptioning=\"false\" ShowAudioControls=\"true\" ShowPositionControls=\"true\" TransparentAtStart=\"TRUE\" VideoBorderWidth=\"0\" VideoBorderColor=\"0\" Volume=\"90\" WindowlessVideo=\"false\"></embed>");
    document.write("</object></center>");
}

function loadWSXPlayer(medialink) {
    document.write("<center>");
    document.write("<object data=\"data:application/x-silverlight,\" type=\"application/x-silverlight-2\" width=\"" + pwidth + "\" height=\"" + pheight + "\">");
    document.write("<param name=\"source\" value=\"ClientBin/MinoPlayer_Ver1_2.xap\"/>");
    document.write("<param name=\"onerror\" value=\"onSilverlightError\" />");
    document.write("<param name=\"background\" value=\"black\" />");
    document.write("<param Name=\"initParams\" value=\"VideoSource=" + medialink + ",AutoPlay=true,EnableScrubbing=true,InitialVolume=1,PreviewImage=http://www.bollypod.com/images/bv_wm.png,LogoImage=http://www.bollypod.com/images/bv_wm.png,MarkersTimeView=5\" />");
    document.write("<param name=\"minRuntimeVersion\" value=\"2.0.31005.0\" />");
    document.write("<param name=\"autoUpgrade\" value=\"true\" />");
    document.write("<a href=\"http://go.microsoft.com/fwlink/?LinkID=124807\" style=\"text-decoration: none;\">");
    document.write("	<img src=\"http://go.microsoft.com/fwlink/?LinkId=108181\" alt=\"Get Microsoft Silverlight\" style=\"border-style: none\" />");
    document.write("</a>");
    document.write("</object>");
    document.write("<iframe style='visibility:hidden;height:0;width:0;border:0px'></iframe>");
    document.write("</center>");
}

function loadSLPlayer(medialink) {
    document.write("<center><div id='errorLocation' style=\"font-size: small;color: Gray;\"></div>");
    document.write("<div id=\"silverlightControlHost\">");
    document.write("   <object data=\"data:application/x-silverlight,\" type=\"application/x-silverlight\" width=\"690\" height=\"360\">");
    document.write("       <param name=\"source\" value=\"ClientBin/MediaPlayerTemplate.xap\"");
    document.write("       <param name=\"onerror\" value=\"onSilverlightError\" />");
    document.write("       <param name=\"autoUpgrade\" value=\"true\" />");
    document.write("       <param name=\"minRuntimeVersion\" value=\"4.0.50401.0\" />");
    document.write("       <param name=\"enableHtmlAccess\" value=\"true\" />");
    document.write("       <param name=\"enableGPUAcceleration\" value=\"true\" />");
    document.write("       <param name=\"initparams\" value='playerSettings = ");
    document.write("		    <Playlist>");
    document.write("			    <AutoLoad>true</AutoLoad>");
    document.write("			    <AutoPlay>true</AutoPlay>");
    document.write("			    <DisplayTimeCode>false</DisplayTimeCode>");
    document.write("			    <EnableOffline>false</EnableOffline>");
    document.write("			    <EnablePopOut>false</EnablePopOut>");
    document.write("			    <EnableCaptions>true</EnableCaptions>");
    document.write("			    <EnableCachedComposition>true</EnableCachedComposition>");
    document.write("			    <StretchNonSquarePixels>NoStretch</StretchNonSquarePixels>");
    document.write("			    <StartMuted>false</StartMuted>");
    document.write("			    <StartWithPlaylistShowing>false</StartWithPlaylistShowing>");
    document.write("			    <Items>");
    document.write("				    <PlaylistItem>");
    document.write("					    <AudioCodec>AAC</AudioCodec>");
    document.write("					    <Description></Description>");
    document.write("					    <FileSize>9436549</FileSize>");
    document.write("					    <IsAdaptiveStreaming>false</IsAdaptiveStreaming>");
    document.write("					    <MediaSource>" + medialink + "</MediaSource>");
    document.write("					    <ThumbSource></ThumbSource>");
    document.write("					    <Title></Title>");
    document.write("					    <DRM>false</DRM>");
    document.write("					    <VideoCodec>H264</VideoCodec>");
    document.write("					    <FrameRate>23.9760431376968</FrameRate>");
    document.write("					    <Width>720</Width>");
    document.write("					    <Height>304</Height>");
    document.write("					    <AspectRatioWidth>2.36842105263158</AspectRatioWidth>");
    document.write("					    <AspectRatioHeight>1</AspectRatioHeight>");
    document.write("				    </PlaylistItem>");
    document.write("			    </Items>");
    document.write("		    </Playlist>'/>");
    /*        <!--  unused valid silverlight init parameters
    <param name="enableFrameRateCounter" value="bool" />
    <param name="enableRedrawRegions" value="bool" />
    <param name="maxFrameRate" value="int" />
    <param name="allowHtmlPopupWindow" value="bool"/>
    <param name="background" value="colorValue"/>
    <param name="splashScreenSource" value="uri"/>
    <param name="fullScreen" value="bool"/>
    <param name="onFullScreenChanged" value="functionname"/>
    <param name="onResize" value="functionname"/>
    <param name="onSourceDownloadComplete" value="functionname"/>
    <param name="onSourceDownloadProgressChanged" value="functionname"/>
    <param name="windowLess" value="bool"/>
    --> 
    */
    document.write("         <div onmouseover=\"highlightDownloadArea(true)\" onmouseout=\"highlightDownloadArea(false)\">");
    document.write("                <img src=\"\" style=\"position:absolute;width:100%;height:100%;border-style:none;\" onerror=\"this.style.display='none'\"/>");
    document.write("                <img src=\"Preview.png\" style=\"position:absolute;width:100%;height:100%;border-style:none;\" onerror=\"this.style.display='none'\"/>");
    document.write("                <div id=\"overlay\" class=\"fadeLots\" style=\"position:absolute;width:100%;height:100%;border-style:none;background-color:white;\"/></div>");
    document.write("                <table width=\"100%\" height=\"100%\" style=\"position:absolute;\"><tr><td align=\"center\" valign=\"middle\">");
    document.write("                <img src=\"http://go2.microsoft.com/fwlink/?LinkId=108181\" alt=\"Get Microsoft Silverlight\">");
    document.write("                </td></tr></table>");
    document.write("                <a href=\"http://go2.microsoft.com/fwlink/?LinkID=149156\">");
    document.write("                    <img src=\"\" class=\"fadeCompletely\" style=\"position:absolute;width:100%;height:100%;border-style:none;\" alt=\"Get Microsoft Silverlight\"/>");
    document.write("                </a>");
    document.write("         </div>");
    document.write("    </object>");
    document.write("    <iframe id='_sl_historyFrame' style='visibility:hidden;height:0;width:0;border:0px'></iframe>");
    document.write("</div></center>");
}
