﻿var vimeoUserName = 'thecrossingmedia';

var playerMenu = "";
var firstTime = true;

// Tell Vimeo what function to call
var clipCallback = 'latestClip';
var oEmbedCallback = 'embedVideo';

// Set up the URLs
var clipsUrl = 'http://www.vimeo.com/api/' + vimeoUserName + '/clips.json?callback=' + clipCallback;
var oEmbedUrl = 'http://www.vimeo.com/api/oembed.json';


// This function uses oEmbed to get the last clip
function latestClip(clips)
{
    var clipUrl = clips[0].url;

    if (firstTime == true)
    {

        for (i = 0; i < 3; i++)
        {
            playerMenu += '<a class="introText" onclick=setNewMiniVideo("' + clips[i].url + '")>';
            playerMenu += '<img src="/images/miniPlayerMenuBullet.jpg" alt="' + clips[i].title + '" style="vertical-align:middle;" /> ' + clips[i].title + '</a><br />';
        }
        
         //alert(playerMenu);
    }

    // Get the oEmbed stuff
    loadScript(oEmbedUrl + '?url=' + encodeURIComponent(clipUrl) + '&callback=' + oEmbedCallback + "&width=256&height=144");
}





// This function puts the video on the page
function embedVideo(video)
{
    
    videoEmbedCode = video.html;
    document.getElementById('miniPlayer').innerHTML = unescape(video.html);

    //if (firstTime == true)
    //{
        //document.getElementById('miniPlayerMenu').innerHTML = playerMenu;
        //firstTime = false;
    //}
}



function embedVideoFull(video)
{
    videoEmbedCode = video.html;
    document.getElementById('mainImage').innerHTML = unescape(video.html);
}


// This function loads the data from Vimeo
function loadScript(url)
{
    var js = document.createElement('script');
    js.setAttribute('type', 'text/javascript');
    js.setAttribute('src', url);
    document.getElementsByTagName('head').item(0).appendChild(js);


}



function setNewMiniVideo(url)
{
    loadScript(oEmbedUrl + '?url=http://www.vimeo.com/' + encodeURIComponent(url) + '&callback=' + oEmbedCallback + "&width=256&height=144");
}


function setNewFullVideo(url)
{
    //alert(url);
    loadScript(oEmbedUrl + "?url=http://www.vimeo.com/" + encodeURIComponent(url) + "&callback=embedVideoFull&width=496&height=279");
}





