BRAIN=(typeof BRAIN=='undefined'?{}:BRAIN);
BRAIN.classes=(typeof BRAIN.classes=='undefined'?{}:BRAIN.classes);

BRAIN.classes.roundedCorners = function()
{
	var test = document.getElementById('surround');
	if(!(typeof test.style.MozBorderRadius == 'undefined' && typeof test.style.WebkitBorderRadius == 'undefined' && typeof test.style.borderRadius == 'undefined')) return;
	this.imagePath = '/templates/brain/images/global/';
	this.make([{element: '#surround', dimension: '10', image: 'surround-corners.gif'}]);
}
BRAIN.classes.roundedCorners.prototype.make = function(corners)
{
	var lteIE6 = (jQuery.browser.msie && jQuery.browser.version < 7);
	var tl = $(document.createElement('span'));
	tl.addClass('rounded-corner');
	tl.css({position: 'absolute', backgroundRepeat: 'no-repeat'});
	if(lteIE6) tl.css({fontSize: '0'});
	var tr = tl.clone();
	var bl = tl.clone();
	var br = tl.clone();
	tl.addClass('top left');
	tr.addClass('top right');
	bl.addClass('bottom left');
	br.addClass('bottom right');
	tl.css({left: '0', top: '0', backgroundPosition: 'left top'});
	tr.css({right: '0', top: '0', backgroundPosition: 'right top'});
	bl.css({left: '0', bottom: '0', backgroundPosition: 'left bottom'});
	br.css({right: '0', bottom: '0', backgroundPosition: 'right bottom'});

	for(var i in corners)
	{
		var corner = corners[i];
		var element = $(corner.element);
		var position = element.css('position');
		if(typeof position == 'undefined' || position == 'static')
		{
			element.css({position: 'relative'});
		}
		element.append(tl.clone());
		element.append(tr.clone());
		element.append(bl.clone());
		element.append(br.clone());
		var _this = this;
		element.find('.rounded-corner').each(function()
		{			
			if(this.tagName.toLowerCase() == 'span' && this.parentNode == element[0])
			{
				if(lteIE6)
				{
					if($(this).hasClass('bottom') && this.offsetParent.clientHeight % 2) $(this).css({bottom: '-1px'});
					if($(this).hasClass('right') && this.offsetParent.clientWidth % 2) $(this).css({right: '-1px'});
				}				
				$(this).css({width: corner.dimension + 'px', height: corner.dimension + 'px', backgroundImage: 'url(' + _this.imagePath + corner.image + ')'});
			}
		});
	}
}
BRAIN.classes.cssPseudoElements = function()
{
	var q = $('h1')[0].childNodes[0];
	if(q.tagName.toLowerCase() == 'q') q.innerText = '“' + q.innerText + '”';
}
$(document).ready(function(){new BRAIN.classes.roundedCorners();});
if(jQuery.browser.msie && jQuery.browser.version < 8) $(document).ready(function(){new BRAIN.classes.cssPseudoElements();});
