﻿	
//-------------------------------------------------------- ** Starting Of Live Medial Player ** ------------------------------------------------------

    //-------------------------------------------------------- ** Variable Declaration ** ------------------------------------------------------
    var volume=50; var isDefault=true; var isStop=true; var AutoStart=true;
    var width=582; var height=367; var Path=""; mute = new Boolean(false);
    //--------------------------------------------------------- ** Load Movie ** ---------------------------------------------------------------

    function thisMovie(movieName) {
        return document.getElementsByName(movieName)[0];
    };

    //--------------------------------------------------------- ** Load Player ** ---------------------------------------------------------------
    function LoadLivePlayers(Filename)
    {
        var pageHost = ((document.location.protocol == "https:") ? "https://" : "http://");
        Filename = Filename.replace("octoshape://streams.octoshape.net/jdl/","");
        var location=document.location.href.toLowerCase();
        var width = 576; var height = 324;var isOctoLive="";

        var allowFullScreenValue;
        
        if($isNarrowEmbedModel=="True")
        {
            allowFullScreenValue="false";
            width=502;
            height=287;
        }
        else
        {
            allowFullScreenValue="true";
        }
        
	    var skinPath;
        //Condition to include skin for videoplayer.aspx and other pages.
        if (location.indexOf('admin/')>0) 
        {
            skinPath= '../includes/Swf/mediaplayerhw.swf'; //Include skin for videoplayer.aspx
        }
        else 
        {
            skinPath='includes/Swf/mediaplayerhw.swf'; //Include skin
        }
        
        var viralSWFPath;
        //Condition to include viralSWFPath for videoplayer.aspx and other pages.
        if (location.indexOf('admin/')>0) 
        {
            viralSWFPath= '../Includes/Swf/player-licensed-viral.swf'; //Include viralSWFPath for videoplayer.aspx
        }
        else 
        {
            viralSWFPath='Includes/Swf/player-licensed-viral.swf'; //Include viralSWFPath
        }
    
        jwplayer("flashbanner").setup({ 
            flashplayer: viralSWFPath, 
            file: "octoshape://streams.octoshape.net/jdl/"+ Filename,
	        provider: pageHost + "d2iwzbhgddzdwl.cloudfront.net/resources/player/jwflvplayer/5/jwplayer-octoshape-mediaprovider2.swf",
            height: height, 
            width: width,
            skin: skinPath,
            allowfullscreen:allowFullScreenValue,
            allowscriptaccess:"always",
           // icons:"false",
            enablejs:"true",
            controlbar:"over",
           // wmode:"transparent",
            stretching:"fill",
            autostart:"true",
            repeat:"true",
            abouttext:'JDL Horizons',
            aboutlink:'http://www.jdlhorizons.com',
           'OctoshapeMediaProvider.clientlist': 'swf',
            "plugins": {
                "gapro-2": {}
            }
        });
    }

    //--------------------------------------------------------- ** Initialize Player ** --------------------------------------------------------

    function playerReady(obj) {//function gets called each and every time when the player is initialized   
	    var id = obj['id'];
    	
	    var version = obj['version'];
    	
	    var client = obj['client'];
    	
	    var player = document.getElementById(id);
	    player.addControllerListener("MUTE","muteTracker");
	    player.addModelListener("STATE", "IncrementVideoCount");
	    player.addControllerListener("VOLUME","RetainVolume");
	    player.addModelListener("TIME","GetTIMEToRedirect");
      //  player.addModelListener("ERROR", "errorMonitor");
    }
    //                 IncrementVideoViewCount() function is used to increment the view count of the video when play button is clicked...................................
    var g = 0;
    function IncrementvideoCount(obj) {
        currentState = obj.newstate;
        previousState = obj.oldstate;
        if (previousState == "BUFFERING" && currentState == "PLAYING") {
            if (g == 0 || g == -1) {
                g = g + 2;
                if (window.location.href.indexOf('EmbedPlayer.aspx') > 0) {
                    EmbedPlayer.IncrementViewCount(true);
                }
                else {
                    Default.IncrementViewCount(true);
                }
            }
        }

        if (currentState == "IDLE") {
            g = 0;
        }
        if (currentState == "COMPLETED") {
            g = 0;
        }
    }
    //--------------------------------------------------------- ** Mute Tracker ** -------------------------------------------------------------


    function muteTracker(obj) {
        mute = obj.state;
        
    }
    //--------------------------------------------------------- ** Error Tracker ** -------------------------------------------------------------


    function errorMonitor(obj)
    {
//    if( obj.message)
//    {
         FindURL('jdlstate_jdlcity_jdlHighSchool_jdlHighSchool_-1/Video_Not_Available_Mssg_b8c2e36cb1664bbab9368ef8693ee5cf.flv');
         setTimeout('StartPlayer()',5000); 
//    }
    }

    //--------------------------------------------------------- ** Retain Volume ** -------------------------------------------------------------


    function RetainVolume(obj) {

        if(mute == false) currentVolume = obj.percentage;
        
        }    

    //--------------------------------------------------------- ** Web Service OnComplete ** -------------------------------------------------------------


    function onlivecomplete(returnvalue){

        LoadLivePlayers(returnvalue);
       
    }

    //--------------------------------------------------------- ** Web Service OnTimeOut ** -------------------------------------------------------------

    function ontimeout(){

    }

    //--------------------------------------------------------- ** Web Service OnError ** -------------------------------------------------------------


    function onerror(){
    }

    //--------------------------------------------------------- ** Live Player Constructor ** -------------------------------------------------------------


       
       
       function LiveGamePlayer(curWidth,curHeight,autoStart,path,url){
       
        var Player=new Object;
        
        width=curWidth;

        AutoStart=autoStart;

        height=curHeight;

        Path=path;
        
        Player.GetPlayer=function(){

        ClientServices.GetLiveUrl(url.replace("octoshape://streams.octoshape.net/jdl/",""),onlivecomplete,ontimeout,onerror);
        }
        
        return Player;
       
       }
//--------------------------------------------------------- ** End Of Live Media Player ** -------------------------------------------------------------

function FindURL(filename) {
    ClientServices.GetVideoUrl(filename.replace("octoshape://streams.octoshape.net/jdl/",""),onlivecomplete,ontimeout,onerror);
}
function StartPlayer(){
    thisMovie('liveplayer').sendEvent('play');
}

