function assignEvents() {
    for (var i = 0; i < document.links.length; i++) {
        if (document.links[i].className.match('offsite')) {
            document.links[i].onclick = function() { offsitePopup(this.href); return false; }
        }
        if (document.links[i].className.match('pdf')) {
            document.links[i].onclick = function() { pdfPopup(this.href); return false; }
        }
        if (document.links[i].className.match('popup')) {
            document.links[i].onclick = function() { popup(this.href); return false; }
        }
        if (document.links[i].className.match('tip')) {
            document.links[i].onclick = function() { tipPopup(this.href); return false; }
        }
        if (document.links[i].className.match('designTip')) {
            document.links[i].onclick = function() { designTipPopup(this.href); return false; }
        }
    }
}

function offsitePopup(url) {
    var popUp = window.open(url, 'offsiteWindow', 'width=750,height=500,scrollbars=yes,resizable=yes,menubar=yes,toolbar=yes,location=yes');
    if (typeof popUp == 'object') {
        popUp.focus();
    }
}

function pdfPopup(url) {
    var popUp = window.open(url, 'offsiteWindow', 'width=750,height=500,scrollbars=yes,resizable=yes,menubar=yes,toolbar=yes,location=yes');
    if (typeof popUp == 'object') {
        popUp.focus();
    }
}

function popup(url) {
    var popUp = window.open(url, 'offsiteWindow', 'width=750,height=500,scrollbars=yes,resizable=yes,menubar=yes,toolbar=yes,location=yes');
    if (typeof popUp == 'object') {
        popUp.focus();
    }
}

function tipPopup(tip) {
	var tmpParts = tip.split('#');
	var url = '../tips/#' + tmpParts[1];
    var popUp = window.open(url, 'tipWindow', 'width=700,height=400,scrollbars=yes,resizable=yes,menubar=no,toolbar=no,location=no');
    if (typeof popUp == 'object') {
        popUp.focus();
    }	
}

function designTipPopup(tip) {
	var tmpParts = tip.split('#');
	var url = '/designs/tips/#' + tmpParts[1];
    var popUp = window.open(url, 'tipWindow', 'width=700,height=400,scrollbars=yes,resizable=yes,menubar=no,toolbar=no,location=no');
    if (typeof popUp == 'object') {
        popUp.focus();
    }	
}

function flasher(elm, startColor, endColor) {
	if (!endColor) endColor = '#FFFFFF';
	new Effect.Highlight($(elm), {startcolor: startColor, endcolor: endColor, duration: 2});
}

function flasherByCSS(cssRules, startColor, endColor) {
	arrEle = $$(cssRules);
	if (!endColor) endColor = '#FFFFFF';
	for(i = 0; i < arrEle.length; i++) {
	    new Effect.Highlight(arrEle[i], {startcolor: startColor, endcolor: endColor, duration: 2});
	}
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

sfHover = function() {
	if (document.getElementById("browseByNav")) {
		var sfEls = document.getElementById("browseByNav").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(/sfhover/, "");
			}
		}
	}
}

addLoadEvent(sfHover);
addLoadEvent(assignEvents);