/* MODULE - Class*/
var Class =
{
    // Creators
    create: function (proto)
    {
        var klass = function ()
        {
            if (this.initialize && arguments.callee.caller != Class.extend)
            {
                this.__class__ = arguments.callee.prototype;
                Object.extend(this, Class.Methods);
                this.initialize.apply(this, arguments);
            }
        };
        klass.prototype = proto || {};
        klass.extend = Class.extend;
        return klass;
    },
    singleton: function (proto)
    {
        var klass =
        {
            instance: function ()
            {
                if (!this.__instance__)
                {
                    var klass = Class.create(proto);
                    this.__instance__ = eval('new klass');
                    proto = null;
                }
                return this.__instance__;
            }
        };
        return klass;
    },
    append_features: function (object, module)
    {
        for (var prop in module)
            if (Class.kind_of(module[prop], Function))
                (function (method)
                {
                    object[method] = function ()
                    {
                        return module[method].apply(object, arguments);
                    };
                })(prop);
            else
                object[prop] = module[prop];
    },
    extend: function (subobj)   // implementation of inheritance
    {
        /* Create an instance of the superclass.  This is necessary to maintain
         * a prototype chain correctly.
         */
        var subproto = new this;
        // Update it with the subclass definitions
        Object.extend(subproto, subobj);
        subproto.__super__ = this.prototype;
        return Class.create(subproto);
    },
    get_method: function (klass, args)  // obtain method name being called
    {
        var c = args.callee.caller;
        for (var method in klass)
            if (klass[method] == c)
                return method;
        return null;
    },
    call_super: function (superclass, self, method, args)
    {
        // NOTE: `self' should always refer to the object being instantiated
        if (superclass && superclass[method])
        {
            /* Make the next call of `this.SUPER()' in the superclass refer
             * farther up the class hierarchy */
            var __class__  = self.__class__;
            self.__class__ = superclass;
            self.__super__ = superclass.__super__;

            try
            {
                superclass[method].apply(self, args);
            }
            finally
            {
                // Restore values
                self.__class__ = __class__;
                self.__super__ = superclass;
            }
        }
    },
    kind_of: function (object, klass)
    {
        return eval('klass.prototype.isPrototypeOf(object)');
    }
};

/*
 * MODULE - Class instance methods
 * Mixed into class-instances, so that these methods will become available asinstance methods
 */
Class.Methods =
{
    extend: function ()
    {
        var i = arguments.length;
        while (--i >= 0)
            Object.extend(this, arguments[i]);
        return this;
    },
    include: function ()
    {
        var i = arguments.length;
        while (--i >= 0)
            Class.append_features(this, arguments[i]);
        return this;
    },
    kind_of: function (klass)
    {
        return Class.kind_of(this, klass);
    },
    SUPER: function ()
    {
        var method = Class.get_method(this.__class__, arguments);
        Class.call_super(this.__super__, this, method, arguments);
    }
};
/*----------------------------- /SUPER CLASS -------------------------*/

// JavaScript Document
Object.extend(Event, {
  _domReady : function() {
    if (arguments.callee.done) return;
    arguments.callee.done = true;

    if (this._timer)  clearInterval(this._timer);
    
    this._readyCallbacks.each(function(f) { f() });
    this._readyCallbacks = null;
},
  onDOMReady : function(f) {
    if (!this._readyCallbacks) {
      var domReady = this._domReady.bind(this);
      
      if (document.addEventListener)
        document.addEventListener("DOMContentLoaded", domReady, false);
        
        /*@cc_on @*/
        /*@if (@_win32)
            document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
            document.getElementById("__ie_onload").onreadystatechange = function() {
                if (this.readyState == "complete") domReady(); 
            };
        /*@end @*/
        
        if (/WebKit/i.test(navigator.userAgent)) { 
          this._timer = setInterval(function() {
            if (/loaded|complete/.test(document.readyState)) domReady(); 
          }, 10);
        }
        
        Event.observe(window, 'load', domReady);
        Event._readyCallbacks =  [];
    }
    Event._readyCallbacks.push(f);
  }
});

