/******************************************
 * Interface: DIALib Main Class
 ******************************************/
function DIALib(xtn){

	//-->>> Add Class
	this.addClass = function(obj,cls){
		var arr = obj.className.split(' ');
		if(!arr.search(cls)) arr.push(cls);
		obj.className = arr.join(' ');
	}

	//-->>> Remove Class
	this.remClass = function(obj,cls){
		var arr = obj.className.split(' ');
		var index = arr.search(cls);
		if(index!=null) arr.splice(index,1);
		obj.className = arr.join(' ');
	}

	//-->>> Replace Class
	this.repClass = function(obj,cls1,cls2){
		var arr = obj.className.split(' ');
		var index = arr.search(cls1);
		if(index!=null) arr[index] = cls2;
		obj.className = arr.join(' ');
	}

	//-->>> Check if object have the specific class
	this.hasClass = function(obj,cls){ return obj.className.split(' ').search(cls) != null ? true : false; }

	//-->>> Create a new element with attributes and styles and append it to a parent (attribute in js format)
	this.create = function(tag,attr,prt,evt,fnc){
		var obj,i,attrs,prop;
		obj = document.createElement(tag);
		obj.dialib = DIALib_HTMLElement; obj.dialib();
		if(typeof prt != 'undefined'&&prt) this.append(prt,obj);
		if(typeof attr == 'string'){
			attr = attr.trim();
			if(attr != ''){
				attrs = attr.split(',');
				for(i=0;i<attrs.length;i++){
					prop = attrs[i].split('=');
					switch(prop[0].trim()){
						case 'class': obj.className = prop[1].trim().trimQuotes(); break;
						case 'opacity': obj.opacity(Number(prop[1].trim().trimQuotes())); break;
						case 'unSelectable': obj.disableSelection(); break;
						case 'style': obj.style.cssText = prop[1].trim().trimQuotes(); break;
						default: eval('obj.'+prop[0].trim()+'='+prop[1].trim()+";");
					}
				}
			}
		}
		if(typeof evt == 'string' && typeof fnc != 'undefined') this.bind(obj,evt,fnc);
		else if(typeof evt == 'object') for(var event in evt) this.bind(obj,event,evt[event]);
		return obj;
	}

	//-->>> Append an object to another object and return it
	this.append = function(prt,obj) {
		return typeof prt.appendChild != 'undefined' ? prt.appendChild(obj) : null;
	}

	//-->>> Bind an event to the object
	this.bind = function(obj,evt,fnc){
		if(typeof evt == 'string') return this.bindone(obj,evt,fnc);
		else if(typeof evt == 'object') for(var event in evt) this.bind(obj,event,evt[event]);
		return true;
	}
	//-->>> Bind one or more event to the object
	this.bindone = function(obj,evt,fnc){
		var clb = function(e){ if(!e) e = window.event; if(!e.target) e.target=e.srcElement; if(e.relatedTarget=='undefined') e.relatedTarget = e.toElement; fnc(e); }
		if(typeof obj.addEventListener != 'undefined') obj.addEventListener(evt,clb,false);
		else if(typeof obj.attachEvent != 'undefined') obj.attachEvent('on'+evt,clb);
		else obj.setAttribute('on'+evt,clb);
		return clb;
	}

	//-->>> Unbind an event to the object
	this.unbind = function(obj,evt,clb){
		if(typeof evt == 'string') { this.unbindone(obj,evt,clb); }
		else if(typeof evt == 'object') for(var event in evt) this.unbind(obj,event,evt[event]);
	}
	//-->>> Unbind one or more event to the object
	this.unbindone = function(obj,evt,clb){
		if(typeof obj.removeEventListener != 'undefined') obj.removeEventListener(evt,clb,false);
		else if(typeof obj.attachEvent != 'undefined') obj.detachEvent('on'+evt,clb);
		else obj.setAttribute('on'+evt,'');
	}

	//-->>> Cancel an event
	this.cancelEvent = function(evt){
		if(typeof evt.preventDefault!='undefined') evt.preventDefault();
		else if(typeof window.event!='undefined'){
			window.event.returnValue = false;
			if(typeof window.event.preventDefault!='undefined') window.event.preventDefault();
		}
		evt.returnValue = false;
	}

	//-->>> Stop event hierarchy propagation
	this.stopEventPropagation = function(evt){
		evt.cancelBubble = true;
		if(typeof evt.stopPropagation!='undefined') evt.stopPropagation();
	}

	//-->>> Fire an event on the specific object
	this.fire = function(elm,event){
		if (document.createEventObject){
			var evt = document.createEventObject();
			return elm.fireEvent('on'+event,evt)
		}else{
			var evt = document.createEvent("HTMLEvents");
			evt.initEvent(event, true, true );
			return !elm.dispatchEvent(evt);
		}
	}

	//-->>> Extend the class for other functionnalities
	this.implement = function(cls){
		eval('this.'+cls.toLowerCase()+'='+cls+';this.'+cls.toLowerCase()+'();');
	}

	//-->>> Load the constructor only when the page is loaded (buggy)
	this.safeinit = function(){
		if(typeof window.addEventListener != 'undefined') window.addEventListener('load',function() { self.init(); },false);
		else if(typeof document.addEventListener != 'undefined') document.addEventListener('load',function() { self.init(); },false);
		else if(typeof window.attachEvent != 'undefined') window.attachEvent('onload',function() { self.init(); });
		else window.onload = function() { self.init(); } // Another way should be with a window.setTimeout();
	}

	//-->>> Execute function at the windowload for safe initialisation
	this.windowLoad = function(fnc){
		if(typeof window.addEventListener != 'undefined') window.addEventListener('load',function() { fnc(); },false);
		else if(typeof document.addEventListener != 'undefined') document.addEventListener('load',function() { fnc(); },false);
		else if(typeof window.attachEvent != 'undefined') window.attachEvent('onload',function() { fnc(); });
		else window.onload = function() { fnc(); } // Another way should be with a window.setTimeout();
	}

	//-->>> Preload images
	this.preload = function(img){
		var i, imgs = new Array();
		if(typeof imgs == 'string') {
			imgs[0] = new Image();
			imgs[0].src = img;
		} else {
			for(i=0;i<img.length;i++){
				imgs[i] = new Image();
				imgs[i].src = img;
			}
		}
	}

	//-->>> Mask an element with an overlay
	this.mask = function(obj,opa){
		if(typeof obj.dialib == 'undefined'){ obj.dialib = DIALib_HTMLElement; obj.dialib(); }
		var overlay = this.create('div','',document.body)
		overlay.css('background-color: #000000; position: absolute; z-index: '+(obj.zIndex()+1)+'; left: '+obj.getOffsetLeft()+'px; top: '+obj.getOffsetTop()+'px; height: '+obj.offsetHeight+'px; width: '+obj.offsetWidth+'px;');
		overlay.opacity(typeof opa != 'undefined'?opa:0.3);
		overlay.disableSelection();
		obj.disableSelection();
		return overlay;
	}

	//-->>> Sleep in milliseconds (browser might be frozzen)
	this.sleep = function(delay){
		var start = new Date().getTime();
		while (new Date().getTime() < start + delay);
	}

	//-->>> Module Implementations
	if(typeof xtn == 'string') this.implement('DIALib_'+xtn);
	else if(typeof xtn != 'undefined') for(var i=0;i<xtn.length;i++) this.implement('DIALib_'+xtn[i]);

}



