

function Bordure (elem)
	{
	this.elem=elem;

	//if (!(elem))
	//	elem=document.createElement('BORDURE');
	//this=elem;

	//alert(getStyle(elem,'width'));
	//alert(Number(getStyle(elem,'width').replace(/[^0-9]/g,'')));
	var type='bord';
	var rayon=20;
	var width=1;
	if ((elem.getAttribute('bordure')) && (elem.getAttribute('bordure').length>0))
		type=elem.getAttribute('bordure');
	if ((elem.getAttribute('epaisseur')) && (elem.getAttribute('epaisseur').length>0))
		width=elem.getAttribute('epaisseur');
	if ((elem.getAttribute('rayon')) && (elem.getAttribute('rayon').length>0))
		rayon=elem.getAttribute('rayon');
	elem.setAttribute('epaisseur',0);
	this.tdBordure=[];
	
	
	this.table=document.createElement('TABLE');
	this.table.className='bordure '+elem.className;
	this.elem.bordure=this.table;
	this.table.style.width=getStyle(elem,'width');

	this.tbody=document.createElement('TBODY');
	this.table.appendChild(this.tbody);
	
	this.haut=document.createElement('TR');
	this.haut.className='haut';
	this.tbody.appendChild(this.haut);
	
	this.hautGauche=document.createElement('TD');
	this.hautGauche.className='hautGauche';
	this.hautGauche.style.backgroundImage='url(/images/Bordures/'+type+'/'+rayon+'x'+width+'/haut_gauche.png)'
	this.hautGauche.style.backgroundRepeat='no-repeat';
	this.hautGauche.style.height=rayon+'px';
	this.hautGauche.style.width=rayon+'px';
	this.haut.appendChild(this.hautGauche);
	this.tdBordure.push(this.hautGauche);
	
	this.hautCentre=document.createElement('TD');
	this.hautCentre.className='hautCentre';
	this.hautCentre.style.backgroundImage='url(/images/Bordures/'+type+'/'+rayon+'x'+width+'/haut_centre.png)'
	this.hautCentre.style.backgroundPosition='top';
	this.hautCentre.style.backgroundRepeat='repeat-x';
	this.haut.appendChild(this.hautCentre);
	this.tdBordure.push(this.hautCentre);
	
	this.hautDroite=document.createElement('TD');
	this.hautDroite.className='hautDroite';
	this.hautDroite.style.backgroundImage='url(/images/Bordures/'+type+'/'+rayon+'x'+width+'/haut_droite.png)'
	this.hautDroite.style.backgroundRepeat='no-repeat';
	this.hautDroite.style.height=rayon+'px';
	this.hautDroite.style.width=rayon+'px';
	this.haut.appendChild(this.hautDroite);
	this.tdBordure.push(this.hautDroite);
	
	this.milieu=document.createElement('TR');
	this.milieu.className='milieu';
	this.tbody.appendChild(this.milieu);
	
	this.milieuGauche=document.createElement('TD');
	this.milieuGauche.className='milieuGauche';
	this.milieuGauche.style.backgroundImage='url(/images/Bordures/'+type+'/'+rayon+'x'+width+'/milieu_gauche.png)'
	this.milieuGauche.style.backgroundPosition='left';
	this.milieuGauche.style.backgroundRepeat='repeat-y';
	this.milieu.appendChild(this.milieuGauche);
	this.tdBordure.push(this.milieuGauche);
	
	this.milieuCentre=document.createElement('TD');
	this.milieuCentre.className='milieuCentre';
	if (type=='bord')
		{
		this.milieuCentre.style.backgroundColor='white';
		elem.style.backgroundColor='white';
		}
	
	this.milieu.appendChild(this.milieuCentre);
	
	this.milieuDroite=document.createElement('TD');
	this.milieuDroite.className='milieuDroite';
	this.milieuDroite.style.backgroundImage='url(/images/Bordures/'+type+'/'+rayon+'x'+width+'/milieu_droite.png)'
	this.milieuDroite.style.backgroundPosition='right';
	this.milieuDroite.style.backgroundRepeat='repeat-y';
	this.milieu.appendChild(this.milieuDroite);
	this.tdBordure.push(this.milieuDroite);
	
	this.bas=document.createElement('TR');
	this.bas.className='bas';
	this.tbody.appendChild(this.bas);
	this.tdBordure.push(this.bas);
	
	this.basGauche=document.createElement('TD');
	this.basGauche.className='basGauche';
	this.basGauche.style.backgroundImage='url(/images/Bordures/'+type+'/'+rayon+'x'+width+'/bas_gauche.png)'
	this.basGauche.style.backgroundRepeat='no-repeat';
	this.basGauche.style.height=rayon+'px';
	this.basGauche.style.width=rayon+'px';
	this.bas.appendChild(this.basGauche);
	this.tdBordure.push(this.basGauche);
	
	this.basCentre=document.createElement('TD');
	this.basCentre.className='basCentre';
	this.basCentre.style.backgroundImage='url(/images/Bordures/'+type+'/'+rayon+'x'+width+'/bas_centre.png)'
	this.basCentre.style.backgroundPosition='bottom';
	this.basCentre.style.backgroundRepeat='repeat-x';
	this.bas.appendChild(this.basCentre);
	this.tdBordure.push(this.basCentre);
	
	this.basDroite=document.createElement('TD');
	this.basDroite.className='basDroite';
	this.basDroite.style.backgroundImage='url(/images/Bordures/'+type+'/'+rayon+'x'+width+'/bas_droite.png)'
	this.basDroite.style.backgroundRepeat='no-repeat';
	this.basDroite.style.height=rayon+'px';
	this.basDroite.style.width=rayon+'px';
	this.bas.appendChild(this.basDroite);
	this.tdBordure.push(this.basDroite);
	
	
	//this.body = document.createElement('DIV');
	this.body=elem;
	/*this.body.style.paddingLeft='0px';
	this.body.style.paddingRight='0px';
	this.body.style.paddingTop='0px';
	this.body.style.paddingBottom='0px';
	this.body.style.marginLeft='-'+Math.floor(rayon/2)+'px';
	this.body.style.marginRight='-'+Math.floor(rayon/2)+'px';
	this.body.style.marginTop='-'+Math.floor(rayon/2)+'px';
	this.body.style.marginBottom='0px';//'-'+Math.floor(rayon/2)+'px';
	//this.elem.style.marginBottom='-'+Math.floor(rayon/2)+'px';
	this.elem.style.width=(Number(getStyle(elem,'width').replace(/[^0-9]/g,''))-rayon-getStyle(elem,'padding-left').replace(/[^0-9]/g,'')-getStyle(elem,'padding-right').replace(/[^0-9]/g,'')-getStyle(elem,'margin-left').replace(/[^0-9]/g,'')-getStyle(elem,'margin-right').replace(/[^0-9]/g,'')-2*width)+'px';
	this.elem.style.height='100%';
	this.elem.style.display='inline';*/
	
	//this.body=this.milieuCentre;
	//this.body.innerHTML='gghouiouigh'
	if (elem.parentNode)
		{
		//alert('heer'+elem.childNodes);
		elem.parentNode.insertBefore(this.table,elem);
		}
	//this.body.appendChild(elem);
	//alert(this.milieuCentre+' '+this.body);
	this.milieuCentre.appendChild(this.body);
	var obj=this;
	this.table.onmouseover = function ()
		{
		obj.table.className+=' hover';
		obj.elem.className+=' hover';
		}
		
	this.table.onmouseout = function ()
		{
		obj.table.className=obj.table.className.replace(/hover/g,'');
		obj.elem.className=obj.table.className.replace(/hover/g,'');
		}
		
	return this;
	}

