var video_content = function(){
	this.init();
}

video_content.prototype = {
	init: function(){
		this.layout = $('#layout');
		this.jFade = $('#fade');
		this.popup = $('#popup_big');
		this.close_button = this.popup.find('.close');
		this.video_popup_link = $('.video_popup_link');
		
		this.video_content = $('#video_content');
		
		if ( !this.video_content.size() ){
			this.video_content = $(document.createElement('div')).attr('id', 'video_content');
			$('#popup_big > .content').append(this.video_content);
		}

		var that = this;
		
		this.video_popup_link.click(function(){
			var	new_link = $(this)[0].href;
			
			if( /rutube.ru/.test(new_link) ){
				var	new_class = new_link.match(/\?v=([\w]+)$/)[1];
				that.video_content.html('<object width="470" height="353"><param name="movie" value="http://video.rutube.ru/' + new_class + '"></param><param name="wmode" value="window"></param><param name="allowFullScreen" value="true"></param><embed src="http://video.rutube.ru/' + new_class + '" type="application/x-shockwave-flash" wmode="window" width="470" height="353" allowFullScreen="true" ></embed></object>');
			} else if( /yandex.ru/.test(new_link) ){
				that.video_content.html('<object width="450" height="338"><param name="video" value="' + new_link + '"/><param name="allowFullScreen" value="true"/><param name="scale" value="noscale"/><embed src="' + new_link + '" type="application/x-shockwave-flash" width="450" height="338" allowFullScreen="true" scale="noscale"/></object>');
			}
			
			that.popup.addClass('video_popup').removeClass('not_display');
			that.jFade.removeClass('not_display');
			
			if( $.browser.msie && $.browser.version == 6 ){
				that.jFade[0].style.height = that.layout[0].offsetHeight + 'px';
			}
			
			that.video_content.removeClass('not_display');

			var top_value = document.documentElement.scrollTop || document.body.scrollTop;
			
			that.popup.css({
				marginLeft: - that.popup[0].offsetWidth/2,
				top: top_value + 50
			});
			
			return false;
		});
		
		this.close_button.click(function(){
			that.video_content.empty();
			that.popup.addClass('not_display').removeClass('video_popup').removeAttr('style');
			that.jFade.addClass('not_display').removeAttr('style');
			that.video_content.addClass('not_display');
		});
	}
}

$(function(){
	new video_content();
});