/******************************************
 * Interface: HTMLElement
 ******************************************/
function DIALib_HTMLElement() {

	//-->>> Add new Class
	this.addClass = function(cls){
		var arr = this.className.split(' ');
		if(!arr.search(cls)) arr.push(cls);
		this.className = arr.join(' ');
	}

	//-->>> Remove Class
	this.remClass = function(cls){
		var arr = this.className.split(' ');
		var index = arr.search(cls);
		if(index!=null) arr.splice(index,1);
		this.className = arr.join(' ');
	}

	//-->>> Replace Class
	this.repClass = function(cls1,cls2){
		var arr = this.className.split(' ');
		var index = arr.search(cls1);
		if(index!=null) arr[index] = cls2;
		this.className = arr.join(' ');
	}

	//-->>> Check if object have the specific class
	this.hasClass = function(cls){ return this.className.split(' ').search(cls) != null ? true : false; }

	//-->>> TODO: Revoir au complet
	//-->>> Disable selection by cursor
	this.disableSelection = function(element){
		if(Browser.app=='Firefox') this.style.MozUserSelect = 'none';
		else if(Browser.app=='Safari'||Browser.app=='Chrome') this.style.webkitUserSelect = 'none';
		else if(Browser.app=='MSIE') this.onselectstart = function(evt){ /*this.cancelEvent(evt); this.stopEventPropagation(evt);*/ return false; }
		else { this.onmousedown=function(){return false;} }
		//--> TODO: on a tu vraiment besoin de ondragstart ? ou avec un cancelevent ?
		this.ondragstart = function(evt){ /*this.cancelEvent(evt); this.stopEventPropagation(evt);*/ return false; }
	}

	//-->>> Set the opacity of the object
	this.opacity = function(prc){
		if(Browser.app=='MSIE') this.style.filter = 'alpha(opacity='+(prc*100)+')';
		else this.style.opacity = prc;
	}

	//-->>> Add new style in one text line
	this.css = function(cssText){
		var i,param,starr;
		var styles = new Array();
		var newstyles = new Array();
		starr = this.style.cssText.split(';');
		for(i=0;i<starr.length;i++){ if(starr[i].trim()!=''){ param = starr[i].split(':'); styles[param[0].trim()] = param[1].trim(); } }
		starr = cssText.split(';');
		for(i=0;i<starr.length;i++){ if(starr[i].trim()!=''){ param = starr[i].split(':'); styles[param[0].trim()] = param[1].trim(); } }
		for(i in styles) if(typeof styles[i] == 'string') newstyles.push(i+': '+styles[i]+';');
		this.style.cssText = newstyles.join(' ');
	}

	//-->>> Append a new object to this
	this.append = function(obj){
		return this.appendChild(obj);
	}

	//-->>> Get absolute top offset
	this.getOffsetTop = function(){
		var offElement=this, top = 0;
		while(offElement&&offElement.tagName!='BODY'){
			top = top + offElement.offsetTop;
			offElement = offElement.offsetParent;
		}
		return top;
	}

	//-->>> Get absolute left offset
	this.getOffsetLeft = function(){
		var offElement = this, left = 0;
		while(offElement&&offElement.tagName!='BODY'){
			left = left + offElement.offsetLeft;
			offElement = offElement.offsetParent;
		}
		return left;
	}

	//-->>> Get the highest z-index of the element/node
	this.zIndex = function(){
		var i,prt,chd,idx,_idx;
		idx = Browser.getZindex(this);
		prt = this.parentNode;
		while(prt.tagName!='BODY'){
			_idx = Browser.getZindex(prt);
			if(_idx>idx) idx = _idx;
			prt = prt.parentNode;
		}
		chd = this.getElementsByTagName('*');
		for(i=0;i<chd.length;i++){
			_idx = Browser.getZindex(chd[i]);
			if(_idx>idx) idx = _idx;
		}
		return idx;
	}

	//-->>> Bind one or more event
	this.bind = function(evt,fnc){
		if(typeof evt == 'string') this.bindone(evt,fnc);
		else if(typeof evt == 'object') for(var event in evt) this.bindone(event,evt[event]);
	}
	//-->>> Bind one event
	this.bindone = function(evt,fnc){
		var clb = function(e){ if(!e) e = window.event; if(!e.target) e.target=e.srcElement; if(e.relatedTarget=='undefined') e.relatedTarget = e.toElement; fnc(e); }
		if(typeof this.addEventListener != 'undefined') this.addEventListener(evt,clb,false);
		else if(typeof this.attachEvent != 'undefined') this.attachEvent('on'+evt,clb);
		else this.setAttribute('on'+evt,clb);
	}

	//-->>> Fire event
	this.fire = function(event){
		if (document.createEventObject){
			var evt = document.createEventObject();
			return this.fireEvent('on'+event,evt)
		}else{
			var evt = document.createEvent("HTMLEvents");
			evt.initEvent(event, true, true );
			return !this.dispatchEvent(evt);
		}
	}
	
	//-->>> Cancel an event
	this.cancelEvent = function(evt){
		if(typeof evt.preventDefault!='undefined') evt.preventDefault();
		else if(typeof window.event!='undefined'){
			window.event.returnValue = false;
			if(typeof window.event.preventDefault!='undefined') window.event.preventDefault();
		}
		evt.returnValue = false;
	}

	//-->>> Stop event hierarchy propagation
	this.stopEventPropagation = function(evt){
		evt.cancelBubble = true;
		if(typeof evt.stopPropagation!='undefined') evt.stopPropagation();
	}
	

	//-->>> TAG:SELECT
	if(this.tagName=='SELECT'){
		//--> Set the selected value
		this.setSelectedValue = function(val){
			for(var i = 0; i < this.length; i++)
				if(this[i].value == val){
					this[i].selected = true;
					return true;
				}
			return false;
		}
	}

}


