/*
Original Author: Remiz Rahnas
Original Author URL: http://www.htmlremix.com
Published date: 2008/09/24
Changes by Nick Fetchak:
- IE8 standards mode compatibility
- VML elements now positioned behind original box rather than inside of it - should be less prone to breakage
Published date : 2009/11/18

Changes by Alric Joffrin, 2010-11-13:
- z-index was not read correctly, now it is
- Resolved the stupid bug impacting target elements WITH position relative declared or other complex-positioned layout. This should solve background disappearance and so on. Dont use the (bad) hacks anymore!
- removed window_resize code as it was buggy and i failed to see in which situation it was useful, maybe im dumb?
- code cleaning, better styling in IE6
*/
<public:attach event="oncontentready" onevent="oncontentready('v08vnSVo78t4JfjH')" />
<script type="text/javascript">

// findPos() borrowed from http://www.quirksmode.org/js/findpos.html
function findPos(obj) {
	var curleft = curtop = 0;

	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}

	return({
		'x': curleft,
		'y': curtop
	});
}
// better function instead of only currentStyle
function getStyle(x, styleProp) {
    //~ var x = document.getElementById(x);
    if(typeof(x) != 'object') return false;
    if (window.getComputedStyle) {
        var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
    }
    else if (x.currentStyle) {
        var y = x.currentStyle[styleProp];
    }
    return y;
}

function oncontentready(classID) {
  if (this.className.match(classID)) return(false);

	if (!document.namespaces.v) { document.namespaces.add("v", "urn:schemas-microsoft-com:vml"); }

	this.className = this.className.concat(' ', classID);
	var arcSize = Math.min(parseInt(getStyle(this, '-webkit-border-radius') ||
	                                getStyle(this, '-moz-border-radius') ||
	                                getStyle(this, 'border-radius') ||
	                                getStyle(this, '-khtml-border-radius')) /
	                       Math.min(this.offsetWidth, this.offsetHeight), 1);
	var fillColor = getStyle(this, 'backgroundColor');
	var fillSrc = getStyle(this, 'backgroundImage').replace(/^url\("(.+)"\)$/, '$1');
	var strokeColor = getStyle(this, 'borderColor');
	var strokeWeight = parseInt(getStyle(this, 'borderWidth'));
	var stroked = 'true';
	if (isNaN(strokeWeight)) {
		strokeWeight = 0;
		strokeColor = fillColor;
		stroked = 'false';
	}

	this.style.background = 'transparent';
	this.style.borderColor = 'transparent';

	// Find which parent provides non static position for the target element (default to BODY)
	var el = this;
	var limit = 100, i = 0;
	do {
	    el = el.parentNode;
	    i++;
	} while ((typeof(el) != 'unknown') && (getStyle(el, 'position') == 'static') && (el.tagName != 'BODY') && (i <= limit));
	var el_zindex = parseInt(getStyle(el, 'zIndex'));
	// IE7 & IE8 differs in their way to treat z-index and it seems both are wrong...
	if (isNaN(el_zindex)) {
	    el.style.zIndex = 0;
	    el_zindex = 0;
	}
	//~ alert('target is positioned inside '+el.tagName+' id #'+el.id+', class .'+el.className+', z-index:'+el_zindex+', pos:'+getStyle(el, 'position'));
	
	var rect_size = {
	    'width': this.offsetWidth - strokeWeight,
	    'height': this.offsetHeight - strokeWeight
	};
	var el_pos = findPos(el);
	var this_pos = findPos(this);
	this_pos.y = this_pos.y + (0.5 * strokeWeight) - el_pos.y;
	this_pos.x = this_pos.x + (0.5 * strokeWeight) - el_pos.x;

	var rect = document.createElement('v:roundrect');
	rect.arcsize = arcSize +'px';
	rect.strokecolor = strokeColor;
	rect.strokeWeight = strokeWeight +'px';
	rect.stroked = stroked;
	rect.style.display = 'block';
	rect.style.position = 'absolute';
	rect.style.top = this_pos.y +'px';
	rect.style.left = this_pos.x +'px';
	rect.style.width = rect_size.width +'px';
	rect.style.height = rect_size.height +'px';
	rect.style.antialias = true;
	rect.style.zIndex = el_zindex - 1;
	this.style.zIndex = el_zindex + 10;

	var fill = document.createElement('v:fill');
	fill.color = fillColor;
	fill.src = fillSrc;
	fill.type = 'tile';

	rect.appendChild(fill);
	el.appendChild(rect);

	var css = el.document.createStyleSheet();
	css.addRule("v\\:roundrect", "behavior: url(#default#VML)");
	css.addRule("v\\:fill", "behavior: url(#default#VML)");

	isIE6 = /msie|MSIE 6/.test(navigator.userAgent);
	// IE6 doesn't support transparent borders, use padding to offset original element
	if (isIE6 && (strokeWeight > 0)) {
	    this.style.borderStyle = 'none';
	    this.style.paddingTop = parseInt(this.currentStyle.paddingTop || 0) + (2 * strokeWeight);
	    this.style.paddingBottom = parseInt(this.currentStyle.paddingBottom || 0) + strokeWeight;
	}
}

</script>