Bordure.prototype.majHeight = function ()
	{
	//this.elem.style.width=(Number(getStyle(elem,'width').replace(/[^0-9]/g,''))-rayon-getStyle(elem,'padding-left').replace(/[^0-9]/g,'')-getStyle(elem,'padding-right').replace(/[^0-9]/g,'')-getStyle(elem,'margin-left').replace(/[^0-9]/g,'')-getStyle(elem,'margin-right').replace(/[^0-9]/g,'')-2*width)+'px';
	}

Bordure.prototype.appendChild = function (child)
		{
		this.body.appendChild(child);
		}

function Bordures ()
	{
	var elems=document.getElementsByTagName('DIV');
	this.bordures=[];
	//var elems=document.getElementById('BORDURE');
	for (var i=0;i<elems.length;i++)
		{
		//alert(elems[i].parentNode);
		//alert('I===='+i);
		if ((elems[i].getAttribute('bordure')) && (elems[i].getAttribute('bordure').length>0) && (elems[i].getAttribute('epaisseur')>0))
			this.bordures.push(new Bordure(elems[i]));
		//alert(tmp.table+'jj');
		}
	//alert(elems.length+' ?');
	return(this);
	}

function getStyle(oElm, strCssRule)
	{
	var strValue = "";
	if(document.defaultView && document.defaultView.getComputedStyle)
		{
		strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
		}
	else if(oElm.currentStyle)
		{
		strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1)
			{
			return p1.toUpperCase();
			});
		strValue = oElm.currentStyle[strCssRule];
		}
	return strValue;
	}










