//var mm =open("","mm");
function debug(obj){
	for(var i in obj)	{
		mm.document.write(i+"="+obj[i]+"<br>");
	}
}
function teste(valeur){
		mm.document.write(valeur+"<br>");
}

function setRollBt(obj,action){
	var  obj = $(obj);
	if(obj){
		if(action==true){
			 //debug(obj.style)
			obj.setStyle({backgroundPosition:"0px -20px"});
		}else{
			obj.setStyle({backgroundPosition:"0px 0px"});
		}
	}
}
/* /(P)//Création de la fonction d'écriture du COOKIE */
function SetCookies(Champ,Valeur){
	var domaine="www.finecollectif.com/";
	document.cookie = Champ+"="+Valeur+";"//expires="+new Date(2010,12,24).toGMTString()+";;
}

function Dmc_GetChamp(Champ){
	var result="";
	if(document.cookie.length>0){
		var chaine=document.cookie;
		var Tableau=new Array();
		while(chaine.indexOf(";")!=-1){
			Tableau[Tableau.length]=chaine.substring(0,chaine.indexOf(";"));
			chaine=chaine.substring(chaine.indexOf(";")+1,chaine.length);
		}
		Tableau[Tableau.length]=chaine;
		for(i=0;i<Tableau.length;i++){
			if(Tableau[i].indexOf(Champ)!=-1){
				result=Tableau[i].substring(Tableau[i].indexOf("=")+1,Tableau[i].length);
				break;
			}
		}	
	}
	return result;
}


var initInfo = Class.create({
	_timer:null,
	_timeout:10,
	_content:null,
	_contentInfo :null,
	_contentTitle:null,
	_nextHeight:20,
	_heightContentTotal:null,
	_heightMax:null,
	_qt:5,
	initialize: function() {
	
		this._content = $("info");

		//alert(this._contentInfo.getWidth())
		if(this._content){
				this._contentInfo = $("descriptifinfo");
				this._contentTitle = $("titleinfo");
				this._contentInfo.setStyle({display:"block",width:(this._contentTitle.getWidth()-15-54)+"px"})
				//
				this.getMaxHeight();
				this._heightContentTotal = parseInt(this._contentTitle.getHeight())+ parseInt(this._contentInfo.getHeight())
				var t = this;
				Event.observe(window,"resize",this.getMaxHeight.bind(t))
			 this._content.observe('mouseover', function(event){
						Event.stop(event)
					 var element = Event.element(event);
					 clearInterval(t._timer);
					 t._timer = setInterval(t.ecouter.bind(t,"+"),t._timeout);
				});	
				this._content.observe('mouseout', function(event){
					 clearInterval(t._timer);
					 t._timer = setInterval(t.ecouter.bind(t,"-"),t._timeout);
				});
		}
		
	},
	getMaxHeight:function(){
		this._heightMax =  parseInt($("content").getHeight());
	},
	ecouter:function(action){
		if(action=="+"){
		 	this._nextHeight +=this._qt;
			//var posiTop=this._heightContentTotal- this._nextPosition+20
			if(this._nextHeight>=this._heightContentTotal){
				this._nextHeight = this._heightContentTotal;
				
				
				clearInterval(this._timer);
			}else if(this._nextHeight>=this._heightMax){
					this._nextHeight = this._heightMax;
					clearInterval(this._timer);
					this._content.setStyle({overflow:"scroll"})
			}
		}else if(action=="-"){
			//this est info
			this._content.setStyle({overflow:"hidden"})
		 	this._nextHeight -= this._qt;
			if(this._nextHeight<=20){
				this._nextHeight = 20;
				clearInterval(this._timer);
			}
			
		}
		this._content.setStyle({height:this._nextHeight+"px"})
	}
});


