/**
 * @author Ulf Tiburtius for projektwerft GbR
 * @since 01/16/2009
 */
var utils = new function() {
	var self = this;
	// public
	this.initialize = function() {
		self.checkAddToFavorites();
		self.initializeExternalLinks();
	};
	
	this.initializeExternalLinks = function() {
		var c = document.getElementById( 'contentwrap' );
		var a = c.getElementsByTagName( 'A' );
		var t = [];
		var anchor;
		for( var i = 0; i < a.length; i++ ) {
			anchor = a[i];
			if( anchor.getAttribute( "rel" ) == "extern" ) {
				//this.addEvent( anchor, "click", window.open( anchor.getAttribute('href') ) );
				anchor.setAttribute( "onclick", 'window.open( \'' + anchor.getAttribute('href') + '\' );return false' );
			}
		}
	
	},	
	// public
	this.addToFavorite = function( title, url ) {
		if( window.sidebar && window.sidebar.addPanel ) {
			// FF / Moz
			window.sidebar.addPanel( title, url, '' );
		} else if( window.opera && window.print ) {
			// Opera 7+
			var elem = document.createElement( 'a' );
			elem.setAttribute( 'href', url );
			elem.setAttribute( 'title', title );
			elem.setAttribute( 'rel', 'sidebar' );
			elem.click();
		} else if( window.external ) {
			// IE
			try {
				window.external.AddFavorite( url, title );
			} catch( e ) {
				// some IEs throwing Errors
			}
		}
	};
	// public
	this.openWindow = function( url ) {
		alert( anchor );
		var w = window.open( url, '', '' );
		w.focus();
		return false;
	},
	// private
	this.checkAddToFavorites = function() {
		var ua=navigator.userAgent.toLowerCase();
		var isKonq=( ua.indexOf( 'konqueror' ) !=-1 );
		var isSafari=( ua.indexOf( 'webkit' ) !=-1 );

		var bookmark = null;
		try {
			bookmark = document.getElementById( 'bookmark' );
		} catch( e ) {}

		if( !isKonq && !isSafari && bookmark != null ) {
			bookmark.style.visibility = 'visible';
			bookmark.previousSibling.nodeValue = ' |';
		} else if( bookmark ) {
			bookmark.style.visibility = 'hidden';
			bookmark.previousSibling.nodeValue = '';
		}
	};
	// public
	this.addEvent = function( obj, type, fn ) {
		if( obj.addEventListener ) {
			obj.addEventListener( type, fn, false );
		} else if( obj.attachEvent ) {
			obj[type+fn] = function() {
				fn.apply( obj, [window.event] );
			};
			obj.attachEvent( "on"+type, obj[type+fn] );
		}
	};
	// public
	this.removeEvent = function( obj, type, fn ) {
		if( obj.removeEventListener ) {
			obj.removeEventListener( type, fn, false );
		} else if( obj.detachEvent ) {
			obj.detachEvent( "on"+type, obj[type+fn] );
			obj[type+fn] = null;
		}
	};
};

function init() {
	utils.initialize();
}

utils.addEvent( window, 'load', init );