
/**
* 	Soca script : Simple and Object oriented Cross browser API Javascript 
* 	Copyright (C) 2007 Gaesys - www.gaesys.com
* 	licensed under GPL (GPL-license.txt) license.
* 	
* 	@author: Julien Poveda
* 	@author: Stéphane Seyer
*
*/
var XHTMLNS = "http://www.w3.org/1999/xhtml";
var documentHead = document.head;
var counter = 0;
var notLoad = 0;
if (!document.all) {
document.write = function(str){
    var moz = !window.opera && !(/Apple/).test(navigator.vendor);           // Watch for writing out closing tags, we just    // ignore these (as we auto-generate our own)    if ( str.match(/^<\//) ) 
    {
    	return;
    }    // Make sure & are formatted properly, but Opera    // messes this up and just ignores it    if ( !window.opera )
    {        str = str.replace(/&(?![#a-z0-9]+;)/g, "&amp;");
    }    // Watch for when no closing tag is provided    // (Only does one element, quite weak)    str = str.replace(/<([a-z]+)(.*[^\/])>$/, "<$1$2></$1>");           // Mozilla assumes that everything in XHTML innerHTML    // is actually XHTML - Opera and Safari assume that it's XML    if ( !moz ) {        str = str.replace(/(<[a-z]+)/g, "$1 xmlns='http://www.w3.org/1999/xhtml'");
    }           // The HTML needs to be within a XHTML element    var div = document.createElementNS("http://www.w3.org/1999/xhtml","div");    div.innerHTML = str;           // Find the last element in the document    var pos;           // Opera and Safari treat getElementsByTagName("*") accurately    // always including the last element on the page    if ( !moz ) {        pos = document.getElementsByTagName("*");        pos = pos[pos.length - 1];                       // Mozilla does not, we have to traverse manually    } else {        pos = document;        while ( pos.lastChild && pos.lastChild.nodeType == 1 ) {            pos = pos.lastChild;
        }    }           // Add all the nodes in that position    var nodes = div.childNodes;    while ( nodes.length ) {        pos.parentNode.appendChild( nodes[0] );
    }};
}
String.prototype.trim = function(){
	return this.replace(/^\s+/, "").replace(/\s+$/, "");
};

window.modules = [];

/*------------------------------------------------------------------------------------
	OBJECT $
	Permet d'unifier pour tous les navigateurs la gestion des événements.
-------------------------------------------------------------------------------------*/

