$(document).ready(function(){
   addrcorners();
   $(document).pngFix();
});

// Function to add rounded corners to an element
// Usage: Add the class "rcorners" to the desired element
// To modify the radius or not round all the corners,
// add another class similar to these examples:
//  "cornerspec-10" adds 10 px radius to all corners
//  "cornerspec-6-nwse" adds 6 px radius to northwest & southeast corners
// Images & styles are available for these radii: 6, 10,18 & 20 pixels
// You can add more by adding the relevant images to common/images/corners/ &
// then modifying the relevant section of common/styles/sbcss.css
function addrcorners()
{
	var default_radius = 6;
	
	// Iterate over all elements with the class "rcorners"
	$(".rcorners").each( function() {
		// Search for an additional class starting with cornerspec
		var radius = 6, affected = 'nwneswse';
		var element = this;
		jQuery.each(element.className.split(' '), function() {
			if (/^cornerspec/.test(this)) {
				var spec   = this.split('-');
				radius = spec[1];
				if(spec[2]) {
					affected = spec[2];
				}
			}
		});
		
		// Now add the corners to the DOM
		for (var i = 0; i < affected.length; i += 2) {
			$(this).append("<div class=\"corner "
				+ " corner-r"+radius
				+ " corner-" +affected.substring(i, i+2)
				+ " corner-r"+radius+"-"+affected.substring(i, i+2)
				+"\"></div>");			
		}
	});
}

/*
Swaps out corner pngs for gifs in IE6
*/

function ieswap() {
	$('.corner').each( function() {
		var bgurl = $(this).css('background-image');
		var match = /^url\((['"])?(.*)\.png(['"])?\)$/.exec(bgurl);
		var newurl = "url("+match[2]+".gif"+")";
		$(this).css('background-image', newurl);
	});
}