﻿
//-------------------------------------------------------- ** Starting Of UI Media Player ** --------------------------------------------------------------------------------//
    var playervolume=50;
    var isDefault=true;
    var isStop=true;
    var isClick=true ;
    var IsHandled=false;
    var player;
    var playerEvent;
    var isstopplayer = false; 

//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------//

    mute = new Boolean(false);
    function sendEvent(swf,typ) {
        thisMovie(swf).sendEvent(typ);
    };

//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------//

    function thisMovie(movieName) {
        return document.getElementsByName(movieName)[0];
    };

//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------//

    function LoadPlayers(Filename, isStop) {
        var pageHost = ((document.location.protocol == "https:") ? "https://" : "http://");
        var location=document.location.href.toLowerCase();
        var width = 576; var height = 324;
        if(location.indexOf('admin/')>0){width=576;height=324;}
        if(location.indexOf('embedplayer')>0) {width=$("#hidwidth").val();height=$("#hidheight").val(); }
        if(location.indexOf('embedplayerwskin')>0) {width=582;height=327;}
        if(location.indexOf('watchlivegame')>0) {width="582px";height="327px";}
        if(location.indexOf('watchlive')>0) {width="582px";height="327px";}
        if(location.indexOf('viewvideo')>0) {width="735px";height="552px";}
        var Path=(location.indexOf('admin/')>0 && location.indexOf('watchlive')<=0)?'../':'';
        var attributes = {'id':'player','name':'player'};      
        
        var skinPath;
        //Condition to include skin for videoplayer.aspx and other pages.
        if (location.indexOf('admin/')>0) 
        {
            skinPath= '../includes/Swf/modieus.swf'; //Include skin for videoplayer.aspx
        }
        else 
        {
            skinPath='includes/Swf/modieus.swf'; //Include skin
        }
        
        var imagePath;
        if(location.indexOf('embedplayer')>0)
        { 
            if($("#hidThumbImage").val().length>0)
            {
                imagePath=$("#hidThumbImage").val();
            }
            else
                imagePath="http://www.eduvisiontest.info/Images/modern/PlayerDefaultImage.png";
        }
        
        var autoStartValue;
        if(!isStop)
        {
            autoStartValue= 'true';
            isstopplayer=false; 
        }
        if (location.indexOf("schoolid") > 0 && location.indexOf("filename") > 0)
           isDefault=false;
        if(document.getElementById("hidCurrentRole"))
        {
            var role = document.getElementById("hidCurrentRole").value;
            if (role.toString() == "True") {
                var videostatus = document.getElementById("hidIsDefaultVideo").value;
                if (videostatus == "True") {
                    autoStartValue = 'false';
                    isstopplayer = true;
                }
                else {
                    autoStartValue = 'true';
                    isstopplayer = false;
                }
            }
            else {
                var IsDefaultVideoAutoPlay = document.getElementById("hidAutoplay").value;
                var videostatus = document.getElementById("hidIsDefaultVideo").value;
                if (videostatus != "True" && IsDefaultVideoAutoPlay == "True") {
                    autoStartValue = 'true';
                    isstopplayer = false;
                }
              
              
               if (document.getElementById("hidAutoplay") != null && videostatus == "True") {
                   if (IsDefaultVideoAutoPlay == "False") {
                       autoStartValue = 'false';
                       isstopplayer = true;
                      }
               }
               else {
                    autoStartValue = 'true';
                    isstopplayer = false;
                }
            }
        } 
             
        if(location.indexOf('embedplayer')>0)
        { 
            if($("#hidtoggle").val().toLowerCase()=='false')   
                autoStartValue= 'false';
        }
        if(location.indexOf('videoplayer')>0) {
           autoStartValue= 'true';                 
        }
        
        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: Filename,
            streamer:'rtmp://jdl.octoshape.net/vod/jdl/',
	    //    provider: pageHost + "d2iwzbhgddzdwl.cloudfront.net/resources/player/jwflvplayer/5/jwplayer-octoshape-mediaprovider2.swf",
            height: height, 
            width: width,
            skin: skinPath,            
            allowfullscreen:"true",
            allowscriptaccess:"always",
           // icons:"false",
            enablejs:"true",
            controlbar: "over",
            volume: playervolume,
            //wmode:"transparent",
            stretching:"uniform",
            image:imagePath,
            autostart:autoStartValue,
            repeat:"true",
            abouttext:'JDL Horizons',
            aboutlink:'http://www.jdlhorizons.com',
            // 'OctoshapeMediaProvider.clientlist': 'swf',
            "plugins": {
                "gapro-2": {}
            }
        }); 
          

//        Filename = Filename+"&menu=false;";                        
//        SWF.addVariable('plugins', 'captions-1');
//        if(mute == false)
//            SWF.addVariable('volume',volume);
//        else   
//            SWF.addVariable('mute','true');

    }

//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------//

    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'];
        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;
        }
   }
