(function($) {	
	var pos = null;
	var yOffset = 0;
	var file = null;
	
	function startMovie() {
		$('#videoOverlay').remove();
		file = $(this).attr('href');
		file = file.substr(file.lastIndexOf('/')+1);
		pos = $(this).position();
		pos.width = $(this).width();
		$('#mask').remove();
		$('<div id="mask"></div>').appendTo('body').css({ visibility:'visible', opacity:0 }).fadeTo(400, .7, function() {
			var vo = $('<div id="videoOverlay"></div>').css({ zIndex:500, position:'absolute', top:0, left:0  }).appendTo('body');
			if(pos.top+437>$('body').height()) yOffset = $('body').height()-pos.top-337; else yOffset = 0;
			if($.browser.msie && $.browser.version<7) { var img = $('<img id="videoBackground" src="/styles/images/videoPlayerBackground.png" />').appendTo(vo).css({ height:'100px', position:'absolute', left:(970/2)-70, top:pos.top+130-yOffset}); startFlash(); }
			else $('<img id="videoBackground" src="/styles/images/videoPlayerBackground.png" />').css({ position:'absolute', left:(pos.width/1.5)+pos.left, top:pos.top+(170/2)+130, width:0, height:0  }).appendTo(vo).animate({ width:'543px', height:'337px', left:(970/2)-70, top:pos.top+130-yOffset }, 450, startFlash);
		}).click(endMovie);
		return false;	
	}
	
	function startFlash() {
		var bPos = $('#videoBackground').position();
		$('<div id="videoFlash"></div>').appendTo('#videoOverlay');	
		swfobject.embedSWF("/flash/videoPlayer-v2.swf", "videoFlash", "543", "337", "9.0.0","/flash/expressInstall.swf", { filename:file }, { menu:"false", wmode:"transparent" }, { style:"position:absolute; top:"+(bPos.top)+"px; left:"+bPos.left+"px;" });	
		$('<img id="videoClose" src="/styles/images/videoPlayerClose.gif" alt="Close" />').css({ position:'absolute', left:(970/2)-70+490, top:pos.top+130-yOffset+5, cursor:'pointer', opacity:0, zIndex:1000 }).appendTo('#videoOverlay').click(endMovie).hover(function() { $(this).css('opacity', 1); }, function() { $(this).css('opacity', .7); }).fadeTo('normal',.7);
	}
	
	function endMovie() {
		if($.browser.msie && $.browser.version<7) { $('#videoOverlay').remove(); return true; }
		$('#videoClose').remove();
		$('#videoFlash').fadeOut(100, function() {
			$('#videoOverlay img').animate({ width:0, height:0, left:(pos.width/1.5)+pos.left, top:pos.top+(170/2)+130 }, 350, function() {
				$('#videoOverlay').remove();
				$('#mask').fadeTo(400, 0, function() { $('#mask').remove(); });	
			});
		});
	}
	
	$(document).ready(function() {
		$('a[@href$=flv]').click(startMovie);
	});
})(jQuery);