//* VIMEO CODE *//

var apiEndpoint = 'http://vimeo.com/api/v2/';
var oEmbedEndpoint = 'http://vimeo.com/api/oembed.json'
var oEmbedCallback = 'switchVideo';
var videosCallback = 'setupGallery';
var videosCallbackTwo = 'setupGalleryTwo';
var vimeoUsername = 'cuff11';

function getFeaturedVideo(url) {
	$.getScript(oEmbedEndpoint + '?url=' + url + '&width=700&height=400&title=0&portrait=0&byline=0&color=ff9933&callback=placeFeaturedVideo');
}

		// Get the user's videos
function insertVimeoList() {
	$.getScript(apiEndpoint + vimeoUsername + '/videos.json?callback=' + videosCallback);
}

function getVideo(url) {
	$.getScript(oEmbedEndpoint + '?url=' + url + '&width=400&height=224&title=0&portrait=0&byline=0&color=ff9933&callback=' + oEmbedCallback);
}
		
function setupGallery(videos) {
	// Load the first video
	getVideo("http://vimeo.com/22259142");
	
	// Add the videos to the gallery
	for (var i = 0; i < 12; i++) {
		if (videos[i].url != "http://vimeo.com/22410421") {
		thisImage = '<a href="' + videos[i].url + '"><img src="' + videos[i].thumbnail_small + '" class="thumb" width="70px" height="50px" /></a>';
		html = "<table width='400px' border='0' cellpadding='0' cellspacing='0'><tr><td width = '10px' align='left' valign='middle' height='70px'>" + thisImage + "</td><td width='78%' align='left' valign='middle'><a href='" + videos[i].url + "'>" + videos[i].title + "</a><br />" + videos[i].description + "</td></tr></table>";
		$('#thumbs').append(html);
		}
	}
			
	// Switch to the video when a thumbnail is clicked
	$('#thumbs a').click(function(event) {
		event.preventDefault();
		getVideo(this.href);
		return false;
	});
	
			
}

	
function switchVideo(video) {
	$('#embed').html(unescape(video.html));
}

function placeFeaturedVideo(video) {
	$('#featuredvideobox').html(unescape(video.html));
}