/******************************************
 * Interface: Ajax
 ******************************************/
function DIALib_Ajax() {

	this.dialib_ajax_req = new Array();

	//-->>> Perform a Ajax GET query and callback the result if clb param
	this.get = function(url,clb){
		if(typeof clb=='undefined'){
			var req = new DIALib_Ajax_Request();
			return req.get(url);
		} else {
			var req = new DIALib_Ajax_Request(clb);
			req.get(url);
			this.dialib_ajax_req.push(req);
			return req;
		}
	}

	//-->>> Perform a Ajax POST request and callback the result if clb param
	this.post = function(url,vrs,clb){
		if(typeof clb=='undefined'){
			var req = new DIALib_Ajax_Request();
			return req.post(url,vrs);
		} else {
			var req = new DIALib_Ajax_Request(clb);
			req.post(url,vrs);
			this.dialib_ajax_req.push(req);
			return req;
		}
	}

}

/******************************************
 * Interface: Ajax
 ******************************************/
function DIALib_Effect() {

	//-->>> Slide up an element
	this.slideUp = function(){
		
	}
	
	//-->>> Slide down an element
	this.slideDown = function(){
		
	}

}
/******************************************
 * Object: Ajax Request
 ******************************************/
function DIALib_Ajax_Request(clb) {
	this.xmlhttp;
	this.callback;

	//-->>> Clone this to prevent event errors
	var self = this;

	//-->>> Constructor
	this.init = function(){
		this.xmlhttp = new XMLHttpRequest();
		this.callback = clb;
	}

	//-->>> Ajax Get
	this.get = function(url){
		if(this.callback==false||typeof this.callback == 'function') {
			this.xmlhttp.open("GET", url,true);
			this.xmlhttp.onreadystatechange=this.rschange;
			return this.xmlhttp.send(null);
		} else {
			this.xmlhttp.open("GET", url,false);
			this.xmlhttp.send(null);
			return this.xmlhttp.responseText;
		}
	}

	//-->>> Ajax Post
	this.post = function(url,vrs){
		var vars = '';
		for(var i in vrs) if(typeof vrs[i]=='string') vars += (vars!=''?'&':'')+i+'='+escape(vrs[i]);
		if(this.callback==false||typeof this.callback == 'function') {
			this.xmlhttp.open("POST", url,true);
			this.xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;"/* charset=UTF-8"*/);
			this.xmlhttp.onreadystatechange=this.rschange;
			return this.xmlhttp.send(vars);
		} else {
			this.xmlhttp.open("POST", url,false);
			this.xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;"/* charset=UTF-8"*/);
			this.xmlhttp.send(vars);
			return this.xmlhttp.responseText;
		}
	}

	//-->>> Request status callback
	this.rschange = function(){ if (self.xmlhttp.readyState==4&&self.callback!=false) self.callback(self.xmlhttp.responseText); }

	//-->>> Call the constructor
	this.init();
}



