function loadYears(){
	var myChainYears = new Chain();
	myChainYears.chain( function(){ loadYear("start_year_day"); } );
	myChainYears.chain( function(){ loadYear("start_year_week"); } );
	myChainYears.chain( function(){ loadYear("start_year_month"); } );
	myChainYears.chain( function(){ loadYear("start_year_year"); } );
	myChainYears.chain( function(){ loadYear("start_year_day_histo"); } );
	myChainYears.chain( function(){ loadYear("start_year_week_histo"); } );
	myChainYears.chain( function(){ loadYear("start_year_month_histo"); } );
	myChainYears.chain( function(){ loadYear("start_year_year_histo"); } );
	
	var runChain = function() { 
		myChainYears.callChain();
		if (myChainYears.chains.length == 0) { runChain = $clear(timerChain); }
		//if (myChainYears.$chain.length== 0) { runChain = $clear(timerChain); } 
	}
	var timerChain = runChain.periodical(1000);
}
function loadYear(_id){
	var url = "./php/inc-serv-panorama.php?action=request_year&id="+_id;
 	new Ajax(url, {
		method: 'get',
		update: $(_id)
	}).request();
}
function loadMonth(_parent,_id,_type){
	//if(($("select_"+_parent).selectedIndex<1)){
		if(_parent == "start_year_day_histo"){
			$("start_month_day_histo").innerHTML="";
			$("start_day_day_histo").innerHTML="";
		}
		else if(_parent == "start_year_day"){
			$("start_month_day").innerHTML="";
			$("start_day_day").innerHTML="";
		}
		else if(_parent == "start_year_month_histo"){
			$("start_month_month_histo").innerHTML="";			
		}
		else if(_parent == "start_year_month"){
			$("start_month_month").innerHTML="";			
		}
		
		//return;
	//}
	//alert($("select_"+_parent).selectedIndex);
	if(($("select_"+_parent).selectedIndex<1)){
		
		return;
	}
	var url = "./php/inc-serv-panorama.php?action=request_month&id="+_id;
	url+="&year="+$("select_"+_parent).options[$("select_"+_parent).selectedIndex].value;
	if(_type)
		url+="&type="+_type;
 	new Ajax(url, {
		method: 'get',
		update: $(_id)
	}).request();
}
function loadDay(_parent,_id,_type){
	//if(($("select_"+_parent).selectedIndex<1)){
		if(_parent == "start_month_day_histo"){
			$("start_day_day_histo").innerHTML="";
		}
		else if(_parent == "start_month_day"){
			$("start_day_day").innerHTML="";
		}
		
		
		//return;
	//}
	if(($("select_"+_parent).selectedIndex<1)){
		return;
	}
	var url = "./php/inc-serv-panorama.php?action=request_day&id="+_id;
	url+="&year="+$("select_start_year_day"+_type).options[$("select_start_year_day"+_type).selectedIndex].value;
	url+="&month="+$("select_"+_parent).options[$("select_"+_parent).selectedIndex].value;
	
 	new Ajax(url, {
		method: 'get',
		update: $(_id)
	}).request();
}
function loadWeek(_parent,_id,_type){
	//if(($("select_"+_parent).selectedIndex<1)){
		if(_parent == "start_year_week_histo"){
			$("start_week_week_histo").innerHTML="";
		}
		else if(_parent == "start_year_week"){
			$("start_week_week").innerHTML="";
		}
		
		
		//return;
	//}
	if(($("select_"+_parent).selectedIndex<1)){
		return;
	}
	var url = "./php/inc-serv-panorama.php?action=request_week&id="+_id;
	url+="&year="+$("select_start_year_week"+_type).options[$("select_start_year_week"+_type).selectedIndex].value;
	
 	new Ajax(url, {
		method: 'get',
		update: $(_id)
	}).request();
}
function setClipType(_type){
	$('clip_type').value=_type;
}
function setHistoType(_type){
	$('histo_type').value=_type;
}
function launch_clip(){
	
	var url = "./php/inc-serv-panorama.php?action=getHisto&id=";
	url+="&type="+$('clip_type').value;
	
	if($('clip_type').value=='day'){
		if($("select_start_year_day").selectedIndex<1){
			alert(lngTab[1]);
			return;
		}
		if($("select_start_month_day").selectedIndex<1){
			alert(lngTab[2]);
			return;
		}
		if($("select_start_day_day").selectedIndex<1){
			alert(lngTab[3]);
			return;
		}
		url+="&year="+$("select_start_year_day").options[$("select_start_year_day").selectedIndex].value;
		url+="&month="+$("select_start_month_day").options[$("select_start_month_day").selectedIndex].value;
		url+="&day="+$("select_start_day_day").options[$("select_start_day_day").selectedIndex].value;
	}
	else if($('clip_type').value=='week'){
		if($("select_start_year_week").selectedIndex<1){
			alert(lngTab[1]);
			return;
		}
		if($("select_start_week_week").selectedIndex<1){
			alert(lngTab[4]);
			return;
		}
		url+="&year="+$("select_start_year_week").options[$("select_start_year_week").selectedIndex].value;
		url+="&week="+$("select_start_week_week").options[$("select_start_week_week").selectedIndex].value;
		
	}
	else if($('clip_type').value=='month'){
		if($("select_start_year_month").selectedIndex<1){
			alert(lngTab[1]);
			return;
		}
		if($("select_start_month_month").selectedIndex<1){
			alert(lngTab[2]);
			return;
		}
		url+="&year="+$("select_start_year_month").options[$("select_start_year_month").selectedIndex].value;
		url+="&month="+$("select_start_month_month").options[$("select_start_month_month").selectedIndex].value;
		
	}
	else if($('clip_type').value=='year'){
		if($("select_start_year_year").selectedIndex<1){
			alert(lngTab[1]);
			return;
		}
		
		url+="&year="+$("select_start_year_year").options[$("select_start_year_year").selectedIndex].value;
	}
	$('clip_global_value').innerHTML = "";
 	new Ajax(url, {
		method: 'get',
		update: $('clip_global_value'),
		onComplete: function() {
			createClip();
			
		}
	}).request();
}
function launch_histo(){
	var url = "./php/inc-serv-panorama.php?action=getHisto&id=";
	url+="&type="+$('histo_type').value;
	var myDate = new Date();
	url+="&suppel="+myDate.getTime();
	if($('histo_type').value=='day'){
		if($("select_start_year_day_histo").selectedIndex<1){
			alert(lngTab[1]);
			return;
		}
		if($("select_start_month_day_histo").selectedIndex<1){
			alert(lngTab[2]);
			return;
		}
		if($("select_start_day_day_histo").selectedIndex<1){
			alert(lngTab[3]);
			return;
		}
		url+="&year="+$("select_start_year_day_histo").options[$("select_start_year_day_histo").selectedIndex].value;
		url+="&month="+$("select_start_month_day_histo").options[$("select_start_month_day_histo").selectedIndex].value;
		url+="&day="+$("select_start_day_day_histo").options[$("select_start_day_day_histo").selectedIndex].value;
	}
	else if($('histo_type').value=='week'){
		if($("select_start_year_week_histo").selectedIndex<1){
			alert(lngTab[1]);
			return;
		}
		if($("select_start_week_week_histo").selectedIndex<1){
			alert(lngTab[4]);
			return;
		}
		url+="&year="+$("select_start_year_week_histo").options[$("select_start_year_week_histo").selectedIndex].value;
		url+="&week="+$("select_start_week_week_histo").options[$("select_start_week_week_histo").selectedIndex].value;
		
	}
	else if($('histo_type').value=='month'){
		if($("select_start_year_month_histo").selectedIndex<1){
			alert(lngTab[1]);
			return;
		}
		if($("select_start_month_month_histo").selectedIndex<1){
			alert(lngTab[2]);
			return;
		}
		url+="&year="+$("select_start_year_month_histo").options[$("select_start_year_month_histo").selectedIndex].value;
		url+="&month="+$("select_start_month_month_histo").options[$("select_start_month_month_histo").selectedIndex].value;
		
	}
	else if($('histo_type').value=='year'){
		if($("select_start_year_year_histo").selectedIndex<1){
			alert(lngTab[1]);
			return;
		}
		
		url+="&year="+$("select_start_year_year_histo").options[$("select_start_year_year_histo").selectedIndex].value;
	}
	$('histo_global_value').innerHTML = "";
 	new Ajax(url, {
		method: 'get',
		update: $('histo_global_value'),
		onComplete: function() {
			createHisto();
			
		}
	}).request();
}
var infosClip = new Array();
var meteosClip = new Array();
function createClip(){
	var valueGlobal=$('clip_global_value').innerHTML;
	
	var globalsValue= new Array();
	globalsValue = valueGlobal.split('[separator]');
	/*if(globalsValue.length>0)
	globalsValue.pop();*/
	
	var valueClip= "";
	var valueInfo= "";
	var valueMeteo="";
	if(globalsValue.length>0)
		valueClip=globalsValue[0];
	if(globalsValue.length>1)
		valueInfo=globalsValue[1];
		
	if(globalsValue.length>2)
		valueMeteo=globalsValue[2];
	/*var valueInfo=$('clip_info').innerHTML;
	var valueMeteo=$('clip_meteo').innerHTML;*/
	
	globalsValue = null;
	
	var images= new Array();
	images = valueClip.split('[sep-int]');
	if(images.length>0)
	images.pop();
	
	meteosClip = new Array();
	meteosClip = valueMeteo.split('[sep-int]');
	if(meteosClip.length>0)
	meteosClip.pop();
	
	
	infosClip = new Array();
	infosClip = valueInfo.split('[sep-int]');
	if(infosClip.length>0)
	infosClip.pop();
	for(var index=0; index<infosClip.length; index++) {
		
		if(infosClip[index].indexOf("[sep-int]")>-1){
			infosClip[index] = infosClip[index].substring(0,infosClip[index].indexOf("[sep-int]"))+infosClip[index].substring(infosClip[index].indexOf("[sep-int]")+"[sep-int]".length,infosClip[index].length);
		}
		/*else if(infosClip[index].indexOf("|||||")>-1){
			infosClip[index] = infosClip[index].substring(0,infosClip[index].indexOf("|||||"))+infosClip[index].substring(infosClip[index].indexOf("|||||")+1,infosClip[index].length);
		}
		else if(infosClip[index].indexOf("||||")>-1){
			infosClip[index] = infosClip[index].substring(0,infosClip[index].indexOf("||||"))+infosClip[index].substring(infosClip[index].indexOf("||||")+1,infosClip[index].length);
		}
		else if(infosClip[index].indexOf("|||")>-1){
			infosClip[index] = infosClip[index].substring(0,infosClip[index].indexOf("|||"))+infosClip[index].substring(infosClip[index].indexOf("|||")+1,infosClip[index].length);
		}
		else if(infosClip[index].indexOf("||")>-1){
			infosClip[index] = infosClip[index].substring(0,infosClip[index].indexOf("||"))+infosClip[index].substring(infosClip[index].indexOf("||")+1,infosClip[index].length);
		}
		else if(infosClip[index].indexOf("|")>-1){
			
			infosClip[index] = infosClip[index].substring(0,infosClip[index].indexOf("|"))+infosClip[index].substring(infosClip[index].indexOf("|")+1,infosClip[index].length);
		}*/
	}
	
	for(var index=0; index<images.length; index++) {
		images[index]=images[index]+"historique/pano_PV.jpg";
	}
	myMooPanoramaClip.removeAllPanoramas();
	myMooPanoramaClip.addPanoramas(images,true,infosClip,meteosClip);
	infosClip = null;
	meteosClip = null;
	valueClip = null;
	valueInfo= null;
	valueMeteo=null;
	$('clip_global_value').innerHTML = "";
	//loadPanoramas(images,'progress-clip','pano_clipDisplay',1,0,0,'',null,0);
	
	
}
var infosHisto = new Array();
var meteosHisto = new Array();
function createHisto(){
	/*var valueClip=$('histo_value').innerHTML;
	var valueInfo=$('histo_info').innerHTML;
	var valueMeteo=$('histo_meteo').innerHTML;*/
	
	var valueGlobal=$('histo_global_value').innerHTML;
	
	var globalsValue= new Array();
	globalsValue = valueGlobal.split('[separator]');
	/*if(globalsValue.length>0)
	globalsValue.pop();
	*/
	var valueClip= "";
	var valueInfo= "";
	var valueMeteo="";
	if(globalsValue.length>0)
		valueClip=globalsValue[0];
	if(globalsValue.length>1)
		valueInfo=globalsValue[1];
	if(globalsValue.length>2)
		valueMeteo=globalsValue[2];
	/*var valueInfo=$('clip_info').innerHTML;
	var valueMeteo=$('clip_meteo').innerHTML;*/
	
	globalsValue = null;
	
	var images= new Array();
	images = valueClip.split('[sep-int]');
	if(images.length>0)
	images.pop();
	
	meteosHisto = new Array();
	meteosHisto = valueMeteo.split('[sep-int]');
	if(meteosHisto.length>0)
	meteosHisto.pop();
	
	infosHisto = new Array();
	infosHisto = valueInfo.split('[sep-int]');
	if(infosHisto.length>0)
	infosHisto.pop();
	
	for(var index=0; index<infosHisto.length; index++) {
		
		if(infosHisto[index].indexOf("[sep-int]")>-1){
			infosHisto[index] = infosHisto[index].substring(0,infosHisto[index].indexOf("[sep-int]"))+infosHisto[index].substring(infosHisto[index].indexOf("[sep-int]")+"[sep-int]".length,infosHisto[index].length);
		}
		/*else if(infosClip[index].indexOf("|||||")>-1){
			infosClip[index] = infosClip[index].substring(0,infosClip[index].indexOf("|||||"))+infosClip[index].substring(infosClip[index].indexOf("|||||")+1,infosClip[index].length);
		}
		else if(infosClip[index].indexOf("||||")>-1){
			infosClip[index] = infosClip[index].substring(0,infosClip[index].indexOf("||||"))+infosClip[index].substring(infosClip[index].indexOf("||||")+1,infosClip[index].length);
		}
		else if(infosClip[index].indexOf("|||")>-1){
			infosClip[index] = infosClip[index].substring(0,infosClip[index].indexOf("|||"))+infosClip[index].substring(infosClip[index].indexOf("|||")+1,infosClip[index].length);
		}
		else if(infosClip[index].indexOf("||")>-1){
			infosClip[index] = infosClip[index].substring(0,infosClip[index].indexOf("||"))+infosClip[index].substring(infosClip[index].indexOf("||")+1,infosClip[index].length);
		}
		else if(infosClip[index].indexOf("|")>-1){
			
			infosClip[index] = infosClip[index].substring(0,infosClip[index].indexOf("|"))+infosClip[index].substring(infosClip[index].indexOf("|")+1,infosClip[index].length);
		}*/
	}
	var sizetab = images.length;
	var imagesThumb= new Array();
	for(var index=0; index<sizetab; index++) {
		imagesThumb.push(images[index]+"historique/pano_thumb.jpg");
	}
	for(var index=0; index<sizetab; index++) {
		images[index]=images[index]+"historique/pano_PV.jpg";
		
	}
	
	myMooPanoramaHisto.removeAllPanoramas();
	myMooPanoramaHisto.removeAllPanoramasThumb();
	
	myMooPanoramaHisto.addPanoramasThumb(imagesThumb,true,infosHisto,meteosHisto);
	infosHisto = null;
	meteosHisto = null;
	valueHisto = null;
	valueInfo= null;
	valueMeteo=null;
	$('histo_global_value').innerHTML = "";
	/*if(loadPanoramas(imagesThumb,'progress-histo','loading_thumb_histo',2,0,0,'',null,0)){
		//loadPanoramas(images,'progress-histo','pano_histoDisplay',3,0,0,'',null,0);
	}*/
	
	
}