﻿var videoID = '';
var thumbURL = '';
var videoURL = '';

function GetVideo(videoURL) {

    EmbedURL = 'https://secure.vimeo.com/api/oembed.json?url=' + videoURL + '&autoplay=true&width=599&height=450&callback=DisplayVideo';

    $.getScript(EmbedURL);

}

function DisplayVideo(video) {
    $('.jqmTitle').text(video.title);
    $('#ajaxMedia').html(unescape(video.html));
}


function VideoParams(video) {
    videoURL = video[0].url;

    GetVideo(videoURL);
}

$(document).ready(function () {

    $('.vid-wrapper').click(function () {
        videoID = $(this).find('span').attr("title");
        video = 'https://secure.vimeo.com/api/v2/video/' + videoID + '.json?callback=VideoParams';

        $.getScript(video);

        return false;
    });

    $('#modalHelpVideo').jqm({ overlay: 80, trigger: '.vid-wrapper',
        onHide: function (hash) {
            hash.o.remove();
            hash.w.customToggle(false);
            $('iframe').remove();
        },
        onShow: function (hash) {
            $(window).scrollTop(0);
            currentModal = hash.w;
            hash.w.customToggle(true);
        }
    });

    $('a.ToggleContent').click(function (event) { ToggleContent(event, $(this)); });

});