var $ = {
	"version" : "Soca 1.0 Alpha",
	"includedFiles" : [],
	"instanciatesModules" : [],
	"objectCounter" : 0,
	"instanciatesClasses" : [],
	
	// Construction
	"init" : function ()
	{
		this.detectClientCaps ();
		// Add Cross Browser DOM Standard
		if (!window.addEventListener) {		    window.addEventListener = this._addEventListener;		}
		if (!document.importNode || window.webkit) {			document.importNode = this._importNode;		}
		Function.prototype.extendsClass = this._extendsClass;
		Function.prototype.bind = this._bind;
		window.getInnerSize = this._getInnerSize;
		setTimeout("$.checkModules()",100);
	},
	
	"detectClientCaps" : function ()
	{
		window.xpath = !!(document.evaluate);
		if (window.ActiveXObject) {
			window.ie = window[window.XMLHttpRequest ? 'ie7' : 'ie6'] = true;
		}
		else if (document.childNodes && !document.all && !navigator.taintEnabled) {
			window.webkit = window[window.xpath ? 'webkit420' : 'webkit419'] = true;
		}
		else if (document.getBoxObjectFor != null) {
			window.gecko = true;
		}
		
	},
	// Fonctions utilitaires
	"isDef" : function (obj) {
		return (obj != undefined);
	},
	"include" : function (filename)	{
		for (i=0; i < this.includedFiles.length; i++) {
			if (this.includedFiles[i] == filename) {
				return false;
			}
		}
		var script = document.createElementNS(XHTMLNS, "script");
		script.setAttribute("type", "text/javascript");
		script.setAttribute("src", filename);
		document.getElementsByTagName("head")[0].appendChild(script);
		this.includedFiles.push (filename);
		return true;
	},
	"parseUri" : function (sourceUri) {			var uriPartNames = ["source","protocol","authority","domain","port","path","directoryPath","fileName","query","anchor"];			var uriParts = new RegExp("^(?:([^:/?#.]+):)?(?://)?(([^:/?#]*)(?::(\\d*))?)?((/(?:[^?#](?![^?#/]*\\.[^?#/.]+(?:[\\?#]|$)))*/?)?([^?#/]*))?(?:\\?([^#]*))?(?:#(.*))?").exec(sourceUri);			var uri = {};						for (var i = 0; i < uriPartNames.length; i++)
			{
				uri[uriPartNames[i]] = (uriParts[i] ? uriParts[i] : "");
			}						// Always end directoryPath with a trailing backslash if a path was present in the source URI			// Note that a trailing backslash is NOT automatically inserted within or appended to the "path" key			if(uri.directoryPath.length > 0) {				uri.directoryPath = uri.directoryPath.replace(/\/?$/, "/");			}			return uri;
	},
	"getElementsByClassName" : function (cName)
	{
		var i=0;
		var coll = [];
		if (document.getElementsByClassName)
		{
			hColl = document.getElementsByClassName(cName);
			for(i=0;i<hColl.length;i++)
			{
				coll.push(hColl.item(i));
			}
		}
		else
		{
			elements = document.getElementsByTagName("*");
			for (i=0; i<elements.length; i++)
			{
				try {
					if (elements.item(i).className.indexOf(cName) != -1) {
						coll.push(elements.item(i));
					}
				}
				catch (e)
				{
					alert(elements.item(i));
				}
			}
		}
		return coll;
	},
	"urlEncode" : function (sStr) {
	    return escape(sStr).replace(/\+/g, '%2B').replace(/\"/g,'%22').replace(/\'/g, '%27').replace(/\//g,'%2F');
	},
	"getType" : function (mixed) {
		if (!this.isDef(mixed)) {
			return false;
		}
		var type = typeof mixed;
		if (type == "object" && mixed.nodeName) {
			switch (mixed.nodeType) {
				case 1: 
					return 'element';
				case 3: 
					return (/\S/).test(mixed.nodeValue) ? 'textnode' : 'whitespace';
				default:
					break;
			}
		}
		if (type == "object" || type == "function") {
			switch (mixed.constructor) {
				case Array: 
					return "array";
				case RegExp: 
					return "regexp";
				case Function: 
					return "function";
				case String: 
					return "string";
				default:
					break;
			}
			if (typeof mixed.length == "number") {
				if (mixed.item) {
					return "collection";
				}
				if (mixed.callee) {
					return 'arguments';
				}
			}
		}
		return type;
	},
	"serialize" : function (mixed) {
		var serializedString = "";
		// DebugModuleInstance.addMsg(mixed+" | "+this.getType(mixed)); 
		switch (this.getType(mixed))
		{
			case "string":
				serializedString = "'"+mixed+"'";
				break;
			case "object":
				for (var prop in mixed)
				{
					serializedString += "'"+prop+"':"+this.serialize(prop)+",";
				}
				serializedString = "{"+serializedString.substr(0,serializedString.length-1)+"}";
				break;
			case "array":
				for (var i=0; i<mixed.length; i++)
				{
					serializedString += this.serialize(mixed[i])+",";
				}
				serializedString = "["+serializedString.substr(0,serializedString.length-1)+"]";
				break;
			default:
				serializedString = mixed;
				break;
		}
		return serializedString;
	},
	"unserialize" : function (mixed) {
		
	},
	"checkModules" : function () {
		if ($.instanciatesModules.length == 0) {
				window.setTimeout("$.checkModules()",100);
		}
			
		for (var i=0; i<$.instanciatesModules.length; i++)
		{
			if (!window[$.instanciatesModules[i]].isLoaded)
			{
				window.setTimeout("$.checkModules()",100);
				return false;
			}
			else {
				if ("isFinalized" in window[$.instanciatesModules[i]] && !window[$.instanciatesModules[i]].isFinalized)
				{
					window[$.instanciatesModules[i]].finalize();
					window[$.instanciatesModules[i]].isFinalized = true;
				}
			}
		}
		//document.body.style.opacity = 0;
		if ("BasicModuleInstance" in window) {
			window["BasicModuleInstance"].addRule("body {overflow:auto}");
			window["BasicModuleInstance"].addRule("#structure {visibility:visible;}");
			document.documentElement.style.backgroundImage = "none";
		}
		//setTimeout($.increaseOpacity.bind(),100);
		return true;
	},
	"increaseOpacity" : function () {
		var cOpacity = 	document.body.style.opacity/1;
		if (cOpacity+0.2<=1) {
			document.body.style.opacity =cOpacity+0.25;
			setTimeout($.increaseOpacity.bind(),10);
		}
	},
	"_bind" : function (object) {		var __method = this;
		return function() {
			return __method.apply(object, arguments);
		};
	},
	"_getInnerSize" : function () {		
		var winWidth = 0, winHeight = 0;
	  		if( typeof( window.innerWidth ) == 'number' ) {
			// Non IE6			winWidth = window.innerWidth;			winHeight = window.innerHeight;	  	} 
	  	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		    //IE 6+ in 'standards compliant mode'	    	winWidth = document.documentElement.clientWidth;		    winHeight = document.documentElement.clientHeight;	  	} 
	  	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {		    //IE 4 compatible		    winWidth = document.body.clientWidth;		    winHeight = document.body.clientHeight;		}
		return {"width":winWidth,"height":winHeight};	},
	"_addEventListener" : function(eventName, func, capture)  {
        if (this.attachEvent) { 
        	this.attachEvent('on' + eventName, func); 
        }	},
	"_importNode" : function(node, deep) {		var imported;
		var attrs;		if (node.nodeType == 1)  {
			imported = document.createElement(node.nodeName);			attrs = node.attributes;			for (i = attrs.length - 1; i >= 0; i--) {				imported.setAttribute(attrs[i].name, attrs[i].value);
			}			if (node.style && node.style.cssText) {
				imported.style.cssText = node.style.cssText;
			}		} 
		else if (node.nodeType == 3) {
			imported = document.createTextNode(node.nodeValue);
		}		if(deep && node.hasChildNodes()) {		   var oChild = node.firstChild;		   do {				imported.appendChild(document.importNode(oChild, true));				oChild = oChild.nextSibling;			} while (oChild);		}		return imported;	},
	"_extendsClass" : function (classHandler) {	    var prop;	    for (prop in classHandler.prototype) {
	      this.prototype[prop] = classHandler.prototype[prop];
	    }
	    this.prototype._className = this.toString().match(/function\s*(\w+)/)[1];
	    if (arguments.length == 2) {
	    	this.prototype._moduleName = arguments[1].toString().match(/function\s*(\w+)/)[1];
	    }	},
	"createElement" : function (mixed) {
		var element = false;
		var classHandler = false;
		if (typeof mixed == "string") {
			element = document.createElement(tagName);
			classHandler = Element;
		}
		else if ("prototype" in mixed) {
			if ("_tagName" in mixed.prototype) {
				element = document.createElement(mixed.prototype._tagName);
			}
			classHandler = mixed;
		}
		var prop = false;			
    	for (prop in classHandler.prototype) {
			element[prop] = classHandler.prototype[prop];
		}
		var args = new Array ();
		for (var i=1; i<arguments.length; i++) {
			args.push(arguments[i]);
		}
		classHandler.call(element,args);
		if (!"addEventListener" in element) {
			element.addEventListener = $._addEventListener;
		}
		return element;
	}
};

$.init();

/*------------------------------------------------------------------------------------
	CLASSE CrossBrowserEvent
	Permet d'unifier pour tous les navigateurs la gestion des événements.
-------------------------------------------------------------------------------------*/
function CrossBrowserEvent (evt)
{
	this.eventHandler = evt;
	this.firstParentWithObject = false;
	this.originalTarget = false;
	if (window.event)
	{
		this.eventHandler = window.event;
		this.target = window.event.srcElement;
		this.originalTarget  = window.event.srcElement;
	}
	else
	{
		this.target = this.eventHandler.target;
		this.originalTarget  = evt.target;
	}
	if (this.target.nodeType != 1)
	{
		node = this.target;
		while (node.nodeType != 1) {
			node = node.parentNode;
		}
		this.target = node;
	}
}

CrossBrowserEvent.prototype.clearEvent = function () {
	if (window.event) {
		window.event.cancelBubble = true;
		window.event.returnValue = false;
	}
	else
	{
		this.eventHandler.stopPropagation();
		this.eventHandler.preventDefault();
	}
	return false;
};

/*------------------------------------------------------------------------------------
	CLASSE BaseElement
	Element de Base avec comportement
-------------------------------------------------------------------------------------*/
function BaseElement (mixed)
{
	this._currentTimeout = false;
	this.xpath = false;
	this.parentObject = false;
	if ("_moduleName" in this && this._moduleName+"Instance" in window)
	{
		var tabInstance = window[this._moduleName+"Instance"].instanciatesBehaviors;
		if (!(this._className in tabInstance))
		{
			tabInstance[this._className]=1;
		}
		else
		{
			tabInstance[this._className]++;
		}
	}	

	if (mixed)
	{
		if ((typeof(mixed) == "array" || typeof(mixed) == "object") && mixed.length != 0) {
			mixed = mixed[0];
		}
		
		if (typeof(mixed) == "string")
		{
			this.htmlElement = document.createElement(mixed);
			this.htmlElement.className = this._className;
		}
		else	{	
			this.htmlElement = mixed;
		}
	}
	if (!this.htmlElement && "createHtmlElement" in this) {
			this.htmlElement = this.createHtmlElement();
	}
		
	if (this.htmlElement)
	{
		// Ajout de addEventListener
		if (!this.htmlElement.addEventListener) {
			this.htmlElement.addEventListener = $._addEventListener;
		}
		this.htmlElement.jsobject = this;
		var eid = this.htmlElement.getAttribute("id");
		if (eid != null && eid.length != 0)
		{
			this.uid = this.htmlElement.getAttribute ("id");
		}
		else
		{
			this.uid = "obj"+$.objectCounter++;
			this.htmlElement.setAttribute ("id", this.uid);
		}
		this.attachEvents();
		if (this.uid) 
		{
			this.pageUid = "#"+this.uid;
		}
	}
}
BaseElement.prototype._className = "BaseElement";
BaseElement.prototype.attachEvents = function () {
	var	evt = false;
	for (var prop in this)
	{
		evt = prop.match(/(.*)Event$/);
		if (evt != null) 
		{
			this.htmlElement.addEventListener(evt [1], this.onevent, true);
		}
	}
	
};
BaseElement.prototype.destruct = function (evt) {
	this.htmlElement.parentNode.removeChild(this.htmlElement);
};

BaseElement.prototype.setPersistentAttribute = function (name, value)
{
	name = this.uid+"__"+name;
	var now = new Date();	var expires = new Date (now.getFullYear()+1, now.getMonth(), now.getDate());
	var path;
	if (arguments.length == 2) {		path  = window.location.pathname;
	}
	else {
		path = "/";
	}
	
	value = $.serialize(value);
	var domain = window.location.hostname;	var secure = false;	document.cookie=name+"="+escape(value)+		((expires==null) ? "" : ("; expires="+expires.toGMTString()))+		((path==null) ? "" : ("; path="+path))+		((domain==null) ? "" : ("; domain="+domain))+		((secure==true) ? "; secure" : "");
};
BaseElement.prototype.getPersistentAttribute = function (name)
{
	name = this.uid+"__"+name;
	var arg=name+"=";	var alen=arg.length;	var clen=document.cookie.length;	var i=0;
	var attVal = false;	while (i<clen) {		var j=i+alen;		if (document.cookie.substring(i, j)==arg) { 			var endstr=document.cookie.indexOf (";", j);			if (endstr==-1) {	    		endstr=document.cookie.length;
			}
			attVal = unescape(document.cookie.substring(j, endstr));
			eval("var attObject = "+attVal+";");
			return attObject;
		}
      i = document.cookie.indexOf(" ",i)+1;
      if (i==0) {
      	break;
      }
   }	return false;};
BaseElement.prototype.onevent = function (evt) {
	try 
	{
		var cbEvent = new CrossBrowserEvent(evt);
		var cnode = cbEvent.target;
		while (typeof(cnode.jsobject) !== "object" || !("htmlElement" in cnode.jsobject)) {
			cnode = cnode.parentNode;
		}
		if ((cbEvent.eventHandler.type+"Event" in cnode.jsobject)) {	
			return cnode.jsobject[cbEvent.eventHandler.type+"Event"](cbEvent);
		}
		else if (("parentObject" in cnode.jsobject) && (cbEvent.eventHandler.type+"Event" in cnode.jsobject.parentObject)) {
			return cnode.jsobject.parentObject[cbEvent.eventHandler.type+"Event"](cbEvent);
		}
	}
	catch (e) {	}
	return true;
};

BaseElement.prototype.append = function (element) {
	this.htmlElement.appendChild(element.htmlElement);
	element.parentObject = this;
	if ("onAttach" in element) {
		element.onAttach();
	}
	return element;
};


BaseElement.prototype.appendChild = function (element) {
	return this.htmlElement.appendChild(element);
};
BaseElement.prototype.appendElement = function (tagName) {
	var elem = new BaseElement(tagName);
	elem.insertIn(this.htmlElement);
	if (arguments.length == 2)
	{
		elem.setAttribute("class", arguments[1]);
	}
	return elem;
};

BaseElement.prototype.insertIn = function (parentElement) {
	parentElement.appendChild(this.htmlElement);
	if ("onAttach" in this) {
		this.onAttach ();
	}
	if ("jsobject" in parentElement)
	{
		this.parentObject = parentElement.jsobject;
	}
};
BaseElement.prototype.insertBefore = function (referenceNode) {
	referenceNode.parentNode.insertBefore(this.htmlElement, referenceNode);
};
BaseElement.prototype.insertAfter = function (referenceNode) {
	if (referenceNode.nextSibling) {
		referenceNode.parentNode.insertBefore(this.htmlElement, referenceNode.nextSibling);
	}
	else {
		referenceNode.parentNode.appendChild(this.htmlElement);
	}
};
BaseElement.prototype.getChildren = function () {
	var items = this.htmlElement.childNodes;
	var len = items.length;
	var i = 0;
	var children = [];
	if (len != 0)
	{		do	{
			if (items[i].nodeType == 1) {
				children.push(items[i]);
			}
		}		while (++i < len);
	}	return children;
};
BaseElement.prototype.setStyles = function (Rule) {
	BaseModuleInstance.addRule("#"+this.uid+" "+Rule);
};
BaseElement.prototype.setPartBackground = function (skin, position,radius,gradientHeight) {
	var cUri = "/services/getImagePart.php?image=images/rounded/"+skin+".png&radius="+radius+"&gradheight="+gradientHeight+"&part="+position;
	var positions = position.split("_");
	var hpos = positions[0];
	var vpos = positions[1];
	
	this.htmlElement.style.backgroundImage = "url('"+cUri+"')";
	this.htmlElement.style.backgroundPosition = hpos+" "+vpos;
	this.htmlElement.style.backgroundRepeat = "no-repeat";
	if (hpos=="center")	{
		this.htmlElement.style.backgroundRepeat = "repeat-y";
	}
	if (vpos=="center")	{
		this.htmlElement.style.backgroundRepeat = "repeat-x";
	}
	
};


BaseElement.prototype.setTimeout = function (cmethod, interval) {
	this.clearTimeout();
	var cmdString = "document.getElementById('"+ this.uid +"').jsobject."+cmethod+"();";
	this._currentTimeout = window.setTimeout(cmdString, interval);
};
BaseElement.prototype.clearTimeout = function () {
	if (this._currentTimeout) {
		window.clearTimeout(this._currentTimeout);
	}
};
BaseElement.prototype.contains = function (relatedElement) {
	if ("contains" in document.documentElement)
	{
		return this.htmlElement.contains(relatedElement);
	}
	else
	{
		return !!(this.htmlElement.compareDocumentPosition(relatedElement) & 16);
	}
};

BaseElement.prototype.display = function () {
	this.htmlElement.style.display = "block";
};
BaseElement.prototype.hide = function () {
	this.htmlElement.style.display = "none";
};
BaseElement.prototype.setVisible = function () {
	this.htmlElement.style.visibility = "visible";
};
BaseElement.prototype.setHidden = function () {
	this.htmlElement.style.visibility = "hidden";
};
BaseElement.prototype.setAttribute = function (aname, avalue) {
	if (aname == "class")
	{
		this.htmlElement.className = avalue;
	}
	else
	{
		this.htmlElement.setAttribute(aname, avalue);
		if (aname == "id") {
			this.uid = avalue;
		}
	}
};
BaseElement.prototype.removeAttribute = function (aname) {
	if (aname != "id") {
		this.htmlElement.removeAttribute(aname);
	}
};

BaseElement.prototype.setStyle = function (astyle, avalue) {
	this.htmlElement.style[astyle] = avalue;
};
BaseElement.prototype.getModule = function () {
	if (this._moduleName && this._moduleName+"Instance" in window) {
		return window[this._moduleName+"Instance"];
	}
	return window["BaseModuleInstance"];
};

/*------------------------------------------------------------------------------------
	CLASSE BaseRequestElement
	Element de Base avec gestion des requêtes HTTP.
-------------------------------------------------------------------------------------*/
BaseRequestElement.extendsClass(BaseElement);
function BaseRequestElement (mixed)
{
	BaseElement.call(this, mixed);
	this.xmlResponse = false;
	this.textResponse = false;
	this.currentUrl = false;
	this.currentParamaters = false;
	this.currentData = null;
	this.currentMethod = "GET";
	this.inProgress = false;
	this.isRefreshOnce = false;
}

BaseRequestElement.prototype._getHTTPObject = function (tt) {
     var http_request = false;       if (window.XMLHttpRequest)    {        try        {            http_request = new XMLHttpRequest();        }        catch (e)        {            http_request = false;        }    }    else    {        try        {            http_request = new ActiveXObject("Msxml2.XMLHTTP");        }        catch (e)        {            try            {                http_request = new ActiveXObject("Microsoft.XMLHTTP");            }            catch (e)            {                http_request = false;            }        }    }    return http_request;};
BaseRequestElement.prototype._SendHTTPRequest = function (rurl, method, data) 
{
	if (!this.xmlReqObject) {
   	this.xmlReqObject = this._getHTTPObject();
	}
   	var target;		if (this.xmlReqObject)
	{
		try 
		{
			if (this.xmlReqObject.status !== 0) {
				this.xmlReqObject.abort();
			}
		}
		catch (e) {}
		
		this.inProgress = true;
		this.currentUrl = rurl;
		this.currentMethod = method;
		this.currentData = data;
	
		if ("addThrobber" in this) {
			this.addThrobber();
		}
			
		this.xmlReqObject.open(method, rurl); 
		if (method == "POST") {
			this.xmlReqObject.setRequestHeader("Content-type","application/x-www-form-urlencoded");
			this.xmlReqObject.setRequestHeader("Content-length",data.length);
		}
		target = this.htmlElement;
		this.xmlReqObject.onreadystatechange = function () {
			var xmlreq = target.jsobject.xmlReqObject;
			if (xmlreq.readyState == 4)
			{
				if (xmlreq.status == 200 || xmlreq.status == 204)
				{
					if (xmlreq.responseXML && xmlreq.responseXML.documentElement.tagName != "parsererror" && xmlreq.responseXML.documentElement.childNodes.length !== 0) {
						target.jsobject.xmlResponse = xmlreq.responseXML;
					}
					else {
						target.jsobject.xmlResponse = false;
					}
					target.jsobject.textResponse = xmlreq.responseText;
					target.jsobject.inProgress = false;
				}
				else
				{
					target.jsobject.xmlResponse = false;
					target.jsobject.textResponse = "Erreur "+xmlreq.status+" url : "+target.jsobject.currentUrl;
				}
				target.jsobject.doRequest();
		  	}
		};
		this.xmlReqObject.send(data); 
	}
};
BaseRequestElement.prototype._SendGETRequest = function (rurl) 
{
	this._SendHTTPRequest (rurl, "GET", null);
};
BaseRequestElement.prototype._getParentJsObject = function (node)
{
	while (node.tagName.toLowerCase() != "body" && !node.jsobject.HTMLElement){
		node = node.parentNode;
	}
	return node;
};
BaseRequestElement.prototype.refresh = function ()
{
	if (arguments.length != 0) {
		this.currentUrl = arguments[0];
	}
	if (this.currentUrl)
	{
		if ("content" in this) {
			this.content.innerHTML = "";
		}
		else {
			this.htmlElement.innerHTML = "";
		}
		this.isRefreshOnce = true;
		var curl = this.currentUrl;
		if ("currentParameters" in this && this.currentParameters.length != 0)
		{
			curl = curl+"&"+this.currentParameters.substr(1);
		}
		this._SendHTTPRequest (curl, this.currentMethod, this.currentData);
	}
};

BaseRequestElement.prototype.doRequest = function () 
{
	this.inProgress = false;
};

/*------------------------------------------------------------------------------------
	CLASSE Module
	Module avec chargement des comportements et règles CSS
-------------------------------------------------------------------------------------*/
function Module ()
{
	this._currentTimeout = false;
	this.instanciatesBehaviors = new Object ();
	this.isLoaded = false;
	window[this._className+"Instance"] = this;
	eval ("var fHandler = function () {"+this._className+"Instance.initBehavior(); "+this._className+"Instance.isLoaded = true;}");
	window.addEventListener("load", fHandler, false);
	this.initStyles();
	if ("addCssRules" in this) {
		this.addCssRules();
	}
	if ("resize" in this) {
		eval ("var fHandler = function () {"+this._className+"Instance.resize();}");
		window.addEventListener("resize", fHandler, false);
	}
	if ("scroll" in this) {
		eval ("var fHandler = function () {"+this._className+"Instance.scroll();}");
		window.addEventListener("scroll", fHandler, false);
	}
	if ("destruct" in this) {
		eval ("var fHandler = function () {"+this._className+"Instance.destruct();}");
		window.addEventListener("beforeunload", fHandler, false);
	}
	$.instanciatesModules.push(this._className+"Instance");
}
Module.prototype.setTimeout = function (cmethod, interval) {
	this.clearTimeout();
	var cmdString = "window['"+this._className+"Instance']."+cmethod+"();";
	this._currentTimeout = window.setTimeout(cmdString, interval);
};
Module.prototype.clearTimeout = function () {
	if (this._currentTimeout) {
		window.clearTimeout(this._currentTimeout);
	}
};
Module.prototype.initStyles = function () {
	if (!document.styleSheets.length && document.head) {
		document.head.appendChild(document.createElement("style"));
	}
	if (!window.webkit)
	{
		this.currentSheet = document.styleSheets[0];
	}
	
};
Module.prototype.addRule = function (rule) {
	var style = false;
	try {
	if(document.styleSheets)
	{
		if (!window.webkit)
		{
		 	var a   = this.currentSheet;
	 		var arr = rule.replace(/}.*/,'').split('{');
	 		if	(a.insertRule) {
	 			a.insertRule(rule,a.cssRules.length);
	 		}
	 		else if(a.addRule)
	 		{
	  			var arr2 = arr[0].split(/,/);
	  			for(var i=0;i<arr2.length;i++) {
	  				a.addRule(arr2[i],arr[1]);
	  			}
	  		}
 		}
 		else
 		{
 			style = document.head.getElementsByTagName("style").item(0);
 			if (!style)
 			{
 				style = document.head.appendChild(document.createElement("style"));
 			}
			style.appendChild(document.createTextNode(rule));
 		}
 	}
	}
	catch (e) {}
};
Module.prototype._getCName = function (fHandler)
{
	return fHandler.toString().match(/function\s*(\w+)/)[1];
};
Module.prototype.attachBehavior = function (className, ClassHandler)
{
	var coll = new Array ();
	var i=0;
	if (arguments.length == 3 && arguments[2] != document)
	{
		var refNode = arguments[2];
		var allChilds = refNode.getElementsByTagName("*");
		for (i=0; i<allChilds.length; i++)
		{
			if (allChilds.item(i).className.indexOf(className) != -1) {
				coll.push(allChilds.item(i));
			}
		}
	}
	else {
		coll = $.getElementsByClassName (className);
	}
	i = 0;
	var exists = false;
	while (coll.length) 
	{
		if (!coll[0].jsobject)
		{
			object = new ClassHandler (coll[0], i++);
			object.module = this;
		}
  		coll.shift();
  	}
};
Module.prototype.attachInputBehavior = function (type, ClassHandler)
{
	var coll = [];
	var refNode = document;
	if (arguments.length == 3 && arguments[2] != document) {
		refNode = arguments[2];
	}
	if (type == "textarea")
	{
		for (j=0; j < refNode.getElementsByTagName("textarea").length; j++) {
			coll.push(refNode.getElementsByTagName("textarea").item(j));
		}
	}
	else if (type == "select")
	{
		for (j=0; j < refNode.getElementsByTagName("select").length; j++) {
			coll.push(refNode.getElementsByTagName("select").item(j));
		}
	}
	else
	{
		if (document.evaluate && refNode == document)
		{
			xpathQuery = "//*[@type='"+type+"']";
			reval = document.evaluate(xpathQuery, document, null, XPathResult.ANY_TYPE, null);
			thisElement = reval.iterateNext();
			while (thisElement) {
		 		coll.push(thisElement);
		 		thisElement = reval.iterateNext();
			}
		}
		else
		{
			elements = refNode.getElementsByTagName("input");
			for (i=0; i < elements.length; i++) {
				try {
					if (elements.item(i).getAttribute("type") == type) {
						coll.push(elements.item(i));
					}
				}
				catch (e)
				{
					alert(elements.item(i));
				}
			}
		}
	}
	
	i = 0;
	while (coll.length) 
	{
		if (!coll[0].jsobject)
		{
  			object = new ClassHandler (coll[0], i++);
		}
  		coll.shift();
  	}
};


/************************************************** * dom-drag.js * 09.25.2001 * www.youngpup.net * Script featured on Dynamic Drive (http://www.dynamicdrive.com) 12.08.2005 ************************************************** * 10.28.2001 - fixed minor bug where events * sometimes fired off the handle, not the root. **************************************************/var Drag = {	"obj" : null,	"init" : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)	{		o.onmousedown	= Drag.start;		o.hmode			= bSwapHorzRef ? false : true ;		o.vmode			= bSwapVertRef ? false : true ;		o.root = oRoot && oRoot != null ? oRoot : o ;		if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) { o.root.style.left   = "0px"; }		if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) { o.root.style.top    = "0px"; }		if (!o.hmode && isNaN(parseInt(o.root.style.right ))) { o.root.style.right  = "0px"; }		if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) { o.root.style.bottom = "0px"; }		o.minX	= typeof minX != 'undefined' ? minX : null;		o.minY	= typeof minY != 'undefined' ? minY : null;		o.maxX	= typeof maxX != 'undefined' ? maxX : null;		o.maxY	= typeof maxY != 'undefined' ? maxY : null;		o.xMapper = fXMapper ? fXMapper : null;		o.yMapper = fYMapper ? fYMapper : null;		o.root.onDragStart	= new Function();		o.root.onDragEnd	= new Function();		o.root.onDrag		= new Function();	},	"start" : function(e)	{		var o = Drag.obj = this;		//e = Drag.fixE(e);		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );		o.root.onDragStart(x, y);		o.lastMouseX	= e.clientX;		o.lastMouseY	= e.clientY;		if (o.hmode) {			if (o.minX != null)	{ o.minMouseX	= e.clientX - x + o.minX; }			if (o.maxX != null)	{ o.maxMouseX	= o.minMouseX + o.maxX - o.minX; }		} else {			if (o.minX != null) { o.maxMouseX = -o.minX + e.clientX + x; }			if (o.maxX != null) { o.minMouseX = -o.maxX + e.clientX + x; }		}		if (o.vmode) {			if (o.minY != null)	{ o.minMouseY	= e.clientY - y + o.minY; }			if (o.maxY != null)	{ o.maxMouseY	= o.minMouseY + o.maxY - o.minY; }		} else {			if (o.minY != null) { o.maxMouseY = -o.minY + e.clientY + y; }			if (o.maxY != null) { o.minMouseY = -o.maxY + e.clientY + y; }		}		document.onmousemove	= Drag.drag;		document.onmouseup		= Drag.end;		return false;	},	"drag" : function(e)	{		//e = Drag.fixE(e);		var o = Drag.obj;		var ey	= e.clientY;		var ex	= e.clientX;		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );		var nx, ny;		if (o.minX != null) { ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX); }		if (o.maxX != null) { ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX); }		if (o.minY != null) { ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY); }		if (o.maxY != null) { ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY); }		nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));		ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));		if (o.xMapper)	{ 
			nx = o.xMapper(y);
		} else if (o.yMapper) {
			ny = o.yMapper(x);
		}		Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";		Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";		Drag.obj.lastMouseX	= ex;		Drag.obj.lastMouseY	= ey;		Drag.obj.root.onDrag(nx, ny);		return false;	},	"end" : function()	{		document.onmousemove = null;		document.onmouseup   = null;		Drag.obj.root.onDragEnd(	parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), 									parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));		Drag.obj = null;	},	"fixE" : function(e)	{		if (typeof e == 'undefined') { e = window.event;		if (typeof e.layerX == 'undefined') { e.layerX = e.offsetX; }		if (typeof e.layerY == 'undefined') { e.layerY = e.offsetY; }		return e;	}}};
