/*
window.browser   __browser 
getScrollPosition __scroll_pos 
__set_style  __set_style 
__get_style  __get_style 
_Extend  __extend 
__remove 
__hide 
__show 
__create_styles_copy  
__compare_styles_copy 

VOIR .toUpperCase()  SUR LES COMPARAISON DE TYPE =='string' 
*/

var ALIAS_EVENT = "dataavailable";

/* ---------------------------------------------------------- DEBUG LOG */
function __log(str){ 
	if(typeof(str) == 'object') {
		var arr = str ; var r = ""; 
		for(a in arr) { r = r + ' ' +  a + ':'+ arr[a] + '<br>' ; };
		str = r;
	}
	var deb = __e('debuginfo');
	if(!deb){
		dbody = document.getElementsByTagName("body")[0];
		deb = document.createElement('div'); 
		deb.id = 'debuginfo';
		deb = __e(deb);
		dbody.appendChild(deb);
		
		__absolutize(deb); 
		__set_style(deb,'opacity',0.9);
		__set_style(deb,'background-color', "#225522");
		__set_style(deb,'color', "#FFFFFF");
		__set_style(deb,'top', "0px");
		__set_style(deb,'left', "700px");
		__set_style(deb,'border', "1px solid #999999");
	}
	deb.innerHTML = deb.innerHTML + str + '<br>' ;
} 

__e = function(obj){
	if(obj == null) return;
	if(typeof obj == "string" && obj != ""){  
		var ret = document.getElementById(obj); 
		if(!ret) {
			var btags = document.getElementsByTagName(obj.toUpperCase());
			if(btags.length > 0) ret = btags.item(0) ;
		}
		if(!ret) return null;
		obj = ret;
	} 
	return obj;
}

__i  = function (id, cap, _params){ 
	var element = __e(id);
	if(!element) return; 
	if(!_params) _params = {};
	var def = _Capability[cap];  
	if(!def) throw 'install cap without def :' + cap + '' + element; 
	if(element[cap + '_params'])return;
	__extend(element, def); 
	if(!element.ensureParameter ){  
		element.ensureParameter = function(cap, key, value){ 
			if(! element[cap + '_params'].hasOwnProperty(key) ) element[cap + '_params'][key] = value;
		}
	}
	element[cap + '_params'] = _params;
	element[cap](cap, element[cap + '_params']);
}

var __extend = function(def, props){ 
	var map = function(pro,Func){ 
	    if(pro.constructor!==Object){ 
	        return null 
	    } 
	    var i=0; for(var p in pro){
	        if(pro.hasOwnProperty(p)){
	        	Func(p,pro[p],i);
	        	i++;
	        }
	    }
	};
	map(props, 
    function(key,val){
        if(!def[key]){ def[key] = val;} else {
        	def['__parent_' + key] = def[key];
        	def[key] = val;
        }
    }); 
	return def; 
};

__extend(String.prototype,{
	trim: function() {
	    return this.replace(/(^\s*)|(\s*$)/g, "")
	},
	camelize: function() {
	    return this.replace(/-\D/g,
	    function(A) {
	        return A.charAt(1).toUpperCase()
	    })
	},
	capitalize: function() {
	    return this.charAt(0).toUpperCase() + this.substring(1).toLowerCase();
	}
});

__capability = function(name, def){ 
	if(__capability[name])return; 
	__capability[name] = def;  
	__capability[name]._capId = name; 
}
_Capability = __capability;


var __class = function(name , def , def2){  
	if(!def2){
		var classDef = function(){
			  if(this.initialize) this.initialize.apply(this, arguments);
		};
		__extend(classDef, def);
	}else{
		var classDef = def.prototype;
		__extend(classDef, def2);
	}
	classDef.prototype = classDef;
	classDef.prototype.constructor = classDef;
	classDef.prototype.__className = name;
	__class[name] = classDef;
	eval(  name + '=' + '__class["'+ name +'"]');
};

var __browser = {
	IE: !!(window.attachEvent && !window.opera) ? true: false,
	Opera: !!window.opera ? true: false,
	WebKit: navigator.userAgent.indexOf("AppleWebKit/") > -1 ? true: false,
	Gecko: navigator.userAgent.indexOf("Gecko") > -1 && navigator.userAgent.indexOf("KHTML") == -1 ? true: false,
	MobileSafari: !!navigator.userAgent.match(/Apple.*Mobile.*Safari/) ? true: false,
	Safari: !!navigator.userAgent.match(/Apple.*Safari/) ? true: false,
	FireFox: navigator.userAgent.indexOf("Fire/") > -1 ? true: false
};

