// Instantie un objet flash

function CartoWEB (divid,swffilename,relpath,vname){
	this.divid = divid;
	this.swffilename = swffilename ;
	this.width = 500;
	this.height = 500;
	this.couches = new Array();
	this.reliconpath = relpath;
	this.vname = vname;
	this.zonex1 = 0;
	this.zonex2 = 0;
	this.zoney1 = 0;
	this.zoney2 = 0;
	this.textrepos = 'Repositionne le plan';
	this.textzoomplus = 'Zoom avant';
	this.textzoommoins = 'Zoom arriere';
	this.bgcolor='#C8C8C8';
	this.bordercolor='#999';
	this.isIE=false;
	this.isNS=false;
	this.isOP=false;
	
	this.drawembed = function(){
		var embed = document.createElement('embed');
  		embed.setAttribute('width',this.width);
  		embed.setAttribute('height',this.height);
  		embed.setAttribute('type','application/x-shockwave-flash');
  		embed.setAttribute('src',this.swffilename);
		embed.setAttribute('class','swfobj');
  		this.flash = embed;
	}
	
	this.drawmenu = function(){
		var menudiv = document.createElement('div');
		menudiv.setAttribute('class', 'menuicons');
		var a1 = document.createElement('a');
		var a2 = document.createElement('a');
		var a3 = document.createElement('a');
		var img1 = document.createElement("img");
   		img1.src = this.reliconpath + "alpha_button_fullExtent.gif";
		img1.alt = this.textrepos;
		img1.title = this.textrepos;
		a1.appendChild(img1);
		a1.setAttribute('class', 'repositionne');
		a1.setAttribute('href', 'javascript:'+this.vname+'.Repositionne()');
		menudiv.appendChild(a1);
		var img2 = document.createElement("img");
   		img2.src = this.reliconpath + "alpha_button_zoomIn.gif";
		img2.alt = this.textzoomplus;
		img2.title = this.textzoomplus;
		a2.appendChild(img2);
		a2.setAttribute('class', 'zoomin');
		a2.setAttribute('href', 'javascript:'+this.vname+'.ZoomIn()');
		menudiv.appendChild(a2);
		var img3 = document.createElement("img");
   		img3.src = this.reliconpath + "alpha_button_zoomOut.gif";
		img3.alt = this.textzoommoins;
		img3.title = this.textzoommoins;
		a3.appendChild(img3);
		a3.setAttribute('class', 'zoomout');
		a3.setAttribute('href', 'javascript:'+this.vname+'.ZoomOut()');
		menudiv.appendChild(a3);
  		this.menu = menudiv;
	}
	
	this.draw = function (){
		this.TypeBrowser();
		this.drawembed();
		if ( this.isNS  || this.isOP) {
			this.drawmenu();
		} 
		if ( this.isIE ) {
			this.drawmenu();
		} 
		
		var globaldiv = document.createElement('div');
		globaldiv.setAttribute('class', 'plan');
		globaldiv.setAttribute('style','background-color: '+this.bgcolor+'; border: 1px solid '+this.bordercolor+'; width: 500px; height: '+(this.height+42)+'px;');
		globaldiv.appendChild(this.flash);
		globaldiv.appendChild(this.menu);
		
		
		var divid=document.getElementById(this.divid);
		document.getElementById(this.divid).parentNode.replaceChild(globaldiv,divid);
	}
	
	// Bascule une couche en visible / non visible
	this.basculeCouche = function (couche){
		var val = 0;
		if (this.flash.TGetProperty('/' + couche,7) == 'true') {
			val = 1;
		};
		this.flash.TSetProperty('/' + couche,7,1-val);
	}
	
		// Rend une couche Visible
	this.CoucheVisible = function (couche){
		this.flash.TSetProperty('/' + couche,7,1);
	}

		// Rend une couche InVisible
	this.CoucheInvisible = function (couche){
		this.flash.TSetProperty('/' + couche,7,0);
	}
	
		// Interroge si une couche est visible ?
	this.isVisibleLayer = function(layer){
		var val = this.flash.TGetProperty('/' + layer,7);
		alert(val);
		return false;
	}
	
		// Zoom in
	this.ZoomIn = function (){
		this.flash.Zoom(50);
	}
	
	// Zoom out
	this.ZoomOut = function (){
		this.flash.Zoom(200);
	}

	// Zoom out
	this.Zoom = function (vl){
		this.flash.Zoom(vl);
	}
	
	// Affiche une zone
	this.AfficheZone = function (x1,y1,x2,y2){
		this.flash.SetZoomRect(x1*20,y1*20,x2*20,y2*20);
	}
	
	// Affiche une zone initiale
	this.AfficheInitZone = function (x1,y1,x2,y2){
		this.zonex1=x1;
		this.zoney1=y1;
		this.zonex2=x2;
		this.zoney2=y2;
		this.AfficheZone(x1,y1,x2,y2);
	}
	
	// Affiche une zone initiale
	this.Repositionne = function (){
		this.AfficheZone(this.zonex1,this.zoney1,this.zonex2,this.zoney2);
	}
	
	// Met en valeur une zone
	this.EntoureZone = function (x1,y1,r1) {
		// Visible
		this.flash.TSetProperty('/pos',7,1);
		// Pos X
		this.flash.TSetProperty('/pos',0,x1);
		// Pox Y
		this.flash.TSetProperty('/pos',1,y1);
		// Pox ALPHA
		this.flash.TSetProperty('/pos',6,50);
		// Largeur
		this.flash.TSetProperty('/pos',8,r1*2);
		// Hauteur
		this.flash.TSetProperty('/pos',9,r1*2);
	}

	// Determine le navigateur
	this.TypeBrowser = function(){
		if ( (navigator.userAgent).indexOf("Opera")!=-1){
			this.isOP=true;
		} else if (navigator.appName=="Netscape") {
			this.isNS=true;
		} else if ((navigator.appName).indexOf("Microsoft")!=-1) {
			this.isIE=true;
		}
		return;
	}
}