// Modules et extensions
BaseModule.extendsClass(Module);
function BaseModule () 
{
	Module.call (this);
	this.cframe = false;
}
BaseModule.prototype.initBehavior = function ()
{
	return true;
};
BaseModule.prototype.setClientReference = function (egClient)
{
	this.client = egClient;
};
BaseModule.prototype.openFrame = function (furl)
{
	this.cframe = new BaseIFrame(furl);
	this.cframe.insertIn(document.body);
	this.cframe.open();
};
BaseModule.prototype.showFrame = function (furl)
{
	this.cframe.setVisible();
};

BaseModule.prototype.addCssRules = function ()
{
	this.addRule("#dialog {width : 90%;left : 5%;position : absolute;z-index : 10000;opacity : 1;}");
	this.addRule(".fdialog {width : 90%;left : 5%;position : absolute;z-index : 10000;opacity : 1; height:300px; top : 40px;border : 1px solid #999;}");
	this.addRule("#mainContent {overflow : auto;position : relative;}");
	this.addRule(".titlebar {padding : 5px;height : 20px;font-weight : bold;}");
	this.addRule(".titlebar img {float : right;cursor : pointer;}");
};
new BaseModule ();
/*------------------------------------------------------------------------------------
	CLASSE BaseIFrame
-------------------------------------------------------------------------------------*/
BaseIFrame.extendsClass(BaseElement);
function BaseIFrame (furl)
{
	BaseElement.call(this, ["iframe"]);
	this.setHidden();
	this.currentUrl = furl;
	this.htmlElement.setAttribute("frameborder", "0");
	this.htmlElement.setAttribute("src", "about:blank");
	this.htmlElement.className = "fdialog";
	this.htmlElement.style.height = (window.getInnerSize().height-80)+"px";
}
BaseIFrame.prototype.loadEvent = function () {
};
BaseIFrame.prototype.open = function () {
	this.overlay = new OverlayFrame (this, false);
};
BaseIFrame.prototype.display = function () {
	this.htmlElement.setAttribute("src", this.currentUrl);
};


/*------------------------------------------------------------------------------------
	CLASSE Dialog
	Boite de dialogue javascript avec Overlay.
	oButton			Boutton lié à l'ouverture (lien)
	oTitle			Titre de la boite de dialogue
	[content]		Noeud XML de contenu
-------------------------------------------------------------------------------------*/
BaseDialog.extendsClass (BaseRequestElement);
function BaseDialog (oButton, oTitle) {
	
	
	this.destroyOnClose = true; 				// Indique si la fenêtre est détruite à la fermeture
	this.mainContent = false;					// Noeud de contenu de la boîte
	this.clickElement = oButton.jsobject;		// Object de l'élément cliqué

	this.redirectLink = true;
	
	var args = ["div"];
	
	// Le troisième parmètre est le contenu de la boîte						
	if (arguments.length == 3) {
		args = [arguments[2]];
		this.mainContent = arguments[2].firstChild;
		if (this.mainContent.nodeType != 1) {
			this.mainContent = this.mainContent.nextSibling;
		}
	}

	// Création de la boite de dialogue
	BaseRequestElement.call(this, args);

	var closeButton = new BaseButton(this, "close", "/skin/images/dialog/close.png");
	this.htmlElement.setAttribute("id", "dialog");
	
	if (!this.clickElement.imageElement) 
	{
		// Création de la barre de titre
		var oTitleBar = document.createElement("div");
		if (this.mainContent) {
			this.htmlElement.insertBefore(oTitleBar, this.mainContent);
		}
		else {
			this.htmlElement.appendChild(oTitleBar);
		}
		oTitleBar.className = "titlebar";
	
		closeButton.insertIn(oTitleBar);
	
		var oSpanTitle = oTitleBar.appendChild(document.createElement("span"));
		oSpanTitle.appendChild(document.createTextNode(oTitle));
		oTitleBar.appendChild(document.createElement("hr"));
	}
	else
	{
		closeButton.insertIn(this.htmlElement);
	}
	
	
	// Ajout de la div de contenu 
	this.currentUrl = "";
	if (!this.mainContent) {
		this.mainContent = this.htmlElement.appendChild(document.createElement("div"));
		if (this.clickElement.imageElement)
		{
			this.setHidden();
			this.currentImage = new BaseImage ();
			this.currentImage.dialog = this;
			if (document.all)
			{
				this.currentImage.htmlElement.detachEvent("onload", BaseElement.prototype.onevent);
				this.currentImage.htmlElement.setAttribute("height", "480px");
				this.currentImage.htmlElement.setAttribute("width", "640px");
				this.currentImage.setImage(this.clickElement.imageElement.src.replace(".140.105",".640.480"));
				this.setVisible();
			}
			else {
				this.currentImage.setImage(this.clickElement.imageElement.src.replace(".140.105",".100"));
			}
			this.currentImage.insertIn(this.htmlElement);

			if ("tasksElement" in this.clickElement) {
				this.htmlElement.appendChild(this.clickElement.tasksElement.cloneNode(true));
			}
		}
		else if (this.clickElement.htmlElement.hasAttribute("href"))
		{
			this.currentUrl = this.clickElement.htmlElement.getAttribute("href");
			this._SendGETRequest (this.currentUrl+"?output=body", this.htmlElement);
		}
	}
	if (!this.clickElement.imageElement) {
		this.mainContent.setAttribute("id", "mainContent");
		this.mainContent.style.height = (window.getInnerSize().height-80)+"px";
	}
	else {
		this.htmlElement.className = "image";
	}
}
BaseDialog.prototype.display = function ()
{
	this.htmlElement.style.top = (document.documentElement.scrollTop+document.body.scrollTop+10)+"px";
	this.mainContent.style.height = (window.getInnerSize().height-80)+"px";
	BaseRequestElement.prototype.display.call(this);
};

