
//Variable déterminant si oui ou non, on affiche les informations fourni par chaque fonction
var infs = true
//Browsercheck (needed)
function lib_bwcheck(){ 
  this.ver 	   = navigator.appVersion;
  this.agent   = navigator.userAgent;
  this.agent_l = navigator.userAgent.toLowerCase()
  this.appName = navigator.appName
  this.platform = navigator.platform
  
  this._all    = (document.all)?1:0;	 
  this._id     = (document.getElementById)?1:0;
  this._layers = (document.layers)?1:0;	 
  this.dom 	   = (this._id || (document.createElement && document.appendChild && document.getElementsByTagName))?1:0;
  
  // Opéra
  this.opera   = this.agent.indexOf("Opera") > -1;
  this.opera5  = this.agent.indexOf("Opera 5") > -1;
  this.opera6  = this.agent.indexOf("Opera 6") > -1;
  this.opera7  = this.agent.indexOf("Opera 7") > -1 || (this.agent.toLowerCase().indexOf('opera/7') > -1)
   
  // Internet Explorer
  this.ie3     = (this.ver.indexOf("MSIE") && (parseInt(this.ver) < 4));
  this.ie4 	   = (this._all && !this.dom && !this.opera5)?1:0;
  this.ie5 	   = (this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0;
  this.ie55	   = (this.ver.indexOf('MSIE 5.5') > 0); 
  this.ie6 	   = (this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
  this.ie 	   = (this.ie3 || this.ie4 || this.ie5 || this.ie55 || this.ie6);
  
  this.ie3Min  = this.ie3 || this.ie4 || this.ie5 || this.ie55 || this.ie6;
  this.ie4Min  = this.ie4 || this.ie5 || this.ie55 || this.ie6;
  this.ie5Min  = this.ie5 || this.ie55 || this.ie6;
  this.ie55Min = this.ie55 || this.ie6;
  this.ie6Min  = this.ie6
  
  // Netscape
  this.ns 	   = (this.agent_l.indexOf("netscape") != -1 || (this.appName == "Netscape" && this._layers))
  // Netscape 4 generation only
  this.ns4 	   = (this._layers && !this.dom)?1:0;
  // Netscape 5 Gecko generation
  this.ns6 	   = (this.ns && this.moz && this.dom && parseInt(this.ver) >= 5)?1:0;
  // Gecko generation
  this.moz 	   = (this.agent_l.indexOf("gecko") != -1)
  
  // OS
  this.mac 	   = this.agent.indexOf("Mac")>-1;
  this.hotjava = (this.agent.toLowerCase().indexOf('hotjava') != -1)?1:0; 
  this.bw 	   = (this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5 || this.moz);
  return this;
}

  //Browsercheck object
  bw = new lib_bwcheck()

//Debug function 
function lib_message(txt){alert(txt); return false}

//Lib objects
function lib_obj(obj,nest,frm,c,w,h,x,y,v,b,hl,z,f,o){
  //lib arguments : id,parent id, frame name, created or not,width, height, left, top, visibility, background, content, z-index, font
  if(!bw.bw) return lib_message('Old browser'); if(!obj) return
  if(frm && top.frames.length < 2) return;
  var dyn_l
  nest_  = (!nest)?'':nest;
  nest   = (!nest)?'':'document.'+nest+'.'; 
  frm    = (!frm)?"":'window.parent.frames["'+frm+'"].';

  // ############### DYNAMIC CREATION (start) ###############
  	if(c){
  	p = (bw.dom)?document.getElementById(nest_):(bw.ie4)?document.all(nest_):(bw.ns4)?document.layers[nest_]:0;
  	this.parent = (!nest)?(bw.ns4)?"":document.body:p;
  
  	// - IE <5 -
  	if(bw.ie || document.all){
  	str = '<div id="' + obj + '" '
 	str += 'style="';
  	str += 'position:absolute;';
  	str += 'left:' + ((x)?x:"0") + 'px;';
	str += 'top:' + ((y)?y:"0") + 'px;';
  	str += 'width:' + ((w)?w:"100") + 'px;';
	str += 'height:' + ((h)?h:"100") + 'px;';
  	str += 'visibility:' + ((!v)?(!v)?"hidden":"visible":"visible") + ';';
  	str += ' ' + ((b)?"background-color: " + b + "; layer-background-color: " + b + ";":"") + '';
  	str += 'z-index: '+ ((z)?z:"") +';';
  	str += 'overflow: '+ ((o)?o:"") +';';
  	str += (f)?'font-family: '+f[0]+'; font-size: '+f[1]+'px; color:'+f[2]+';':'';
  	str += '">';
  	//html content
  	str += (hl)?hl:"";
  	str += '</div>';
  	this.parent.insertAdjacentHTML('BeforeEnd',str)
  	}
  	// - IE -
  
  	// - NS4 -
  	if(bw.ns4){
  	if(!nest) dyn_l = document.layers[obj] = new Layer(0); else dyn_l = this.parent.document.obj = new Layer(0,this.parent);
  
  	dyn_l.left = (x)?x:0;
	dyn_l.top  = (y)?y:0;
  	dyn_l.clip.right = (w)?w:0;
	dyn_l.clip.bottom = (h)?h:0;
	dyn_l.clip.left = dyn_l.clip.top = 0;
  	dyn_l.visibility = (!v)?(!v)?"hide":"show":"show";
  	if(b) dyn_l.bgColor = b
  	if(hl){dyn_l.document.open(); dyn_l.document.write(hl); dyn_l.document.close()}
  	dyn_l.zIndex = (z)?z:"";
  	}
  	// - NS4 -

  	// - GECKO -	
  	if(bw.moz){
  	dyn_l = document.createElement('div');
  	dyn_l.setAttribute('id',obj);
	str_attribute =  'position: absolute;'+
					 'z-index: '	+ ((z)?z:"") 								+';'+
					 'overflow: '	+ ((o)?o:"") 								+';'+
					 'left:'		+ ((x)?x:"0") 								+';'+
					 'top:'			+ ((y)?y:"0") 								+';'+
					 'width:'		+ ((w)?w:"100") 							+'px;'+
					 'height:'		+ ((h)?h:"100") 							+'px;'+
					 'visibility:'	+ ((!v)?(!v)?"hidden":"visible":"visible") +';'+
					 ''+ ((b)?"background-color: "+b+"; layer-background-color: "+b+"":"") +''+
					 ((f)?'font-family: '+f[0]+'; font-size: '+f[1]+'px; color:'+f[2]+';':'') + '';
					
  	dyn_l.setAttribute('style',str_attribute)
  	this.parent.appendChild(dyn_l)
  
  	//html content
  	if(hl){
  	var newRange = document.createRange()
  	newRange.setStartBefore(dyn_l)
  	str_tmp = newRange.createContextualFragment(hl)	
  	dyn_l.appendChild(str_tmp);
  	}
  	}
  	// - GECKO -	

  	}
  // ############### DYNAMIC CREATION (end) ###############

  this.evnt = (bw.dom)?eval(frm+"document.getElementById(obj)"):(bw.ie4)?eval(frm+"document.all[obj]"):(bw.ns4)?(!c)?eval(""+frm+""+nest+"document.layers."+obj):dyn_l:0;
  if(!this.evnt) return lib_message('The layer does not exist ('+obj+')'+'\nIf your using Netscape please check the nesting of your tags!');

  this.css = (bw.dom||bw.ie4)?this.evnt.style:this.evnt;
  this.ref = (bw.dom||bw.ie4)?document:this.css.document;

  this.x = parseInt(this.css.left)||this.css.pixelLeft||this.evnt.offsetLeft||0;
  this.y = parseInt(this.css.top)||this.css.pixelTop||this.evnt.offsetTop||0;

  this.w = this.evnt.offsetWidth||this.css.clip.width||this.ref.width||this.css.pixelWidth||0;
  this.h = this.evnt.offsetHeight||this.css.clip.height||this.ref.height||this.css.pixelHeight||0;

  this.z = this.css.zIndex;
  this.bgC = (bw.dom||bw.ie4)?this.css.backgroundColor:(bw.ns4)?this.ref.bgColor:0;
  this.bgImage
  this.v

  this.c = 0; //Clip values
  if((bw.dom || bw.ie4) && this.css.clip){
  										 this.c = this.css.clip;
										 this.c = this.c.slice(5,this.c.length-1);
										 //style.clip="rect(0 300 300 0)";
										 //			   rect(t  r   b  l)
  										 this.c = this.c.split(' ');
  										 for(var i=0;i<4;i++){
					  										 this.c[i] = parseInt(this.c[i]);
					  										 }
  										 }
  this.ct = this.css.clip.top||this.c[0]||0; 
  this.cr = this.css.clip.right||this.c[1]||this.w||0;
  this.cb = this.css.clip.bottom||this.c[2]||this.h||0; 
  this.cl = this.css.clip.left||this.c[3]||0;
    
  this.id = obj
  this.obj = obj + "Object";
  eval(this.obj + "=this");
  return this
}


// A unit of measure that will be added when setting the position of a layer.
var px = (bw.ns4||window.opera)?"":"px";

//NS4 resize fix
if(bw.ns4){ 
  scrX = innerWidth;
  scrY = innerHeight;
  onresize = function(){
			 if(scrX!= innerWidth || scrY!= innerHeight){
			 history.go(0);
			 }
			 };
}

if(bw.agent.indexOf('Opera')>-1 && (bw.opera5 || bw.opera6) && bw.dom){ //Opera 5/6 resize fix.
  document.onmousemove = function(){
						 if(scrX < innerWidth-10 || scrY < innerHeight-10 || scrX > innerWidth+10 || scrY > innerHeight+10){
						 scrX = innerWidth;
						 scrY = innerHeight;
						 //Relance la fonction d'initialisation
						 
						 //
						 }
						 };
}
//

lib_obj.prototype.getP = function(t){/* t = 'x'||'y' */ v = eval("this."+t+""); return v}
lib_obj.prototype.getS = function(t){/* t = 'w'||'h' */ v = eval("this."+t+""); return v}
lib_obj.prototype.getC = function(t){/* t = 't'||'r'||'b'||'l' */ v = eval("this.c"+t+""); return v}

lib_obj.prototype.getZ = function(){return this.z}
lib_obj.prototype.setZ = function(v){
						 this.css.zIndex = v
						 this.z = v
						 }

lib_obj.prototype.getV = function(){
						 /* true = visible, false = hidden */
						 v = this.css.visibility; return v.indexOf("hid") == -1
						 }
						 
lib_obj.prototype.setVisible = function(v){this.v = v; this.css.visibility = (v?'inherit':'hidden')}
lib_obj.prototype.showIt = function(){this.css.visibility = "visible"}
lib_obj.prototype.hideIt = function(){this.css.visibility = "hidden"}

lib_obj.prototype.setOpacity = function(o){
							   if(navigator.userAgent.match(/MSIE/)) this.css.filter = 'alpha(opacity='+ o +')'
							   else this.css.MozOpacity = o/100
							   }

lib_obj.prototype.resizeTo = function(w,h,c){
							 // Mise à jour des propriétés width et height
							 if(!bw.ns4){
							 	//w
							 	if(w != null){
							 	this.w = w;
							 	this.css.width = (w != 'auto'?(w < 0?0:w)+'px':'auto')
							 	}
							 	//h
							 	if(h != null){
								 this.h = h;
							 	this.css.height = (h != 'auto'?(h < 0?0:h)+'px':'auto'); 
							 	}
							 }
							 else if(w != 'auto' && h != 'auto') this.evnt.resizeTo(w,h)

							 // Mise à jour du clipping
							 if(c){
							 	if(!bw.ns4) this.css.clip = 'rect(0px '+ this.css.width + ' ' + this.css.height +' 0px)'
							 	else{
									if(w != 'auto' && h != 'auto'){
    						 		this.css.clip.top = '0'
							 		this.css.clip.right = w
    						 		this.css.clip.bottom = h
							 		this.css.clip.left = '0'
									}
							 	}
								
								this.ct = 0
  								if(w != null) this.cr = w
  								if(h != null) this.cb = h
  								this.cl = 0

							 	if(infs){
								window.status = "clip:rect(0 "+ this.cr +" "+ this.cb +" 0)"
								setTimeout("window.status = ''",3000)
								}
							 }
}
//Moving object to
lib_obj.prototype.moveIt = function(x,y){
							//Update properties
							this.x = x; this.y = y;
							//Upadte positions
							this.css.left = x; this.css.top = y
						   }
						   
lib_obj.prototype.moveItX = function(x){this.x = x; this.css.left = x}
lib_obj.prototype.moveItY = function(y){this.y = y; this.css.top = y}

//Moving object by
lib_obj.prototype.moveBy = function(x,y){
  						   this.css.left = this.x += x;
						   this.css.top = this.y += y;
						   }

lib_obj.prototype.setBgImage = function(p){
							   this.bgImage = p
							   this.css.backgroundImage = ((p && p != '')?'url('+p+')':'')
							   }


//Changing backgroundcolor
lib_obj.prototype.bg = function(color){ 
					   if(bw.opera) this.css.background = color;
					   else if(bw.dom||bw.ie4) this.css.backgroundColor = color
					   else if(bw.ns4) this.css.bgColor = color  
}

//Writing content to object
lib_obj.prototype.writeIt = function(text,startHTML,endHTML){
							if(bw.ns4){
    								  if(!startHTML){
													startHTML = endHTML = "";
													}
	  								  this.ref.open("text/html"); 
    								  this.ref.write(startHTML + text + endHTML); 
    								  this.ref.close()
									  }
							else this.evnt.innerHTML=text
}


//Clipping object to
lib_obj.prototype.clipTo = function(t,r,b,l,setwidth){ 
  						   this.ct = t; this.cr = r; this.cb = b; this.cl = l;
  						   if(bw.ns4){
    								 this.css.clip.top = t;
									 this.css.clip.right = r
    								 this.css.clip.bottom = b;
									 this.css.clip.left = l
  									 }
						   else{
    						   if(t<0) t = 0;
							   if(r<0) r = 0;
							   if(b<0) b = 0;
							   if(b<0) b = 0
    						   this.css.clip = "rect("+t+","+r+","+b+","+l+")";
							   //
							   //Actualisation de la taille
    						   if(setwidth){
										   this.css.pixelWidth = this.css.width = r; 
    									   this.css.pixelHeight = this.css.height = b;
										   this.w = r;
										   this.h = b
										   }
							   //
  							   }
						   }

//Clipping object by
lib_obj.prototype.clipBy = function(t,r,b,l,setwidth){ 
  						   this.clipTo(this.ct+t,this.cr+r,this.cb+b,this.cl+l,setwidth)
}

//Clip animation
lib_obj.prototype.clipIt = function(t,r,b,l,step,fn,wh){
  tstep=Math.max(Math.max(Math.abs((t-this.ct)/step),Math.abs((r-this.cr)/step)),
    Math.max(Math.abs((b-this.cb)/step),Math.abs((l-this.cl)/step)))
  if(!this.clipactive){
    this.clipactive=true; if(!wh) wh=0; if(!fn) fn=0
    this.clip(t,r,b,l,(t-this.ct)/tstep,(r-this.cr)/tstep,
      (b-this.cb)/tstep,(l-this.cl)/tstep,tstep,0, fn,wh)
  }
}
lib_obj.prototype.clip = function(t,r,b,l,ts,rs,bs,ls,tstep,astep,fn,wh){
  if(astep<tstep){
    if(wh) eval(wh); 
    astep++
    this.clipBy(ts,rs,bs,ls,1);
    setTimeout(this.obj+".clip("+t+","+r+","+b+","+l+","+ts+","+rs+","
      +bs+","+ls+","+tstep+","+astep+",'"+fn+"','"+wh+"')",1)
  }else{
    this.clipactive=false; this.clipTo(t,r,b,l,1);
    if(fn) eval(fn)
  }
}

//Slide animation
lib_obj.prototype.slideIt = function(endx,endy,inc,speed,fn,wh){
  if(!this.slideactive){
    var distx = endx - this.x;
    var disty = endy - this.y
    var num = Math.sqrt(Math.pow(distx,2)+Math.pow(disty,2))/inc
    var dx = distx/num; var dy = disty/num
    this.slideactive = 1; 
    if(!wh) wh=0; if(!fn) fn=0
    this.slide(dx,dy,endx,endy,speed,fn,wh)
    }
}
lib_obj.prototype.slide = function(dx,dy,endx,endy,speed,fn,wh) {
  if(this.slideactive&&
  (Math.floor(Math.abs(dx))<Math.floor(Math.abs(endx-this.x))|| 
    Math.floor(Math.abs(dy))<Math.floor(Math.abs(endy-this.y)))){
    this.moveBy(dx,dy); 
    if(wh) eval(wh)
    setTimeout(this.obj+".slide("+dx+","+dy+","+endx+","+endy+","+speed+",'"
    +fn+"','"+wh+"')",speed)
  }else{
    this.slideactive = 0; 
    this.moveIt(endx,endy);
    if(fn) eval(fn)
  }
}

//Circle animation ****************
lib_obj.prototype.circleIt = function(rad,ainc,a,enda,xc,yc,speed,fn) {
  if((Math.abs(ainc)<Math.abs(enda-a))) {
    a += ainc
    var x = xc + rad*Math.cos(a*Math.PI/180)
    var y = yc - rad*Math.sin(a*Math.PI/180)
    this.moveIt(x,y)
    setTimeout(this.obj+".circleIt("+rad+","+ainc+","+a+","+enda+","
      +xc+","+yc+","+speed+",'"+fn+"')",speed)
  }else if(fn&&fn!="undefined") eval(fn)
}

//Document size object
function lib_doc_size(d){ 
  this.x = 0;
  this.x2 = bw.ie && document.body.offsetWidth-20||innerWidth||0;
  this.y = 0;
  this.y2 = bw.ie && document.body.offsetHeight-5||innerHeight||0;
  if(!this.x2||!this.y2) return message('Document has no width or height') 
  this.x50 = this.x2/2;
  this.y50 = this.y2/2;
  //
  if(d != 0){
  r = [];
  r['w'] = this.x2;
  r['h'] = this.y2;
  return r
  }
  else return this;
  //
}

	
// --- Drag drop functions start
dd_zx = 0
dd_is_active = 0;
dd_obj = 0;
dd_mobj = 0

function lib_dd(){
  dd_is_active = 1
  if(bw.ns4) document.captureEvents(Event.MOUSEMOVE|Event.MOUSEDOWN|Event.MOUSEUP)
  document.onmousemove = lib_dd_move;
  document.onmousedown = lib_dd_down
  document.onmouseup   = lib_dd_up
}

lib_obj.prototype.dragdrop = function(obj_h,minX,minY,maxX,maxY){
  							 if(!dd_is_active) lib_dd()
							 
  							 if(obj_h) this.handle = obj_h
  							 this.ct = (obj_h)?this.handle:'this'
							 
							 // Limites
							 this.minX = (typeof minX != 'undefined')?minX:null;
							 this.minY = (typeof minY != 'undefined')?minY:null;
							 this.maxX = (typeof maxX != 'undefined')?maxX:null;
							 this.maxY = (typeof maxY != 'undefined')?maxY:null;
							 
							 this._mx  = (this.minX != null && this.maxX != null)?1:0;
							 this._my  = (this.minY != null && this.maxY != null)?1:0;
							 this.cl   = (this._mx || this._my)?1:0;
							 
  							 with(eval(''+this.ct+'')){
							 evnt.onmouseover = new Function("lib_dd_over("+this.obj+")")
  							 evnt.onmouseout = new Function("dd_mobj = 0")
							 }
}

lib_obj.prototype.nodragdrop = function(){
							   with(eval(''+ this.ct +'')){
							   evnt.onmouseover = ""
  							   evnt.onmouseout = ""
							   }
							   //eval(""+r+".css.cursor = 'move'")
  							   dd_obj = 0; dd_mobj = 0
}

//Drag drop event functions
function lib_dd_over(obj){
	dd_mobj = obj
	r = (dd_mobj.handle)?dd_mobj.handle:'dd_mobj'
	eval(""+r+".css.cursor = 'move'")
}
function lib_dd_up(e){dd_obj = 0}

function lib_dd_down(e){
  if(dd_mobj){
  	x = (bw.ns4 || bw.ns6)?e.pageX:event.x||event.clientX
    y = (bw.ns4 || bw.ns6)?e.pageY:event.y||event.clientY
    dd_obj = dd_mobj;
	
    dd_obj.clX = x - dd_obj.x;
    dd_obj.clY = y - dd_obj.y
	
	dd_obj.setZ(++dd_zx)
  }
}

function lib_dd_move(e,y,rresize){
  x = (bw.ns4 || bw.ns6)?e.pageX:event.x||event.clientX
  y = (bw.ns4 || bw.ns6)?e.pageY:event.y||event.clientY
  if(dd_obj){
    nx = x - dd_obj.clX
	ny = y - dd_obj.clY

	if(dd_obj.cl == 1){
		if(dd_obj._mx == 1){
			if(nx >= dd_obj.maxX || nx <= dd_obj.minX){
				if(nx >= dd_obj.maxX) nx = dd_obj.maxX
				else if(nx <= dd_obj.minX) nx = dd_obj.minX
			}
		}
	}
		
	if(dd_obj._my == 1){
		if(ny >= dd_obj.maxY || ny <= dd_obj.minY){
			if(ny >= dd_obj.maxY) ny = dd_obj.maxY
			else if(ny <= dd_obj.minY) ny = dd_obj.minY
		}
	}

  dd_obj.moveIt(nx,ny)
  }
  if(!bw.ns4) return false      
}
// --- Drag drop functions end



function getPageOffsetLeft(el){
  var x;
  // Return the x coordinate of an element relative to the page.
  if(!document.layers){
  x = el.offsetLeft;
  if(el.offsetParent != null) x += getPageOffsetLeft(el.offsetParent)
  }
  else x = el.x
  return x;
}

function getPageOffsetTop(el){
  var y;
  // Return the x coordinate of an element relative to the page.
  if(!document.layers){
  y = el.offsetTop;
  if(el.offsetParent != null) y += getPageOffsetTop(el.offsetParent);
  }
  else y = el.y
  return y;
}










