function PostVideo(container) {
	this.container = $(container);
	this.secondary = false;
	this.id;
	this.videoType;
	this.videoId;
	this.image;
	
	this.hasThumbnail = false;
	this.width = 0;
	this.height = 0;
	
	this.sizeLoader = new Image();
	this.thumbnail = new Image();
	
	this.init = function() {
		var parts = this.container.attr('id').split('-');
		if( this.container.hasClass('secondary-video') )
		{
			this.secondary = true;
			this.videoType = parts[1];
			this.videoId = parts[2];
		}
		else
		{
			this.id = parts[1];
		}
	};
	
	this.loadThumbnail = function() {
		if( this.container.hasClass('post-video-container-loading') || this.container.hasClass('post-video-container-big-loading') || this.container.hasClass('raw-video-container-loading') )
		{
			var params = {action:'stocktown_get_post_thumbnail', width:this.container.width(), resolution:'large'};
		
			if( !this.secondary )
			{
				params.postId = this.id;
			}
			else
			{
				params.videoType = this.videoType;
				params.videoId = this.videoId;
			}
		
			$.getJSON(AJAX_URL, params,	function(obj) { return function(data) { obj.onThumbnailDataLoaded(data) } }(this) );
		}
		else
		{
			this.height = $('.featured-image', this.container).height();
			this.width = $('.featured-image', this.container).width();
			
			$('.play-button', this.container).click( function(obj) { return function() { obj.loadVideo(); return false; } }(this) );
		}
	}
	
	this.onThumbnailDataLoaded = function(data) {
		
		this.sizeLoader.onload = function(obj) { return function() { obj.onThumbnailLoaded(); } }(this);
		
		if( data.thumbnail )
		{
			this.hasThumbnail = true;
			this.thumbnail.src = data.thumbnail;
			this.thumbnail.width = data.thumbnailWidth;
			this.thumbnail.height = data.thumbnailHeight;
		}
		
		this.sizeLoader.src = data.src;
	}
	
	this.onThumbnailLoaded = function() {
		this.container.removeClass('raw-video-container-loading');
		this.container.removeClass('post-video-container-loading');
		this.container.removeClass('post-video-container-big-loading');
		this.container.html('');
		
		var playButton = $('<a />');
		playButton.attr({href:'#', id:'play-button-' + this.id});
		playButton.addClass('play-button');
		playButton.click( function(obj) { return function() { obj.loadVideo(); return false; } }(this) );
		
		var ratio = this.sizeLoader.height / this.sizeLoader.width;
		
		this.width = this.container.width();
		this.height = Math.round( this.container.width() * ratio );
		
		if( !this.hasThumbnail )
		{
			this.thumbnail.src = this.sizeLoader.src;
			this.thumbnail.width = this.width;
			this.thumbnail.height = this.height;
		}
		
		$(this.thumbnail).addClass('featured-image');
		
		this.container.append( playButton );
		this.container.append( this.thumbnail );
	}
	
	this.loadVideo = function() {
		var params = {
			action:'stocktown_get_video_player',
			width:this.width,
			height:this.height
		};
		
		if( !this.secondary )
		{
			params.postId = this.id;
		}
		else
		{
			params.type = this.videoType;
			params.id = this.videoId;
		}
		
		this.container.load(AJAX_URL, params);
		
		return false;
	}
	
	this.onPlay = function() {
		
	}
	
	this.init();
}