BaseDialog.prototype.doRequest = function ()
{
	var xmlDocument = this.xmlResponse;
	var rootNode;
	try {
		if (xmlDocument.documentElement.getElementsByTagName("body").length !== 0) {
			rootNode = xmlDocument.documentElement.getElementsByTagName("body").item(0);
		}
		else if (xmlDocument.documentElement.getElementsByTagName("div").length !== 0) {
			rootNode = xmlDocument.documentElement.getElementsByTagName("div").item(0);
		}
		else {
			rootNode = xmlDocument.documentElement.getElementsByTagName("ul").item(0);
		}
		var childs = rootNode.childNodes;
		var full = false;
		for (var i = 0; i< childs.length; i++)
		{
			if (childs.item(i).nodeType == "1")
			{
				full = true;
				break;
			}
		}
		if (full)
		{
			var mainTarget = this.mainContent;
			mainTarget.innerHTML = "";
    		var node = document.importNode(rootNode, true);
   			node = mainTarget.appendChild(node);
   			if (this.redirectLink)
   			{
				var cAnchors = mainTarget.getElementsByTagName("a");
				for (i = 0; i < cAnchors.length; i++)
				{
					var curl = cAnchors.item(i).getAttribute("href");
					//if (curl.substr(curl.length-1) != "/")
					//	cAnchors.item(i).setAttribute("href", "/#"+curl)
					cAnchors.item(i).onclick = this.refresh;
					cAnchors.item(i).jsobject = this;
				}
   			}
    	}
	}
	catch (e) {
		alert("An exception occurred in the script. Error name: " + e.name + ". Error message: " + e.message);
	}
};

BaseDialog.prototype.refresh = function (evt) {
	var tAnchor;
	var cbevent = new CrossBrowserEvent (evt);
	cbevent.clearEvent();
	switch (cbevent.target.tagName.toLowerCase())
	{
		case "div":
		case "h3":
			tAnchor = cbevent.target.parentNode;
			break;
		case "object":
		case "img":
			if (cbevent.target.parentNode.tagName == "a")
			{
				tAnchor = cbevent.target.parentNode;
			}
			else
			{
				tAnchor = cbevent.target.parentNode.parentNode;
			}
			break;
		case "a":
			tAnchor = cbevent.target;
			break;
		default:
			alert ("Dialog : impossible de trouver le lien href");
			break;
	}
	if (tAnchor.getAttribute("href").indexOf("#") != -1)
	{
		tAnchor.jsobject.clickElement.updateRelatedElement(tAnchor.getAttribute("href").substr(tAnchor.getAttribute("href").indexOf("#")+1));
		tAnchor.jsobject.close();
	}	
	else {
		tAnchor.jsobject._SendGETRequest (tAnchor.getAttribute("href")+"&output=htmlContent", tAnchor.jsobject.htmlElement);
	}
};
BaseDialog.prototype.open = function () {
	this.overlay = new OverlayFrame (this, false);
};

BaseDialog.prototype.close = function (closeButton) {
	this.hide();
	this.overlay.setTimeout("decreaseOpacity", 5);
	//setTimeout("document.getElementById('dialog').jsobject.minimize()", 1);
};

BaseDialog.prototype.minimize = function () {
	var mheight = getWinInnerSize().height-120;
	if (this.htmlElement.clientHeight > 80)
	{
		this.htmlElement.style.height = (this.htmlElement.clientHeight-80)+"px";
		this.htmlElement.style.opacity = (this.htmlElement.clientHeight-80)/mheight;
		setTimeout("if (document.getElementById('dialog')) document.getElementById('dialog').jsobject.minimize()", 1);
	}
	else {
		document.getElementById("dialog").parentNode.removeChild(document.getElementById("dialog"));
	}
};

BaseDialog.prototype.maximize = function () {
	mheight = getWinInnerSize().height-200;
	if (this.htmlElement.clientHeight < mheight)
	{
		this.htmlElement.style.height = (this.htmlElement.clientHeight+80)+"px";
		this.htmlElement.style.opacity = (this.htmlElement.clientHeight+80)/mheight;
		setTimeout("if (document.getElementById('dialog')) document.getElementById('dialog').jsobject.maximize()", 1);
	}
};
/*------------------------------------------------------------------------------------
	CLASSE BaseFrame
	Boite de dialogue javascript avec Overlay.
	oButton			Boutton lié à l'ouverture (lien)
	oTitle			Titre de la boite de dialogue
	[content]		Noeud XML de contenu
-------------------------------------------------------------------------------------*/
BaseFrame.extendsClass (BaseRequestElement);
function BaseFrame (oButton, oTitle) {
	
	
	this.destroyOnClose = true; 				// Indique si la fenêtre est détruite à la fermeture
	this.mainContent = false;					// Noeud de contenu de la boîte
	if ("jsobject" in oButton) {
		this.clickElement = oButton.jsobject;
	}
	else {
		this.clickElement = oButton;		// Object de l'élément cliqué
	}
	this.redirectLink = true;
	
	var args = ["div"];
	
	// Le troisième parmètre est le contenu de la boîte						
	if (arguments.length == 3) {
		args = [arguments[2]];
		this.mainContent = arguments[2].firstChild;
		if (this.mainContent.nodeType != 1) {
			this.mainContent = this.mainContent.nextSibling;
		}
	}

	// Création de la boite de dialogue
	BaseRequestElement.call(this, args);

	this.htmlElement.setAttribute("id", "bframe");
	
	// Ajout de la div de contenu 
	this.currentUrl = "";
	if (!this.mainContent) {
		this.mainContent = this.appendElement("div");
		if (this.clickElement.imageElement)
		{
			this.setHidden();
			this.currentImage = new BaseImage ();
			this.currentImage.dialog = this;
			if (document.all)
			{
				this.currentImage.htmlElement.detachEvent("onload", BaseElement.prototype.onevent);
				this.currentImage.htmlElement.setAttribute("height", "480px");
				this.currentImage.htmlElement.setAttribute("width", "640px");
				this.currentImage.setImage(this.clickElement.imageElement.src.replace(".140.105",".640.480"));
				this.setVisible();
			}
			else {
				this.currentImage.setImage(this.clickElement.imageElement.src.replace(".140.105",".100"));
			}
			this.currentImage.insertIn(this.htmlElement);

			if ("tasksElement" in this.clickElement) {
				this.htmlElement.appendChild(this.clickElement.tasksElement.cloneNode(true));
			}
		}
		else if (this.clickElement.htmlElement.hasAttribute("href"))
		{
			if (this.clickElement.htmlElement.getAttribute("href") != "#") {
				this.currentUrl = this.clickElement.htmlElement.getAttribute("href");
				this._SendGETRequest (this.currentUrl+"?output=body", this.htmlElement);
			}
		}
	}
}
BaseFrame.prototype.loadView = function (currentUrl)
{
	this.mainContent.setHidden();
	this.mainContent.htmlElement.innerHTML = "";
	this.currentUrl = currentUrl;
	this.redirectLink = true;
	this.open();
	this._SendGETRequest (this.currentUrl+"&output=body", this.htmlElement);
};
BaseFrame.prototype.doRequest = function ()
{
	var xmlDocument = this.xmlResponse;
	var rootNode;
	try {
		if (xmlDocument.documentElement.getElementsByTagName("body").length !== 0) {
			rootNode = xmlDocument.documentElement.getElementsByTagName("body").item(0);
		}
		else if (xmlDocument.documentElement.getElementsByTagName("form").length !== 0) {
			rootNode = xmlDocument.documentElement.getElementsByTagName("form").item(0);
		}
		else if (xmlDocument.documentElement.getElementsByTagName("div").length !== 0) {
			rootNode = xmlDocument.documentElement.getElementsByTagName("div").item(0);
		}
		else {
			rootNode = xmlDocument.documentElement.getElementsByTagName("ul").item(0);
		}
		var childs = rootNode.childNodes;
		var full = false;
		for (var i = 0; i< childs.length; i++)
		{
			if (childs.item(i).nodeType == "1")
			{
				full = true;
				break;
			}
		}
		if (full)
		{
			var mainTarget = this.mainContent.htmlElement;
			mainTarget.innerHTML = "";
    		var node = document.importNode(rootNode, true);
  			node = mainTarget.appendChild(node);
  			if ("FormModuleInstance" in window) {
   			FormModuleInstance.refreshBehavior(node);
  			}
  			if (this.redirectLink)
  			{
				var cAnchors = mainTarget.getElementsByTagName("a");
				for (i = 0; i < cAnchors.length; i++)
				{
					var curl = cAnchors.item(i).getAttribute("href");
					//if (curl.substr(curl.length-1) != "/")
					//	cAnchors.item(i).setAttribute("href", "/#"+curl)
					cAnchors.item(i).onclick = this.refresh;
					cAnchors.item(i).jsobject = this;
				}
				var cForms = mainTarget.getElementsByTagName("form");
				for (i = 0; i < cForms.length; i++)
				{
					cForms.item(i).onsubmit = this.post;
					cForms.item(i).jsobject = this;
				}
  			}
  			this.mainContent.setVisible();
    	}
	}
	catch (e) {
		alert("An exception occurred in the script. Error name: " + e.name + ". Error message: " + e.message);
	}
};
BaseFrame.prototype.post = function (evt) {
	var cbevent = new CrossBrowserEvent (evt);
	var clickButton = evt.explicitOriginalTarget;
	cbevent.clearEvent();
	var cForm = cbevent.target;
	var cFields = cForm.elements;
	var qparts = [];
	for (var i=0;i<cFields.length;i++)
	{
		if ((cFields[i].tagName != "button" || cFields[i] == clickButton) && $.isDef(cFields[i].name) && cFields[i].name.length !=0) {
			qparts.push($.urlEncode(cFields[i].name)+"="+$.urlEncode(cFields[i].value))
		}
	}
	qparts.push("isRequest=true");
	var formData = qparts.join("&");
	this.jsobject.mainContent.setHidden();
	this.jsobject.mainContent.htmlElement.innerHTML = "";
	this.jsobject._SendHTTPRequest (this.action, "POST",formData);
	
	return false;
};
BaseFrame.prototype.refresh = function (evt) {
	var tAnchor;
	var cbevent = new CrossBrowserEvent (evt);
	cbevent.clearEvent();
	switch (cbevent.target.tagName.toLowerCase())
	{
		case "div":
		case "h3":
			tAnchor = cbevent.target.parentNode;
			break;
		case "object":
		case "img":
			if (cbevent.target.parentNode.tagName == "a")
			{
				tAnchor = cbevent.target.parentNode;
			}
			else
			{
				tAnchor = cbevent.target.parentNode.parentNode;
			}
			break;
		case "a":
			tAnchor = cbevent.target;
			break;
		default:
			alert ("Dialog : impossible de trouver le lien href");
			break;
	}
	if (tAnchor.getAttribute("href").indexOf("#") != -1)
	{
		tAnchor.jsobject.clickElement.updateRelatedElement(tAnchor.getAttribute("href").substr(tAnchor.getAttribute("href").indexOf("#")+1));
		tAnchor.jsobject.close();
	}	
	else {
		tAnchor.jsobject._SendGETRequest (tAnchor.getAttribute("href")+"&output=htmlContent", tAnchor.jsobject.htmlElement);
	}
};
BaseFrame.prototype.open = function () {
	this.display();
};

BaseFrame.prototype.close = function (closeButton) {
	this.hide();
};

/*------------------------------------------------------------------------------------
	CLASSE BaseButton
-------------------------------------------------------------------------------------*/
BaseButton.extendsClass(BaseElement);
function BaseButton (targetObject, targetMethod, imageSrc)
{
	BaseElement.call(this, ["div"]);
	this.isEnabled = true;
	this.isToogle = false;
	this.image = this.appendChild(new Image());
	this.targetObject = targetObject;
	this.targetMethod = targetMethod;
	this.canvas = false;
	if (arguments.length != 4)
	{
		this.image.style.display = "none";
		this.canvas = new CanvasElement(16,16);
		this.canvas.insertIn(this.htmlElement);
		this.image.onload = this.loadImage;
	}
	this.image.setAttribute("src", imageSrc);
}
BaseButton.prototype.clickEvent = function (cbevent) {
	if (this.isToogle || (!this.isToogle && this.isEnabled))
	{
		return this.targetObject[this.targetMethod](this);
	}
};
BaseButton.prototype.enable = function () {
	this.isEnabled = true;
	this.htmlElement.style.opacity = 1;
	if (this.canvasDisabled)
	{
		this.canvas.display();
		this.canvasDisabled.hide();
	}
};
BaseButton.prototype.disable = function () {
	this.isEnabled = false;
	this.htmlElement.style.opacity = 0.6;
	if (this.canvasDisabled)
	{
		this.canvas.hide();
		this.canvasDisabled.display();
	}
};
BaseButton.prototype.loadImage = function (evt) {
	var event = new CrossBrowserEvent(evt);
	var cObject = event.target.parentNode.jsobject;
	cObject.canvas.context.drawImage(cObject.image,0,0,16,16);
	cObject.desaturate();
};