var __window_dims = function(){
	return {  width: __window_width() , height: __window_height() };   
}

var __window_width = function() {
    var w = window.WebKit && !document.evaluate ? self.innerWidth: __browser.Opera ? document.body.clientWidth: document.documentElement.clientWidth
    return parseInt(w);
}

var __window_height = function() { 
    var h = window.WebKit && !document.evaluate ? self.innerHeight: __browser.Opera ? document.body.clientHeight: document.documentElement.clientHeight
    return parseInt(h);
} 

var __scroll_pos = function() {  
	
	var position = [0, 0];
	if (typeof window.pageYOffset != 'undefined')
	{ position = [ window.pageXOffset, window.pageYOffset ]; }
	else if (typeof document.documentElement.scrollTop
	!= 'undefined' && document.documentElement.scrollTop > 0) {
		position = [ document.documentElement.scrollLeft, document.documentElement.scrollTop ]; }
	else if (typeof document.body.scrollTop != 'undefined')
	{ position = [ document.body.scrollLeft, document.body.scrollTop ]; }
		position[0] = parseInt(position[0]);
		position[1] = parseInt(position[1]);
	var rpos = {
				left:position[0] , top:position[1]
	};
	return rpos;
}

__get_style  = function(e, s){
	   var C = s;
	   if (C == "opacity" && __browser.IE && ! e.style.opacity) {
	        if (value = (__get_style(e,"filter") || "").match(/alpha\(opacity=(.*)\)/)) {
	            if (value[1]) {
	                return parseFloat(value[1]) / 100
	            }
	        }
	        return 1;
	    }
	    var C = C == "float" ? "cssFloat": C.camelize();
	    var B = e.style[C];
	    if ( (C == "margin" || C == "padding") && !B) {
	        B = [];
	        for(AN in ["Top", "Right", "Bottom", "Left"]){
	            var Q = e.getStyle(C + AN);
	            var P = (Q ? Q: 0);
	            B = B + ' ' + P;
	        }
	        return B;
	    }
	  	if (!B) {
	        if (window.getComputedStyle) {
	            var A = document.defaultView.getComputedStyle(e, null) || null; 
	            B = A ? A[C] : null;
	        } else {
	            B = e.currentStyle[C];
	        } 
	    }
	    if (!B || B == "undefined") {
	        return null;
	    }
	    B  = B + "";
	    if (B == "auto" || B.lastIndexOf('%')  > 0) {
	        if ((C == "width" || C == "height") && (
	        		__get_style(e,"display") != "none")  
	        		
	        ) {
	            return e["offset" + C.capitalize()]; 
	        }
	        return 0;
	    }
	    if (B == "rgba(0, 0, 0, 0)") {
	        return "transparent";
	    }
	    
	    B  = B+'';  
	    if(B.indexOf('px') > 0 && B.indexOf(' ') < 0){
	    	var v = parseInt(B);   
			return v;
		}
	    
	    return B;
};

__set_style = function(e,s,v){  
	v+='';  
	if(v.indexOf('#') > 0){ 
		e.style[s.camelize()] = v;  
		return; 
	}
	if(s=="float") s="cssFloat"; 
	if (s == "opacity") { 
		var A = parseFloat(v);
		if (A > 1) { A = 1 }  
		if (A < 0.001) {  A = 0 }
		if (__browser.IE) {
		    e.style.filter = "alpha(opacity=" + A * 100 + ")"
		}
		e.style.opacity = A;
		return;
	}
	if(s == 'zoom' || s == 'opacity' ) v = parseFloat(v);  
	if(s == 'width' || s == 'height'
		 ||  s == 'top' || s == 'left'  ||  s == 'border-width' || s == 'border-left' 
	)  v = parseInt(v) + 'px'; 
	if(s.camelize()  == 'fontSize' ) {
		 v = parseInt(v) + 'pt'; 
	}
	e.style[s.camelize()] = v; 
};

