﻿

$(document).ready(function() {
    AddHoverEffects();
});

function AddHoverEffects() {
    //hover effects
    $('.video').hover(function() {
        $(this).addClass('hover');
    }, function() {
        $(this).removeClass('hover');
    });
}

//$(function() {

//    flowplayer("player", "swf/flowplayer.commercial-3.1.0.swf", {

//        key: '$78e707491e890e6ceb0',

//        //play:{opacity:0},

//        onLoad: function() {
//            this.setVolume(60);
//        },

//        clip:
//                {
//                    baseUrl: 'http://e1p1.simplecdn.net/offshoretv/',
//                    scaling: 'fit',


//                    onBeforeBegin: function() {
//                        if (this.getClip().isAd)
//                            this.getControls().hide();
//                        else
//                            this.getControls().show();

//                        //PageMethods.Playing(this.getClip().videoId);
//                    },

//                    onStart: function() {
//                        $("a.playing").removeClass("playing");
//                        $("a.paused").removeClass("paused");
//                        $(".clipHolder a[href='#player," + this.getClip().url + "']").addClass("playing");
//                    },

//                    onFinish: function() {
//                        $("a[href='#player," + this.getClip().url + "']").removeClass("playing");
//                    },

//                    onBeforePause: function() {
//                        return !this.getClip().isAd;
//                    },

//                    onPause: function() {
//                        $("a[href=#player,'" + this.getClip().url + "']").addClass("paused");
//                    },

//                    onResume: function() {
//                        $("a[href='#player," + this.getClip().url + "']").removeClass("paused");
//                    }

//                },

//        plugins: {
//            //controls: { display: 'none' }

//            controls:
//                        {
//                            //                            all: false, 
//                            //                            scrubber: true, 
//                            //                            play: true, 
//                            //                            playlist: true, 
//                            //                            mute: true, 
//                            //                            time: true, 
//                            //                            volume: true, 
//                            //                            fullscreen: true, 
//                            //height: '30', 
//                            //background: 'url(media/images/controlbar.png) no-repeat', 
//                            buttonColor: '#666666',
//                            buttonOverColor: '#ef7700',
//                            bufferColor: '#666666',
//                            sliderColor: '#FFFFFF',
//                            progressColor: '#ef7700',
//                            timeColor: '#FFFFFF',
//                            durationColor: '#ef7700'
//                        }
//        }

//        // streaming plugins are configured under the plugins node  
//        //                plugins: { 
//        //                    simplecdn: {  
//        //                        url: 'http://www.simplecdn.com/flow31/flowplayer.rtmp-3.1.0.swf',  
//        //                        netConnectionUrl: 'rtmp://e1f1.simplecdn.net/play/_definst_/offshoretv/'  
//        //                } 

//        // use playlist plugin.
//    }); //.playlist("div.petrol", { loop: true });

//    //setMainPlayerPlayList();
//});