var ImageFond = Class.create({
	_heightImage:0,
	_widthImage:0,
	_timer:null,
	tagName:"ImageFond",
	_timeout:10,
	_content:null,
	_pointerX:0,
	_pointerY:0,
	_pointerInitX:0,
	_pointerInitY:0,
	_isActif:false,
	_positionContent:{left:0,top:0},
	_tailleZone:{height: 0, width: 0},
	initialize: function(width,height) {
		this._content = $("content");
		if(this._content){
			this.getPointers = this.getPointer.bindAsEventListener(this);

			this._heightImage=height;
			this._widthImage=width;
			if(this._widthImage!=0 && this._heightImage!=0 && this._content.getStyle("backgroundImage")!="" && this._content.getStyle("backgroundImage")!="url()" && this._content.getStyle("backgroundImage")!=undefined){
					this._url = this._content.getStyle("backgroundImage").gsub(/url\((.*?)\)/, function(match){ 													
								return match[1] 
					}); 
					var isExiste = Dmc_GetChamp(this._url);
					if(isExiste=="true"){
						this.setChargement(false);
						this._isActif=true;
					}else{
						var chargement= new Image();
								chargement.onload = (function (){
										this._heightImage=chargement.height;
										this._widthImage=chargement.width;
										this.setChargement(false);
										SetCookies(this._url,"true");
										this._isActif=true;
								}).bind(this)
	
						chargement.src = this._url;
					}
				  //this._content.setStyle({backgroundPosition:"0px 0px"});
					//this._tailleZone =$("content").getDimensions();
					this.getTailleZone();
					Event.observe(window,"resize",this.getTailleZone.bind(this))
									
								if(this._heightImage>this._tailleZone.height || this._widthImage >this._tailleZone.width){
									var t = this;
										this._content.observe("mouseover",function(event){
											var element = Event.element(event);							   
											element.setStyle({cursor:"move"});							   							   
										});
										this._content.observe("mouseout",function(event){
											Event.stop(event)
											var element = Event.element(event);							   
												element.setStyle({cursor:"default"});
												t.stoper.bindAsEventListener(t);
										});
										this._content.observe("mousedown",this.starter.bindAsEventListener(this));
										this._content.observe("mouseup",this.stoper.bindAsEventListener(this));
								}
			}else{
				this.setChargement(false);
			}
		}
	
	},
	setChargement : function(action){
		var layerChargement = $("layerChargement")
		if(layerChargement){
			new Effect.Opacity(layerChargement, { from: ((action==false)? 1.0 : 0.0), to: ((action==false)? 0.0 : 1.0), duration: 0.5 });
		}
	},
	getTailleZone:function(){
		this._tailleZone = $("content").getDimensions();
		this._content.setStyle({backgroundPosition:"0px 0px"});
	},
	ecouter:function(){
		
		var posX=this._pointerX+this._pointerInitX;
		var posY=this._pointerY+this._pointerInitY;
		
		if(posY<=-(this._heightImage-this._tailleZone.height)){
			posY= -(this._heightImage-this._tailleZone.height)
		}
		if(posY>=0){
			posY= 0
		}
		
		if(posX>=0){
			posX= 0
		}
		
		if(posX<=-(this._widthImage-this._tailleZone.width)){
			posX= -(this._widthImage-this._tailleZone.width);
		}
		if(this._widthImage<=this._tailleZone.width){
			posX= 0;
		}
		if(this._positionContent.left != posY || this._positionContent.left != posX){
			this._positionContent={left:posX,top:posY};
			this._content.setStyle({backgroundPosition:posX+"px "+posY+"px"});
		}
	},
	starter:function(event){
		if(this._isActif==true){
			this._pointerX=event.pointerX(event);
			this._pointerY=event.pointerY(event);	
			
			this._pointerInitX = this._positionContent.left-this._pointerX;
			this._pointerInitY = this._positionContent.top-this._pointerY;
			this._content.observe("mousemove",this.getPointers);
		}
	},
	stoper:function(event){
		this._content.stopObserving("mousemove",this.getPointers);
	},
	getPointer:function(event){
		this._pointerX=event.pointerX(event);
		this._pointerY=event.pointerY(event);	
		this.ecouter()
	}
});

function initMenu(){
	if($("menu")){
		var fils = $("menu").childElements();
		for(var i =0;i<fils.length;i++){
			var t = $(fils[i]);
			var a  = t.childElements()[0];
			if(a.hasClassName('selected')){
				$("menu").selection=a;
				
			}
			a.observe('mouseover', function(event){
					var element = Event.element(event);
					 element.addClassName('hover');
			});
			a.observe('mouseout', function(event){
			  	var element = Event.element(event);
				if(element!=$("menu").selection){
					element.removeClassName('hover');
				}
			 });
		}
	}
	
}
function initListeprojet(){
	if($("listeprojet")){
		var ul = $('listeprojet').firstDescendant();
		var fils = ul.childElements();
		
		for(var i =0;i<fils.length;i++){
			var t = $(fils[i]);
			var a  = $(t.childElements()[0]);
			if(a.href!="javascript:void(0)"){
				if(a.hasClassName('selected')){
					ul.selection=a;
				}
				a.observe('mouseover', function(event){
					var element = Event.element(event);
					 element.addClassName('selected');
				});
				
				a.childElements()[0].observe('mouseover', function(event){
					var element = Event.element(event);
					 element.parentNode.addClassName('selected');
					 
				});
				
				a.observe('mouseout', function(event){
						var element = Event.element(event);
					if(element!=ul.selection){
						element.removeClassName('selected');
					}
					/*
					var infobulle = $("infobulle");
					if(infobulle){
						if(element.title!=""){
							infobulle.select("span")[0].update(element.title); 
							var position = element.viewportOffset()
							infobulle.setStyle({top:(position.top-70)+"px",left:(position.left+12)+"px",display:"block"})
						}else{
							infobulle.setStyle({display:"none"})
						}
					}
					*/
					
				 });
				a.childElements()[0].observe('mouseout', function(event){
					var element = Event.element(event);
					if(element.parentNode!=ul.selection){
						element.parentNode.removeClassName('selected');
					}
					 var infobulle = $("infobulle");
					 if(infobulle){
						infobulle.setStyle({display:"none"})
						//alert("fdsdf")
					}
				});
			}
			else{
				a.setStyle({cursor:"default"});
			}
		}
	}
}