BaseButton.prototype.desaturate = function()
{
	this.canvasDisabled = new CanvasElement(16,16);
	if (this.isEnabled)
	{
		this.canvasDisabled.hide();
	}
	else
	{
		this.canvas.hide();
	}
	this.canvasDisabled.insertIn(this.htmlElement);
	this.canvasDisabled.context.drawImage(this.image,0,0,16,16);
	var oDataSrc = this.canvasDisabled.context.getImageData(0, 0, 16, 16);
	var oDataDst = this.canvasDisabled.context.getImageData(0, 0, 16, 16);
	var aDataSrc = oDataSrc.data;
	var aDataDst = oDataDst.data;

	var h = 16;
	var w = 16;
	var y = h;
	do {
		var iOffsetY = (y-1)*w*4;
		var x = w;
		do {
			var iOffset = iOffsetY + (x-1)*4;
			var iBrightness = Math.round(aDataSrc[iOffset]*0.3 + aDataSrc[iOffset+1]*0.59 + aDataSrc[iOffset+2]*0.11);

			aDataDst[iOffset] = iBrightness;
			aDataDst[iOffset+1] = iBrightness;
			aDataDst[iOffset+2] = iBrightness;
			aDataDst[iOffset+3] = aDataSrc[iOffset+3];

		} while (--x);
	} while (--y);
	this.canvasDisabled.context.putImageData(oDataDst,0,0);
	return true;
	
};
/*------------------------------------------------------------------------------------
	CLASSE BaseList
-------------------------------------------------------------------------------------*/
BaseList.extendsClass(BaseElement);
function BaseList ()
{
	BaseElement.call(this, ["ul"]);
	this.items = new Array ();
}
BaseList.prototype.insertItem = function (label) {
	var item = new BaseItem();
	this.items.push (item);
	item.setLabel(label);
	item.insertIn(this.htmlElement);
	return item;
};
/*------------------------------------------------------------------------------------
	CLASSE BaseItem
-------------------------------------------------------------------------------------*/
BaseItem.extendsClass(BaseElement);
function BaseItem ()
{
	BaseElement.call(this, ["li"]);
	this.activeElement = this.htmlElement.appendChild(document.createElement("a"));
}
BaseItem.prototype.setLabel = function (label) {
	this.activeElement.innerHTML = "";
	this.activeElement.appendChild(document.createTextNode(label));
};

/*------------------------------------------------------------------------------------
	CLASSE BaseScroller
-------------------------------------------------------------------------------------*/
BaseScroller.extendsClass(BaseElement);
function BaseScroller (targetObject, scrollStep, className)
{
	BaseElement.call(this, ["div"]);
	this.htmlElement.className = className;
	this.targetObject = targetObject;
	this.originalStep = scrollStep;
	if (this.originalStep < 0) {
		this.htmlElement.appendChild(document.createTextNode("«"));
	}
	else {
		this.htmlElement.appendChild(document.createTextNode("»"));
	}
	this.maxTime = 200;
}
BaseScroller.prototype.mouseoverEvent = function (cbevent) {
	this.targetObject.noscroll = true;
	this.setTimeout("scrollTarget", this.maxTime);
};
BaseScroller.prototype.scrollTarget = function (cbevent) {
	this.targetObject.scrollStep(this.originalStep);
	this.setTimeout("scrollTarget", this.maxTime);
	if (this.maxTime > 10) {
		this.maxTime = this.maxTime-10;
	}
};
BaseScroller.prototype.mouseoutEvent = function (cbevent) {
	this.clearTimeout();
	this.maxTime = 200;
	this.targetObject.noscroll = false;
};

/*------------------------------------------------------------------------------------
	CLASSE BaseLinkButton
-------------------------------------------------------------------------------------*/
BaseLinkButton.extendsClass(BaseElement);
function BaseLinkButton (targetObject, targetMethod, atext)
{
	var className = false;
	if (arguments.length == 4) {
		className = arguments[3];
	}
	 
	BaseElement.call(this, ["a"]);
	this.targetObject = targetObject;
	this.targetMethod = targetMethod;
	this.htmlElement.setAttribute("href", "#");
	if (className)
	{
		this.htmlElement.className = className;
		this.setStyles("{background : url(/skin/tasks/"+className+".png) no-repeat top left;}");
	}
	this.htmlElement.appendChild(document.createTextNode(atext));
}
BaseLinkButton.prototype.clickEvent = function (cbevent) {
	cbevent.clearEvent();
	return this.targetObject[this.targetMethod](this);
};
BaseLinkButton.prototype.enable = function () {
	if (!document.all) {		this.htmlElement.style.opacity = 1;
	}	this.htmlElement.style.color = "#000";};BaseLinkButton.prototype.disable = function () {	if (!document.all) {		this.htmlElement.style.opacity = 0.5;
	}	this.htmlElement.style.color = "#999";};
/*------------------------------------------------------------------------------------
	CLASSE BaseImage
-------------------------------------------------------------------------------------*/
BaseImage.extendsClass(BaseElement);
function BaseImage ()
{
	BaseElement.call(this, ["img"]);
	this.htmlElement.className = "mimg";
	this.tempImage;
}
BaseImage.prototype.loadEvent = function (event) {

	var wImg = this.tempImage.width;
	var hImg = this.tempImage.height;

	var wMax = getWinInnerSize().width-50;
	var hMax = getWinInnerSize().height-120;
	if ("viewElement" in this)
	{
		wMax = this.viewElement.htmlElement.clientWidth-50;
		hMax = hImg;
	}
	var wFinal;
	var hFinal;
	var ratio = 1;
	if (wImg > wMax && hImg > hMax) {
		if (wMax/wImg < hMax/hImg) {
			ratio = wMax/wImg;
		}
		else {
			ratio = hMax/hImg;
		}
	}
	else if (wImg > wMax) {
		ratio = wMax/wImg;
	}
	else if (hImg > hMax) {
		ratio = hMax/hImg;
	}
	this.htmlElement.width = Math.round(wImg*ratio);
	this.htmlElement.height = Math.round(hImg*ratio);
	var dLeft = Math.round((getWinInnerSize().width - this.htmlElement.width - 10)/2);
	var dTop = document.documentElement.scrollTop+document.body.scrollTop + Math.round((getWinInnerSize().height - this.htmlElement.height - 60)/2);
	if ("dialog" in this)
	{
		this.dialog.htmlElement.style.left = dLeft+"px";
		this.dialog.htmlElement.style.top = dTop+"px";
		this.dialog.setVisible();
	}
};
BaseImage.prototype.setImage = function (imgSrc) {
	this.tempImage = new Image ();
	this.tempImage.src = imgSrc;
	this.htmlElement.src = imgSrc;
};
/*------------------------------------------------------------------------------------
	CLASSE OverlayFrame
-------------------------------------------------------------------------------------*/
OverlayFrame.extendsClass(BaseElement);
function OverlayFrame (elementToShow)
{
	BaseElement.call(this, ["div"]);
	this.elementToShow = elementToShow;
	this.opacity = 0;
	
	this.setHidden();
	this.setStyles("{"+
		"z-index : 8000;"+
		"position : absolute;"+
		"top : "+(document.documentElement.scrollTop+document.body.scrollTop)+"px;"+
		"left : 0;"+
		"height: "+window.getInnerSize().height+"px;"+
		"width: "+window.getInnerSize().width+"px;"+
		"background-color : #888;"+
		"opacity : 0;"+
		"filter : alpha(opacity:0);"+
		"}");
	this.insertIn(document.getElementsByTagName("body").item(0));
	document.getElementsByTagName("body").item(0).style.overflow = "hidden";
	this.setTimeout("increaseOpacity", 5);
	
}
OverlayFrame.prototype.increaseOpacity = function ()
{
	this.setVisible();
	this.opacity = this.opacity+0.2;
	this.htmlElement.style.opacity = this.opacity;
	this.htmlElement.style.filter = "alpha(opacity:"+this.opacity*100+")";
	if (this.opacity < 0.6)	{
		this.setTimeout("increaseOpacity", 5);
	}
	else {
		this.clearTimeout();
		this.elementToShow.display ();
	}
};
OverlayFrame.prototype.decreaseOpacity = function ()
{
	this.opacity = this.opacity-0.2;
	this.htmlElement.style.opacity = this.opacity;
	this.htmlElement.style.filter = "alpha(opacity:"+this.opacity*100+")";
	if (this.opacity > 0) {
		this.setTimeout("decreaseOpacity", 5);
	}
	else {
		this.clearTimeout();
		document.getElementsByTagName("body").item(0).style.overflow = "auto";
		this.destruct();
	}
};
/*------------------------------------------------------------------------------------
	CLASSE CanvasElement
-------------------------------------------------------------------------------------*/
CanvasElement.extendsClass(BaseElement);
function CanvasElement ()
{
	BaseElement.call(this, ["canvas"]);
	this.context = this.htmlElement.getContext('2d');
	if (arguments.length == 2) {
		this.htmlElement.width = arguments[0];
		this.htmlElement.height = arguments[1];
	}	
}
CanvasElement.prototype.roundedRect = function (x,y,width,height,radius){  this.context.beginPath();  this.context.moveTo(x,y+radius);  this.context.lineTo(x,y+height-radius);  this.context.quadraticCurveTo(x,y+height,x+radius,y+height);  this.context.lineTo(x+width-radius,y+height);  this.context.quadraticCurveTo(x+width,y+height,x+width,y+height-radius);  this.context.lineTo(x+width,y+radius);  this.context.quadraticCurveTo(x+width,y,x+width-radius,y);  this.context.lineTo(x+radius,y);  this.context.quadraticCurveTo(x,y,x,y+radius);  this.context.fill();  this.context.stroke();};
	

// Modules et extensions
VigneronModule.extendsClass(Module);
function VigneronModule () 
{
	Module.call (this);
}
VigneronModule.prototype.initBehavior = function ()
{
	this.attachBehavior("mainmenu", MainmenuElement);
	this.attachBehavior("diaporama", DiaporamaElement);
	this.attachBehavior("mgalerie", GalerieElement);
	this.attachBehavior("autoscroll",	AutoscrollBlock);
	this.attachBehavior("matj",	TabTable);
	this.attachBehavior("tabsCont",	TabsElement);

	this.attachBehavior("thumbview", ThumbnailViewElement);

	//attachBehavior("listview", 	BlockViewElement);
	//attachBehavior("blockview", 	IconViewElement);
	//attachBehavior("sblockview", 	BlockViewElement);
	//attachBehavior("iconview", 	IconViewElement);
	//attachBehavior("homeModules", UserBlocks);
};
VigneronModule.prototype.addCssRules = function ()
{
	// Règles de style de base pour les champs de formulaire
	this.addRule(".diaporama ul {display : none;}");
	this.addRule(".matj div {display : none; clear : both;}");
	this.addRule(".matj .curcont {display : block;}");
	this.addRule(".matj h3 {width : 25%; margin-bottom : 0; text-align : center; padding : 5px 0 5px 0; float : left; cursor : pointer;}");
	this.addRule(".matj .curtab {color : #A60; background : #fffcc5;}");
	if (document.all)
	{
		this.addRule(".image {left : 50% !important; margin-left : -325px;");

	}
	/*
	addRule(".others > ul {display : none;}");
	addRule(".others {display : inline;}");
	addRule(".gtab {position : relative; float : left; margin-right : 2px;}");
	addRule(".gtab span {display : block; width : 100%; text-align : center; padding : 4px 0 0 0;}");
	addRule(".tabsContainer {height : 26px; width : 100%; }");
	addRule(".blockview {clear : both !important;}");
	*/
};
vigneronInstance = new VigneronModule ();
/*------------------------------------------------------------------------------------
	CLASSE MainmenuElement
	Gère un diaporama de photos
-------------------------------------------------------------------------------------*/
MainmenuElement.extendsClass(BaseElement);
function MainmenuElement ()
{
	BaseElement.call(this, arguments);
	var oUls = this.htmlElement.parentNode.getElementsByTagName("ul");
	// Construction des sous-menus
	this.submenus = [];
	for (var i=0; i<oUls.length; i++) 
	{
		if (oUls.item(i).className.indexOf("submenu") != -1)
		{
			var newmenu = new SubmenuElement(oUls.item(i));
			newmenu.mainmenu = this;
			this.submenus.push(newmenu);
		}
	}
	// Attachement de sous menus au menu principal, ajout du hover
	var oLis = this.htmlElement.getElementsByTagName("li");
	this.mainitems = [];
	this.currentMenu = 0;
	for (i=0; i<oLis.length; i++) 
	{
		if (oLis.item(i).className == "current")
		{
			this.currentMenu = i;
		}
		var newitem = new MainitemElement(oLis.item(i));
		newitem.submenu = this.submenus[i];
		newitem.submenu.mainitem = newitem;
		newitem.mainmenu = this;
		this.mainitems.push(newitem);
	}
	this.hideSubmenus();
	this.showCurrent();
}
MainmenuElement.prototype.hideSubmenus = function (currentMenu)
{
	for (var i=0; i<this.submenus.length; i++)
	{
		if (this.submenus[i] !== currentMenu)
		{
			this.submenus[i].hide();
		}
	}
	for (i=0; i<this.mainitems.length; i++)
	{
		this.mainitems[i].removeAttribute("class");
	}
};
MainmenuElement.prototype.showCurrent = function ()
{
	this.hideSubmenus();
	//this.submenus[this.currentMenu].display();
	this.mainitems[this.currentMenu].setAttribute("class", "current");
};

/*------------------------------------------------------------------------------------
	CLASSE MainmenuElement
	Gère un diaporama de photos
-------------------------------------------------------------------------------------*/
MainitemElement.extendsClass(BaseElement);
function MainitemElement ()
{
	BaseElement.call(this, arguments);
	this.submenu = false;
	this.mainmenu = false;
}
MainitemElement.prototype.mouseoverEvent = function (evt)
{
	this.mainmenu.hideSubmenus(this.submenu);
	this.setAttribute("class", "current");
	var oleft = 0;
	if (this.htmlElement.offsetLeft!=0) {
		oleft =	this.htmlElement.offsetLeft-1;
	}
		
	this.submenu.htmlElement.style.left = oleft+"px";
	this.submenu.display();
};
MainitemElement.prototype.mouseoutEvent = function (evt)
{
	var destNode = evt.eventHandler.relatedTarget; 
	if ("toElement" in evt.eventHandler) {
		destNode = evt.eventHandler.toElement; 
	}
	
		this.clearTimeout();
		this.mainmenu.showCurrent();
};