$(function() {

    //return;  //Quick fix until a CDN solution is up and running

    //    flowplayer("player", "swf/flowplayer.commercial-3.1.0.swf", {

    //        key: '$78e707491e890e6ceb0',


$f("a.player", "http://offshoretv.no/swf/flowplayer-3.1.5.swf", {


        onLoad: function() {
            this.setVolume(60);
        },

        clip:
                {
                    //baseUrl: 'http://e1p1.simplecdn.net/offshoretv/',
                    scaling: 'fit',

                    provider: 'rtmp',


                    onBeforeBegin: function() {
                        if (this.getClip().isAd)
                            this.getControls().hide();
                        else
                            this.getControls().show();

                        //PageMethods.Playing(this.getClip().videoId);
                    },

                    onStart: function() {
                        $("a.playing").removeClass("playing");
                        $("a.paused").removeClass("paused");
                        $(".clipHolder a[href='#player," + this.getClip().url + "']").addClass("playing");
                    },

                    onFinish: function() {
                        $("a[href='#player," + this.getClip().url + "']").removeClass("playing");
                    },

                    onBeforePause: function() {
                        return !this.getClip().isAd;
                    },

                    onPause: function() {
                        $("a[href=#player,'" + this.getClip().url + "']").addClass("paused");
                    },

                    onResume: function() {
                        $("a[href='#player," + this.getClip().url + "']").removeClass("paused");
                    }

//                },

                },

        plugins: {
            //controls: { display: 'none' }

            controls:
                        {
                            //                            all: false, 
                            //                            scrubber: true, 
                            //                            play: true, 
                            //                            playlist: true, 
                            //                            mute: true, 
                            //                            time: true, 
                            //                            volume: true, 
                            //                            fullscreen: true, 
                            //height: '30', 
                            //background: 'url(media/images/controlbar.png) no-repeat', 
                            buttonColor: '#666666',
                            buttonOverColor: '#ef7700',
                            bufferColor: '#666666',
                            sliderColor: '#FFFFFF',
                            progressColor: '#ef7700',
                            timeColor: '#FFFFFF',
                            durationColor: '#ef7700'
                        },

            rtmp: {

                //This is where you call on the rtmp plugin. You uploaded this in step 2d. It is recognizable by its .swf suffix and the section with 'rtmp' in the file name 

                url: 'http://offshoretv.no/swf/flowplayer.rtmp-3.1.3.swf',
                /*
                "netConnectionUrl" below defines where the streams are found;
                this URL is specific to Amazon CloudFront. it is the address you are given when you made a streaming distribution of the bucket in which your video resides, ending in .cloudfront.net. YOU *MUST* ADD "/cfx/st" IN ORDER TO ENSURE THAT YOUR VIDEO WILL STREAM. Mine would read 'rtmp://s1jng015tymskd.cloudfront.net/cfx/st'
                */
                netConnectionUrl: 'rtmp://s1ku9t0nengwti.cloudfront.net/cfx/st'
            }
        }

        // streaming plugins are configured under the plugins node  
        //                plugins: { 
        //                    simplecdn: {  
        //                        url: 'http://www.simplecdn.com/flow31/flowplayer.rtmp-3.1.0.swf',  
        //                        netConnectionUrl: 'rtmp://e1f1.simplecdn.net/play/_definst_/offshoretv/'  
        //                } 

        // use playlist plugin.
    }); //.playlist("div.petrol", { loop: true });

    //setMainPlayerPlayList();
});

//function setMainPlayerPlayList() {
//    $f("player").playlist("div.petrol", { loop: false });
//}

function playVideo(link, id, url) {

    $f("player").play(url);

//    playVideoNow(url);
//    
//    if ($(link).hasClass('paused')) {
//        $(link).addClass('playing');
//        $(link).removeClass('paused');
//        $f("player").play();
//    }
//    
//    else if ($(link).hasClass('playing')) {
//        $(link).addClass('paused');
//        $f("player").pause();

//    }
//    else {
//        if (document.getElementById('videoTitle'))
//            showVideoInfo(id);
//        
//        playVideoWithAd(url, id);
//    }
}


function showVideoInfo(id) {
    PageMethods.GetVideoInfo(id, GetVideoInfoCallback);    
}


function GetVideoInfoCallback(videoJson) {

    var vid = eval("(" + videoJson + ")");
    
    document.getElementById('videoTitle').innerHTML = vid.Title;
    document.getElementById('videoDescription').innerHTML = vid.Description;
    document.getElementById('videoTimestamp').innerHTML = vid.PublishedOn;
    document.getElementById('videoTags').innerHTML = vid.Tags;
    document.getElementById('videoLinkInput').value = vid.Permalink;
    
    
}


function playVideoNow(urlToPlay) {

    //alert('got called');

    //urlToPlay = urlToPlay.replace(".flv", "");

    alert(urlToPlay.replace("http://", ""));
    

    $f('player').play();

}

//function playVideoWithAd(urlToPlay, id) {
//    
//    //These can be grabbed 
//    var preUrl = '04.flv'; var preId = 15;
//    var postUrl = '03.flv'; var postId = 14;
//    
//    $f("player").play([
//                
//                // the pre-roll video  
//                {
//                    url: preUrl,
//                    autoPlay: true,
//                    isAd: false,
//                    videoId: preId
//                },

//                // content video   
//                {
//                    url: urlToPlay,
//                    isAd: false,
//                    videoId: id
//                },

//                // the post-roll video
//                {
//                    url: postUrl,
//                    autoPlay: true,
//                    isAd: true,
//                    videoId: postId
//                }

//            ]);
//}