/******************************************
 * Object: XMLHttpRequest (Standard)
 ******************************************/
if (typeof XMLHttpRequest == "undefined") {
  XMLHttpRequest = function () {
    try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); }
      catch (e1) {}
    try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); }
      catch (e2) {}
    try { return new ActiveXObject("Msxml2.XMLHTTP"); }
      catch (e3) {}
    throw new Error("This browser does not support XMLHttpRequest.");
  };
}



/******************************************
 * Singleton: Browser
 ******************************************/
var Browser = new function() { this.dialib = DIALib; this.dialib();
	this.app;
	this.appversion;
	this.os;
	this.osversion;
	this.nav = '';

	//-->>> Get page and window size
	this.getSize = function(){
		var xScroll, yScroll, pageHeight, pageWidth, arrayPageSize;
		if (window.innerHeight && window.scrollMaxY) {
			xScroll = document.body.scrollWidth;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		var windowWidth, windowHeight;
		if (self.innerHeight) {	// all except Explorer
			windowWidth = self.innerWidth;
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}
		if(yScroll < windowHeight) pageHeight = windowHeight;
		else pageHeight = yScroll;
		if(xScroll < windowWidth) pageWidth = windowWidth;
		else pageWidth = xScroll;
		if(document.body.scrollWidth>pageWidth) pageWidth = document.body.scrollWidth;
		return {'pageWidth':pageWidth,'pageHeight':pageHeight,'windowWidth':windowWidth,'windowHeight':windowHeight};
	}

	//-->>> Get computed z-index of an object
	this.getZindex = function(obj){
	  var index = 0;
	  if (obj.currentStyle) index = parseFloat(obj.currentStyle['zIndex']);
	  else if(window.getComputedStyle) index = parseFloat(document.defaultView.getComputedStyle(obj,null).getPropertyValue('z-index'));
		return String(index)=='NaN'?0:index;
	}

	//-->>> Initialize Browser & OS Version
	if((this.nav = String(navigator.userAgent).match(/MSIE ([0-9]\.[0-9])\;/))){
		this.app = 'MSIE';
		this.appserversion = this.nav[1];
	} else if((this.nav = String(navigator.userAgent).match(/Firefox\/([0-9]*(\.[0-9]*)*)/))){
		this.app = 'Firefox';
		this.appversion = this.nav[1];
	} else if((this.nav = String(navigator.userAgent).match(/Chrome\/([0-9]*(\.[0-9]*)*)/))){
		this.app = 'Chrome';
		this.appversion = this.nav[1];
 	} else if((this.nav = String(navigator.userAgent).match(/Version\/([0-9]*(\.[0-9]*)*).*Safari\//))){
		this.app = 'Safari';
		this.appversion = this.nav[1];
	}
	delete this.nav;

}


/******************************************
 * Singleton: LightBox
 ******************************************/
var LightBox = new function(){ this.dialib = DIALib; this.dialib();
	this.visible = false;
	this.lock = false;

	this.opacity = 0.3;
	this.color = '#000000';

	this.evtkey;
	this.resize;
	this.overlay;
	this.container;
	this.content;
	this.img;
	this.simg = false;

	var self = this;
	this.init = function(){
		self.overlay = self.create('div','style="display: none; position: absolute; top: 0px; left: 0px; height: 100px; width: 100px; z-index: 898; background-color: '+self.color+';", opacity="'+self.opacity+'"',document.body);
		self.container = self.create('div','',document.body);
		self.container.style.cssText = 'display:none; position: absolute; top:0px; left: 0px; z-index: 899;';
		self.content = self.create('td','textAlign="center", verticalAlign="middle"',self.create('tr','',self.create('tbody','',self.create('table','',self.container))));
		self.container.children[0].style.cssText = 'width: 100%; height: 100%;';
		self.content.style.cssText = 'text-align: center; vertical-align: middle;';
		self.img = self.create('img','style="border: 1px solid #ffffff;"',null,'load',self.imageLoaded);
		self.container.bind('click',function(){self.hide()});
	}

	this.show = function(obj,lock){
		self.simg = false;
		self.content.innerHTML = '';
		if(typeof lock != 'undefined') self.lock = lock;
		self.visible = true;
		document.body.style.overflow = 'hidden';
		self.update();
		self.overlay.style.display = 'block';
		self.container.style.display = 'block';
		if(typeof obj == 'string') self.content.innerHTML = obj;
		if(typeof obj == 'object') self.content.append(obj);
		self.resize = self.bind(window,'resize',self.update);
		self.evtkey = self.bind(document.body,'keypress',self.esc);
	}

	this.showImage = function(img){
		var center = this.create('center');
		var table = this.create('table','',center);
		var td = this.create('td','',this.create('tr','',this.create('tbody','',table)));
		td.append(Loading.container);
		this.show(center);
		Loading.start();
		this.simg = true;
		if(Browser.app=='MSIE') self.img.src = img;
		else self.img = self.create('img','src="'+img+'", style="border: 1px solid #ffffff;"',null,'load',self.imageLoaded);
	}

	this.hide = function(unlock){
		if(self.simg) Loading.stop();
		if(self.lock&&!unlock) return;
		self.overlay.style.display = 'none';
		self.container.style.display = 'none';
		document.body.style.overflow = 'auto';
		self.visible = false;
		self.unbind(window,'resize',self.resize);
		self.unbind(document.body,'keypress',self.evtkey);
		self.lock = false;
	}

	this.update = function(){
		var size = Browser.getSize();
		self.overlay.style.width = size['pageWidth']+'px';
		self.overlay.style.height = size['pageHeight']+'px';
		self.container.style.top = document.body.scrollTop+'px';
		self.container.style.left = document.body.scrollLeft+'px';
		self.container.style.width = size['windowWidth']+'px';
		self.container.style.height = size['windowHeight']+'px';
	}

	this.imageLoaded = function(evt){
		if(self.visible){
			Loading.stop();
			self.show(self.img);
		}
	}

	this.esc = function(evt){
		if(!self.lock&&evt.keyCode==27)
			self.hide();
	}

	this.windowLoad(this.init);
}



/******************************************
 * Singleton: Loading
 ******************************************/
var Loading = new function(){ this.dialib = DIALib; this.dialib();

	this.speed = 100;
	this.nbdiv = 10;
	this.loop  = -1;
	this.container = null;
	this.timer = null;
	this.squares = new Array();
	this.prt = null;

	var self = this;
	this.init = function(){
		self.container = self.create('div','id="loading"');
		for(var i=0;i<self.nbdiv;i++) self.squares[i] = self.create('div','className="sq"',self.container);
	}

	this.draw = function(){
		this.drawSquare(this.loop-6,'sq');
		this.loop++;
		if(this.loop>(this.nbdiv+6)) this.loop = 0;
		this.drawSquare(this.loop-6,'sq less');
		this.drawSquare(this.loop-5,'sq mid');
		this.drawSquare(this.loop-4,'sq more');
		this.drawSquare(this.loop-3,'sq full');
		this.drawSquare(this.loop-2,'sq more');
		this.drawSquare(this.loop-1,'sq mid');
		this.drawSquare(this.loop,'sq less');
	}

	this.attach = function(prt){
		this.prt = prt;
		prt.appendChild(this.container);
		this.start();
	}

	this.detach = function(){
		this.prt.removeChild(this.container);
		this.stop();
	}

	this.drawSquare = function(sq,sqClass){ if(sq>=0&&sq<this.nbdiv) this.squares[sq].className = sqClass; }
	this.start = function(){
		for(var i=0;i<self.nbdiv;i++) this.squares[i].className = 'sq';
		this.loop = -1;
		this.timer = window.setInterval(function(){self.draw();},this.speed);
	}
	this.stop = function(){ window.clearInterval(this.timer); }

	this.windowLoad(this.init);
}


/******************************************
 * Object: ImageButton
 ******************************************/
function ImageButton(imgurl,prt){ this.dialib = DIALib; this.dialib();
	this.mousedown = false;
	this.imgurl = imgurl;
	this.parent = prt;
	this.image;
	this.width;
	this.height;
	this.button;

	var self = this;
	this.init = function(){
		this.image = this.create('img','src="'+this.imgurl+'"',null,'load',this.load);
	}

	this.load = function(){
		self.width = self.image.width;
		self.height = self.image.height / 4;
		self.button = self.create('div','unSelectable="on"',self.parent,{'mouseover':self.over,'mouseout':self.out,'mousedown':self.down,'mouseup':self.up});
		self.button.style.cssText = 'width: '+self.width+'px; height: '+self.height+'px; background-image: url('+self.image.src+'); background-position: 0px 0px; background-repeat: no-repeat; cursor: pointer;';
	}

	this.over = function(){ self.button.style.backgroundPosition = '0px '+(0-self.height)+'px'; }
	this.out = function(){ self.button.style.backgroundPosition = '0px 0px'; self.mousedown = false;}
	this.down = function(evt){
		self.button.style.backgroundPosition = '0px '+((0-self.height)*2)+'px';
		self.mousedown = true;
		self.stopEventPropagation(evt);
		self.cancelEvent(evt);
	}
	this.up = function(evt){
		self.button.style.backgroundPosition = '0px '+(0-self.height)+'px';
		if(self.mousedown){
			alert('click');
		}
		self.mousedown = false;
		self.stopEventPropagation(evt);
		self.cancelEvent(evt);
	}

	this.disable = function(){}
	this.enable = function(){}

	this.init();
}


/******************************************
 * Object: Drag & Drop Zone
 ******************************************/
function DragDropZone(settings){ this.dialib = DIALib; this.dialib();
	this.settings = {
		'onchange':null,
		'ondrag':null,
		'ondrop':null,
		'objects':new Array(),
		'placeholder':document.body,
		'class':'ddzone',
		'classobj':'ddobj',
		'ghostopacity':0.5,
		'draggingopacity':0.7,
		'margin':5
	};

	this.container;
	this.ghost;
	this.objects = new Array();
	this.mousemvevt = null;
	this.mouseupevt = null;
	this.dragging = false;
	this.dragzidx = 0;
	this.dragoff = null;
	this.dragidx = 0;
	this.idx = 0;
	this.order;
	this.ordstr;
	this.disabled = false;

	//-->>> Clone this to prevent event reference errors
	var self = this;
	this.init = function(){
		for(var i in settings) this.settings[i] = settings[i];
		this.container = this.create('div','class="'+this.settings['class']+'", style="float: left;", unSelectable="true"',this.settings['placeholder']);
		this.ghost = this.create('div','class="ddghost", style="float: left; display: none;", ddidx="ghost", opacity="'+this.settings['ghostopacity']+'"',this.container);
		this.create('td','innerHTML="&nbsp;"',this.create('tr',null,this.create('tbody',null,this.create('table','style="width: 100%; height: 100%;"',this.ghost))));
		for(i=0;i<this.settings['objects'].length;i++) this.add(this.settings['objects'][i],false);
		this.ordstr = this.getOrderString();
	}

	//-->>> Add a new object
	this.add = function(obj,fire){
		var cnt = this.create('div','class="'+this.settings['classobj']+'", style="float: left;", ddidx="'+this.idx+'"',this.container);
		cnt.append(obj);
		cnt.bind({'mousedown':this.mousedown});
		cnt.disableSelection();
		this.objects[this.idx] = cnt;
		this.idx++;
		if(typeof fire == 'undefined' || fire == true) this.change();
		else this.change(false);
	}
	
	//-->>> Remove an object
	this.rem = function(ddidx,fire){
		this.container.removeChild(this.objects[ddidx]);
		delete this.objects[ddidx];
		this.change();
	}

	//-->>> Set the active zone of each draggable objects
	this.setCoord = function(){
		var i, left, top, width, height;
		for(i in this.objects){
			if(typeof this.objects[i] == 'object'){
				left = this.objects[i].getOffsetLeft();
				top = this.objects[i].getOffsetTop();
				width = this.objects[i].offsetWidth;
				height = this.objects[i].offsetHeight;
				this.objects[i].coord = {'x1':left,'y1':top,'x2':(left+width),'y2':(top+height)};
			}
		}
		for(this.order=new Array(),i=0;i<this.container.childNodes.length;i++)
			this.order[this.container.childNodes[i].ddidx] = i;
	}

	//-->>> Get a string representation of the order
	this.getOrderString = function(){
		var i, arr = new Array();
		for(i=0;i<this.container.childNodes.length;i++)
			if(this.container.childNodes[i].ddidx!='ghost')
				arr.push(this.container.childNodes[i].ddidx);
		return arr.join('-');
	}

	//-->>> Verify order status and call the onchange callback
	this.change = function(force){
		var i, str, arr = new Array();
		str = self.getOrderString();
		if(self.settings['onchange']){
			for(i=0;i<self.container.childNodes.length;i++)
				if(self.container.childNodes[i].ddidx!='ghost')
					arr.push(self.container.childNodes[i].childNodes[0]);
		}
		if(typeof force != 'undefined'&&!force){ }
		else if(str!=self.ordstr||(typeof force != 'undefined'&&force)) self.settings['onchange'](arr);
		self.ordstr = str;
	}
	
	this.getObjects = function(){
		var i, arr = new Array();
		for(i=0;i<self.container.childNodes.length;i++)
			if(self.container.childNodes[i].ddidx!='ghost')
				arr.push(self.container.childNodes[i].childNodes[0]);
		return arr;
	}
	
	//-->>> Disable dragging
	this.disable = function(dis){
		if(typeof dis == 'undefined' || dis){
			this.disabled = true;
			this.container.addClass('disabled');
		}else{
			this.disabled = false;
			this.container.remClass('disabled');
		}
	}
	
	this.getFirstObject = function(){
		if(this.container.childNodes.length>1)
			for(var i=0;i<this.container.childNodes.length;i++)
				if(this.container.childNodes[i].ddidx!='ghost')
					return this.container.childNodes[i].childNodes[0];
		return null;
	}

	//-->>> Mouse down event (start dragging)
	this.mousedown = function(evt){
		if(self.disabled) return;
		var obj = evt.target.parentNode;
		while(typeof obj.ddidx=='undefined'&&obj.tagName!='BODY') obj = obj.parentNode;
		if(typeof obj.ddidx == 'undefined') return;
		self.setCoord();
		self.dragidx = obj.ddidx;
		self.dragoff = {"x":(evt.clientX-obj.getOffsetLeft()),"y":(evt.clientY-obj.getOffsetTop())};
		obj.addClass('dragging');
		obj.opacity(self.settings['draggingopacity']);
		self.container.insertBefore(self.ghost,obj);
		self.ghost.css('display: block; width: '+obj.offsetWidth+'px; height: '+obj.offsetHeight+'px;');
		self.dragzidx = obj.zIndex();
		document.body.appendChild(obj);
		obj.css('left: '+(evt.clientX-self.dragoff['x'])+'px; top: '+(evt.clientY-self.dragoff['y'])+'px; position: absolute; z-index: 700;');
		self.mousemvevt = self.bind(document,'mousemove',self.mousemove);
		self.mouseupevt = self.bind(obj,'mouseup',self.mouseup);
		self.dragging = true;
		self.cancelEvent(evt);
	}

	//-->>> Mouse up event (stop dragging)
	this.mouseup = function(evt){
		if(self.disabled) return;
		self.unbind(document,'mousemove',self.mousemvevt);
		self.unbind(evt.target.parentNode,'mouseup',self.mouseupevt);
		self.objects[self.dragidx].remClass('dragging');
		self.objects[self.dragidx].css('position: relative; top: 0px; left: 0px; z-index: '+self.dragzidx+';');
		self.objects[self.dragidx].opacity(1);
		self.container.insertBefore(self.objects[self.dragidx],self.ghost);
		self.ghost.css('display: none;');
		self.dragging = false;
		self.change();
		self.cancelEvent(evt);
	}

	//-->>> Mouse move event (dragging)
	this.mousemove = function(evt){
		var left = document.body.scrollLeft;
		var top = document.body.scrollTop;
		self.objects[self.dragidx].css('left: '+(evt.clientX-self.dragoff['x'])+'px; top: '+(evt.clientY-self.dragoff['y'])+'px;');
		for(var i in self.objects){
			if(typeof self.objects[i] == 'object'){
				if((evt.clientX+left)>=self.objects[i].coord['x1']&&(evt.clientX+left)<=self.objects[i].coord['x2']&&(evt.clientY+top)>=self.objects[i].coord['y1']&&(evt.clientY+top)<=self.objects[i].coord['y2']&&self.objects[i].ddidx!=self.dragidx){
					if(self.order['ghost']>self.order[self.objects[i].ddidx]) self.container.insertBefore(self.ghost,self.objects[i]);
					else self.container.insertBefore(self.ghost,self.objects[i].nextSibling);
					self.setCoord();
					return;
				}
			}
		}
		self.cancelEvent(evt);
	}

	//-->>> Call the constructor
	this.init();
}


/******************************************
 * Object: HSlider
 ******************************************/
function HSlider(settings){ this.dialib = DIALib; this.dialib();
	this.settings = {
		'placeholder':document.body,
		'onslide':null,
		'onchange':null,
		'class':'slider',
		'width': 200,
		'height':30,
		'value':75,
		'disabled':false
	};

	this.obj;
	this.sld;
	this.dbg;

	this.evtmv;
	this.evtdmu;

	var self = this;
	this.init = function(){
		this.obj = this.create('div','unSelectable="true", className="'+this.settings['class']+'"',this.settings['placeholder'],{'mousedown':this.mousedown});
		this.obj.css('width: '+this.settings['width']+'px; height: '+this.settings['height']+'px; font-size: 1px;'+(this.settings['disabled']?'':' cursor: pointer;'));
		this.sld = this.create('div','unSelectable="true"',this.obj);
		this.sld.css('width: 0px; height: '+this.settings['height']+'px; font-size: 1px;');
		this.create('div','style="clear: left;"',this.settings['placeholder']);
		this.dbg = this.create('div','',this.settings['placeholder']);
		this.setValue(this.settings['value']);
	}

	this.setValue = function(val){
		if(val>100) val = 100;
		if(val<0) val = 0;
		this.sld.style.width = Math.round(val/100*this.settings['width'],0)+'px';
		this.dbg.innerHTML = val;
		this.settings['value'] = val;
	}

	this.mousedown = function(e){
		if(self.settings['disabled']) return;
		self.setValue((e.clientX-self.obj.getOffsetLeft())*100/self.settings['width']);
		if(self.settings['onslide']) self.settings['onslide'](self.settings['value']);
		self.evtmv = self.bind(self.obj,'mousemove',self.mousemove);
		self.evtdmu = self.bind(document,'mouseup',self.mouseup);
		self.obj.addClass('sliding');
		self.cancelEvent(e);
	}

	this.mouseup = function(e){
		self.obj.remClass('sliding');
		self.unbind(self.obj,'mousemove',self.evtmv);
		self.unbind(document,'mouseup',self.evtdmu);
		if(self.settings['onchange']) self.settings['onchange'](self.settings['value']);
		self.cancelEvent(e);
	}

	this.mousemove = function(e){
		self.setValue((e.clientX-e.target.getOffsetLeft())*100/self.settings['width']);
		if(self.settings['onslide']) self.settings['onslide'](self.settings['value']);
		self.cancelEvent(e);
	}

	if(typeof settings != 'undefined') for(var i in settings) this.settings[i] = settings[i];
	this.init();
}


/******************************************
 * Object: VSlider
 ******************************************/
function VSlider(settings) { this.dialib = DIALib; this.dialib();
	this.settings = {
		'placeholder':document.body,
		'onslide':null,
		'onchange':null,
		'class':'slider',
		'width': 30,
		'height':200,
		'value':75,
		'disabled':false
	};

	this.obj;
	this.sld;
	this.dbg;

	this.evtmv;
	this.evtdmu;

	var self = this;
	this.init = function(){
		this.obj = this.create('div','className="'+this.settings['class']+'", unSelectable="true"',this.settings['placeholder'],{'mousedown':this.mousedown});
		this.obj.css('overflow: hidden; width: '+this.settings['width']+'px; height: '+this.settings['height']+'px; font-size: 1px;'+(this.settings['disabled']?'':' cursor: pointer;'));
		this.sld = this.create('div','unSelectable="true"',this.obj);
		this.sld.css('position: relative; top: 0px; left: 0px; width: '+this.settings['width']+'px; height: 0px; font-size: 1px;');
		this.create('div','style="clear: left;"',this.settings['placeholder']);
		this.dbg = this.create('div','',this.settings['placeholder']);
		this.setValue(this.settings['value']);
	}

	this.setValue = function(val){
		if(val>100) val = 100;
		if(val<0) val = 0;
		var px = Math.round(val/100*this.settings['height'],0);
		this.sld.css('top: '+(this.settings['height']-px)+'px; height: '+px+'px;');
		this.dbg.innerHTML = val;
		this.settings['value'] = val;
	}

	this.mousedown = function(e){
		if(self.settings['disabled']) return;
		self.setValue((self.settings['height']-(e.clientY-self.obj.getOffsetTop()))*100/self.settings['height']);
		if(self.settings['onslide']) self.settings['onslide'](self.settings['value']);
		self.evtmv = self.bind(self.obj,'mousemove',self.mousemove);
		self.evtdmu = self.bind(document,'mouseup',self.mouseup);
		self.obj.addClass('sliding');
		self.cancelEvent(e);
	}

	this.mouseup = function(e){
		self.obj.remClass('sliding');
		self.unbind(self.obj,'mousemove',self.evtmv);
		self.unbind(document,'mouseup',self.evtdmu);
		if(self.settings['onchange']) self.settings['onchange'](self.settings['value']);
		self.cancelEvent(e);
	}

	this.mousemove = function(e){
		self.setValue((self.settings['height']-(e.clientY-self.obj.getOffsetTop()))*100/self.settings['height']);
		if(self.settings['onslide']) self.settings['onslide'](self.settings['value']);
		self.cancelEvent(e);
	}


	if(typeof settings != 'undefined') for(var i in settings) this.settings[i] = settings[i];
	this.init();
}





/******************************************
 * Call Compression Functions
 ******************************************/
//if(typeof $ == 'undefined'){ var $ = function $(id) { return document.getElementById(id); } }
if(typeof $ == 'undefined'){ var $ = function $(id) { var elm = document.getElementById(id); elm.dialib = DIALib_HTMLElement; elm.dialib(); return elm; } }


/******************************************
 * Augmented Native Objects
 ******************************************/
Array.prototype.search = function(p_val) { for(var i = 0, l = this.length; i < l; i++) if(this[i] == p_val) return i; return null; }
Number.prototype.pad = function(length){ var str = '' + this; while(str.length < length) str = '0' + str; return str; }
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g,""); }
String.prototype.ltrim = function() { return this.replace(/^\s+/,""); }
String.prototype.rtrim = function() { return this.replace(/\s+$/,""); }
String.prototype.trimQuotes = function() { return this.replace(/^[\"|\']|[\"|\']$/g,""); }
String.prototype.noWhiteSpaces = function() { return this.trim().replace(/([\s|\t]){2,}/gi,' '); }
String.prototype.stripTags = function(){ return this.replace(/<\/?(?!\!)[^>]*>/gi,' ').noWhiteSpaces(); }