__create_styles_copy = function(e){
	var cs = {
		element:e,
		getVal : function(p){
			var pc = p.camelize();
			if(pc != 'opacity' &&  pc != 'zoom' )return parseInt(this[pc]);  
			else return parseFloat(this[pc]); 
		},
		setVal : function(p,v){
			p = p.camelize();
			if(p != 'opacity' &&  p != 'zoom' ) v = v + 'px';
			if(p == 'font-size' ) v = v + 'pt';
			this[p]=v;
		}
	};
	for(p in e.style){
		p = p.camelize();
		cs[p] = e.style[p];
	}
	cs['width'] = __get_style(e, 'width');
	cs['height'] = __get_style(e, 'height');
 	var pos = __get_pos(e);
 	cs['top'] = pos.top;
 	cs['left'] = pos.left;
 	cs['opacity'] = __get_style(e,'opacity');
 	cs['zoom'] = e.style.zoom;
 	cs['marginTop'] = __get_style(e,'margin-top'); 
 	cs['marginLeft'] = __get_style(e,'margin-left'); 
 	cs['fontSize'] = __get_style(e,'font-size');
 	
	return cs;
}  

__compare_styles_copy = function(c, d){
	var cr = {};
	for(p in d){
		if(c[p] != d[p] && p != 'getVal' && p != 'setVal'  ){
			cr[p] = c[p];
		}
	}
	return cr;
}

__remove = function(e) {
	if(e.parentNode)e.parentNode.removeChild(e);
}

__hide = function(e) {
    e.style.display = "none";
}

__show = function(e) {
    e.style.display = "";
}

__absolutize = function(e) {
	if(__get_style(e, "position") == "absolute") {
        return ;
    }
    var A = __get_pos(e); 
    e.style.position = "absolute"; 
    e.style.top = A.top + "px"; 
    e.style.left = A.left + "px" 
}

__get_pos = function(C){
	var B = 0, 
	A = 0;
	do {
	   B += C.offsetTop || 0;
	   A += C.offsetLeft || 0;
	   C = C.offsetParent 
	} while ( C ); 
	return {
	  left: A,
	  top: B
	} 
}
__get_dims =  function(e) { 

    var D = __get_style(e, "display");
    if (D && D != "none") {
        return {
            width: e.offsetWidth, 
            height: e.offsetHeight  
        } 
    }
    var B = { 
        visibility: e.visibility,  
        position: e.style.position,  
        display: e.style.display 
    };  
    this.visibility = "hidden";  
    if (__browser.IE) {   
        e.style.position = "absolute"  
    }  
    __show(e); 
    var A = e.clientWidth; 
    var C = e.clientHeight; 
    e.style.display = B.display;
    if (__browser.IE) {
        e.style.position = B.position
    }
    e.visibility = B.visibility;
    return {
        width: A,
        height: C
    }
}

__clone_to = function(e){ 
	var c = e.cloneNode(true);
	if(c.id) c.id = 'c_' + c.id; 
	//__clone_to.cloneIds(c);
    return __e(c);  
}

__get_parent_by_property = function(obj, cap){
	var fobj = obj;
	if(fobj[cap])return fobj;   
		if(obj.parentNode) { 
			do{
				  obj = fobj;
				 
				  if( fobj[cap]) return fobj;  
			} while(fobj = obj.parentNode);   
	}
	return false;
}

__get_form_value = function(e) {  
    var C = e.tagName.toLowerCase();
    var B = e.type ? e.type.toLowerCase() : null; 
    var A = null;
    if (C == "select" || C == "textarea") {
            return e.value;
        }
    if (C == "input" && C != "button" && C != "submit" && C != "radio" && C != "checkbox") {
            return e.value;
        }
    if (C == "input" && B == "checkbox") {
            return e.checked;
        }
    if (C == "input" && B == "radio") {
      // __e(document.getElementsByName(e.name)).each(function(D) {
      //           if (D.checked) {
      //               A = D.value;
      //           }
      //  })
    }
    return A;
}

__element_from_class  = function(cssclass,tag){  
    if(!tag)tag ='div'; 
    var m = __e(document.createElement(tag));
    m.setAttribute('class',cssclass); 
    m.setAttribute('className',cssclass); 
    __hide(m);
    return __e(m);   
}

__add_class = function(element , cssclass){
	var c = __get_class(element); 
	__set_class(element, c + ' ' + cssclass);
} 

__remove_class = function(element , cssclass){
	var c = __get_class(element);  
	c = c.replace(cssclass, '');
	__set_class(element, c);
} 

__set_class  = function(element , cssclass){  
    element.setAttribute('class',cssclass); 
    element.setAttribute('className',cssclass); 
}

__get_class = function(element){  
    var cl =   element.getAttribute('class');  
    if(cl == null) element.getAttribute('className'); 
    return cl;
}

__scope_timeout = function(scope, fnc, duration){
	if(!duration) duration = 300;
	window.setTimeout(__scope(scope, fnc), duration); 
}