/*------------------------------------------------------------------------------------
	CLASSE SubmenuElement
	Gère un diaporama de photos
-------------------------------------------------------------------------------------*/
SubmenuElement.extendsClass(BaseElement);
function SubmenuElement ()
{
	BaseElement.call(this, arguments);
	this.mainmenu = false;
	this.mainitem = false;
	this.ison = false;
}
SubmenuElement.prototype.mouseoverEvent = function (evt)
{
	this.ison = true;
	this.mainmenu.hideSubmenus(this);
	this.mainitem.setAttribute("class", "current");
	this.display();
};

SubmenuElement.prototype.mouseoutEvent = function (evt)
{
	var destNode = evt.eventHandler.relatedTarget; 
	
	if (this.ison && !this.contains(destNode))
	{
		this.hide();
		this.ison = false;
		this.mainitem.mouseoutEvent(evt);
	}
	return evt.clearEvent();
};
SubmenuElement.prototype.display = function () {
	this.htmlElement.style.display = "block";
};

/*------------------------------------------------------------------------------------
	CLASSE ThumbnailViewElement
	Element de type block en autoscroll
-------------------------------------------------------------------------------------*/
ThumbnailViewElement.extendsClass(BaseElement);
function ThumbnailViewElement ()
{
	BaseElement.call(this, arguments);
	this.thumbnails = new Array ();
	this.currentThumbnailIndex = 0;
	this.paused = false;
	this.noscroll = false;
	
	// Div pour le scroll
	var cDivs = this.htmlElement.getElementsByTagName("div");
	var initialContainer = cDivs.item(0);
	
	// Ajout des scroller pour le navigateur
	this.overflow = document.createElement("div");
	this.overflow.style.overflow = "hidden";
	this.scrollLeft = new BaseScroller (this, -5, "sleft");
	this.scrollRight = new BaseScroller (this, 5, "sright");
	this.scrollLeft.hide();
	this.scrollRight.hide();
	this.scrollLeft.insertIn(this.htmlElement);
	this.scrollRight.insertIn(this.htmlElement);
	this.htmlElement.appendChild (this.overflow);
	// Div contenant les images
	this.container = this.overflow.appendChild(initialContainer);
	this.container.style.overflow = "hidden";
	
	// Ajout des thumbnails
	var oAnchors = this.htmlElement.getElementsByTagName("a");
	var currentThumbnail = false;
	for (var i=0; i<oAnchors.length; i++)
	{
		if (oAnchors.item(i).getElementsByTagName("img").length == 1)
		{
			currentThumbnail = new ThumbnailElement (oAnchors.item(i));
			currentThumbnail.thumbnailView = this;
			currentThumbnail.viewIndex = this.thumbnails.length;
			this.thumbnails.push(currentThumbnail);
		}
	}

	// Ajout de la toolbar
	this.createToolbar ();
	
	// Ajout de la Div pour le diaporama;
	this.createDiapoContainer ();
	
	if (this.container.className == "thumbs") {
		this.setNavigatorView ();
	}
	else {
		this.setDiaporamaView ();
	}
	
}
ThumbnailViewElement.prototype.createToolbar = function () 
{
	this.toolbar = this.htmlElement.insertBefore (document.createElement("div"), this.htmlElement.firstChild);
	this.toolbar.className = "diaptoolbar";
	this.standardViewButton = new BaseLinkButton(this, "setStandardView", "Standard", "application_view_2columns");
	this.standardViewButton.hide();
	this.diaporamaViewButton = new BaseLinkButton(this, "setDiaporamaView", "Diaporama", "application_view_gallery");
	this.navigatorViewButton = new BaseLinkButton(this, "setNavigatorView", "Navigation", "application_view_tile");
	this.navigatorViewButton.insertIn(this.toolbar);
	this.diaporamaViewButton.insertIn(this.toolbar);
	this.standardViewButton.insertIn(this.toolbar);
	this.toolbar.appendChild(document.createElement("hr"));
};
ThumbnailViewElement.prototype.createDiapoContainer = function () 
{
	
	this.diapoContainer = this.htmlElement.appendChild (document.createElement("div"));
	this.diapoContainer.className = "diapocont";
	// Toolbar 
	var dtool = this.diapoContainer.appendChild (document.createElement("div"));
	dtool.className = "diaptools";
	var bNext = new BaseLinkButton (this, "goNext", "Suivant", "control_fastforward_blue");
	var bPrevious = new BaseLinkButton (this, "goPrevious", "Précédent", "control_rewind_blue");
	var bPause = new BaseLinkButton (this, "startPause", "Pause", "control_pause_blue");
	bPrevious.insertIn(dtool);
	bPause.insertIn(dtool);
	bNext.insertIn(dtool);
	// Image viewer
	this.viewer = new BaseImage();
	this.viewer.viewElement = this;
	this.viewer.insertIn(this.diapoContainer);
	this.diapoContainer.style.display = "none";
};
ThumbnailViewElement.prototype.setStandardView = function () 
{
	this.currentView = 0;
	this.clearTimeout();
	this.overflow.className = "onav";
	this.overflow.scrollLeft = 0;
	this.scrollLeft.hide();
	this.scrollRight.hide();
	
	this.diapoContainer.style.display = "none";
	this.navigatorViewButton.disable();
	this.diaporamaViewButton.disable();
	this.standardViewButton.enable();

	this.container.className = "standardView";
	this.container.style.width = "auto";
	this.container.style.height = "auto";
};

ThumbnailViewElement.prototype.setNavigatorView = function () 
{
	this.currentView = 1;
	this.clearTimeout();
	this.overflow.className = "onav";
	this.overflow.scrollLeft = 0;
	this.scrollLeft.hide();
	this.scrollRight.hide();
	
	this.navigatorViewButton.enable();
	this.diaporamaViewButton.disable();
	this.standardViewButton.disable();
	
	this.diapoContainer.style.display = "none";

	this.container.className = "thumbs";
	this.container.style.width = "auto";
	this.container.style.height = "auto";

};
ThumbnailViewElement.prototype.setDiaporamaView = function () 
{
	this.currentView = 2;
	this.scrollLeft.display();
	this.scrollRight.display();
	
	this.navigatorViewButton.disable();
	this.diaporamaViewButton.enable();
	this.standardViewButton.disable();
	
	this.diapoContainer.style.display = "block";
	
	this.container.className = "diaporamaView";
	this.container.style.width = (this.thumbnails.length*149)+"px";
	this.container.style.height = "115px";
	
	this.overflow.className = "odiap";

	this.nextThumbnail();
};
ThumbnailViewElement.prototype.nextThumbnail = function () 
{
	this.clearTimeout();
	if (arguments.length != 0) {
		this.currentThumbnailIndex = arguments[0];
	}
	if (document.all)
	{
		this.viewer.htmlElement.detachEvent("onload", BaseElement.prototype.onevent);
		this.viewer.htmlElement.setAttribute("height", "480px");
		this.viewer.htmlElement.setAttribute("width", "640px");
		this.viewer.setImage(this.thumbnails[this.currentThumbnailIndex].imageElement.src.replace(".140.105",".600.450"));
	}
	else {
		this.viewer.setImage(this.thumbnails[this.currentThumbnailIndex].imageElement.src.replace(".140.105",".100"));
	}
	
	this.thumbnails[this.currentThumbnailIndex].getFocus();
	this.currentThumbnailIndex++;
	if (this.currentThumbnailIndex >= this.thumbnails.length) {
		this.currentThumbnailIndex = 0;
	}
	if (!this.paused) {
		this.setTimeout("nextThumbnail", 5000);
	}
};
ThumbnailViewElement.prototype.goNext = function () 
{
	this.clearTimeout();
	if (this.currentThumbnailIndex >= this.thumbnails.length) {
		this.currentThumbnailIndex = 0;
	}
	this.nextThumbnail ();
};
ThumbnailViewElement.prototype.goPrevious = function () 
{
	this.clearTimeout();
	this.currentThumbnailIndex = this.currentThumbnailIndex-2;
	if (this.currentThumbnailIndex < 0) {
		this.currentThumbnailIndex = this.thumbnails.length+this.currentThumbnailIndex;
	}
	this.nextThumbnail ();
};
ThumbnailViewElement.prototype.startPause = function (aBut) 
{
	if (this.paused)
	{
		aBut.htmlElement.textContent = "Pause";
		this.paused = false;
		this.nextThumbnail ();
	}
	else 
	{
		aBut.htmlElement.textContent = "Reprendre";
		this.paused = true;
		this.clearTimeout();
	}
};
ThumbnailViewElement.prototype.scrollStep = function (indice) 
{
	this.overflow.scrollLeft = this.overflow.scrollLeft + indice;
};

/*------------------------------------------------------------------------------------
	CLASSE ThumbnailElement
	Element de type block en autoscroll
-------------------------------------------------------------------------------------*/
ThumbnailElement.extendsClass(BaseElement);
function ThumbnailElement ()
{
	BaseElement.call(this, arguments);
	var cImgs = this.htmlElement.getElementsByTagName("img");
	this.imageElement = cImgs.item(0);
	var cUls = this.htmlElement.parentNode.getElementsByTagName("ul");
	if (cUls.length != 0) {
		this.tasksElement = cUls.item(0);
	}
//	cvi_instant.add( this.imageElement, { tilt: "none", shadow: 33, color: "#fff", noshade: false } );
}
ThumbnailElement.prototype.clickEvent = function (event) 
{
	var oTitle;
	var currentView = 1;
	if ("thumbnailView" in this) {
		currentView = this.thumbnailView.currentView+0;
	}
	if (currentView != 0)
	{
		event.clearEvent();
		
		if (this.htmlElement.getAttribute("title")) {
			oTitle = this.htmlElement.getAttribute("title");
		}
		else {
			oTitle = "Image";
		}
		if (currentView == 1)
		{
			this.dialog = new BaseDialog(this.htmlElement, oTitle);
			this.dialog.htmlElement.style.zIndex = 9000;
			this.dialog.hide();
			this.dialog.insertIn (document.body);
			this.dialog.overlay = new OverlayFrame (this.dialog);
		}
		else if (currentView == 2) {
			this.thumbnailView.nextThumbnail(this.viewIndex);
		}
		return false;
	}
	return true;
};
ThumbnailElement.prototype.getFocus = function () 
{
	var cThumb = document.getElementById ("curThumb");
	if (cThumb) {
		cThumb.removeAttribute ("id");
	}
	this.htmlElement.setAttribute("id", "curThumb");	
	
	if (!this.thumbnailView.noscroll)
	{
		if ((this.htmlElement.offsetLeft+149) > (this.thumbnailView.overflow.scrollLeft + this.thumbnailView.overflow.clientWidth)) {
			this.thumbnailView.overflow.scrollLeft = this.htmlElement.offsetLeft+149;
		}
		if (this.htmlElement.offsetLeft < this.thumbnailView.overflow.scrollLeft) {
			this.thumbnailView.overflow.scrollLeft = this.htmlElement.offsetLeft-30;
		}
		if ((this.htmlElement.offsetLeft+149) < this.thumbnailView.overflow.clientWidth) {
			this.thumbnailView.overflow.scrollLeft = 0;
		}
		if ((this.htmlElement.offsetLeft+150) == (this.thumbnailView.thumbnails.length*149)) {
			this.thumbnailView.overflow.scrollLeft = this.thumbnailView.thumbnails.length*149;
		}
	}
};
ThumbnailElement.prototype.mouseoverEvent = function (cbevent) {
	this.thumbnailView.noscroll = true;
};
ThumbnailElement.prototype.mouseoutEvent = function (cbevent) {
	this.thumbnailView.noscroll = false;
};


/*------------------------------------------------------------------------------------
	CLASSE AutoscrollBlock
	Element de type block en autoscroll
-------------------------------------------------------------------------------------*/
AutoscrollBlock.extendsClass(BaseElement);
function AutoscrollBlock ()
{
	BaseElement.call(this, arguments);

	this.list = this.htmlElement.getElementsByTagName("dl").item(0);
	this.aList = this.htmlElement.appendChild(this.list.cloneNode(true));
	this.aList.style.position = "relative";

	this.scrollMax = this.list.offsetHeight;
	this.currentTop = 0;
	this.currentStep = 1;
	this.currentInterval = 100;

	this.htmlElement.style.position = "relative";
	this.list.style.position = "relative";
	this.list.style.top = "0";
	this.list.style.left = "0";

	this.setTimeout("scrollto", this.currentInterval);
}
AutoscrollBlock.prototype.scrollto = function ()
{
	if (this.currentTop + this.currentStep <= this.scrollMax)	
	{
		this.currentTop = this.currentTop + this.currentStep;
	}
	else
	{
		this.currentTop = 0;
	}
	this.list.style.top = "-"+this.currentTop+"px";
	this.aList.style.top = "-"+this.currentTop+"px";
	this.setTimeout("scrollto", this.currentInterval);
};
AutoscrollBlock.prototype.mouseoverEvent = function ()
{
	this.clearTimeout();
};
AutoscrollBlock.prototype.mouseoutEvent = function ()
{
	this.setTimeout("scrollto", this.currentInterval);
};
/*------------------------------------------------------------------------------------
	CLASSE TabTable
	Element de type block en autoscroll
-------------------------------------------------------------------------------------*/
TabTable.extendsClass(BaseElement);
function TabTable ()
{
	BaseElement.call(this, arguments);
	
	this.tabs = new Array ();
	this.containers = new Array ();
	
	var currentChild = false;
	var currentTab = false;
	var currentContainer = false;
	var selectedTab = false;
	
	for (var i=0; i < this.htmlElement.childNodes.length; i++)
	{
		currentChild = this.htmlElement.childNodes.item(i);
		if (currentChild.nodeType == 1)
		{
			switch(currentChild.tagName.toLowerCase())
			{
				case "h3":
					currentTab = this.tabs.push(currentChild);
					if (currentChild.className.indexOf("curtab") != -1) {
						selectedTab = currentChild;
					}
					currentChild.onclick = this.tabclk;
					break;
				case "div":
					currentContainer = this.containers.push(currentChild);
					currentContainer.jsobject = this;
					currentTab.jsobject = currentContainer;
					break;
				default:
					break;
			}
		}
	}
	for (i=0; i < this.tabs.length; i++)
	{
		this.htmlElement.insertBefore(this.tabs[i], this.containers[0]);
		this.tabs[i].style.width = Math.floor(100/this.tabs.length)+"%";
	}
	if (selectedTab) {
		this.activateTab(selectedTab);
	}
	

}
TabTable.prototype.activateTab = function (cont)
{
	for (var i=0; i < this.containers.length; i++)
	{
		if (this.tabs[i].className.indexOf("curtab") != -1)
		{
			this.containers[i].className = "";
			this.tabs[i].className = "";
		}
		if (this.tabs[i] == cont)
		{
			this.containers[i].className = "curcont";
			this.tabs[i].className = "curtab";
		}
	}
};

