function playVideoOnClick(e) {
	//Cancel the link behavior
	e.preventDefault();
	
	//Get the A tag
	var id = $(this).attr('href');

	//Get the screen height and width
	var maskHeight = $(document).height();
	var maskWidth = $(window).width();


	//Set heigth and width to mask to fill up the whole screen
	$('#mask').css({'width':maskWidth,'height':maskHeight});
	
	//transition effect		
//		$('#mask').fadeIn(1000);	
	$('#mask').fadeTo(0,0.0001);
	$('#mask').show();
	$('#mask').fadeTo(1000,0.8);	

	//Get the window height and width
	var winH = $(window).height();
	var winW = $(window).width();
	var winOff = $(window).scrollTop();
      
	//Set the popup window to center
	$('#player').css('top',  (winH/2-$('#player').height()/2) + winOff);
	$('#player').css('left', winW/2-$('#player').width()/2);
	$('#player').attr('href', $(this).attr('ref'));
	$('#playerClose').css('top', (winH/2+$('#player').height()/2) + winOff + 10);
	$('#playerClose').css('left', winW/2-$('#playerClose').width()/2);
	//transition effect
	$('#player').show(); 
	$('#playerClose').show();
	var clipUrl = $('#player').attr('href');
	flowplayer("player", "/media/flowplayer/flowplayer-3.2.2.swf", {
		clip: {
			scaling: 'orig'
		},
		canvas: {
			background: '#000000',
			backgroundGradient: 'none'
		}
	});
}


$(document).ready(function() {	

	$('body').append('<div id="mask" style="position:absolute;left:0;top:0;z-index:9000;background-color:#000;display:none;"></div>');
	$('body').append('<a id="player" style="position:absolute;left:0;top:0;width:640px;height:381px;z-index:10000;background-color:#fff;display:none;"></a><a id="playerClose" style="position:absolute;left:0;top:0;z-index:10000;display:none;color:#fff;" href="#">[Закрыть]</a>');



	//select all the a tag with name equal to modal
	$('.showVideoModal').click(playVideoOnClick);
	
	//if mask is clicked
	$('#mask').click(function () {
		flowplayer().stop();
		$('#playerClose').hide();
		$('#player').hide();
		$('#mask').hide();
	});			
	
	$('#playerClose').click(function() {
		flowplayer().stop();
		$('#playerClose').hide();
		$('#player').hide();
		$('#mask').hide();
		return false;
	});
});


