$(window).load(function() {
	// modal windows for works
	$('.torso a.photo').colorbox();
	
	// if the person has flash available
	if ($$.hasFlash(10)) {
		// go through each audio link
		$('.torso a.audio').click(function(i) {

			var link = $(this).attr('href');
			var image = $(this).find('img').attr('src');

			var audioHtml = $('<div id="audio_player"><div id="audio" style="display:block;width:500;height:30px;padding:25px" href="' + link + '"></div></div>');
			$(this).after(audioHtml);
			audioHtml.hide();

			// and set up colorbox to modal the audio
			$(this).colorbox({
				width: 607,
				height: 155, 
				inline: true, 
				href:'#audio_player',
				onOpen: function() {
					$('#audio_player').show();

					// install flowplayer into container 
					$f("audio", "http://releases.flowplayer.org/swf/flowplayer-3.1.5.swf", { 

					    // fullscreen button not needed here 
					    plugins: { 
					        controls: { 
					            fullscreen: false, 
					            height: 30 
					        } 
					    }, 

					    clip: { 
					        autoPlay: false, 

					        // optional: when playback starts close the first audio playback 
					        onBeforeBegin: function() { 
					            $f("player").close(); 
					        } 
					    } 

					});
				},
				onCleanup: function() {
					$('#audio_player').remove()
				}
			});
		})
		
		
		// go through each video link
		$('.torso a.video').each(function(i) {
			
			var link = $(this).attr('href');
			var vimeoId = link.match(/(\d+)$/);
			
			// if there is no vimeo id, simply link to video
			if (vimeoId == null) {
				return;
			}
			
			// overwise embed the video
			var vimeoEmbedUrl = 'http://vimeo.com/moogaloop.swf?clip_id=' + vimeoId[1];
			
			var videoHtml = $('<div id="video_' + i + '"><object id="video_' + i + '" width="640" height="360"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="' + vimeoEmbedUrl + '&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=000000&amp;fullscreen=1" /><embed src="' + vimeoEmbedUrl + '&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=000000&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="640" height="360"></embed></object></div>');
			$(this).after(videoHtml);
			videoHtml.hide();

			// and set up colorbox to modal the video
			$(this).colorbox({
				width: videoHtml.find('embed').outerWidth(), 
				inline:true, 
				href:'#' + videoHtml.attr('id'),
				onOpen: function() {
					$('#' + videoHtml.attr('id')).show()
				},
				onCleanup: function() {
					$('#' + videoHtml.attr('id')).hide()
				}
			});
		});
	}

})



/**
 * Flash (http://jquery.lukelutman.com/plugins/flash)
 * A jQuery plugin for embedding Flash movies.
 * 
 * Version 1.0
 * November 9th, 2006
 *
 * Copyright (c) 2006 Luke Lutman (http://www.lukelutman.com)
 * Dual licensed under the MIT and GPL licenses.
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.opensource.org/licenses/gpl-license.php
 * 
 * Inspired by:
 * SWFObject (http://blog.deconcept.com/swfobject/)
 * UFO (http://www.bobbyvandersluis.com/ufo/)
 * sIFR (http://www.mikeindustries.com/sifr/)
 * 
 * IMPORTANT: 
 * The packed version of jQuery breaks ActiveX control
 * activation in Internet Explorer. Use JSMin to minifiy
 * jQuery (see: http://jquery.lukelutman.com/plugins/flash#activex).
 *
 **/ 

var $$ = function() {};

/*
 * @name flash.hasFlash
 * @desc Check if a specific version of the Flash plugin is installed
 * @type Boolean
 *
**/
$$.hasFlash = function() {
	// look for a flag in the query string to bypass flash detection
	if(/hasFlash\=true/.test(location)) return true;
	if(/hasFlash\=false/.test(location)) return false;
	var pv = $$.hasFlash.playerVersion().match(/\d+/g);
	var rv = String([arguments[0], arguments[1], arguments[2]]).match(/\d+/g) || String($$.pluginOptions.version).match(/\d+/g);
	for(var i = 0; i < 3; i++) {
		pv[i] = parseInt(pv[i] || 0);
		rv[i] = parseInt(rv[i] || 0);
		// player is less than required
		if(pv[i] < rv[i]) return false;
		// player is greater than required
		if(pv[i] > rv[i]) return true;
	}
	// major version, minor version and revision match exactly
	return true;
};


/**
 *
 * @name flash.hasFlash.playerVersion
 * @desc Get the version of the installed Flash plugin.
 * @type String
 *
**/
$$.hasFlash.playerVersion = function() {
	// ie
	try {
		try {
			// avoid fp6 minor version lookup issues
			// see: http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/
			var axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6');
			try { axo.AllowScriptAccess = 'always';	} 
			catch(e) { return '6,0,0'; }				
		} catch(e) {}
		return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g, ',').match(/^,?(.+),?$/)[1];
	// other browsers
	} catch(e) {
		try {
			if(navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin){
				return (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g, ",").match(/^,?(.+),?$/)[1];
			}
		} catch(e) {}		
	}
	return '0,0,0';
};

