var DataServiceViewer = Class.create();
DataServiceViewer.prototype={
	initialize:function(divRapport,reflexionName,gestEvtDyn,params){
		this.extend(new GestEvt(),this);
		this.divRapport=divRapport;
		this.swfIsReady=false;
		this.inited=false;
		this.nameObj=reflexionName;

		
		this.gestEvtDyn=gestEvtDyn;
		this.params = {
			
				'width': $(this.divRapport).offsetWidth,
				'height':  $(this.divRapport).offsetHeight,
				
				'swf':"/dynmap/extensions/DataServiceViewer/DataServiceViewer.swf",
				'endPoint':'/dynmap/extensions/amfphp/gateway.php?test=1'
			}.extend(params || {});
			if(!this.params.height){
					this.params.height=200;
			}
			if(!this.params.width){
					this.params.width=740;
			}
			
		this.ajouteEvenement('SWFREADY');
		

		this.lSel=0;

		this.embedScript='<object id="'+divRapport+'flashVG" type="application/x-shockwave-flash" data="'+this.params.swf+'" width="'+this.params.width+'" Height="'+this.params.height+'">'
		+ '<param name="movie" value="'+this.params.swf+'" />'
		+ ' <param name="wmode" value="transparent" />'
		+ '<param name="flashVars" value="reflexionName='+reflexionName+'"'
		+'/>'
		+ '</object>';
	/*
		this.embedScript='<embed type="application/x-shockwave-flash"  id="'+divRapport+'flashVG" '
		+ 'src ="'+this.params.swf+'" width="'+this.params.width+'" height="'+this.params.height
		+ ' wmode="transparent" flashVars="reflexionName='+reflexionName+'" >';
		
		src="so_tester.swf" style="" id="sotester" name="sotester" bgcolor="#FF6600" quality="high" flashvars="flashVarText=this is passed in via FlashVars for example only" width="300" height="300"></div>
*/

		Element.addClassName(divRapport,'cacheFlashLittle');
		

	},
	bindDS:function(obR){
		obR.ajouteEcouteur('DS_DELETE',this.dsdel,this);
		obR.ajouteEcouteur('DS_MODIFIED',this.dsmod,this);
	},
	dsdel:function(idR){

		Element.addClassName(this.divRapport,'cacheFlashLittle');
		Element.addClassName(this.divRapport+'flashVG','cacheFlashLittle');
		if(this.lSel){
			this.lSel=0;
			this.gestEvtDyn.enleveEcouteur('SELECTION_MODIFIED',this._updateSel,this);
			this.gestEvtDyn.enleveEcouteur('SELECTION_RESET',this._delSl,this);
		}
	},
	dsmod:function(idRapport,p){
	
		this.viewRapport(idRapport,path_application,p);
	},
	initializeFla:function(){
		this.inited=true;
	//	alert('initializeFla');
		$(this.divRapport).innerHTML=this.embedScript;
	//	Element.addClassName(divRapport+'flashVG','cacheFlash');
		Element.addClassName(this.divRapport+'flashVG','cacheFlashLittle');

	},
	onRapportEnabled:function(nomVue){
		if(nomVue==this.nameObj){
			this.swfIsReady=true;
			this.fla=$(this.divRapport+'flashVG');
			this.lanceEvenement('SW_I_FREADY');
		
		}
		
		
	},
	
	viewRapport:function(idRapport,path_application,options){
		this.pRap=arguments;
		this.ajouteEcouteur('SW_I_FREADY',this._viewRapport,this);
	
		if(this.lSel){
	
			this.lSel=0;
			this.gestEvtDyn.enleveEcouteur('SELECTION_MODIFIED',this._updateSel,this);
			this.gestEvtDyn.enleveEcouteur('SELECTION_RESET',this._delSl,this);
		}
		Element.removeClassName(this.divRapport,'cacheFlashLittle');
		Element.removeClassName(this.divRapport+'flashVG','cacheFlashLittle');
		//alert('toto');
		if(!this.swfIsReady&&!this.inited){
		

			this.initializeFla();
		}
		if(this.swfIsReady){
			this._viewRapport();
		}
	},
	_updateSel:function(sel){
		if(sel[this.lSel]){
			var options={"page":0,'ref':true};
			this.fla.lauchCommand('UpdateDS',options);
		}
	},
	_delSl:function(){
		var options={"page":0};
		this.fla.lauchCommand('UpdateDS',options);
	},
	_viewRapport:function(){
		if(Element.hasClassName(this.divRapport+'flashVG','cacheFlashLittle')){
			Element.removeClassName(this.divRapport+'flashVG','cacheFlashLittle');
		}
		this.enleveEcouteur('SW_I_FREADY',this._viewRapport,this);
		var opt=this.pRap[2] ;
		var options={
			'path_application':this.pRap[1],
			'idRapport':this.pRap[0],
			'endPoint':this.params.endPoint
			
		}.extend(	opt || {});
		if(opt['selection_listen']){
			
				this.lSel=opt['selection_listen'];
				this.gestEvtDyn.ajouteEcouteur('SELECTION_MODIFIED',this._updateSel,this);
				this.gestEvtDyn.ajouteEcouteur('SELECTION_RESET',this._delSl,this);
			
		}
		this.fla.lauchCommand('ViewRapport',options);
	}
};


var DataConteneurCss= Class.create();
DataConteneurCss.prototype={
	initialize:function(divRapport,csd,csv){
	
		this.divRapport=divRapport;
		this.csd=csd;
		this.csv=csv;
	},
	bindDS:function(obR){
		obR.ajouteEcouteur('DS_DELETE',this.dsdel,this);
		obR.ajouteEcouteur('DS_MODIFIED',this.dsmod,this);
	},
	dsdel:function(idR){
	
		Element.addClassName(this.divRapport,this.csd);
		Element.removeClassName(this.divRapport,this.csv);
	},
	dsmod:function(idRapport,p){

		Element.removeClassName(this.divRapport,this.csd);
		Element.addClassName(this.divRapport,this.csv);
	}
}