TabTable.prototype.tabclk = function (evt)
{
	var event = new CrossBrowserEvent(evt);
	var tabMgr = event.target.parentNode.jsobject;
	tabMgr.activateTab(event.target);
	
};
/*------------------------------------------------------------------------------------
	CLASSE TabsElement
	Tabs avec structure 
	<div class="tabsCont">
		<ul>
			<li><a>Item 1</a></li>
			<li><a>Item 2</a></li>
			...
		</ul>
		<div class="cont">
			<element1/>
			<element2/>
			...
		</div>
	</div>
-------------------------------------------------------------------------------------*/
TabsElement.extendsClass(BaseElement);
function TabsElement ()
{
	BaseElement.call(this, arguments);
	
	this.tabs = new Array ();
	this.containers = new Array ();
	
	var currentChild = false;
	var currentTab = false;
	var currentContainer = false;
	var tcont = false;
	var ccont = false;
	var maxHeight = 0;
	
	// Vérification de la structure
	if (this.htmlElement.getElementsByTagName("ul").length != 0)
	{
		tcont = this.htmlElement.getElementsByTagName("ul").item(0);
	}
	if (this.htmlElement.getElementsByTagName("div").length != 0 && this.htmlElement.getElementsByTagName("div").item(0).className == "cont")
	{
		ccont = this.htmlElement.getElementsByTagName("div").item(0);
	}
	
	// Construction des collections
	if (tcont && ccont)
	{
		for (var i=0; i < tcont.childNodes.length; i++)
		{
			currentChild = tcont.childNodes.item(i);
			if (currentChild.nodeType == 1)
			{
				currentTab = this.tabs.push(currentChild);	
				currentChild.onclick = this.tabclk;
			}
			
		}
		for (var j=0; j < ccont.childNodes.length; j++)
		{
			currentChild = ccont.childNodes.item(j);
			if (currentChild.nodeType == 1)
			{
				currentContainer = this.containers.push(currentChild);
				if (currentChild.clientHeight > maxHeight) {
					maxHeight = currentChild.clientHeight;
				}
				currentContainer.jsobject = this;
				this.tabs[this.containers.length-1].jsobject = currentContainer;
			}
			
		}
		
		for (i=0; i < this.containers.length; i++)
		{
			this.containers[i].style.height = maxHeight+"px";
		}
		
	}
}
TabsElement.prototype.activateTab = function (cont)
{
	for (var i=0; i < this.containers.length; i++)
	{
		if (this.tabs[i].className.indexOf("curtab") != -1)
		{
			this.containers[i].className = "";
			this.tabs[i].className = "";
		}
		if (this.tabs[i] == cont)
		{
			this.containers[i].className = "curcont";
			this.tabs[i].className = "curtab";
		}
	}
};

TabsElement.prototype.tabclk = function (evt)
{
	var event = new CrossBrowserEvent(evt);
	var tabMgr = false;
	var curTab = false;
	if (event.target.tagName.toLowerCase() == "li") {
	 	tabMgr = event.target.parentNode.parentNode.jsobject;
	 	curTab = event.target;
	}
	else if (event.target.tagName.toLowerCase() == "a") {
	 	tabMgr = event.target.parentNode.parentNode.parentNode.jsobject;
	 	curTab = event.target.parentNode;
	}
	if (tabMgr) {
		tabMgr.activateTab(curTab);
	}
	event.clearEvent ();
};


/*------------------------------------------------------------------------------------
	CLASSE GalerieElement
	Gère un diaporama de photos avec titre
-------------------------------------------------------------------------------------*/
GalerieElement.extendsClass(BaseElement);
function GalerieElement ()
{
	BaseElement.call(this, arguments);
	this.containers = this.htmlElement.getElementsByTagName("div");
	this.currentIndex = 1;
	this.nbImages = this.containers.length;
	this.setTimeout("showNextImage", 6000);
}
GalerieElement.prototype.showNextImage = function ()
{
	// Cache l'image active
	if (this.currentIndex != 0)
	{
		this.containers.item(this.currentIndex).style.display = "none";
	}
	this.currentIndex += 1;
	/// Retour au début si on est à la fin
	if (this.currentIndex+1 > this.nbImages)
	{
		this.currentIndex = 1;
	}
	// Active la nouvelle image
	var currentContainer = this.containers.item(this.currentIndex);
	currentContainer.style.backgroundImage = "url("+currentContainer.getAttribute("href")+")";
	this.containers.item(this.currentIndex).style.display = "block";
	this.setTimeout("showNextImage", 2000);
};


/*------------------------------------------------------------------------------------
	CLASSE DiaporamaElement
	Gère un diaporama de photos
-------------------------------------------------------------------------------------*/
function DiaporamaElement (oDiv)
{
	/*---------------------
			PROPRIETES
	---------------------*/
	/* Element a à transformer */
	this.htmlElement = oDiv;
	this.images = new Array();
	this.currentImage = 0;
	this.img = document.createElement("img");
	this.title = document.createElement("h2");
	this.previous = document.createElement("a");
	this.next = document.createElement("a");
	this.pause = document.createElement("a");
	this.isStopped = false;
	this.timeout;

	/*---------------------
			METHODES
	---------------------*/
	this.goPrevious = function (evt)
	{
		if (evt != null)
		{
			var cbevent = new CrossBrowserEvent(evt);
		}

		var DiapElement = document.getElementById('_diaporama').jsobject;
		
		if (DiapElement.currentImage > 0)
		{
			DiapElement.currentImage--;
			DiapElement.img.setAttribute("src", DiapElement.images[DiapElement.currentImage][0]);
			DiapElement.title.firstChild.nodeValue = DiapElement.images[DiapElement.currentImage][1];
		}
		if (!DiapElement.isStopped)
		{
			clearTimeout(DiapElement.timeout);
			DiapElement.timeout = setTimeout("document.getElementById('_diaporama').jsobject.goNext(null);",3000);
		}
		
		DiapElement.updateNavig();
		if (evt != null)
		{
			return cbevent.clearEvent();
		}
	};
	
	this.goStop = function (evt)
	{
		if (evt != null)
		{
			var cbevent = new CrossBrowserEvent(evt);
		}

		var DiapElement = document.getElementById('_diaporama').jsobject;
		var tbutton = DiapElement.pause;
		clearTimeout(DiapElement.timeout);
		if (!DiapElement.isStopped)
		{
			tbutton.removeChild(tbutton.firstChild);
			tbutton.appendChild(document.createTextNode("Reprendre"));
			DiapElement.isStopped = true;
		}
		else
		{
			tbutton.removeChild(tbutton.firstChild);
			tbutton.appendChild(document.createTextNode("Pause"));
			DiapElement.isStopped = false;
			DiapElement.timeout = setTimeout("document.getElementById('_diaporama').jsobject.goNext(null);",3000);
		}	

		if (evt != null)
		{
			return cbevent.clearEvent();
		}
	};
	
	this.goNext = function (evt)
	{
		if (evt != null)
		{
			var cbevent = new CrossBrowserEvent(evt);
		}
		
		var DiapElement = document.getElementById('_diaporama').jsobject;

		if (DiapElement.currentImage < (DiapElement.images.length-1))
		{
			DiapElement.currentImage++;
			DiapElement.img.setAttribute("src", DiapElement.images[DiapElement.currentImage][0]);
			DiapElement.title.firstChild.nodeValue = DiapElement.images[DiapElement.currentImage][1];
		}
		else
		{
			if (evt == null)
			{
				DiapElement.currentImage = 0;
				DiapElement.img.setAttribute("src", DiapElement.images[DiapElement.currentImage][0]);
				DiapElement.title.firstChild.nodeValue = DiapElement.images[DiapElement.currentImage][1];
			}
		}
		
		if (!DiapElement.isStopped)
		{
			clearTimeout(DiapElement.timeout);
			DiapElement.timeout = setTimeout("document.getElementById('_diaporama').jsobject.goNext(null);",3000);
		}
			
		DiapElement.updateNavig();
		if (evt != null)
		{
			return cbevent.clearEvent();
		}
	};
	
	this.updateNavig = function ()
	{
		if (this.currentImage == 0)
		{
			this.previous.removeAttribute("href");
			this.previous.onclick = null;
	
			this.next.setAttribute("href",  "#");
			this.next.onclick = this.goNext;
		}
		else if (this.currentImage == (this.images.length-1))
		{
			this.previous.setAttribute("href", "#");
			this.previous.onclick = this.goPrevious;
	
			this.next.removeAttribute("href");
			this.next.onclick = null;
		}
		else
		{
			this.previous.setAttribute("href",  "#");
			this.previous.onclick = this.goPrevious;
			
			this.next.setAttribute("href",  "#");
			this.next.onclick = this.goNext;
		}
	};
	
	/*---------------------
			CONSTRUCTEUR
	---------------------*/
	this.htmlElement.jsobject = this;
	this.htmlElement.setAttribute("id","_diaporama");
	var licoll = this.htmlElement.getElementsByTagName("li");
	for (var i=0; i<licoll.length; i++)
	{
		var anchor = licoll.item(i).getElementsByTagName("a").item(0);
		this.images.push(new Array(anchor.getAttribute("href"), anchor.firstChild.nodeValue));
	}
	
	var odiv  = document.createElement("div");
	
	this.previous.setAttribute("class", "previous");
	this.previous.appendChild(document.createTextNode("« Précédent"));

	this.next.setAttribute("class", "next");
	this.next.appendChild(document.createTextNode("Suivant »"));
	
	this.pause.setAttribute("class", "pause");
	this.pause.appendChild(document.createTextNode("Pause"));
	this.pause.setAttribute("href",  "#");
	this.pause.onclick = this.goStop;

	this.updateNavig();
	odiv.appendChild(this.previous);
	odiv.appendChild(this.next);
	this.title.appendChild(document.createTextNode(this.images[0][1]));
	odiv.appendChild(this.title);
	odiv.appendChild(this.pause);
	this.htmlElement.appendChild(odiv);
	
	this.img.setAttribute("src", this.images[0][0]);
	this.img.setAttribute("width", "600px");
	this.img.setAttribute("height", "400px");
	this.htmlElement.appendChild(this.img);
	
	
	this.timeout = setTimeout("document.getElementById('_diaporama').jsobject.goNext(null);",3000);
}
DiaporamaElement.prototype = new BaseElement;


/**
 * cvi_instant_lib.js 1.1 (16-Oct-2007)
 * (c) by Christian Effenberger 
 * All Rights Reserved
 * Source: instant.netzgesta.de
 * Distributed under NSL
 * License permits free of charge
 * use on non-commercial and 
 * private web sites only 
 * syntax:
	cvi_instant.defaultTilt = 'none'; 		//STR  'n|l|r'-'none|left|right'
	cvi_instant.defaultShade = 33;  		//INT  0-100 (% opacity)
	cvi_instant.defaultShadow = 33;  		//INT  0-100 (% opacity)
	cvi_instant.defaultColor = '#f0f4ff'; 	//STR '#000000'-'#ffffff'
	cvi_instant.defaultNoshade = false; 	//BOOLEAN
	cvi_instant.remove( image );
	cvi_instant.add( image, options );
	cvi_instant.modify( image, options );
	cvi_instant.add( image, { tilt: value, shadow: value, color: value, noshade: value } );
	cvi_instant.modify( image, { tilt: value, shadow: value, color: value, noshade: value } );
 *
**/

