var MovieClipBox=Class.create();
MovieClipBox.prototype={
	initialize:function() {
		var options = Object.extend({
			border:10,
			width:250,
			height:250,
			bg:"#fff",
			border:"1px solid #006699"
		}, arguments[0] || {});
		this.options=options;
		
		this.options.swf={
			width:this.options.width,
			height:this.options.height,
			src:this.options.swf_name
		};
		//this.options.width+=this.options.border*2;
		this.options.height+=+10*2;
		
		var arrayPageScroll = document.viewport.getScrollOffsets();
		var arrayPageDimensions=document.viewport.getDimensions();
		
		this.position={
			top:Math.round(arrayPageScroll[1] + arrayPageDimensions.height/2-options.height/2),
			left:Math.round(arrayPageDimensions.width/2-options.width/2)
		};
		var objBody=$$('body')[0];
		this.box=new Element('div',{'id':'bb_container','class':'mcbox'});
		
		objBody.appendChild(this.box);
		
		this.box.setStyle({
			top:this.position.top+"px",
			left:this.position.left+"px",
			width:this.options.width+"px",
			height:this.options.height+"px",
			padding:"0",//+this.options.border+"px",
			backgroundColor:this.options.bg,
			border:this.options.border
		});
		
		var close=new Element('div',{'class':'close'}).update("<a href=\"javascript:void(0);\">chiudi X</a>&nbsp;");
		close.observe("click",function(e){
			Event.stopObserving(window,"scroll",function(e){
				this.updatePosition();
			}.bind(this),false);
			this.box.remove();
			return false;
		}.bind(this));
		this.box.appendChild(close);
		
		Event.observe(window,"scroll",function(e){
			this.updatePosition();
		}.bind(this),false);
	},
	setSWF:function() {
		
		
		swfbox=new Element('div',{'id':'bb'});
		swfbox.setStyle({
			width:this.options.swf.width+"px",
			height:this.options.swf.height+"px"
		});
		this.box.appendChild(swfbox);
		var flashvars={};
		var params={};
		var attributes={};
		swfobject.embedSWF(this.options.swf.src,"bb",this.options.swf.width,this.options.swf.height,"9.0.0",false,flashvars,params,attributes);
	},
	show:function() {
		this.setSWF();
	},
	updatePosition:function() {
		var arrayPageScroll = document.viewport.getScrollOffsets();
		var arrayPageDimensions=document.viewport.getDimensions();
		this.position={
			top:Math.round(arrayPageScroll[1] + arrayPageDimensions.height/2-this.options.height/2),
			left:Math.round(arrayPageDimensions.width/2-this.options.width/2)
		};
		if (this.sc_timer) {
			clearTimeout(this.sc_timer);
			this.sc_timer=null;
		}
		this.sc_timer=setTimeout(function() {
			new Effect.Move(this.box,{x:this.position.left,y:this.position.top,mode:'absolute',duration:0.6});
		}.bind(this) ,300);
	}
};

