var VideoBox = function() {
	function hideOverlay() {
		var o = document.getElementById('overlay');
		if (o == null) {
			return;	
		}		
		var p = o.parentNode;
		p.removeChild(o);
	}
	
	function showOverlay() {
		var o = document.createElement('div');
		o.id = 'overlay';
		document.getElementsByTagName('body')[0].appendChild(o);			
		o.display = 'block';
		var pz = PageUtil.getPageSize();
		o.style.width = pz.width + 'px';
		o.style.height = pz.height + 'px';		
		o.onclick = hide;
	}	
	
	function showBox(urlPlayer, params, w, h) {
		var top = 0;
		var left = 0;
		var o = document.createElement('div');
		o.id = "containerVideoPlayer";
		h += 20;
		var pz = PageUtil.getPageSize();
		var so = PageUtil.getScrollOffsets();
		if (pz.windowWidth > w) {
			left = Math.round((pz.windowWidth - w)/2 + so.left);
		}
		if (pz.windowHeight > h) {
			top = Math.round((pz.windowHeight - h)/2 + so.top);						
		}
		o.style.top = top + 'px';
		o.style.left = left + 'px';		
		o.style.width = w + 'px';		
		o.style.height = h + 'px';		
		o.innerHTML = '<div id="videoPlayer"></div>';
		document.getElementsByTagName('body')[0].appendChild(o);
		var a = document.createElement('a');
		a.innerHTML = 'CHIUDI';
		a.className = 'chiudi';
		a.onclick = hide;
		a.href = "javascript:void(0)";
		o.appendChild(a);
		
		setTimeout(function() {
			var sw = new SWFObject(urlPlayer,"videoPlayer", w, h-20,"9","#FFFFFF"); 
			sw.addParam("allowfullscreen","true");
			sw.addParam("allowscriptaccess","always"); 
			sw.addParam("flashvars",params); 
			sw.write("videoPlayer"); 												
		}, 50);
	}

	function hideBox() {
		var o = document.getElementById('containerVideoPlayer');
		if (o == null) {
			return;	
		}
		var p = o.parentNode;
		p.removeChild(o);
	}
	
	function hide() {
		hideOverlay();
		hideBox();
	}
	
	function show(urlPlayer, params, w, h) {
		showOverlay();
		showBox(urlPlayer, params, w, h);
	}
	
	return {
		show : function(urlPlayer, params, w, h) {
			show(urlPlayer, params, w, h);
		},
		hide : function() {
			hide();	
		}
	}
}();
