//	jQuery lightbox plugin for videos created by HPU Internet services
(function($) {
	$.fn.videoBox = function(options) {
	    var config = $.extend({
	        video: '',
	        id: '',
	        effect: 'default',
	        background: '#000000',
	        opacity: '0.8',
	        loadSpeed: '400',
	        wmode: 'opaque',
	        fullscreen: 'true',
	        folder: '../movies/',
	        top: 'center',
	        left: 'center',
	        height: '1024px',
	        width: '768px'
	    }, options);
	    
	    var videobox = $('#videooverlay');
	    
		if (!videobox.length) {
			videobox = $('<div id="videooverlay"><div id="videocontainer"></div>')
						.appendTo(document.body)
						.hide()
						.slideUp(0); 
		}		
		var item = $('#'+config.id);
		item.overlay({
			api: true,
			oneInstance: false,
			expose : { 
				color : config.background,
				loadSpeed : config.loadspeed,
				opacity : config.opacity
			},
			top: config.top,
			left: config.left,
			target: '#videooverlay',
			speed: config.loadspeed,
			effect: config.effect,
			onStart: function() {
			},
			onBeforeLoad: function() {
				$(videobox).height(config.height);
				$(videobox).width(config.width);				
				var swfDiv = $('#video_overlay');
				if (!swfDiv.length) {
					swfDiv = $('<div id="video_overlay"></div>');
					$('#videocontainer').append(swfDiv);
				}
				var params = {
					wmode: config.wmode,
					allowScriptAcces: 'always',
					width: '100%',
					height: '100%',
					allowFullScreen: config.fullscreen
				};
				var flashvars = {
					file: config.folder+config.video,
					autostart: 'true',
					skin: 'scripts/modieus.swf',
					controlbar: 'bottom',
					displayclick: 'fullscreen',
					fullscreen: true
				};
				var attributes = false;
				try {
					swfobject.embedSWF(
								'scripts/player.swf?url='+config.folder+config.video,
								"video_overlay",
								config.width,
								config.height,
								"9.0.0",
								false,
								flashvars,
								params,
								attributes
					);
				} catch (e) {
					console.log(e);
				}					
			},
			onClose: function() {
				swfobject.removeSWF("video_overlay");
			}
		});
	};
})(jQuery);
