SPARK=(typeof SPARK=='undefined'?{}:SPARK);
SPARK.classes=(typeof SPARK.classes=='undefined'?{}:SPARK.classes);
SPARK.classes.roundedCorners = function()
{
	var test = document.getElementById('main-content');
	this.supported = (typeof test.style.MozBorderRadius != 'undefined' || typeof test.style.WebkitBorderRadius != 'undefined' || typeof test.style.borderRadius != 'undefined');
}
SPARK.classes.roundedCorners.prototype.createCornerSpan = function(horizontal, vertical)
{
	var span = $(document.createElement('span'));
	span.addClass('rounded-corner');
	span.css('position', 'absolute');
	span.css('background-repeat', 'no-repeat');
	span.css('background-position', horizontal + ' ' + vertical);
	span.addClass(horizontal);
	span.addClass(vertical);
	if(this.lteIE6)
	{
		span.css('fontSize', '0');
		span.addClass(vertical + '-' + horizontal);
	}
	return span;
}
SPARK.classes.roundedCorners.prototype.customiseCorner = function(parent, corner, span, borderWidth)
{
	if(this.lteIE6)
	{
		if($(span).hasClass('bottom') && parent.clientHeight % 2) $(span).css('bottom', (-borderWidth - 1) + 'px');
		if($(span).hasClass('right') && parent.clientWidth % 2) $(span).css('right', (-borderWidth - 1) + 'px');
	}
	var dimension = corner.dimension + 'px';
	$(span).css('width', dimension);
	$(span).css('height', dimension);
	$(span).css('background-image', 'url(' + this.imagePath + corner.image + ')');
	return span[0];
}
// You would only use this function to add rounded corners to images as even capable browsers won't do it
// Make sure to create a new instance of roundedCorners specifically used for this purpose
SPARK.classes.roundedCorners.prototype.disableSupportTest = function()
{
	this.supportTestDisabled = true;
}
SPARK.classes.roundedCorners.prototype.make = function(corners)
{
	if(!this.supportTestDisabled && (typeof this.supported == 'undefined' || this.supported === true)) return;
	
	this.lteIE6 = (jQuery.browser.msie && jQuery.browser.version < 7);

	var tl = this.createCornerSpan('left', 'top');
	var tr = this.createCornerSpan('right', 'top');
	var bl = this.createCornerSpan('left', 'bottom');
	var br = this.createCornerSpan('right', 'bottom');
	
	_this = this;
	for(var i in corners)
	{
		var corner = corners[i];
		$(corner.element).each(function()
		{
			var position = $(this).css('position');
			if(typeof position == 'undefined' || !position || position == 'static') $(this).css('position', 'relative');

			var width = ($(this).outerWidth(false) - $(this).innerWidth()) / 2;
			var widthPX = '-' + width + 'px';

			tl.css({'left': widthPX, 'top': widthPX});
			tr.css({'right': widthPX, 'top': widthPX});
			bl.css({'left': widthPX, 'bottom': widthPX});
			br.css({'right': widthPX, 'bottom': widthPX});

			this.appendChild(_this.customiseCorner(this, corner, tl.clone(), width));
			this.appendChild(_this.customiseCorner(this, corner, tr.clone(), width));
			this.appendChild(_this.customiseCorner(this, corner, bl.clone(), width));
			this.appendChild(_this.customiseCorner(this, corner, br.clone(), width));
		});
	}
}
