﻿var ytplayer;

function onYouTubePlayerReady(eleid) {
    lastwatchedid = "myytplayer" + eleid;
    ytplayer = document.getElementById(lastwatchedid);
    //ytplayer.mute();
    ytplayer.playVideo();

}


function loadmovie(vid, srctype) {

    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "/embed.asmx/embedcode",
        data: "{id:" + vid + "}",
        dataType: "json",
        success: function(htmlresults) {

            if (srctype == 1) {
                var params = { allowScriptAccess: "always", allowFullScreen : "true" };
                var atts = { id: "myytplayer" + vid };

                swfobject.embedSWF("http://www.youtube.com/v/" + htmlresults.d + "&enablejsapi=1&fs=1&cc_load_policy=1&playerapiid=" + vid,
                       "watch" + vid, "640", "385", "8", null, null, params, atts);
            }
            else {
                $("#watch" + vid).html(htmlresults.d);
            }

            $('#closeme' + vid).css('display', 'inline');
            $("#moviecontainer" + vid).css('display', 'block');
            setTimeout(function() { $.scrollTo('#scrollwatch' + vid, { duration: 250 }) }, 800);
        }
    });

    $.ajax({});
}


function closemovie(vid) {
    $("#moviecontainer" + vid).css('display', 'none');
    $("#watch" + vid).html("");
    ytplayer.stopVideo();
}


function openinlink(lnkid, vid) {
    var gotourl = false;
    var thelink = $('a#' + lnkid);
    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "/embed.asmx/exlink",
        data: "{id:" + vid + "}",
        dataType: "json",
        async: false,
        timeout: 3000,
        success: function(axres) {

            thelink.attr("href", axres.d);
            $.ajax({});
            gotourl = true;
        }
    });

    return gotourl;
}


function openexlink(lnkid, vid) {
    var gotourl = false;
    var thelink = $('a#' + lnkid);
    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "/embed.asmx/exlink",
        data: "{id:" + vid + "}",
        dataType: "json",
        async: false,
        timeout: 3000,
        success: function(axres) {

            thelink.attr("href", axres.d);
            $.ajax({});
            gotourl = true;
        }
    });

    return gotourl;
}