//---------------------------------------------------------------------- Meta Monitor-------------------------------------------------------------------
    function metaMonitor(obj) 
    {
        if (obj.info=='NetStream.Buffer.Full') 
        {
            player.sendEvent("PLAY","true");
        } 
        else
            if (obj.info=='NetStream.Play.Stop') 
            {
                player.sendEvent("PLAY","false");
            }
    }; 

//---------------------------------------------------------------------- Error Monitor-------------------------------------------------------------------
    function errorMonitor(obj)
    {
//        if(obj.message)
//        {
            var locationValue=document.location.href.toLowerCase();
            GetVideoNotAvailble('octoshape://streams.octoshape.net/jdl/jdlstate_jdlcity_jdlHighSchool_jdlHighSchool_-1/Video_Not_Available_Mssg_b8c2e36cb1664bbab9368ef8693ee5cf.flv'); 
            if(locationValue.indexOf('admin/')>0)
            {
                setTimeout('StartPlayer()',1000); 
            }
//        }
    }

//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------//

    function muteTracker(obj) 
    {
        mute = obj.state; 
    }

//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------//

    function RetainVolume(obj) 
    {
        if(mute == false)
        {
            volume = obj.percentage; 
        }
    }   

//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------//

    function GetFileName(id,isstop,replaceObj,filename) 
    {
        isDefault=false;
        isStop=isstop;
        if(document.getElementById("playtitle"))
        document.getElementById("playtitle").innerHTML=document.getElementById(id.replace(replaceObj,"lblTitle")).innerHTML;
        ClientServices.GetVideoUrl(document.getElementById(id.replace(replaceObj,"hidVideoName")).value,oncomplete,ontimeout,onerror);
    }

//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
    function oncomplete(returnvalue)
    {
        if(document.location.href.toLowerCase().indexOf('admin/')<0)
            isStop=false
        if(document.getElementById('eduplayer')==null)
            LoadPlayers(returnvalue,isStop);
        else PlayVideo(returnvalue);
    }
    
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------//

    function ontimeout()
    {
    
    }
    
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------//

    function onerror()
    {
    
    }

//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------//

    var sys=function()
    { 
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
        function EndRequestHandler(sender, args)
        {
            if (args.get_error() != null)args.set_errorHandled(true);
        } 
    } 

//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------//

    function FindURL(filename)
    {
        if((filename)=="") 
            ClientServices.GetVideoUrl('default',oncomplete,ontimeout,onerror);
        else  
            ClientServices.GetVideoUrl(filename,oncomplete,ontimeout,onerror);
    }

//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------//

    function AlreadyPreviewed1(paymenturl)
    { 
        setTimeout("CallAlready("+paymenturl+"),500");
    }

//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
    function VideoAlreadyPreviewed(paymenturl,IsLiveCheck)
    {
        if (confirm("You have already previewed the Video. Please click OK to pay"))
            window.location.href = paymenturl; 
        else 
        {
            urltoRewrite=window.location.href.split('?').length==2?window.location.href.split('?')[0]:window.location.href;     
            if($("#hidAlreadyPreviewed")!=null)IsLiveCheck=$("#hidAlreadyPreviewed").val();
            window.location.href=urltoRewrite+"?q="+IsLiveCheck;
        }
    }

//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------//

    function StopPlayer() 
    {
        if(document.getElementById('eduplayer')!=null)
        document.getElementById('eduplayer').sendEvent('stop');
    }

//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------//

    function StartPlayer() 
    {
        if (thisMovie('eduplayer') != null && thisMovie('eduplayer') != undefined)
           thisMovie('eduplayer').sendEvent('play');
    }

//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------//

    function CheckPlayerStatus(){
        if(!IsHandled)
        {
            HandleVideo();
        }
    }
        
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
    
    function GetHWurl(title,fileName)
    {
        document.getElementById("playtitle").innerHTML=title;
        ClientServices.GetVideoUrl(fileName,oncomplete1,ontimeout,onerror);
    }  
    
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------//    
    
    function GetVideoNotAvailble(fileName)
    {
        ClientServices.GetVideoUrl(fileName,oncomplete1,ontimeout,onerror);
    }    
    
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
    
    function oncomplete1(returnvalue)
    {
        PlayVideo(returnvalue);
    }
    
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
    
    function PlayVideo(returnvalue)
    {
        try 
        {
            isStop=false
            if(document.getElementById('eduplayer')==null) 
            {
                LoadPlayers(returnvalue,isStop);
                return;
            }
            document.getElementById('eduplayer').sendEvent('LOAD', {file:returnvalue, type: 'highwinds'});
            if (!isstopplayer) 
            {
                document.getElementById('eduplayer').sendEvent('play');
            }
            else 
            {
                document.getElementById('eduplayer').sendEvent('stop');
            }
            isstopplayer = false;           
        }
        catch(errorMonitord)
        {
        
        }
    }

