// JavaScript Document

//START JQUERY CODE//
$(function(){
	$('a').click(function(event){
	
		//extract the file extension from the link
		ext = $(this).attr("href");
		ext = ext.substring(ext.lastIndexOf('.') + 1,ext.length);
		
		//Check the file extension of the link
		if (ext == "mp4" || ext == "flv") {
			$('#darken').fadeIn('500');
			$('#darken').css({"filter" : "Alpha(opacity=50)"});
			$('#modalBox').fadeIn('500');	
			//Prevent the anchor link from loading		
			event.preventDefault();
			//Embed Flash Video Player
			embedVidPlayer($(this).attr("href"),'800','600');
		}
	});
	
	$('#darken').click(function(){
		$('#modalBox').fadeOut('500');
		$('#darken').fadeOut('500');
	});

});
//END JQUERY CODE//

// Custom JS function to embed Flash Video Player
function embedVidPlayer(vidFile, width, height) {

	var divID = vidFile.replace('.mp4','');
	divID = vidFile.replace('.flv','');
	
	var s1 = new SWFObject('http://knowledge.wilsonstudioweb.com/player.swf','player',width,eval(height)+20,'9');
	var flashvars =  "autostart=true&file=" + vidFile;
	s1.addParam('allowfullscreen','true');
	s1.addParam('allowscriptaccess','always');
	s1.addParam('flashvars',flashvars);
	s1.addParam('background','transparent');
	//document.write("");
	s1.write('modalBox');
}