/**
 * @function openVideoUrl
 */
(function ( undefined ) {

Publicis.onDomReady( function() {

	if( EnergyApps.App.Video === undefined ) {
		window.openVideoUrl = function () {};
		return;
	}

	/**
	 * @param {String} url
	 * @param {Object} config PlainObject
	 * @param {Boolean} isRelativePath [optional] default : false
	 * @see Publicis.getAbsolutePath
	 * @returns {EnergyApps.Video.Layer} | false
	 */
	window.openVideoUrl = function( url, config, isRelativePath ) {

		if( !url ) {
			return;
		}

		if( ! config ) {
			config = {};
		}

		if( !! isRelativePath ) {
			url = Publicis.getAbsolutePath( url );
		}

		var videoEl = new Element( "video", {
				title : config.title !== undefined ? config.title : "",
				width : config.width !== undefined ? config.width : 980,
				height : config.height !== undefined ? config.height : 552,
				thumbnail : config.thumbnail !== undefined ? config.thumbnail : "",
				poster : config.poster !== undefined ? config.poster : "",
				autostart : typeof config.autostart === "boolean" ? config.autostart.toString() : "true"
			} ),
			layer;

		videoEl.update( new Element( "source", {
			src : url
		}) );

		$( document.body ).insert({
			bottom: videoEl
		});

		layer = EnergyApps.App.Video.bindVideo( videoEl, false );
		layer.open();
		if( Prototype.Browser.Gecko ) {
			window.setTimeout( function () {
				layer.videoContainer.up().setStyle({ display : 'block'});
				layer.videoContainer.up().next().setStyle({ display : 'block'});
			}.bind( this ), 0 );
		}
	}
} );

})();

