
Event.observe(window, 'load', function() { init(); });

function init() {
    target_links();
}

function target_links(target_div) {
    var target = "a";
    
	$$(target).each(function(e) { 
	    
	    var destination = e.readAttribute("href");
        if(!destination) return;

	    if(e.readAttribute("class") == "lightwindow") return;
	    if(e.readAttribute("target")) return;
	    if(destination.startsWith('http://www.widmeyer.com')) return;
	    
	    if(destination.startsWith('http://')) {
	        
	        var edestination = destination.replace(/http:\/\/([^\/]+).*/, "$1");
	        if(edestination != document.domain) {
			if(edestination.match(/twitter.com/) || 
			edestination.match(/facebook.com/) ||
			edestination.match(/flickr.com/)) {
				e.setAttribute('target','_new');
			} else {   
	            e.setAttribute('href','javascript:widstrip(\''+destination+'\')');
			}
	        }
	    }
	});
}

function widstrip(destination) {
    window.location.href="/widstrip/external.html?origin="+
        encodeURIComponent(window.location)+"&target="+encodeURIComponent(destination);
}

