/*
 * Hung Punctuation
 * Version 1.0
 * (c) Igor Topilsky
 */

function setPunctuationMargins(className) { // loosely based on http://archon.name/trash/quotes/
	var testBlock = document.createElement('div');
	testBlock.setAttribute('class', className);
	testBlock.style.position = 'absolute';
	testBlock.style.left = '-1em';
	testBlock.style.bottom = '0'; // FF, Opera & IE
	testBlock.style.margin = '0';
	testBlock.style.padding = '0';
	var em = document.createElement('div');
	em.style.width = '1em';
	var quote = document.createElement('span');
	quote.innerHTML = '&laquo;';
	var bracket = document.createElement('span');
	bracket.innerHTML = '(';
	testBlock.appendChild(em);
	testBlock.appendChild(quote);
	testBlock.appendChild(bracket);
	document.body.appendChild(testBlock);
	quoteMargin = quote.offsetWidth / em.offsetWidth;
	bracketMargin = bracket.offsetWidth / em.offsetWidth;
	var stylesheet = document.styleSheets[0];
	if (stylesheet.insertRule) {
		with (stylesheet) {
			insertRule('.' + className + ' .hung-quote { margin-left: -' + quoteMargin + 'em; }', 0);
			insertRule('.' + className + ' .hung-quote-space { margin-left: ' + quoteMargin + 'em; }', 0);
			insertRule('.' + className + ' .hung-bracket { margin-left: -' + bracketMargin + 'em; }', 0);
			insertRule('.' + className + ' .hung-bracket-space { margin-left: ' + bracketMargin + 'em; }', 0);
			if (window.opera) {
				insertRule('.' + className + ' .hung-quote { display: inline-block; }', 0);
				insertRule('.' + className + ' .hung-bracket { display: inline-block; }', 0);
			}
		}
	} else { // IE
		with (stylesheet) {
			addRule('.' + className + ' .hung-quote', 'margin-left: -' + quoteMargin + 'em');
			addRule('.' + className + ' .hung-quote-space', 'margin-left: ' + quoteMargin + 'em');
			addRule('.' + className + ' .hung-bracket', 'margin-left: -' + bracketMargin + 'em');
			addRule('.' + className + ' .hung-bracket-space', 'margin-left: ' + bracketMargin + 'em');
		}
	}
}
