$(document).ready(function(){
	$('td.vi-video-button').each(function(){
		var parent = $(this);
		var divContainer = parent.children().eq(0);
		var backGround = parent.find('span.back');
		var button = parent.find('a');
		var videoBlock = parent.parents('table').next();
		var startHeightVideoBlock = videoBlock.height();
		videoBlock.css({
			height:0,
			display:'none',
			overflow:'hidden'
		});
		backGround.css({
			height:0,
			overflow:'hidden',
			display:'block'
		});
		var startHeightBackGround = 9 + (parent.height() - (divContainer.offset().top - parent.offset().top) + parseInt(parent.css('padding-bottom'))) + 'px';
		button.click(function(){
			backGround.stop();
			videoBlock.stop();
			if(button.hasClass('active')){
				button.removeClass('active');
				videoBlock.animate({height:0},400,function(){
					backGround.animate({height:0},100)
				});
			}
			else {
				button.addClass('active');
				backGround.css({display:'block'});
				backGround.animate({height:startHeightBackGround},100,function(){
					videoBlock.animate({height:startHeightVideoBlock},400);
				});
			};
			return false;
		});
	});
});
