/* Requires json.js (MooTools.net) */

window.addEvent('domready', loadVideos);

var videos = [
	{ 	"id" : 246, 
		"index" : 0,
		"image" : "WinterCarni07.jpg",
		"category" : "events",
		"filename" : "Wintercarnival07.flv",
		"title" : "2007 Winter Carnival",
		"description" : "Scenes from Michigan Tech's 2007 Winter Carnival. - Justin Plichta"
	},
	{ 	"id" : 243, 
		"index" : 1,
		"image" : "StatueTour07.jpg",
		"category" : "events", 
		"filename" : "StatueTour07.flv",
		"title" : "2007 Snow Statue Tour", 
		"description" : "A video tour of the snow statues created as part of Michigan Tech's 2007 Winter Carnival. - Justin Plichta"
	},
	{ 	"id" : 245, 
		"index" : 2,
		"image" : "TV6WorldRec.jpg",
		"category" : "events",
		"filename" : "TV6WorldRec.flv",
		"title" : "World Record Coverage by WLUC TV6",
		"description" : "TV6 WLUC covers Michigan Tech's attempt to break three world records in one day. - Courtesy of WLUC TV6"
	},
	{ 	"id" : 240, 
		"index" : 3,
		"image" : "snowball.jpg", 
		"category" : "events", 
		"filename" : "Snowball06.flv",
		"title" : "The World's Largest Snowball", 
		"description" : "In 2006 a group of Michigan Tech students took on the challenge of rolling the world's largest snowball. - Justin Plichta"
	},
	{ 	"id" : 341, 
		"index" : 4,
		"image" : "Snowfight.jpg",
		"category" : "events",
		"filename" : "Snowfight.flv",
		"title" : "A Massive Snowball Fight & Snow Angel Event"
		, "description" : "For a short while Michigan Tech also held the World Record for the largest snowball fight and most simultanious snow angels. - Justin Plichta"
	}
];
var active = 0;

function loadVideos() {
	//alert(videos.length);
	for (var i=0; i<videos.length; i++) {
		var strFunctMD = 'activate('+i+');';
		var video = new Element('a', {
						 'href': 	'http://www.techtube.mtu.edu/watch.php?v='+videos[i].id,
						 'title': 	videos[i].title,
						 'rel':		i,
						 'events': 	{
							 'click': function(e) {
								 new Event(e).stop();
								 activate(this.rel);
								 //activate(''+i+'');
							 }
						 }
		});
		var image = new Element('img', {
						 'src':		'images/'+videos[i].image,
						 'alt':		videos[i].title,
						 'id':		'video'+i
		});
			
		image.injectInside(video);
		video.injectInside($('playlist'));
	}
	if (videos.length > 0)
		setVideo(0);
}

function setVideo(which) {
	if (videos[which]) {
		$('video'+active).setProperty('class', '');
		$('video'+which).setProperty('class', 'active');
		
		var embed = '<object type="application/x-shockwave-flash" data="http://www.techtube.mtu.edu/FlowPlayerMTU.swf"	width="415" height="334" id="FlowPlayer"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="http://www.techtube.mtu.edu/FlowPlayerMTU.swf" /><param name="allowFullScreen" value="true" /><param name="flashvars" value="config={videoFile: \'videos/'+videos[which].category+'/'+videos[which].filename+'\'}" /></object>'
		$('player').setHTML(embed);
		
		$('share_link').setProperty('href', 'http://www.techtube.mtu.edu/watch.php?v='+videos[which].id);
		$('shareURL').setProperty('value', 'http://www.techtube.mtu.edu/watch.php?v='+videos[which].id);
		$('shareEmbed').setProperty('value', embed);
		$('fbshare').addEvent('click', function() {return fbs_click("http://www.techtube.mtu.edu/watch.php?v="+videos[which].id);});
		del_url = "http://www.techtube.mtu.edu/watch.php?v="+videos[which].id;
		del_title = videos[which].title;
		//$('delshare').addEvent('click', function() { window.open('http://del.icio.us/post?v=4&noui&jump=close&url='+encodeURIComponent(del_url)+'&title='+encodeURIComponent(del_title), 'delicious','toolbar=no,width=700,height=400'); return false;});
		$('diggshare').setProperty('href', "http://digg.com/submit?phase=2&url=http%3A%2F%2Fwww.techtube.mtu.edu%2Fwatch.php%3Fv%3D"+videos[which].id+"&title="+encodeURIComponent(videos[which].title)+"&bodytext="+encodeURIComponent(videos[which].description)+"&topic=videos_educational");
		$('emailshare').setProperty('href', "mailto:?subject=You've been sent a Michigan Tech video!&body=http://www.techtube.mtu.edu/watch.php?v="+videos[which].id);
		active = which;
	}
}

function activate(which) {
	setVideo(which);
}