// 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;
  });
}*/

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;
	},
	getOffSetPositionLeftIFrame: function(element,id_cible,id_a_sauter) {
		element = $(element);
		var position = 0;
		var saut = false;
		while (element && (element.id != id_cible.id))
		{
			if(element.id == id_a_sauter)
			{
				var saut = true				
			}
			if(!saut)
			{
				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);
  	},
	coordXY : function(objet,conteneur)
	{
			var pos_obj = Position.cumulativeOffset($(objet));
			var pos_c = Position.cumulativeOffset($(conteneur));
		//alert(pos_obj+' '+pos_c)
		return  [pos_obj[0] - pos_c[0],pos_obj[1] - pos_c[1]]
	},
	pointXY : function(obj,pos)
	{
		var objet = $(obj)
		var h = Element.getHeight(objet)
		var v = Element.getWidth(objet)
		var l = null;
		var t = null;
		switch(pos)
		{
			case 1: l = 0; t = 0;
			break;
			case 2: l = v/2; t = 0;
			break;
			case 3: l = v; t = 0;
			break;
			case 4: l = 0; t = h/2;
			break;
			case 5: l = v/2; t = h/2;
			break;
			case 6: l = v; t = h/2;
			break;
			case 7: l = 0; t = h;
			break;
			case 8: l = v/2; t =h;
			break;
			case 9: l = v; t = h;
			break;
		}
		return  [l,t]
	}
});

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);
			this.rollover_actif = true;
	   },
	   change_on: function(evt) {
		 if(this.rollover_actif) this.set_src_on();
	   },
	   change_off: function(evt) {
		 if(this.rollover_actif) this.set_src_off();
	   },
	   set_rollover_actif: function(bool) {
		 this.rollover_actif = bool;
	   },
	   set_src_off: function() {
		 this.image.src = this.source;
	   },
	   set_src_on: function() {
		 this.image.src = this.source_on;
	   }

	};
/* ------------------------ /Img_Rollover ---------------------------------*/
/* ------------------------ Input_value ---------------------------------*/
Input_value = Class.create();
Input_value.prototype = {
	   initialize: function(element) {
			this.element = $(element);
			this.value = this.element.value;
			//assigning our method to the event
			this.element.onfocus = this.enlever_value.bindAsEventListener(this);
			this.element.onblur = this.remettre_value.bindAsEventListener(this);
	   },
	   enlever_value: function(evt) {
		 this.element.value = '';
	   },
	   remettre_value: function(evt) {
		 if(this.element.value == "") this.element.value = this.value;
	   }
	};
/* ------------------------ /Input_value ---------------------------------*/
/* ------------------------ 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 ---------------------------------*/
/* ------------------------ Cookie ---------------------------------*/
var Cookie = {
  set: function(name, value, daysToExpire) {
    var expire = '';
    if (daysToExpire != undefined) {
      var d = new Date();
      d.setTime(d.getTime() + (86400000 * parseFloat(daysToExpire)));
      expire = '; expires=' + d.toGMTString();
    }
    return (document.cookie = escape(name) + '=' + escape(value || '') + expire);
  },
  get: function(name) {
    var cookie = document.cookie.match(new RegExp('(^|;)\\s*' + escape(name) + '=([^;\\s]*)'));
    return (cookie ? unescape(cookie[2]) : null);
  },
  erase: function(name) {
    var cookie = Cookie.get(name) || true;
    Cookie.set(name, '', -1);
    return cookie;
  },
  accept: function() {
    if (typeof navigator.cookieEnabled == 'boolean') {
      return navigator.cookieEnabled;
    }
    Cookie.set('_test', '1');
    return (Cookie.erase('_test') == '1');
  }
};
/* ------------------------ /Cookie ---------------------------------*/