window.osvb = {};
			
ABC.ready( function() {
	window.osvb.settings = {
		borderTop: 10,
		borderLeft: 10,
		borderRight: 10,
		borderBottom: 10,
		windowHeadHeight: 30,
		clientAreaSize: ABC.getClientAreaSize()
	};
	
	ABC.addEvent( window, 'resize', function() {
		window.osvb.settings.clientAreaSize = ABC.getClientAreaSize();
	}, false);
	
	window.osvb.getAvailVideoWidth = function( videoWidth ) {
		var containerWidth = videoWidth + this.settings.borderLeft + this.settings.borderRight;
		var newVideoWidth = videoWidth;
		
		if( containerWidth > this.settings.clientAreaSize.w ) {
			newVideoWidth -= containerWidth - this.settings.clientAreaSize.w
		}
		return newVideoWidth;
	}
	
	window.osvb.getAvailVideoHeight = function( videoHeight ) {
		var containerHeight = videoHeight + this.settings.borderTop + this.settings.borderBottom + this.settings.windowHeadHeight;
		var newHeight = videoHeight;
		
		if( containerHeight > this.settings.clientAreaSize.h ) {
			videoHeight -= containerHeight - this.settings.clientAreaSize.h;
		}
		return videoHeight;
	}
	
	var dragSettings = {
		notDraggableChildren		: [],
		replaceBySameSizeConatainer	: null,
		limitBy						: null,
		callbackMoveFnc				: null,
		draggable					: 'orig-size-video-popup',
		cursorStyle					: true
	}
	ABC.ready( function() {var drag = new Draggable(dragSettings);} );
	//var container = ABC.$( 'orig-size-video-popup' );
});

window.osvb.isOpen = false;

function resizeVideoWindow( flashVars, width, height, updatePlayerHtml ) {
	var html = '';
	var obj = window.osvb;
	
	if( width == 0 || height == 0 ) {
		return false;
	}
	
	var container = ABC.$( 'orig-size-video-popup' );
	var videoContainer = ABC.$( 'osv-video' );
	var closeBtn = ABC.$( 'osv-close-btn' );
	
	var greaterProp = 1;
	
	availWidth = obj.getAvailVideoWidth( width );
	availHeight = obj.getAvailVideoHeight( height );
	
	if( width > availWidth || height > availHeight ) {
		var greaterProp = Math.min( availWidth/width, availHeight/height );
	}
	
	width = greaterProp * width;
	height = greaterProp * height;
	
	var containerWidth = width + obj.settings.borderLeft + obj.settings.borderRight;
	var containerHeight = height + obj.settings.borderTop + obj.settings.borderBottom + obj.settings.windowHeadHeight;
	
	
	ABC.css( ABC.$( 'osv-close' ), {'width': width+'px', 'height': obj.settings.windowHeadHeight+'px'} );				
	ABC.css( videoContainer, {'width': width+'px', 'height': height+'px'} );
	
	var embed = videoContainer.getElementsByTagName( 'EMBED' )[0] || null;
	html = '<embed src="/img_0/main4.swf" quality="high" \
	pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" \
	width="'+width+'" height="'+height+'" \
	flashvars="'+flashVars+'"\
	id="efplayer" allowfullscreen="true" wmode="transparent"></embed>';
	
	if( !embed ) {
		var close = function() {
			videoContainer.innerHTML = '';
			ABC.css( container, {'display': 'none'} );
			window.osvb.isOpen = false;
		}
		
		ABC.addEvent( closeBtn, 'click', close, false );
		
		videoContainer.innerHTML = html;
	} else {
		embed.width = width;
		embed.height = height;
		
		if(updatePlayerHtml) {
			videoContainer.innerHTML = html;
		}
	}				
	
	
	var top = Math.floor( (obj.settings.clientAreaSize.h - containerHeight)/2 );
	var left = Math.floor( (obj.settings.clientAreaSize.w - containerWidth)/2 );
	
	top += ABC.getBodyScrollTop();
	left += ABC.getBodyScrollLeft();
	
	ABC.css( container, {
		'width'		: containerWidth + 'px',
		'height'	: containerHeight + 'px',
		'top'		: top + 'px',
		'left'		: left + 'px',
		'display'	: 'block'
	} );
	obj.isOpen = true;
}

function showOriginalSizeVideo( flashVars, width, height ) {
	resizeVideoWindow( flashVars, width, height, true );
	
	ABC.addEvent( window, 'resize', function(){ if(window.osvb.isOpen) resizeVideoWindow( flashVars, width, height ); }, false );
}