function addShading(ctx,x,y,width,height,opacity) {
	var style = ctx.createLinearGradient(0,y,0,y+height);
	style.addColorStop(0,'rgba(0,0,0,'+(opacity/2)+')');
	style.addColorStop(0.3,'rgba(0,0,0,0)');
	style.addColorStop(0.7,'rgba(254,254,254,0)');
	style.addColorStop(1,'rgba(254,254,254,'+(opacity)+')');
	ctx.beginPath();
	ctx.rect(x,y,width,height);
	ctx.closePath();
	ctx.fillStyle = style;
	ctx.fill();
}
function addLining(ctx,x,y,width,height,opacity,inset,inner,color) {
	var style = ctx.createLinearGradient(x,y,width,height);
	if(inner==true) {
		style.addColorStop(0,'rgba(192,192,192,'+opacity+')');
		style.addColorStop(0.7,'rgba(254,254,254,0.8)');
		style.addColorStop(1,'rgba(254,254,254,0.9)');
	}else {
		if(color=='#f0f4ff') {
			style.addColorStop(0,'rgba(254,254,254,0.9)');
			style.addColorStop(0.3,'rgba(254,254,254,0.8)');
			style.addColorStop(1,'rgba(192,192,192,0)');
		}else {
			style.addColorStop(0,'rgba(254,254,254,0)');
			style.addColorStop(1,'rgba(192,192,192,0)');
		}
	}
	ctx.strokeStyle = style; ctx.lineWidth = inset;
	ctx.rect(x,y,width,height); ctx.stroke();
}
function addRadialStyle(ctx,x1,y1,r1,x2,y2,r2,opacity) {
	var tmp = ctx.createRadialGradient(x1,y1,r1,x2,y2,r2);
	var opt = Math.min(parseFloat(opacity+0.1),1.0);
	tmp.addColorStop(0,'rgba(0,0,0,'+opt+')');
	tmp.addColorStop(0.25,'rgba(0,0,0,'+opacity+')');
	tmp.addColorStop(1,'rgba(0,0,0,0)');
	return tmp;
}
function addLinearStyle(ctx,x,y,w,h,opacity) {
	var tmp = ctx.createLinearGradient(x,y,w,h);
	var opt = Math.min(parseFloat(opacity+0.1),1.0);
	tmp.addColorStop(0,'rgba(0,0,0,'+opt+')');
	tmp.addColorStop(0.25,'rgba(0,0,0,'+opacity+')');
	tmp.addColorStop(1,'rgba(0,0,0,0)');
	return tmp;
}
function tiltShadow(ctx,x,y,width,height,radius,opacity){
	var style; 
	ctx.beginPath(); ctx.rect(x,y+height-radius,radius,radius); ctx.closePath();
	style = addRadialStyle(ctx,x+radius,y+height-radius,radius-x,x+radius,y+height-radius,radius,opacity);
	ctx.fillStyle = style; ctx.fill();
	ctx.beginPath(); ctx.rect(x+radius,y+height-y,width-(radius*2.25),y); ctx.closePath();
	style = addLinearStyle(ctx,x+radius,y+height-y,x+radius,y+height,opacity);
	ctx.fillStyle = style; ctx.fill();
	ctx.beginPath(); ctx.rect(x+width-(radius*1.25),y+height-(radius*1.25),radius*1.25,radius*1.25); ctx.closePath();
	style = addRadialStyle(ctx,x+width-(radius*1.25),y+height-(radius*1.25),(radius*1.25)-1.5-x,x+width-(radius*1.25),y+height-(radius*1.25),radius*1.25,opacity);
	ctx.fillStyle = style; ctx.fill();
	ctx.beginPath(); ctx.moveTo(x+width-x,y+radius); ctx.lineTo(x+width,y+radius); ctx.quadraticCurveTo(x+width-x,y+(height/2),x+width,y+height-(radius*1.25)); ctx.lineTo(x+width-x,y+height-(radius*1.25)); ctx.quadraticCurveTo(x+width-(x*2),y+(height/2),x+width-x,y+radius); ctx.closePath();
	style = addLinearStyle(ctx,x+width-x,y+radius,x+width,y+radius,opacity);
	ctx.fillStyle = style; ctx.fill();
	ctx.beginPath(); ctx.rect(x+width-radius,y,radius,radius); ctx.closePath();
	style = addRadialStyle(ctx,x+width-radius,y+radius,radius-x,x+width-radius,y+radius,radius,opacity);
	ctx.fillStyle = style; ctx.fill();
}

var cvi_instant = {
	defaultTilt : 'none',
	defaultShadow : 33,
	defaultColor : '#f0f4ff',
	defaultNoshade : false,
	add: function(image, options) {
		if(image.tagName.toUpperCase() == "IMG") {
			var defopts = { "tilt" : cvi_instant.defaultTilt, "shade" : cvi_instant.defaultShade, "shadow" : cvi_instant.defaultShadow, "color" : cvi_instant.defaultColor , "noshade" : cvi_instant.defaultNoshade };
			if(options) {
				for(var i in defopts) { if(!options[i]) { options[i] = defopts[i]; }}
			}else {
				options = defopts;
			}
			var canvas;
			try {
				var object = image.parentNode; 
				if(document.all && document.namespaces && !window.opera) {
					if(document.namespaces['v'] == null) {
						var stl = document.createStyleSheet();
						stl.addRule("v\\:*", "behavior: url(#default#VML);"); 
						document.namespaces.add("v", "urn:schemas-microsoft-com:vml");
					}
					var display = (image.currentStyle.display.toLowerCase()=='block')?'block':'inline-block';        
					canvas = document.createElement(['<var style="zoom:1;overflow:hidden;display:'+display+';width:'+image.width+'px;height:'+image.height+'px;padding:0;">'].join(''));
					var flt =  image.currentStyle.styleFloat.toLowerCase();
					display = (flt=='left'||flt=='right')?'inline':display;
					canvas.options = options;
					canvas.dpl = display;
					canvas.id = image.id;
					canvas.alt = image.alt;
					canvas.name = image.name;
					canvas.title = image.title;
					canvas.source = image.src;
					canvas.className = image.className;
					canvas.style.cssText = image.style.cssText;
					canvas.height = image.height;
					canvas.width = image.width;
					object.replaceChild(canvas,image);
					cvi_instant.modify(canvas, options);
				}else {
					canvas = document.createElement('canvas');
					if(canvas.getContext("2d")) {
						canvas.options = options;
						canvas.isOP = navigator.userAgent.indexOf('Opera') > -1 ? 1 : 0;
						canvas.id = image.id;
						canvas.alt = image.alt;
						canvas.name = image.name;
						canvas.title = image.title;
						canvas.source = image.src;
						canvas.className = image.className;
						canvas.style.cssText = image.style.cssText;
						canvas.style.height = image.height+'px';
						canvas.style.width = image.width+'px';
						canvas.height = image.height;
						canvas.width = image.width;
						object.replaceChild(canvas,image);
						cvi_instant.modify(canvas, options);
					}
				}
			} catch (e) {
			}
		}
		return canvas;
	},
	
	modify: function(canvas, options) {
		try {
			var f, it, rt, head, foot, shadow, shade, shine, frame, fill;
			
			var tilt = (typeof options['tilt']=='string'?options['tilt']:canvas.options['tilt']); canvas.options['tilt']=tilt;
			shade = (typeof options['shade']=='number'?options['shade']:canvas.options['shade']); canvas.options['shade']=shade;
			shadow = (typeof options['shadow']=='number'?options['shadow']:canvas.options['shadow']); canvas.options['shadow']=shadow;
			var color = (typeof options['color']=='string'?options['color']:canvas.options['color']); canvas.options['color']=color;
			var noshade = (typeof options['noshade']=='boolean'?options['noshade']:canvas.options['noshade']); canvas.options['noshade']=noshade;
			var ih = canvas.height; var iw = canvas.width; var ishade = shadow==0?0.1:shade/100; 
			var ishadow = shadow==0?0.33:shadow/100; var itilt = (tilt.match(/^[lnr]/i)?tilt.substr(0,1):'n');
			var icolor = (color.match(/^#[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]$/i)?color:'#f0f4ff');
			var bd = Math.round(Math.max(iw,ih)*0.05); var os = bd/2; var sc = 1.333333; 
			var xs;
			var ys;
			if(iw>ih) {xs = 0.05; ys = xs*(iw/ih);}else if(iw<ih) {ys = 0.05; xs = ys*(ih/iw);}else {xs = 0.05; ys = 0.05;}
			if(document.all && document.namespaces && !window.opera) {
				if (canvas.tagName.toUpperCase() == "VAR") {
					f = (noshade==false?'t':'f'); it = parseInt(os*0.75); if(itilt=='r') {rt=2.8; sc=0.95;}else if(itilt=='l') {rt=-2.8; sc=0.95;}else {rt=0; sc=1;}
					head = '<v:group style="rotation:'+rt+';zoom:'+sc+';display:'+canvas.dpl+';margin:0;padding:0;position:relative;width:'+iw+'px;height:'+ih+'px;" coordsize="'+iw+','+ih+'"><v:rect strokeweight="0" filled="f" stroked="f" fillcolor="transparent" style="zoom:1;margin:0;padding:0;display:block;position:absolute;top:0px;left:0px;width:'+iw+'px;height:'+ih+';"><v:fill opacity="0" color="#000000" /></v:rect>';
					shadow = '<v:rect strokeweight="0" filled="t" stroked="f" fillcolor="#000000" style="filter:Alpha(opacity='+(ishadow*100)+'), progid:dxImageTransform.Microsoft.Blur(PixelRadius='+it+', MakeShadow=false); zoom:1;margin:0;padding:0;display:block;position:absolute;top:'+os+'px;left:'+os+'px;width:'+(iw-(2*os))+'px;height:'+(ih-(2*os))+';"><v:fill color="#000000" opacity="1" /></v:rect>';
					frame = '<v:rect strokeweight="0" filled="t" stroked="f" fillcolor="'+icolor+'" style="zoom:1;margin:0;padding:0;display:block;position:absolute;top:0px;left:0px;width:'+(iw-os)+'px;height:'+(ih-os)+';"></v:rect>';
					shine = '<v:rect strokeweight="0" filled="t" stroked="f" fillcolor="'+icolor+'" style="zoom:1;margin:0;padding:0;display:block;position:absolute;top:'+bd+'px;left:'+bd+'px;width:'+(iw-os-(2*bd))+'px;height:'+(ih-os-(2*bd))+';"><v:fill color="#000000" opacity="'+ishadow+'" /></v:rect>';
					fill = '<v:image src="'+canvas.source+'" style="zoom:1;margin:0;padding:0;display:block;position:absolute;top:'+bd+'px;left:'+bd+'px;width:'+(iw-os-(2*bd))+'px;height:'+(ih-os-(2*bd))+';"></v:image>';
					shade = '<v:rect strokeweight="3" filled="'+f+'" stroked="t" strokecolor="'+icolor+'" fillcolor="transparent" style="zoom:1;margin:0;padding:0;display:block;position:absolute;top:'+bd+'px;left:'+bd+'px;width:'+(iw-os-(2*bd))+'px;height:'+(ih-os-(2*bd))+';"><v:fill method="sigma" type="gradient" angle="0" color="#ffffff" opacity="'+(ishade/2)+'" color2="#000000" o:opacity2="'+(ishade/2)+'" /></v:rect>';
					foot = '</v:group>';
					canvas.innerHTML = head+shadow+frame+shine+fill+shade+foot;
				}
			}else {
				if(canvas.tagName.toUpperCase() == "CANVAS" && canvas.getContext("2d")) {
					it = Math.floor(Math.min(Math.max(bd/8,1),2));
					var context = canvas.getContext("2d");
					var img = new Image();
					img.onload = function() {
						context.clearRect(0,0,iw,ih);
						context.save();  
						if(itilt=='r') {
							context.translate(bd,0); context.scale(1-(sc*xs),1-(sc*ys)); context.rotate(0.05); 
						}else if(itilt=='n') {
							context.scale(1-(xs/1.5),1-(ys/1.5));
						}else if(itilt=='l') {
							context.translate(0,bd); context.scale(1-(sc*xs),1-(sc*ys)); context.rotate(-0.05);
						}
						tiltShadow(context,os,os,iw,ih,os,ishadow);
						context.fillStyle = icolor;
						context.fillRect(0,0,iw,ih);
						context.fillStyle = 'rgba(0,0,0,'+ishadow+')';
						context.fillRect(bd,bd,iw-(bd*2),ih-(bd*2));
						if(!canvas.isOP) { addLining(context,1.5,1.5,iw-3,ih-3,ishadow,it,false,icolor); }
						context.drawImage(img,bd,bd,iw-(bd*2),ih-(bd*2));
						if(noshade==false) { addShading(context,bd,bd,iw-(bd*2),ih-(bd*2),ishade); }
						if(!canvas.isOP) { addLining(context,bd,bd,iw-(bd*2),ih-(bd*2),ishadow,it,true); }
						context.restore();
					};
					img.src = canvas.source;
				}
			}
		} catch (e) {
		}
	},

	replace : function(canvas) {
		var object = canvas.parentNode; 
		var img = document.createElement('img');
		img.id = canvas.id;
		img.alt = canvas.alt;
		img.title = canvas.title;
		img.src = canvas.source;
		img.className = canvas.className;
		img.style.cssText = canvas.style.cssText;
		img.style.height = canvas.height+'px';
		img.style.width = canvas.width+'px';
		object.replaceChild(img,canvas);
	},

	remove : function(canvas) {
		if(document.all && document.namespaces && !window.opera) {
			if(canvas.tagName.toUpperCase() == "VAR") {
				cvi_instant.replace(canvas);
			}
		}else {
			if(canvas.tagName.toUpperCase() == "CANVAS") {
				cvi_instant.replace(canvas);
			}
		}
	}
};
