

var oEmbedCallback = 'embedVideo';		//Tell Vimeo what function to call
var oEmbedUrl = 'http://vimeo.com/api/oembed.json'; //Set up the URL

//This function puts the video on the page
function embedVideo(video) {
	var videoEmbedCode = video.html;
	document.getElementById('embed').innerHTML = unescape(videoEmbedCode);
}

//adds click events to the links 'thumbs' , 
function initVimeo() {
	
	$("#vimeodiv").css({'display':'none'});

	var links = document.getElementById('thumbs').getElementsByTagName('a');
	for (var i = 0; i < links.length; i++) {
		// Load a video using oEmbed when you click on a thumb
		if (document.addEventListener) {
			links[i].addEventListener(
					'click', 
					function(e) {
						var link = this;
						loadScript(oEmbedUrl + '?url=' + link.href + '&width=800&height=450&callback=' + oEmbedCallback);
						document.getElementById('fbbutton').innerHTML = unescape('<iframe src="http://www.facebook.com/plugins/like.php?href='+link.href+'&amp;layout=standard&amp;show_faces=false&amp;width=450&amp;action=like&amp;colorscheme=dark&amp;height=35" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:35px;" allowTransparency="true"></iframe>');
						e.preventDefault();},
						false
			);
		}
		// IE (sucks)
		else {
			links[i].attachEvent(
					'onclick', 
					function(e) {
						var link = e.srcElement.parentNode;
						loadScript(oEmbedUrl + '?url=' + link.href + '&width=800&height=450&callback=' + oEmbedCallback);
						document.getElementById('fbbutton').innerHTML = unescape('<iframe src="http://www.facebook.com/plugins/like.php?href='+link.href+'&amp;layout=standard&amp;show_faces=false&amp;width=450&amp;action=like&amp;colorscheme=dark&amp;height=35" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:35px;" allowTransparency="true"></iframe>');
						return false;}
			);
		}
	}

	$("#vimeodiv").css({'display':'block'});  
	
	// Load in the first vidz
	loadScript(oEmbedUrl + '?url=' + links[0].href + '&width=800&height=450&callback=' + oEmbedCallback);
	document.getElementById('fbbutton').innerHTML = unescape('<iframe src="http://www.facebook.com/plugins/like.php?href='+ links[0].href +'&amp;layout=standard&amp;show_faces=false&amp;width=450&amp;action=like&amp;colorscheme=dark&amp;height=35" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:35px;" allowTransparency="true"></iframe>');
}

//This function loads the data from Vimeo
function loadScript(url) {
	var js = document.createElement('script');
	js.setAttribute('src', url);
	document.getElementsByTagName('head').item(0).appendChild(js);
}



var menu_on_screen = 0;  


function clickMenu(menu){  
	if (menu_on_screen == 0){		// nothing on screen
		$("#vimeodiv").css({'display':'none'});
		$("#fbbutton").css({'display':'none'});
		$(menu).css({'display':'block'});  
		menu_on_screen = menu;
		return false;
	}else if(menu_on_screen==menu){  // remove from screen
		$(menu).hide();  
		$("#vimeodiv").css({'display':'block'});
		$("#fbbutton").css({'display':'block'});
		menu_on_screen = 0;  
	}else{		// replace  
		$(menu_on_screen).css({'display':'none'});
		$(menu).css({'display':'block'});  
		menu_on_screen = menu;  
	}
}  






