var GUU=(typeof GUU=='undefined'?{}:GUU);
GUU.classes=(typeof GUU.classes=='undefined'?{}:GUU.classes);
GUU.classes.roundedCorners = function()
{
	var test = document.getElementById('wrapper');
	if(typeof test == 'undefined' || !(typeof test.style.MozBorderRadius == 'undefined' && typeof test.style.WebkitBorderRadius == 'undefined' && typeof test.style.borderRadius == 'undefined')) return;
	this.imagePath = '/templates/guu/images/';
	this.lteIE6 = (Shine.browser.isIE && Shine.browser.ieVersion < 7);
	var elements = [];
	var bodyClasses = document.getElementsByTagName('body')[0].className;
	if(bodyClasses.indexOf('home') != -1)
	{
		var infos = Shine.getElementsByClass(document.getElementById('content_right'), 'div', 'info');
		for(var i in infos)
		{
			elements.push({element: infos[i], dimension: '6', image: 'info-corners.png'});
		}
	}
	this.make(elements);
}
GUU.classes.roundedCorners.prototype.createCornerSpan = function(horizontal, vertical)
{
	var span = Shine.createHTMLElement('span');
	Shine.addElementClass(span, 'rounded-corner');
	span.style.position = 'absolute';
	span.style.backgroundRepeat = 'no-repeat';
	span.style.backgroundPosition = horizontal + ' ' + vertical;
	Shine.addElementClass(span, horizontal);
	Shine.addElementClass(span, vertical);
	if(this.lteIE6)
	{
		span.style.fontSize = '0';
		Shine.addElementClass(span, vertical + '-' + horizontal);
	}
	return span;
}
GUU.classes.roundedCorners.prototype.make = function(corners)
{
	var tl = this.createCornerSpan('left', 'top');
	var tr = this.createCornerSpan('right', 'top');
	var bl = this.createCornerSpan('left', 'bottom');
	var br = this.createCornerSpan('right', 'bottom');

	for(var i in corners)
	{
		var corner = corners[i];

		var position;
		if(window.getComputedStyle) position = window.getComputedStyle(corner.element, null).getPropertyValue('position');
		else if(corner.element.currentStyle) position = corner.element.currentStyle['position'];
		if(typeof position == 'undefined' || !position || position == 'static') corner.element.style.position = 'relative';

		var borderWidth = 0;
		if(window.getComputedStyle) borderWidth = window.getComputedStyle(corner.element, null).getPropertyValue('border-top-width');
		else if(corner.element.currentStyle) borderWidth = corner.element.currentStyle['borderTopWidth'];
		borderWidth = parseInt(borderWidth) | 0;
		borderWidth = '-' + borderWidth + 'px';
		tl.style.left = borderWidth; tl.style.top = borderWidth;
		tr.style.right = borderWidth; tr.style.top = borderWidth;
		bl.style.left = borderWidth; bl.style.bottom = borderWidth;
		br.style.right = borderWidth; br.style.bottom = borderWidth;

		corner.element.appendChild(tl.cloneNode(false));
		corner.element.appendChild(tr.cloneNode(false));
		corner.element.appendChild(bl.cloneNode(false));
		corner.element.appendChild(br.cloneNode(false));

		var spans = Shine.getElementsByClass(corner.element, 'span', 'rounded-corner');
		for(var j in spans)
		{
			var span = spans[j];
			if(span.parentNode == corner.element)
			{
				if(this.lteIE6)
				{
					if(Shine.hasElementClass(span, 'bottom') && span.offsetParent.clientHeight % 2) span.style.bottom = parseInt(borderWidth) -1 + 'px';
					if(Shine.hasElementClass(span, 'right') && span.offsetParent.clientWidth % 2) span.style.right = parseInt(borderWidth) -1 + 'px';
				}				
				span.style.width = corner.dimension + 'px';
				span.style.height = corner.dimension + 'px';
				span.style.backgroundImage = 'url(' + this.imagePath + corner.image + ')';
			}
		}
	}
}
if(typeof document.loadHooks == 'undefined') document.loadHooks = [];
document.loadHooks.push(function(){new GUU.classes.roundedCorners();});
