function feature(a,lng,recover,imagepath){
	
	this.imagePath=imagepath;
	this.loc=a;
	
	this.lng=lng;
	this.init();
	
	this.recover=recover;
}

feature.prototype.init=function(){
	
	new Ajax.Request('../../script/amfphp/gateway2.php?s=Feature&m=GetFamily&a0='+this.lng, {
	  onSuccess: function(transport){feature.buildFamily(transport.responseText)}
	});

}


feature.prototype.buildFamily=function(s){
		var temp=eval(s);
		var a=new Array();
		a.push({data:"",label:this.loc["feature"]});
		for (var i=0;i<temp.length;i++){
			a.push({data:temp[i]["id"],label:temp[i]["titre"]});
		}
		$('family').innerHTML=this.buildListBox(a,"lstfamily","","feature.makeCategory");
		
		
		
		
		if (this.recover=="_"){
			//this.makeCategory($("lstfamily"));

		}else{
			var temp=this.recover.split("_");
			$("lstfamily").value=temp[0];
			this.makeCategory($("lstfamily"));
		}
}
feature.prototype.makeCategory=function(e){
	var a=e.value;
	new Ajax.Request('../../script/amfphp/gateway2.php?s=Feature&m=GetCategory&a0='+this.lng+"&a1="+a, {
	  onSuccess: function(transport){feature.buildCategory(transport.responseText)}
	});
}
feature.prototype.buildCategory=function(s){
		
		var temp=eval(s);
		
		if (temp.length>0){
			var a=new Array();
			for (var i=0;i<temp.length;i++){
				
				a.push({data:temp[i]["id"],label:temp[i]["titre"]});
			}
			$('category').innerHTML=this.buildListBox(a,"lstcategory","","feature.makeSearch");
			
			if (this.recover==""){
				this.makeSearch($('lstcategory').value);
			}else{
				var temp=this.recover.split("_");
			//	alert(temp[1]);
				if (temp[1]!=""){
					$("lstcategory").value=temp[1];
					this.recover="";
					this.makeSearch($("lstfamily"));
				}else{
					this.makeSearch($('lstcategory').value);
				}
				
			}
		
		}else{
			$('category').innerHTML="";	
			$('resultsearch').innerHTML="";
		}
		
}



feature.prototype.buildListBox=function(a,id,selected,action,arg){
	
		arg=(arg==undefined)?"":","+arg;
		var maker=(action==undefined || action=='')?"":" onChange=\"javascript:"+action+"(this"+arg+")\" ";
		var s='<select name="'+id+'" id="'+id+'" '+maker+' >';
		for (var i=0;i<a.length;i++){

		  if (selected!=a[i]["data"]){
         	 s+='<option value="'+a[i]["data"]+'" >'+a[i]["label"]+'</option>';
		  }else{
			 s+='<option value="'+a[i]["data"]+'"  selected="selected">'+a[i]["label"]+'</option>';
			  
		  }
		 
		}
		s+='</select>';
		return s;
}


feature.prototype.makeSearch=function(){
	
	a1=($("lstfamily")!=undefined)?$("lstfamily").value:"";
	a2=($("lstcategory")!=undefined)?$("lstcategory").value:"";
	
	//alert(this.imagePath);
	//console.log(this.imagePath.split("../"));
	var n=this.imagePath.split("../").length-1;
	
	new Ajax.Request('../../script/amfphp/gateway2.php?s=Feature&m=GetManuel&a0='+this.lng+'&a1='+a1+'&a2='+a2+"&a3="+n, {
	  onSuccess: function(transport){feature.buildSearch(transport.responseText)}
	});
}
feature.prototype.buildSearch=function(s){

		$('vignette').innerHTML="";
	

		var temp=eval(s);
		
		//console.log(temp[0]["video"]["article"]);
		
		if (temp.length>0){
				var s="";
				if (temp[0]["logo"].length>0) s+="<img src='../../files/files_feature/"+temp[0]["logo"][0]["chemin"]+"' />"
				s+="<h1>"+temp[0]["titre"]+"</h1>";
				s+="<div id='article'>"+temp[0]["article"]+"</div>";
				s+="<br>";
				if (temp[0]["image"].length>0) s+="<img src='../../files/files_feature/"+temp[0]["image"][0]["chemin"]+"' />"
			
				$('resultsearch').innerHTML=s
				
				s="";
				if (temp[0]["video"].length>0) {
					s+="<ul><li id='featurevideoicon'></li>";
					for (var i=0;i<temp[0]["video"].length;i++){
						var a=temp[0]["video"][i];
 						s+="<li>";
						if (a["duration"]!="")  s+="<div id='time'><div id='time2'>"+a["duration"]+"</div></div>";
						s+="<div id='b1'>";
                        s+=a["image"];
						s+="</div>";
						s+="<div id='b2'>";
                        s+=a["titre"];
						s+="</div>";
						s+="</li>";
						
						if (i%3<1 && temp[0]["video"].length>1) s+= "<li id='vignetteseparateur'><img src='../../images/video_separateur.jpg' /></li>";
					}
					s+="</ul>";	
					s+="<div id='bgbottomfeature'></div>"
				}
				
				//alert(temp[0]["video"][0]);
				$('vignette').innerHTML=s;
			}else{
				
				$('resultsearch').innerHTML="";
			}
	
}