function addFavoris() {
	 bookmarkurl= "http://www.finecollectif.com"
	 bookmarktitle= "Fine! : regroupement de freelance lyonnais";
	if(Prototype.Browser.IE){
		window.external.AddFavorite(bookmarkurl,bookmarktitle);
	}else if(Prototype.Browser.Gecko){
		window.sidebar.addPanel(bookmarktitle,bookmarkurl,"");
	}else {
		alert ('La fonction n\'est implémentée sur ce navigateur web');
	} 
	/*
	
279
280 var title="title"
281 var url="http://www.domain.com"
282
283 if (window.sidebar) {
284 alert ("Firefox ne permet pas d'ajouter automatiquement un site aux favoris. Utilisez le raccourci Ctrl + D à la place");
 // firefox
 //window.sidebar.addPanel (descriptif,url,"");
 } else if ( window.opera && window.print ) {
 // opera
 var mbm = document.createElement ('a');
 mbm.setAttribute ('rel','sidebar');
 mbm.setAttribute ('href',url);
292 mbm.setAttribute ('title',title);
 mbm.click ();
 } else if ( window.external ) {
 window.external.AddFavorite (url,descriptif);
 } else {
 */
}

function setEntreprise(){
var b ="n"
var t = "a";
var n = "li";
var e = "o";var d ="d";
document.write(t+d+d+"&nbsp;"+e+b+n+b+"e");
}

function getNom(nom){
var A =["n","a","k","b","c","e"," ","d","f","g","h","x","v","i","l","m","j","o","p","s","q","t","u","w","é","y","r","z","-",".","ô","'","@"];
	var count = 0;
	for(var h=0;h<nom.length;h++){
		for(var i=0;i<A.length;i++){
			if(nom.charAt(h)==A[i]){
				
			document.write(i+",");	
				break;
			}
		}
	}
}	  
function setNom(table,isMaj){
var A =["n","a","k","b","c","e"," ","d","f","g","h","x","v","i","l","m","j","o","p","s","q","t","u","w","é","y","r","z","-",".","ô","'","@"];
var temps = new Array();
var temps2 = "";
	
	for(var i=0;i<table.length;i++){
		temps.push(A[table[i]]);
	}
	for(var i=0;i<temps.length;i++){
		if(i==0){
			temps2 += temps[i].toUpperCase()
		}else if(temps[i-1]=="'" && i>0){
			temps2 += temps[i].toUpperCase()
		}else if(temps[i+1]=="'" && temps[i-2]!=" " && i>0){
			temps2 += temps[i];
		}else if(temps[i-1]==" " && temps[i+2]!=" " && i>0){
			temps2 += temps[i].toUpperCase()
		}else if(temps[i-1]=="." && i>0){
			temps2 += temps[i].toUpperCase()
		}else{
			temps2 += temps[i];
		}
	}
	if(isMaj==true){
		temps2 = temps2.toUpperCase()
	}
	if(arguments.length==3){
		temps2 = temps2.toLowerCase();
	}
	document.write(temps2);
}

function roolOver(){
	var allImg= $$('.lignereference a.zoom');
	allImg.each(function(lien) {
	  var lien = $(lien);
	  lien.observe('mouseover', function(event){
					var element = Event.element(event);
					var img = $(this).firstDescendant();
					 img.setStyle({top:"-30px"})
				});
	  lien.observe('mouseout', function(event){
					var element = Event.element(event);
					 var img = $(this).firstDescendant();
					 img.setStyle({top:"0px"})
				});
	});
}
function setBackgroungHome(url,color,colorlink,background){
	var f = $('content');var t = $('texthome');
	if(f && t){
  	 if(url.indexOf('.jpg')!=-1){
      f.writeAttribute('style','background-image:url('+url+')');
     }else{
      	 var params = {WMODE:"TRANSPARENT", menu :"false"};
         var attributes = {id: "blocswf",name: "blocswf"};
        if (swfobject.hasFlashPlayerVersion("9.0.0")) {
            f.writeAttribute('style','');
          	swfobject.embedSWF(url, "blocswf", "812", "120", "9.0.0","expressInstall.swf", {}, params, attributes);
    	  }
    	  
     }
		setColorTextHome(t.getElementsByTagName('h1'),color,background);
		setColorTextHome(t.getElementsByTagName('p'),color,background);
		setColorTextHome(t.getElementsByTagName('a'),colorlink,background);
	}
}
function setColorTextHome(element,color,background){for(var i=0;i<element.length;i++){var para = $(element[i]);para.setStyle({'backgroundColor':background});para.setStyle({'color':color});}}

document.observe('dom:loaded', function () {roolOver()});