/**
 * initialize a slide, bind click events to the main image/link to open
 * the video player
 */
function initSlide () {

	$('a.myVideo').unbind('click').bind('click', function(e) {
	
		// stop slider
		window.stopShowcase();
		
		// load videojs for everything else
		$(this).hide();		
		$(".video-js-box").empty().append('<video id="video-' + $(this).attr('id') + '" ' 
				+ 'class="video-js" width="672" height="384" autoplay controls '
				+ 'poster="' + $(this).find('img').attr('src') + '"><source ' 
				+ 'src="' + $(this).attr('href') + '" type=\'video/mp4\' />' 
				+ '<object id="flash_fallback_1" class="vjs-flash-fallback" ' 
				+ ' width="672" height="384" type="application/x-shockwave-flash" ' 
				+ ' data="/fileadmin/templates/misc/swf/flowplayer-3.2.1.swf">' 
				+ ' <param name="movie" value="/fileadmin/templates/misc/swf/flowplayer-3.2.1.swf" />' 
				+ ' <param name="allowfullscreen" value="true" />' 
				+ ' <param name="flashvars" value=\'config={"canvas": { "backgroundColor": "#000000", "backgroundGradient": "none"}, "clip":{"scaling":"fit"}, "playlist":["' + $(this).find('img').attr('src') + '",{"url":"' + $(this).attr('href') + '","autoPlay":true,"autoBuffering":true}]}\' /><img src="' + $(this).find('img').attr('src') + '" width="672" height="384" alt="Poster Image" title="No video playback capabilities." /></object></video>');
		
		VideoJS.setup('video-' + $(this).attr('id'), {
			playerFallbackOrder: ["html5", "flash", "links"]
		});
		
		// autoplay for ipad
		var video = $('#video-' + $(this).attr('id')).get(0);
		fakeClick(function() {
			video.play();
		});
		
		$('.showcase-caption').fadeOut('slow');
		e.stopPropagation();
		return false;		
	});
}

function fakeClick(fn) {
	var $a = $('<a href="#" id="fakeClick"></a>');
		$a.bind("click", function(e) {
			e.preventDefault();
			fn();
		});
	
	$("body").append($a);
			
	var evt, 
		el = $("#fakeClick").get(0);
	
	if (document.createEvent) {
		evt = document.createEvent("MouseEvents");
		if (evt.initMouseEvent) {
			evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
			el.dispatchEvent(evt);
		}
	}
	
	$(el).remove();
}
