SF=(typeof SF=='undefined'?{}:SF);
SF.classes=(typeof SF.classes=='undefined'?{}:SF.classes);
SF.classes.roundedCorners = function(elements)
{
	var test = document.getElementById('main-content');
	if(typeof test.style.MozBorderRadius != 'undefined' || typeof test.style.WebkitBorderRadius != 'undefined' || typeof test.style.borderRadius != 'undefined') return;
	this.imagePath = '/wp-content/themes/sanctuary/images/global/';
	this.lteIE6 = (jQuery.browser.msie && jQuery.browser.version < 7);
	var corners = [];
	corners.push({element: '#main-nav li.active', dimension: '4', image: 'nav-active-corners.gif'});
	corners.push({element: '.panel', dimension: '6', image: 'panel-corners.gif'});
	corners.push({element: '#sub-content .panel:first-child', dimension: '6', image: 'first-panel-corners.gif'});
	corners.push({element: 'body.home #daily-prayer.panel', dimension: '6', image: 'first-panel-corners.gif'});
	corners.push({element: 'body.home #masthead.panel', dimension: '6', image: 'first-panel-corners.gif'});
	corners.push({element: 'body.encourage #reading .panel', dimension: '6', image: 'first-panel-corners.gif'});
	corners.push({element: '.panel.featured', dimension: '6', image: 'panel-corners.png'});
	corners.push({element: 'body.live p.live-date', dimension: '6', image: 'live-date-corners.gif'});
	this.make(corners);
	$('#main-nav li.active .bottom').css('display', 'none');
}
SF.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;
}
SF.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];
}
SF.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');
	
	_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));
		});
	}
}
$(document).ready(function(){new SF.classes.roundedCorners();});

