var Panorama = new Class({
	Implements: [Options, Events],
	offsetPanorama:false,
	drag:false,
	dragPosX:0,
	dragPosY:0,
	timerPlay:-1,
	playing:false,
  deltaX:0,
  deltaY:0,
	hotspots:[],
	bshowHotspots:false,
	current:false,
	options: {
		urlbase:"http://www.neos360.com/saetde/collblanc360/",
		elPanoramacontainer:"neospanocontainer",
		elPanorama:"neospano",
		elLoader:"neoloader",
		widthMax:5305,
		heightMax:400,
		delay:40,
		step:2,
		longdelay:5000,
		widthAuto:800,
		liveOnAir:false,
		lightversion:0
	},

	initialize: function(options){
		this.setOptions(options);
		var currentThis = this;
		if(this.options.widthAuto.trim() == "auto"){

			$(currentThis.options.elPanorama).setStyle("width",window.getWidth().toInt()-($(currentThis.options.elPanoramacontainer).getStyle("margin-left").toInt()*2));
			$(currentThis.options.elPanoramacontainer).setStyle("width",window.getWidth().toInt()-($(currentThis.options.elPanoramacontainer).getStyle("margin-left").toInt()*2));
			$(currentThis.options.elLoader).setStyle("left",$(currentThis.options.elPanorama).getWidth().toInt()/2 - $(currentThis.options.elLoader).getStyle('width').toInt()/2);
       			 $(currentThis.options.elLoader).setStyle("top",$(currentThis.options.elPanorama).getHeight().toInt()/2 - $(currentThis.options.elLoader).getHeight().toInt()/2);

		}
		var timer = -1;
		window.addEvent('resize', function(){
		  $clear(timer);
		  timer = (function(){
			  if(currentThis.options.widthAuto.trim() == "auto"){

					$(currentThis.options.elPanorama).setStyle("width",window.getWidth().toInt()-($(currentThis.options.elPanoramacontainer).getStyle("margin-left").toInt()*2));
					$(currentThis.options.elPanoramacontainer).setStyle("width",window.getWidth().toInt()-($(currentThis.options.elPanoramacontainer).getStyle("margin-left").toInt()*2));


				}
				$('hotspot_display_layer').setStyle("height",window.getScrollHeight().toInt());
				if((window.getHeight().toInt()-60)<$('table_hotspot').getHeight().toInt()){
					$("hotspot_display_container").setStyle("height",window.getHeight().toInt()-60);
				}
				else{
					$("hotspot_display_container").setStyle("height",$('table_hotspot').getHeight().toInt());
				}
				$('hotspot_display_container').setStyle('left',(window.getWidth().toInt() - $('hotspot_display_container').getStyle("width").toInt())/2);
				$('hotspot_display_container').setStyle('top',(window.getHeight().toInt() - $('hotspot_display_container').getStyle("height").toInt())/2);
				//$("hotspot_display").setStyle("height",$('table_hotspot').getHeight().toInt());
				$("hotspot_display").setStyle("height",$("hotspot_display_container").getHeight().toInt() -  $('hotspot_display_container').getStyle("padding-top").toInt()*2);


				$(currentThis.options.elLoader).setStyle("left",$(currentThis.options.elPanorama).getWidth().toInt()/2 - $(currentThis.options.elLoader).getWidth().toInt()/2);
        $(currentThis.options.elLoader).setStyle("top",$(currentThis.options.elPanorama).getHeight().toInt()/2 - $(currentThis.options.elLoader).getHeight().toInt()/2);

		  }).delay(50);
		});
		/*window.addEvent('onresize',function(){
			if(currentThis.options.widthAuto.trim() == "auto"){
				$(currentThis.options.elPanorama).setStyle("width",window.getWidth().toInt());
				$(currentThis.options.elPanoramacontainer).setStyle("width",window.getWidth().toInt());
			}
		})*/
		$(this.options.elPanorama).addEvent('mousedown',function(_e){
			currentThis.drag = true;
			currentThis.pausePanorama();

			var ev = new Event(_e);
			if(ev.preventDefault)
       {
        ev.preventDefault();
       }
			$(currentThis.options.elPanorama).focus();

			currentThis.dragPosX = ev.page.x - $(currentThis.options.elPanorama).getLeft();
			//currentThis.dragPosY = ev.page.y - $(currentThis.options.elPanorama).getTop();

		});
		$(this.options.elPanorama).addEvent('mouseup',function(_e){
			if(currentThis.drag){
			  if((currentThis.deltaX>10) || (currentThis.deltaX<-10)){
			     currentThis.positionPanorama(currentThis.deltaX,true);
			     currentThis.deltaX = 0;
        }
        currentThis.unpausePanorama(currentThis.options.longdelay);
      }
      currentThis.drag = false;


		});
		$(this.options.elPanorama).addEvent('mouseleave',function(_e){
			if(currentThis.drag){
        currentThis.unpausePanorama(currentThis.options.longdelay);
      }
      currentThis.drag = false;



		});
		$(this.options.elPanorama).addEvent('mousemove',function(_e){
			if(currentThis.drag){

				var ev = new Event(_e);
				if(ev.preventDefault)
       {
        ev.preventDefault();
       }
				var posX = ev.page.x - $(currentThis.options.elPanorama).getLeft();
				//var posY = ev.page.y - $(currentThis.options.elPanorama).getTop();
				/*if((posX<0) || (posY<0) || (posX>$(currentThis.options.elPanorama).getWidth().toInt()) || (posY>$(currentThis.options.elPanorama).getHeight().toInt())){
					currentThis.drag = false;
					return;
				}*/
				currentThis.deltaX = currentThis.dragPosX - posX;
				//currentThis.deltaY = currentThis.dragPosY - posY;
				currentThis.dragPosX = posX;
				//currentThis.dragPosY = posY;
				currentThis.positionPanorama(currentThis.deltaX);

				//$('panorama_debug').innerHTML="x:"+ev.client.x;
				//$('panorama_debug').innerHTML="x:"+ev.page.x;
				$('panorama_debug').innerHTML="x:"+currentThis.deltaX;
				//$('panorama_debug').innerHTML+="<br>y:"+currentThis.posY;
			}

		});

		$('hotspot_display_layer').setStyle("height",window.getScrollHeight().toInt());
    $('hotspot_display_layer').setStyle("opacity",0.7);
		$('hotspot_display_layer').addEvent('click',function(){
			currentThis.hideLayer();

		});
		$('hotspot_display_close').addEvent('click',function(){
			$('hotspot_display_layer').setStyle("display","none");
			$('hotspot_display_container').setStyle("display","none");
			currentThis.unpausePanorama(0);

		});

		$('histo_display_close').addEvent('click',function(){
			$('hotspot_display_layer').setStyle("display","none");
			$('histo_display_container').setStyle("display","none");
			currentThis.unpausePanorama(0);

		});



	},
	showLoading:function(_text){
		$(this.options.elLoader).addClass("ajaxLoading");
		$(this.options.elLoader).setStyle("left",$(this.options.elPanorama).getWidth().toInt()/2 - $(this.options.elLoader).getStyle('width').toInt()/2);
  		$(this.options.elLoader).setStyle("top",$(this.options.elPanorama).getHeight().toInt()/2 - $(this.options.elLoader).getHeight().toInt()/2);

		$$(".defaultLoading label")[0].innerHTML = _text;
	},
	hideLoading:function(){
		$(this.options.elLoader).removeClass("ajaxLoading");
	},
	setPanorama:function (_path,_pathlowdef,_textloading){
	  if(this.current == _path)
	   return;
//	  this.current = _path;
		var currentThis = this;
		if(_pathlowdef){
			currentThis.current = _pathlowdef;
			//alert(currentThis.options.urlbase+currentThis.current);
			var myurl3 = currentThis.current;
			if(myurl3.indexOf("http://")==-1)
				myurl3 = currentThis.options.urlbase+currentThis.current;

			var myImage = Asset.image(myurl3, {
			    onLoad: function(){
					$(currentThis.options.elPanorama).setStyle('background',"url("+currentThis.current+") repeat-x");
					currentThis.current = _path;

					currentThis.showLoading(_textloading);
					var myurl2 = currentThis.current;
					if(myurl2.indexOf("http://")==-1)
						myurl2 = currentThis.options.urlbase+currentThis.current;
	  				var myImage2 = Asset.image(myurl2, {
					    onLoad: function(){
			  				$(currentThis.options.elPanorama).setStyle('background','url('+myurl2+") repeat-x");
			  				var myurl = (_path).split("/");
			  				myurl = myurl.erase("nojava");
			  				myurl = myurl.erase("historique");
			  				myurl[myurl.length-1] = "info.txt";
			  				myurl = myurl.join("/");

			  				new Request({
			  				  url:myurl,
			  				  onSuccess:function(_response){
			  				   $('info').innerHTML = _response;
			  				  }
			  				}).send();

							myurl = myurl.replace("info.txt","meteo.txt");

			  				new Request({
			  				  url:myurl,
			  				  onSuccess:function(_response){
			  				   $('meteo').innerHTML = _response;
			  				  }
			  				}).send();
			  				currentThis.hideLoading();
			  				//currentThis.playPanorama();
			  			}
					});
	  				//currentThis.playPanorama();
	  			}
			});
		}
		else{
		currentThis.showLoading(_textloading);
		currentThis.current = _path;
		var myurl2 = currentThis.current;
		if(myurl2.indexOf("http://")==-1)
			myurl2 = currentThis.options.urlbase+currentThis.current;

		var myImage = Asset.image(myurl2, {
		    onLoad: function(){

  				$(currentThis.options.elPanorama).setStyle('background','url('+myurl2+") repeat-x");
  				var myurl = (_path).split("/");
  				myurl = myurl.erase("nojava");
  				myurl = myurl.erase("historique");
  				myurl[myurl.length-1] = "info.txt";
  				myurl = myurl.join("/");

  				new Request({
  				  url:myurl,
  				  onSuccess:function(_response){
  				   $('info').innerHTML = _response;
  				  }
  				}).send();

				myurl = myurl.replace("info.txt","meteo.txt");

  				new Request({
  				  url:myurl,
  				  onSuccess:function(_response){
  				   $('meteo').innerHTML = _response;
  				  }
  				}).send();
  				currentThis.hideLoading();
  				//currentThis.playPanorama();
  			}
		});
}
	},
	playPanorama:function (){
		this.playing = true;
		if(!this.options.lightversion){
			$('btn_play').removeClass('btn_play');
			$('btn_play').removeClass('btn_play3');
			$('btn_play').addClass('btn_play2');
			$('btn_play').setAttribute("alt","Arrêter le défilement du panorama");
			$('btn_play').setAttribute("title","Arrêter le défilement du panorama");
		}
		this.positionPanorama(this.options.step);
		this.timerPlay = this.playPanorama.delay(this.options.delay,this);
	},
	getRealPositionHotSpot:function(){

	},
	positionPanorama:function (_delta,_effect){
		var currentThis = this;
		this.offsetPanorama = this.offsetPanorama % this.options.widthMax;
		if(_effect){
		  _delta = _delta * 5;
		  if(currentThis.bshowHotspots){
	        $$(".hotspot").each(function(_el){
	          _el.setStyle("display","none");
	        });
	      }
		  var myFx = new Fx.Tween($(currentThis.options.elPanorama),{
		    duration:500,
		    transition:"quad:out",
		    onComplete:function(){
		      currentThis.offsetPanorama = currentThis.offsetPanorama - _delta;
		      if(currentThis.bshowHotspots){
	            $$(".hotspot").each(function(_el){
	            	if(_delta>0){
	  					$("debug_pano").innerHTML="1";
	  					if((((_el.getAttribute("hotspot_x").toInt()+currentThis.offsetPanorama))>0)&&((_el.getAttribute("hotspot_x").toInt()+currentThis.offsetPanorama)<$(currentThis.options.elPanoramacontainer).getStyle("width").toInt())){
	  						//$("debug_pano").innerHTML+=" 1";
	  						_el.setStyle("left",_el.getAttribute("hotspot_x").toInt()+currentThis.offsetPanorama);
	  					}
	  					else{
	  						//$("debug_pano").innerHTML+=" 2";
	  						_el.setStyle("left",_el.getAttribute("hotspot_x").toInt()+currentThis.offsetPanorama+currentThis.options.widthMax);
	  					}
	  				}
	  				else{
	  					//$("debug_pano").innerHTML="2";
	  					if((((_el.getAttribute("hotspot_x").toInt()+currentThis.offsetPanorama))>0)&&((_el.getAttribute("hotspot_x").toInt()+currentThis.offsetPanorama)<$(currentThis.options.elPanoramacontainer).getStyle("width").toInt())){
	  						//$("debug_pano").innerHTML+=" 1";
	  						_el.setStyle("left",_el.getAttribute("hotspot_x").toInt()+currentThis.offsetPanorama);
	  					}
	  					else{
	  						//$("debug_pano").innerHTML+=" 2";
	  						_el.setStyle("left",_el.getAttribute("hotspot_x").toInt()+currentThis.offsetPanorama-currentThis.options.widthMax);
	  					}
	  				}
	            	//_el.setStyle("left",_el.getAttribute("hotspot_x").toInt()+currentThis.offsetPanorama);
	              _el.setStyle("display","block");
	            });
          }
		    }
		  });
      // sets the background color of the element to red:
      myFx.start('background-position', currentThis.offsetPanorama+'px 0px', (currentThis.offsetPanorama-_delta)+'px 0px');
		}
		else{
	  		this.offsetPanorama = this.offsetPanorama - _delta;
	  		if(this.bshowHotspots){
	  			$$(".hotspot").each(function(_el){
	  				//if((Math.abs(currentThis.offsetPanorama)+$(currentThis.options.elPanoramacontainer).getStyle("width").toInt())>currentThis.options.widthMax){
	  				if(_delta>0){
	  					//$("debug_pano").innerHTML="3";
	  					if((((_el.getAttribute("hotspot_x").toInt()+currentThis.offsetPanorama))>0)&&((_el.getAttribute("hotspot_x").toInt()+currentThis.offsetPanorama)<$(currentThis.options.elPanoramacontainer).getStyle("width").toInt())){
	  						//$("debug_pano").innerHTML+=" 1";
	  						_el.setStyle("left",_el.getAttribute("hotspot_x").toInt()+currentThis.offsetPanorama);
	  					}
	  					else{
	  						//$("debug_pano").innerHTML+=" 2";
	  						_el.setStyle("left",_el.getAttribute("hotspot_x").toInt()+currentThis.offsetPanorama+currentThis.options.widthMax);
	  					}
	  				}
	  				else{
	  					//$("debug_pano").innerHTML="4";
	  					if((((_el.getAttribute("hotspot_x").toInt()+currentThis.offsetPanorama))>0)&&((_el.getAttribute("hotspot_x").toInt()+currentThis.offsetPanorama)<$(currentThis.options.elPanoramacontainer).getStyle("width").toInt())){
	  						//$("debug_pano").innerHTML+=" 1";
	  						_el.setStyle("left",_el.getAttribute("hotspot_x").toInt()+currentThis.offsetPanorama);
	  					}
	  					else{
	  						//$("debug_pano").innerHTML+=" 2";
	  						_el.setStyle("left",_el.getAttribute("hotspot_x").toInt()+currentThis.offsetPanorama-currentThis.options.widthMax);
	  					}
	  				}

	  			});
	  		}
	  		$(currentThis.options.elPanorama).setStyle('background-position',currentThis.offsetPanorama+'px 0px');
		}

	},
	stopPanorama:function (){
		this.playing = false;
		if(!this.options.lightversion){
		$('btn_play').removeClass('btn_play2');
		$('btn_play').removeClass('btn_play3');
   		 $('btn_play').addClass('btn_play');
		$('btn_play').setAttribute("alt","Faire défiler le panorama");
		$('btn_play').setAttribute("title","Faire défiler le panorama");
		}

    clearTimeout(this.timerPlay);
	},
	pausePanorama:function (){
	  if(this.playing){
	  	if(!this.options.lightversion){
	  $('btn_play').removeClass('btn_play');
	    $('btn_play').removeClass('btn_play2');
	    $('btn_play').addClass('btn_play3');
		$('btn_play').setAttribute("alt","Faire défiler le panorama");
		$('btn_play').setAttribute("title","Faire défiler le panorama");
		}

    }
		clearTimeout(this.timerPlay);
	},
	unpausePanorama:function (_delay){
		if(this.playing){
			this.timerPlay = this.playPanorama.delay(_delay,this);
			if(!this.options.lightversion){
			$('btn_play').removeClass('btn_play3');
		      $('btn_play').removeClass('btn_play');
		      $('btn_play').addClass('btn_play2');
		     }

		}
	},
	togglePanorama:function (){
		if(!this.playing)
			this.playPanorama();
		else
			this.stopPanorama();

	},
	showOnAir:function (_path,_width,_height,_delay,_delayms,_status){
		var currentThis = this;
			currentThis.pausePanorama();

			/*if($('live_display').getElement("iframe"))
			$('live_display').getElement("iframe").destroy();*/
			var iframe = new Element("iframe",{
				src:currentThis.options.urlbase+"index.php?view=live&width="+_width+"&height="+_height+"&delay="+_delay+"&delayms="+_delayms+"&status="+_status+"&path="+_path,
				width:(_width.toInt()+15)+"px",
				height:(_height.toInt()+60)+"px",
				frameborder:0,
				id:'framelive',
				bgcolor:'#000',
				scrolling:"no"
			});
			iframe.setStyle("background",'#000');
			// = "";
			$('live_display').innerHTML = "";
			iframe.injectInside($('live_display'));
			$('hotspot_display_layer').setStyle('display','block');
			$('live_display_container').setStyle('visibility','hidden');
			$('live_display_container').setStyle('display','block');
			//$("histo_display_container").setStyle("height",window.getHeight().toInt()-100);
			//$('histo_display_container').setStyle('left',(window.getWidth().toInt() - $('histo_display_container').getStyle("width").toInt())/2);
			//$('histo_display_container').setStyle('top',(window.getHeight().toInt() - $('histo_display_container').getStyle("height").toInt())/2);
			//$("histo_display").setStyle("height",$("histo_display_container").getStyle('height').toInt()-$("histo_display_container").getStyle("padding").toInt()*2);

			//$("histo_display_container").setStyle("height",$('table_histo').getHeight().toInt());
			$("live_display_container").setStyle("height",_height.toInt()+60);
			$("live_display_container").setStyle("width",_width.toInt()+15);
			$('live_display_container').setStyle('left',(window.getWidth().toInt() - $('live_display_container').getStyle("width").toInt())/2);
			$('live_display_container').setStyle('top',(window.getHeight().toInt() - $('live_display_container').getStyle("height").toInt())/2);
			//$("histo_display").setStyle("height",$('table_histo').getHeight().toInt());
			$("live_display").setStyle("height",$("histo_display_container").getStyle('height').toInt());
			$('live_display_container').setStyle('visibility','visible');

	},
	showHotspots:function (_forceShow,_forceHide){
		var currentThis = this;
		this.bshowHotspots = !this.bshowHotspots;
		if(_forceShow){
		  this.bshowHotspots = true;
		}
		if(_forceHide){
			this.bshowHotspots = false;
		}
		if(this.bshowHotspots){
		  this.setPanorama("img/panojavascript/nojava/pano_PV.jpg","img/panojavascript/nojava/pano_PV_lowdef.jpg","Chargement en cours de l’image HD...");

		  $('btn_hotspots').removeClass('btn_hotspots1');
		  $('btn_hotspots').addClass('btn_hotspots2');
		  this.positionPanorama(0);
		}
		else{
		  $('btn_hotspots').removeClass('btn_hotspots2');
		  $('btn_hotspots').addClass('btn_hotspots1');
		}
		$$(".hotspot").each(function(_el){
			if(currentThis.bshowHotspots)
				_el.setStyle("display","block");
			else
				_el.setStyle("display","none");
		});

	},
	setHotspots:function (){
		var currentThis = this;
		new Request.JSON({
			url:'config/hotspots.php',
			onSuccess:function(_jsonobj){

				if(_jsonobj && _jsonobj.hotspots && (_jsonobj.hotspots.length>0)){
					for ( var index = 0; index < _jsonobj.hotspots.length; index++) {

						var hot = new Element("a",{
							id:"hostpost"+index,
							hotspot_name:_jsonobj.hotspots[index].hotspot_name,
							title:decodeXml(_jsonobj.hotspots[index].hotspot_name),
							alt:decodeXml(_jsonobj.hotspots[index].hotspot_name),

							hotspot_img:_jsonobj.hotspots[index].hotspot_img,
							hotspot_img_pointer:_jsonobj.hotspots[index].hotspot_img_pointer,
							hotspot_categorie:_jsonobj.hotspots[index].hotspot_categorie,
							hotspot_description:_jsonobj.hotspots[index].hotspot_description,
							hotspot_url:_jsonobj.hotspots[index].hotspot_url,
							hotspot_x:_jsonobj.hotspots[index].hotspot_x.toInt(),
							hotspot_y:_jsonobj.hotspots[index].hotspot_y.toInt()
						});
						hot.addClass("hotspot");


						hot.addClass("tiphot");
						hot.setStyles({
							left:_jsonobj.hotspots[index].hotspot_x.toInt(),
							top:_jsonobj.hotspots[index].hotspot_y.toInt()
						});
					//	hot.store('tip:title',"<label>"+_jsonobj.hotspots[index].hotspot_name+"<label>");
					//	hot.store('tip:text', _jsonobj.hotspots[index].hotspot_description);


						hot.injectInside($(currentThis.options.elPanoramacontainer));
						hot.addEvent('click',function(){
							currentThis.showHotspot(this);
						})
						 // $('hostpost'+index).setStyle("opacity",30);

					}

				}
				else{
					$('btn_hotspots').setStyle('display','none');
					if(currentThis.options.liveOnAir){
						$('panorama_navigation_container').setStyle('width',210);
					}
					else{
						$('panorama_navigation_container').setStyle('width',160);
					}
				}
				//currentThis.myTips = new Tips('.tiphot');
			},
			onFailure:function(){
				$('btn_hotspots').setStyle('display','none');
				if(currentThis.options.liveOnAir){
					$('panorama_navigation_container').setStyle('width',210);
				}
				else{
					$('panorama_navigation_container').setStyle('width',160);
				}
			}
		}).send();
	},
	showHotspot:function(hot){
		this.pausePanorama();
		$('hotspot_display_name').innerHTML = hot.getAttribute('hotspot_name').tidy();
		$('hotspot_display_desc').innerHTML = hot.getAttribute('hotspot_description').tidy();
		//$('hotspot_display_categorie').innerHTML = hot.getAttribute('hotspot_categorie');
		$('hotspot_display_site').href = hot.getAttribute('hotspot_url');

		$('hotspot_display_img').src = hot.getAttribute('hotspot_img');
		$('hotspot_display_container').setStyle('left',(window.getWidth().toInt() - $('hotspot_display_container').getStyle("width").toInt())/2);
		$('hotspot_display_container').setStyle('top',(window.getHeight().toInt() - $('hotspot_display_container').getStyle("height").toInt())/2);
		$('hotspot_display_layer').setStyle('display','block');
		$('hotspot_display_container').setStyle('visibility','hidden');
		$('hotspot_display_container').setStyle('display','block');

		var myImage = Asset.image(hot.getAttribute('hotspot_img'), {
		    onLoad: function(){
				if((window.getHeight().toInt()-60)<$('table_hotspot').getHeight().toInt()){
					$("hotspot_display_container").setStyle("height",window.getHeight().toInt()-60);
				}
				else{
					$("hotspot_display_container").setStyle("height",$('table_hotspot').getHeight().toInt());
				}
				$('hotspot_display_container').setStyle('left',(window.getWidth().toInt() - $('hotspot_display_container').getStyle("width").toInt())/2);
				$('hotspot_display_container').setStyle('top',(window.getHeight().toInt() - $('hotspot_display_container').getStyle("height").toInt())/2);
				$("hotspot_display").setStyle("height",$("hotspot_display_container").getHeight().toInt() -  $('hotspot_display_container').getStyle("padding-top").toInt()*2);
				$('hotspot_display_container').setStyle('visibility','visible');
				//$("hotspot_display").setStyle("height",$("histo_display_container").getStyle('height').toInt());
			}
		});
		//alert($("hotspot_display_container").getStyle('height').toInt()+" "+$("hotspot_display_container").getStyle("padding").toInt()*2);

	},
	setHisto:function(_jsonobj,_date){
		var currentThis = this;
		$('histo').innerHTML = "";

		if(_jsonobj && _jsonobj.histo && (_jsonobj.histo.length>0)){

			currentThis.pausePanorama();
			var table = new Element ("table",{
					"id":"table_histo"
			});
			table.addClass('table_histo');
			for ( var index = 0; index < _jsonobj.histo.length; index++) {
					var pano = _jsonobj.histo[index];
					var tr = new Element ("tr");
					var td = new Element ("td");

					/*var histo = new Element("div",{
						id:"histo"+index,
						desc:pano.desc,
						info:pano.info,
						date:pano.date,
						imgfull:pano.imgfull
					});
					*/
					td.addClass('histo_label');
					td.innerHTML = pano.desc;
					td.injectInside(tr);
					tr.injectInside(table);

					tr = new Element ("tr");
					td = new Element ("td");
					td.setStyle("text-align","center");
					var histoimg = new Element("img",{
						id:"histoimg"+index,
						border:0,
						title:pano.desc,
						alt:pano.desc,
						src:pano.imgthumb,
						fullsrc:pano.imgfull
					});
					histoimg.injectInside(td);
					histoimg.addClass("histoimg");
					td.injectInside(tr);

					tr.injectInside(table);



					/*histolabel.injectInside(histo);
					histoimg.injectInside(histo);*/
					//histo.addClass("histo");




			}

			table.injectInside($('histo'));
			$('histo').innerHTML += " ";
			$('hotspot_display_layer').setStyle('display','block');
			$('histo_display_container').setStyle('visibility','hidden');
			$('histo_display_container').setStyle('display','block');
			//$("histo_display_container").setStyle("height",window.getHeight().toInt()-100);
			//$('histo_display_container').setStyle('left',(window.getWidth().toInt() - $('histo_display_container').getStyle("width").toInt())/2);
			//$('histo_display_container').setStyle('top',(window.getHeight().toInt() - $('histo_display_container').getStyle("height").toInt())/2);
			//$("histo_display").setStyle("height",$("histo_display_container").getStyle('height').toInt()-$("histo_display_container").getStyle("padding").toInt()*2);

			//$("histo_display_container").setStyle("height",$('table_histo').getHeight().toInt());
			$("histo_display_container").setStyle("height",window.getHeight().toInt()-100);
			$('histo_display_container').setStyle('left',(window.getWidth().toInt() - $('histo_display_container').getStyle("width").toInt())/2);
			$('histo_display_container').setStyle('top',(window.getHeight().toInt() - $('histo_display_container').getStyle("height").toInt())/2);
			//$("histo_display").setStyle("height",$('table_histo').getHeight().toInt());
			$("histo_display").setStyle("height",$("histo_display_container").getStyle('height').toInt());



			$('histo_display_container').setStyle('visibility','visible');

			$$('.histoimg').each(function(histoimg,_index){
					histoimg.addEvent('click',function(){
					       currentThis.showHotspots(false,true);
						currentThis.offsetPanorama = 0;
						currentThis.positionPanorama(0);
						currentThis.setPanorama(this.getAttribute("fullsrc"),null,"Chargement en cours du panorama sélectionné…");
						currentThis.hideLayer();
					})
			})
		}
		else{
			currentThis.pausePanorama();
			$('histo').innerHTML = "<br><br>Il n’y a pas d’historique pour le "+_date+",<br> merci de choisir un autre jour";
			$('hotspot_display_layer').setStyle('display','block');
			$('histo_display_container').setStyle('visibility','hidden');
			$('histo_display_container').setStyle('display','block');
			//$("histo_display_container").setStyle("height",window.getHeight().toInt()-100);
			//$('histo_display_container').setStyle('left',(window.getWidth().toInt() - $('histo_display_container').getStyle("width").toInt())/2);
			//$('histo_display_container').setStyle('top',(window.getHeight().toInt() - $('histo_display_container').getStyle("height").toInt())/2);
			//$("histo_display").setStyle("height",$("histo_display_container").getStyle('height').toInt()-$("histo_display_container").getStyle("padding").toInt()*2);

			//$("histo_display_container").setStyle("height",$('table_histo').getHeight().toInt());
			$("histo_display_container").setStyle("height",100);
			$('histo_display_container').setStyle('left',(window.getWidth().toInt() - $('histo_display_container').getStyle("width").toInt())/2);
			$('histo_display_container').setStyle('top',(window.getHeight().toInt() - $('histo_display_container').getStyle("height").toInt())/2);
			//$("histo_display").setStyle("height",$('table_histo').getHeight().toInt());
			$("histo_display").setStyle("height",$("histo_display_container").getStyle('height').toInt());
			$('histo_display_container').setStyle('visibility','visible');

		}
	},
	hideLayer:function(){
		$('hotspot_display_layer').setStyle("display","none");
		$('hotspot_display_container').setStyle("display","none");
		$('histo_display_container').setStyle("display","none");
		if($('live_display_container')){
			$('live_display_container').setStyle("display","none");
			$('live_display').innerHTML = "";
		}
		if($('krpancontainer')){
			$('btn_krview').setAttribute("state","close");
			$('krpancontainer').destroy();
		}
			 
		this.unpausePanorama(0);
	},
	loadPanoramas:function (_date){
		Request.JSON({
			url:"pages/ajax.php?date="+_date,
			onSuccess:function(_jsonobj){
				/*var tabImg
				var myImages = Asset.images(['/images/myImage.png', '/images/myImage2.gif'], {
				    properties: {
				        'class': 'myImage',
				        title: 'myImage'
				    },
				    onComplete: function(){
				        alert('All images loaded!');
				    }
				});*/

			}
		}).send();

	}

});
//http://www.neos360.fr/saetde/collblanc360//img/2010/11/24/06/historique/pano_thumb.jpg
//http://www.neos360.com/saetde/collblanc360/img/panojavascript/nojava/pano_PV.jpg
//http://www.neos360.fr/saetde/collblanc360//img/2010/11/24/07/historique/pano_PV.jpg

var xml_special_to_escaped_one_map = {
	    '&': '&amp;',
	    '"': '&quot;',
	    '<': '&lt;',
	    '>': '&gt;'
	};
	 
	var escaped_one_to_xml_special_map = {
	    '&amp;': '&',
	    '&quot;': '"',
	    '&lt;': '<',
	    '&gt;': '>',
	    '&eacute;':'é',
	    '&egrave;':'è',
	    '&agrave;':'à',
	    '&ecirc;':'ê',
	    '&deg;':'°'
	};
	 
	function encodeXml(string) {
	    return string.replace(/([\&"<>])/g, function(str, item) {
	        return xml_special_to_escaped_one_map[item];
	    });
	};
	 
	function decodeXml(string) {
//alert(1);
		//return string.replace('&deg;','°');
	    return string.replace(/(&deg;|&eacute;|&egrave;|&agrave;|&ecirc;|&quot;|&lt;|&gt;|&amp;)/g,
	        function(str, item) {
	            return escaped_one_to_xml_special_map[item];
	    });
	}



