// JavaScript Document
Object.extend(Element, {
   	getWidth: function(element) {
    element = $(element);
    return element.offsetWidth;
	},
    getX: function(element) {
    element = $(element);
    return (document.all)?element.style.pixelLeft:parseInt(element.style.left) 
	},
 	getY: function(element) {
    element = $(element);
    return (document.all)?element.style.pixelTop:parseInt(element.style.top) 
	},
	setX: function(element) {
    element = $(element);
    return (document.all)?element.style.pixelLeft:parseInt(element.style.left) 
	},
 	setY: function(element) {
    element = $(element);
    return (document.all)?element.style.pixelTop:parseInt(element.style.top) 
	},

  	htZoneAffichage: function() {
		var windowHeight=0;
		if (typeof(window.innerHeight)=='number') {
			windowHeight=window.innerHeight;
		}
		else {
		 if (document.documentElement&&
		   document.documentElement.clientHeight) {
			 windowHeight = document.documentElement.clientHeight;
		}
		else {
		 if (document.body&&document.body.clientHeight) {
			 windowHeight=document.body.clientHeight;
		  }
		}
    }
    return windowHeight;
	},
	getOffSetPositionTop: function(element) {
		element = $(element);
		var position = 0;
		while (element && element.tagName != 'body')
		{
			position += element.offsetTop;
			element = element.offsetParent;
		}
		return position;
	},
	getOffSetPositionLeft: function(element,id_cible) {
		element = $(element);
		var position = 0;
		while (element && (element.id != id_cible))
		{
			position += element.offsetLeft;
			element = element.offsetParent;
		}
		return position;
	},
  	getScrollTop: function() {
		return document.documentElement.scrollTop || document.body.scrollTop;
	},
 	fixeHeight: function(element) {
		element = $(element);
		Element.setStyle(element,{height:Element.getHeight(element)+'px'});
	},
	fixeWidth: function(element) {
		element = $(element);
		Element.setStyle(element,{width:Element.getWidth(element)+'px'});
	},
 	fixeElement: function(element) {
   		element = $(element)
		Element.fixeHeight(element)
		Element.fixeWidth(element)
	},
	versPosition: function(element) {
		element = $(element);
		var x = 0,
		   y=Element.getOffSetPositionTop(element);
		window.scrollTo(x, y);
  	}
});

// detection sur tout le document (et non body (original)); Ie5.5 : ne marche pas avec un parent
document.getElementsByClassName = function(className, parentElement) {
	var children = $(parentElement) ?  $(parentElement).getElementsByTagName('*') : document.all || document.getElementsByTagName('*');
	return $A(children).inject([], function(elements, child) {
    if (child.className.match(new RegExp("(^|\\s)" + className + "(\\s|$)")))
      elements.push(child);
    return elements;
  });
}

function mpx(element) {
	return parseInt(element.replace(/px/,""));
}

function ppx(element) {
	element = element.toString()
	return element.search(/px/)== -1 ? element+'px':element;
}
/* ------------------------ Img_Rollover ---------------------------------*/
Img_rollover = Class.create();
Img_rollover.prototype = {
	   initialize: function(img) {
			this.image = img;
			this.source = this.image.src;
			this.url = this.source.substring(0,this.source.lastIndexOf('.'));
			this.format = this.source.substring(this.source.lastIndexOf('.'),this.source.length);
			this.source_on = this.url+"_on"+this.format;
			//assigning our method to the event
			this.image.onmouseover = this.change_on.bindAsEventListener(this);
			this.image.onmouseout = this.change_off.bindAsEventListener(this);
	   },
	   change_on: function(evt) {
		 this.image.src = this.source_on;
	   },
	   change_off: function(evt) {
		  this.image.src = this.source;
	   }
	};
/* ------------------------ /Img_Rollover ---------------------------------*/
/* ------------------------ TimerExecuter ---------------------------------*/

var TimerExecuter = Class.create();
TimerExecuter.prototype = {
  initialize: function(callback, frequency) {
    this.callback = callback;
    this.frequency = frequency;
    this.currentlyExecuting = false;

    this.registerCallback();
  },

  registerCallback: function() {
    this.var_timer = setTimeout(this.onTimerEvent.bind(this), this.frequency * 1000);
  },
  
  arret: function() {
	clearTimeout(this.var_timer)
  },

  onTimerEvent: function() {
	this.callback();
  }
}
/* ------------------------ /TimerExecuter ---------------------------------*/