var dom_timer;

function external_links() {
	if (!document.getElementsByTagName) {
		return;
	}

    var anchors = document.getElementsByTagName('a');

    for (var i = 0; i < anchors.length; i++) {
        var anchor = anchors[i];

        if (anchor.getAttribute('href') && (anchor.getAttribute('rel') === 'external' || anchor.getAttribute('rel') === 'new-window')) {
            if (anchor.getAttribute('className')) {
                anchor.target = anchor.getAttribute('className');
            }
            else {
                anchor.target = '_blank';
            }
        }
    }
}

/**
 * init()
 * initialise JS when DOM loaded (quicker than window.onload for Moz/Webkit/IE/Opera9+)
 * ref: http://dean.edwards.name/weblog/2006/06/again/#comment5338
 **/

function init() {
	if (arguments.callee.done) {
		return;
	}
	
	arguments.callee.done = true;
	
	if (dom_timer) {
		clearInterval(dom_timer);
	}
	
	external_links();
}

if (document.addEventListener) {
	document.addEventListener("DOMContentLoaded", init, false);
}

/*@cc_on @*/
/*@if (@_win32)
	document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
	var script = document.getElementById("__ie_onload");
	script.onreadystatechange = function() {
		if (this.readyState == "complete") {
			init();
		}
	};
/*@end @*/

if (/WebKit/i.test(navigator.userAgent)) {
	dom_timer = setInterval(function() {
		if (/loaded|complete/.test(document.readyState)) {
			init();
		}
	}, 10);
}

window.onload = init;
