function $() {
	var elements = new Array();
	for (var i=0;i<arguments.length;i++) {
		var element = arguments[i];
		if (typeof element == 'string') element = document.getElementById(element);
		if (arguments.length == 1) return element;
		elements.push(element);
	}
	return elements;
}


function init() {
	if (!document.getElementById || !document.createElement) return; // One check for compatibility
    if (arguments.callee.done) return;
    arguments.callee.done = true;
    if (_timer) clearInterval(_timer);
	document.getElementsByTagName('body')[0].className += ' js';
	initFavs();
};

/* for Mozilla/Opera9 */
if (document.addEventListener) {
    document.addEventListener("DOMContentLoaded", init, false);
}

/* for Internet Explorer */
/*@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(); // call the onload handler
        }
    };
/*@end @*/

/* for Safari */
if (/WebKit/i.test(navigator.userAgent)) { // sniff
    var _timer = setInterval(function() {
        if (/loaded|complete/.test(document.readyState)) {
            init(); // call the onload handler
        }
    }, 10);
}


function initFavs() {
	// check to see that the browser supports the getElementsByTagName method
	// if not, exit the loop 
	if (!document.getElementsByTagName) {
		return false; 
	}
	
	var browser = '';
	var linkclass = '';
	
	if (window.sidebar) {		
		browser = 'Firefox';
	} else if(window.external) {
		browser = 'MSIE';
	}
	

	// create an array of objects of each link in the document 
	var favlinks = document.getElementsByTagName("a");
	// loop through each of these links (anchor tags) 	
	for (var i=0; i < favlinks.length; i++) {		
		
		if (browser == 'MSIE') {
			linkclass = favlinks[i].getAttribute("className");
		} else {
			linkclass = favlinks[i].getAttribute("class");
		}
		
		// if the link has a class of "popup"...	
		if (linkclass == "bookmark") {
			// add an onclick event on the fly to pass the href attribute	
			// of the link to our second function, openPopUp 	
			favlinks[i].onclick = function() {	
			addToFav(document.location, document.title, browser);	
			return false; 	
			} 	
		}
	} 
} 


function addToFav(url, title, browser) {
	
	if (browser == 'Firefox') {
		// Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");	
	} else if(browser == 'MSIE') {
		// IE Favorite
		window.external.AddFavorite(url, title);

	} else {
		alert('Use (Ctrl+D) to bookmark this page!');
	}

	return true;
}


/* for other browsers */
window.onload = init;
