this.blankwin = function(){
	var hostname = window.location.hostname;
	hostname = hostname.replace("www.","").toLowerCase();
	var a = document.getElementsByTagName("a");

	this.check = function(obj){
		var href = obj.href.toLowerCase();
		if ( href.indexOf("http://") != -1 &&
			 href.indexOf("apollo-magazine.com") == -1 &&
			 href.indexOf(hostname)==-1 )
			 return true ;
		else
			return false;
	};
	this.set = function(obj){
		obj.target = "_blank";
		obj.className = "external";
	};

	this.remember = function(obj, ida) {
		pattern = /\/[0-9]+\// ;
		matches = obj.href.toLowerCase().match(pattern) ;
		if (matches != null)
			ida.push(matches[0].replace('/', '')) ;
	} ;
	var ida = new Array() ;

	for (var i=0;i<a.length;i++){
		if (check(a[i])) {
			set(a[i]);
		} else {
			remember(a[i], ida) ;
		}
	};

	var idb = [], i, len = ida.length;
    for(i=0; i<len; i++ ) {
        if( idb.indexOf( ida[i]) < 0 ) {
            idb.push(ida[i]);
        }
    }
}


this.addEvent = function(obj,type,fn){
	if(obj.attachEvent){
		obj['e'+type+fn] = fn;
		obj[type+fn] = function(){obj['e'+type+fn](window.event );}
		obj.attachEvent('on'+type, obj[type+fn]);
	} else {
		obj.addEventListener(type,fn,false);
	};
};

addEvent(window,"load",blankwin);
