

// *******************************************************************************
// **********************  LIBRAIRIE JAVASCRIPT  *********************************                                            
// *******************************************************************************



//============================================================ 
// Détermine le navigateur
//============================================================ 
var nsv=document.layers;
var iev=document.all;
if(!iev)var mov=document.getElementById;
var MouseX=0; 
var MouseY=0;
var ScrollX=0;
var ScrollY=0;


//============================================================ 
// Retourne la position des scrollbars
//============================================================ 
function GetScrollPos(){
var curScrollX=ScrollX;
var curScrollY=ScrollY;
if(nsv){
ScrollX=window.pageXOffset;
ScrollY=window.pageYOffset;
}else{
if(document.documentElement.scrollLeft)
ScrollX=document.documentElement.scrollLeft;
else ScrollX=document.body.scrollLeft;
if(document.documentElement.scrollTop)
ScrollY=document.documentElement.scrollTop;
else ScrollY=document.body.scrollTop;
}
if(curScrollX!=ScrollX||curScrollY!=ScrollY) NewScrollPos();
}


//============================================================ 
// Retourne la position de la souris
//============================================================ 
function GetMousePos(e){
var curMouseX=MouseX;
var curMouseY=MouseY;
if(nsv){
MouseX=e.pageX-2-ScrollX;
MouseY=e.pageY-2-ScrollY;
}else if(mov){
MouseX=e.clientX;
MouseY=e.clientY;
}else{ 
MouseX=window.event.x;
MouseY=window.event.y;
if((navigator.userAgent).indexOf('Opera',0)<0){ 
MouseX=MouseX-2; 
MouseY=MouseY-2;
}
}
if(curMouseX!=MouseX||curMouseY!=MouseY) NewMousePos();
}


//============================================================ 
// Permet de get par class
//============================================================ 
function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

// **********************************************************************************************
// **********************************************************************************************
// ***************************** TICKER *********************************************************
// **********************************************************************************************
// **********************************************************************************************

var offsetxpoint=20 //Customize x offset of tooltip
var offsetypoint=-10 //Customize y offset of tooltip
var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
if (ie||ns6)

