
/**
 * Loads style
 */
function newpres_load() {
	
	// this can go away when the CSS is embedded
	//var css = new Element("link", { type: "text/css", rel: "stylesheet", media: "screen", href: "http://www.mtholyoke.edu/offices/comm/newpresident/style.css" });
	//$$('head')[0].insert(css);
	
	// <div id="mhclink"><a href="http://www.mtholyoke.edu"><img src="img/mhc.jpg" /></a></div>
//	var mhclink = new Element("div", { id: "mhclink" });
//	var a = new Element("a", { href: "http://www.mtholyoke.edu" });
//	var img = new Element("img", { src: "/offices/comm/newpresident/mhc.jpg" });
//	a.insert({'top': img});
//	mhclink.insert({'top': a});
//	$$('body')[0].insert({ 'top': mhclink });
		
}

/**
 * Embed a video.
 */
function mhcEmbedPresidentVideo(container, hq_file, flv_file, poster, captions, w, h, autostart) {
	
	var playerVersion = swfobject.getFlashPlayerVersion(); // returns a JavaScript object
	var major = playerVersion.major;
	var minor = playerVersion.minor;
	var release = playerVersion.release;
	
	// decide if we use the high quality h.264 or the 'low quality' flv
	// version 9.0.98 of the player and higher offers support for h.264
	var file;
	if (major >= 9) {
		if (minor == 0 && release < 98) {
			file = flv_file;
		} else {
			file = hq_file;
		}
	} else {
		file = flv_file;
	}
	
	// autostart?
	if (autostart == null) autostart = 'true';
	
	var flashvars = {
		file: file,
		image: poster,
		captions: captions,
		usecaptions: 'false', // 'false' to hide by default
		width: w,
		height: h,
		autostart: autostart,
		fullscreen: 'true'
	};
	
	var params = {
		allowfullscreen: 'true',
		allowscriptaccess: 'always',
		seamlesstabbing: 'true'
	};
	
	swfobject.embedSWF("http://www.mtholyoke.edu/scripts/mediaplayer-3.17.swf", container, w, h, "8", "", flashvars, params);
		
}


function mhcShowPresidentVideo(event) {

	// get the link that was clicked on
	//var element = event.element();
	var element = Event.element(event);
	
	// get the info from the contents of the link
	var href, poster;
	if (element.tagName == 'A') {
		// user clicked on the text link
		href = this.href;
		var imgs = this.select('img');
		poster = imgs[0].src;
	} else {
		// user clicked on the thumbnail
		href = this.href;
		poster = element.src;
	}
	
	// set the class to 'here'
	var links = $$('#videos ul li a');
	for (var i = 0; i < links.length; i++) {
		links[i].removeClassName('here');
	}
	this.addClassName('here');
	this.blur();
	
	// get the URL to the poster image by replacing the /thumbnails/ directory with /posters/
	Element.extend(poster);
	poster = poster.sub('/thumbnails/','/posters/');
	
	// get the FLV version of the video by replacing the mp4 with flv
	Element.extend(href);
	var flv = href.sub('mp4','flv');
		
	// embed 
	mhcEmbedPresidentVideo('videoBox', href, flv, poster, '', 525, 315, 'true'); // video is 525x295
	
	// prevent the onclick from going to the href
	event.stop();
	
}

/**
 * Adds a click handler to each video thumbnail in the <div id="videos">.
 * Use this code on the page to load:
 * document.observe('dom:loaded', addVideoEvents);
 */
function addVideoEvents() {
		
	// make the links activate the video player
	var links = $$('#videos ul li a');
	for (var i = 0; i < links.length; i++) {
		links[i].observe('click', mhcShowPresidentVideo);
	}
		
}

function addAnnouncementVideoEvents() {
	
	addVideoEvents();
	
	var links = $$('#videos ul li a');
	// embed the main video
	mhcEmbedPresidentVideo('videoBox', 'http://www.mtholyoke.edu/offices/comm/newpresident/flv/lp.flv', 'http://www.mtholyoke.edu/offices/comm/newpresident/flv/lp.flv', 'http://www.mtholyoke.edu/offices/comm/newpresident/posters/lp.jpg', '', 525, 315, 'false');
	// set the current video class to 'here'
	links[0].addClassName('here');
	
}

function addInterviewVideoEvents() {
	
	addVideoEvents();
	
	var links = $$('#videos ul li a');
	// embed the main video
	mhcEmbedPresidentVideo('videoBox', 'http://www.mtholyoke.edu/offices/comm/newpresident/flv/president01.flv', 'http://www.mtholyoke.edu/offices/comm/newpresident/flv/president01.flv', 'http://www.mtholyoke.edu/offices/comm/newpresident/posters/president01.jpg', '', 525, 315, 'false');
	// set the current video class to 'here'
	links[0].addClassName('here');
	
}

// called when the page's DOM is loaded
document.observe('dom:loaded', newpres_load);