function ietruebody()
{
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function ddrivetip(thetext, thecolor, thewidth)
{
	var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : "";
	if (ns6||ie)
	{
		if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
		if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
		tipobj.innerHTML='<div class="dhtmltooltip_inner" style="display:none;" id="dhtmltooltip_appear"><img src="'+thetext+'"></div>'
		new Effect.Appear('dhtmltooltip_appear');
		enabletip=true
		return false
	}
}

function positiontip(e)
{
	if (enabletip)
	{
		var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""
		var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
		var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
		//Find out how close the mouse is to the corner of the window
		var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20
		var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20

		var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000

		//if the horizontal distance isn't enough to accomodate the width of the context menu
		if (rightedge<tipobj.offsetWidth)
		//move the horizontal position of the menu to the left by it's width
		tipobj.style.left=ie? ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth+"px" : window.pageXOffset+e.clientX-tipobj.offsetWidth+"px"
		else if (curX<leftedge)
		tipobj.style.left="5px"
		else
		//position the horizontal position of the menu where the mouse is positioned
		tipobj.style.left=curX+offsetxpoint+"px"

		//same concept with the vertical position
		if (bottomedge<tipobj.offsetHeight)
		tipobj.style.top=ie? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px"
		else
		tipobj.style.top=curY+offsetypoint+"px"
		tipobj.style.visibility="visible"
	}
}

function hideddrivetip(){
	if (ns6||ie)
	{
		enabletip=false;
		var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""
		tipobj.style.backgroundColor='';
		tipobj.style.width='';
		document.getElementById("dhtmltooltip_appear").style.display="none";
		//new Effect.Fade('dhtmltooltip_appear', { duration: 0.2 });
	}
}
document.onmousemove=positiontip





// *******************************************************************************
// **********************  TITLE REPLACE  ****************************************                                            
// *******************************************************************************

var qTipTag = "a"; //Which tag do you want to qTip-ize? Keep it lowercase!//
var qTipX =-30; //This is qTip's X offset//
var qTipY =25; //This is qTip's Y offset//



//There's No need to edit anything below this line//
tooltip = {  name : "qTip",  offsetX : qTipX,  offsetY : qTipY,  tip : null}

tooltip.init = function () {
	var tipNameSpaceURI = "http://www.w3.org/1999/xhtml";
	if(!tipContainerID){ var tipContainerID = "qTip";}
	var tipContainer = document.getElementById(tipContainerID);

	if(!tipContainer) {
	  tipContainer = document.createElementNS ? document.createElementNS(tipNameSpaceURI, "div") : document.createElement("div");
		tipContainer.setAttribute("id", tipContainerID);
	  document.getElementsByTagName("body").item(0).appendChild(tipContainer);
	}

	if (!document.getElementById) return;
	this.tip = document.getElementById (this.name);

	var a, sTitle;
	var anchors = document.getElementsByTagName (qTipTag);

	for (var i = 0; i < anchors.length; i ++) {
		a = anchors[i];
		sTitle = a.getAttribute("title");
		if(sTitle && sTitle.substr(0, 1)== "*") {
			sTitle=sTitle.substring(1, sTitle.length);		
			a.setAttribute("tiptitle", sTitle);
			a.removeAttribute("title");
			a.onmouseover = function() {tooltip.show(this.getAttribute('tiptitle'))};
			a.onmouseout = function() {tooltip.hide()};
		}
	}
}

tooltip.move = function (evt) {
	var x=0, y=0;
	if (document.all) {//IE
		x = (document.documentElement && document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft;
		y = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
		x += window.event.clientX;
		y += window.event.clientY;
		
	} else {//Good Browsers
		x = evt.pageX;
		y = evt.pageY;
	}
	this.tip.style.left = (x + this.offsetX) + "px";
	this.tip.style.top = (y + this.offsetY) + "px";
}

tooltip.show = function (text) {
	if (!this.tip) return;
	this.tip.innerHTML = text;
	this.tip.style.display="block";
	if (this.tip) document.onmousemove = function (evt) {tooltip.move (evt)};
}

tooltip.hide = function () {
	if (!this.tip) return;
	this.tip.innerHTML = "";
	this.tip.style.display = "none";
}

window.onload = function () {
	tooltip.init ();
}




// **********************************************************************************************
// **********************************************************************************************
// ******************************MENU CATEGORIES ************************************************
// **********************************************************************************************
// **********************************************************************************************

function montre(id, pnlName) {
	
	
	
	var d = document.getElementById(id);
	
	/*var el = getElementsByClass('enfant',document,'*');
	for (var i=0; i < el.length ; i++) {
		el[i].style.display='none';
	}*/
	
		new Effect.toggle(d,'blind', {duration:0.3});
		
}

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}



// **********************************************************************************************
// **********************************************************************************************
// ****************************** SLIDING PHOTOS ************************************************
// **********************************************************************************************
// **********************************************************************************************
	
		imgPath = new Array;
		
		function generate (source1,source2,source3,url,target){
			if (document.images)
			{
			i0 = new Image;	
			i0.src = source1;
		
			imgPath[0] = i0.src;
			i1 = new Image;
			i1.src = source2;
		
			imgPath[1] = i1.src;
			i2 = new Image;
			i2.src = source3;
		
			imgPath[2] = i2.src;
			}
			a = 0;
			StartAnim(source1,url,target);
		}
		
		function ejs_img_fx(img)
			{
			if(img && img.filters && img.filters[0])
				{
				img.filters[0].apply();
				img.filters[0].play();
				}
			}
		
		function StartAnim(source1)
			{
			if (document.images)
				{
				document.write('<IMG SRC="'+source1+'" BORDER=0 NAME=defil style="FILTER: blendTrans(duration=1)" width="334" height="203">');
				defilimg()
				}
			else
				{document.write('<IMG SRC="'+source1+'"  BORDER=0>')}
			}
			
		function ImgDest()
			{
			document.location.href = SiClickGoTo[a-1];
			}
			
		function defilimg()
			{
			if (a == 3)
				{
				a = 0;
				}
			if (document.images)
				{
				ejs_img_fx(document.defil)
				document.defil.src = imgPath[a];
				tempo3 = setTimeout("defilimg()",4000);
				a++;
				}
			}

// **********************************************************************************************
// **********************************************************************************************
// **********************************    GLIDER      ********************************************
// **********************************************************************************************
// **********************************************************************************************

dynObj.holder = {}; 
// constructor
function dynObj(id,x,y,w,h) {
  var el = dynObj.getElemRef(id);
  if (!el) return;  this.id = id; 
  dynObj.holder[this.id] = this; this.animString = "dynObj.holder." + this.id;
  var px = window.opera? 0: "px";
	this.x = x || 0;	if (x) el.style.left = this.x + px;
	this.y = y || 0;	if (y) el.style.top = this.y + px;
	this.w = w || el.offsetWidth || 0;	this.h = h || el.offsetHeight || 0;
	// if w/h passed, set style width/height
	if (w) el.style.width = w + px; if (h) el.style.height = h + px;
}

dynObj.getElemRef = function(id) { 
  var el = document.getElementById? document.getElementById(id): null;
  return el;
} 

dynObj.getInstance = function(id) {
  var obj = dynObj.holder[id];
  if (!obj) obj = new dynObj(id);
  else if (!obj.el) obj.el = dynObj.getElemRef(id);
  return obj;
}

dynObj.prototype.shiftTo = function(x,y) {
  var el = this.el? this.el: dynObj.getElemRef(this.id)? dynObj.getElemRef(this.id): null;
  if (el) {
    if (x != null) el.style.left = (this.x = x) + "px";
    if (y != null) el.style.top = (this.y = y) + "px";
  }
}

dynObj.prototype.shiftBy = function(x,y) { this.shiftTo(this.x+x, this.y+y); }

dynObj.prototype.show = function() { 
  var el = this.el? this.el: dynObj.getElemRef(this.id)? dynObj.getElemRef(this.id): null;
  if (el) el.style.visibility = "visible";
}
dynObj.prototype.hide = function() { 
  var el = this.el? this.el: dynObj.getElemRef(this.id)? dynObj.getElemRef(this.id): null;
  if (el) el.style.visibility = "hidden"; 
}

// for time-based animations
// resources: www.13thparallel.org and www.youngpup.net (accelimation)
var dw_Bezier = {
  B1: function (t) { return t*t*t },
  B2: function (t) { return 3*t*t*(1-t) },
  B3: function (t) { return 3*t*(1-t)*(1-t) },
  B4: function (t) { return (1-t)*(1-t)*(1-t) },
  // returns current value based on percentage of time passed
  getValue: function (percent,startVal,endVal,c1,c2) {
    return endVal * this.B1(percent) + c2 * this.B2(percent) + c1 * this.B3(percent) + startVal * this.B4(percent);
  }
}

// adapted from accelimation.js by Aaron Boodman of www.youngpup.net
dw_Animation = {
  instances: [],
  add: function(fp) {
    this.instances[this.instances.length] = fp;
  	if (this.instances.length == 1) this.timerID = window.setInterval("dw_Animation.control()", 10);
  },
  
  remove: function(fp) {
    for (var i = 0; this.instances[i]; i++) {
  		if (fp == this.instances[i]) {
  			this.instances = this.instances.slice(0,i).concat( this.instances.slice(i+1) );
  			break;
  		}
  	}
  	if (this.instances.length == 0) {
  		window.clearInterval(this.timerID);	this.timerID = null;
  	}
  },
  
  control: function() {
    for (var i = 0; this.instances[i]; i++) {
  		if (typeof this.instances[i] == "function" ) this.instances[i]();
      else eval(this.instances[i]);
    }
  }
}

Glider.holder = [];
function Glider(id,x,y,w,h,d,ac) {
	this.glideDur = d || 1000; this.origX = x; this.origY = y; this.ac = -ac || 0;
	this.baseObj = dynObj;
	this.baseObj(id,x,y,w,h);
  Glider.holder[Glider.holder.length] = this;
  if (!Glider.winHt) Glider.winHt = getWinHeight();
}
Glider.prototype = new dynObj;
Glider.prototype.onGlideInit = function () {}

Glider.prototype.checkGlider = function() {
	var destY = getScrollY() + this.origY;
	if (destY != this.y) {
		if (destY != this.dy) {
			this.dy = destY;
			this.glideInit();
      this.onGlideInit();
		} 
		this.glide();
	}
}

Glider.prototype.glideInit = function() {
	this.gt = new Date().getTime();
	var distY = this.dy - this.y;
	if ( Math.abs(distY) > Glider.winHt ) {	// distance greater than window height?
		this.gsy = (distY > 0)? this.dy - Glider.winHt: this.dy + Glider.winHt;
	} else this.gsy = this.y;
  this.g_yc1 = this.gsy + ( (1+this.ac) * (this.dy - this.gsy)/3 );
	this.g_yc2 = this.gsy + ( (2+this.ac) * (this.dy - this.gsy)/3 );
}

Glider.prototype.glide = function() {
	var elapsed = new Date().getTime() - this.gt;
  if (elapsed < this.glideDur) {
    var y = dw_Bezier.getValue( elapsed/this.glideDur, this.gsy, this.dy, this.g_yc1, this.g_yc2 );
    this.shiftTo(null,y);
  } else this.shiftTo(null,this.dy);
}

Glider.control = function() {
  for (var i=0; Glider.holder[i]; i++) {
    var curObj = Glider.holder[i];
    if (curObj) curObj.checkGlider();
  }
}
//Glider.timer = setInterval("Glider.control()",20);
dw_Animation.add(Glider.control);

// returns height of window
function getWinHeight() {
	var winHt = 0;
	if (window.innerHeight) winHt = window.innerHeight-18;
	else if (document.documentElement && document.documentElement.clientHeight) 
		winHt = document.documentElement.clientHeight;
	else if (document.body && document.body.clientHeight) 
		winHt = document.body.clientHeight;
	return winHt;
}	

// returns amount of vertical scroll
function getScrollY() {
	var sy = 0;
	if (document.documentElement && document.documentElement.scrollTop)
		sy = document.documentElement.scrollTop;
	else if (document.body && document.body.scrollTop) 
		sy = document.body.scrollTop; 
	else if (window.pageYOffset)
		sy = window.pageYOffset;
	else if (window.scrollY)
		sy = window.scrollY;
	return sy;
}

// onresize, get window height
if (window.addEventListener)
  window.addEventListener("resize", function(){ Glider.winHt = getWinHeight(); }, "false");
else if (window.attachEvent)
  window.attachEvent("onresize", function(){ Glider.winHt = getWinHeight(); } );
  


/**********************************************************************************************************************/
/********************************************BORDER INPUT *************************************************************/
/**********************************************************************************************************************/

function inputBorder(){
for(j=0;j<document.forms.length;j++){
	for(i=0;i<document.forms[j].elements.length;i++){
		var element = document.forms['aspnetForm'].elements[i];	
			if(document.getElementsByTagName("INPUT") || document.getElementsByTagName("TEXTAREA")){
				if(element.parentNode.className=="input"){
					element.onfocus=function(){
					this.parentNode.className="inputBorder";
					}
					element.onblur=function(){
					this.parentNode.className="input";
					}
				}
				if(element.className == "input"){
					element.onfocus=function(){
					this.className="inputBorder";
					}
					element.onblur=function(){
					this.className="input";
					}
				}
			}
		}
	}
}

// *******************************************************************************
// *******************************************************************************
// ******************************** POPUP **************************************
function synchrone_popup(url,winname,width,height,scrollbars) 
{
	var toolbar=0;
	var location=0;
	var directories=0;
	var status=0;
	var resizable=0;
	var copy=0;
	var menubar=0;
	var ScreenWidth=window.screen.width;
	var ScreenHeight=window.screen.height;
	var movefromedge=0;
	   
		placementx=(ScreenWidth/2)-((width)/2);
		placementy=(ScreenHeight/2)-((height)/2);

	var base_href = "";
	var theBase = document.getElementsByTagName("base");

	if (theBase[0] != undefined && url.substr(0, 4).toLowerCase() != "http")
	{
		base_href = theBase[0].href+"/";
	}	
	return window.open(base_href+url,"","width="+width+",height="+height+",toolbar="+toolbar+",location="+location+",directories="+directories+",status="+status+",scrollbars="+scrollbars+",menubar="+menubar+",resizable="+resizable+",left="+placementx+",top="+placementy+",screenX="+placementx+",screenY="+placementy+",");
}

// *******************************************************************************
// *******************************************************************************
// ******************************* DRAG ***************************************
function drag(id){
new Draggable(id,{scroll:window,handle:id});
document.getElementById(id).style.cursor="move";
}


// *******************************************************************************
// *******************************************************************************
// ******************************* OVERLAY ***************************************
function showOverlay(){
	var arrayPageSize = getPageSize();
	
	Element.setHeight('overlay', arrayPageSize[1]);
	new Effect.Appear('overlay', { duration: 0.2, from: 0.0, to: 0.8 });

}

function hideOverlay(div){
	new Effect.Fade(div);					
	document.getElementById("overlay").style.display = "none";
}

// ------ Affichage d'un DIV -------------
	
	function showDiv(div){		
		// args: id, left, top, w, h, duration of glide to location onscroll, acceleration factor
		// acceleration factor should be -1 to 1. -1 is full deceleration
		showOverlay()

		document.getElementById(div).style.display="block";
		var posX = (document.documentElement.clientWidth/2)-(document.getElementById(div).offsetWidth/2);

		document.getElementById(div).style.left=posX+"px";
		
		var glideDiv = new Glider(div,posX,100,null,null,500,-1);
		glideDiv.show();		
	}
	
	// ------ Désaffichage d'un DIV -------------
	function hideDiv(div){					
		
		hideOverlay(div);

		if(div == "popShoppingCart"){
			document.location.href=document.location.href;
		}
	}
