// CUSTOM BLOG JS LIB - v.1.0
// COPYRIGHT SUN MICROSYSTEMS INC. 2006
// QUESTIONS? webdesign -at- sun.com

is = new ottosniff();
function ottosniff() {
    var b = navigator.appName
    if (b=="Netscape") this.b = "ns"
    else this.b = b
    this.version = navigator.appVersion
    this.v = parseInt(this.version)
    this.ns = (this.b=="ns" && this.v>=5)
    this.op = (navigator.userAgent.indexOf('Opera')>-1)
    this.safari = (navigator.userAgent.indexOf('Safari')>-1)
    this.op7 = (navigator.userAgent.indexOf('Opera')>-1 && this.v>=7 && this.v<8)
    this.op78 = (navigator.userAgent.indexOf('Opera')>-1 && this.v>=7 || navigator.userAgent.indexOf('Opera')>-1 && this.v>=8)
    this.ie5 = (this.version.indexOf('MSIE 5')>-1)
    this.ie6 = (this.version.indexOf('MSIE 6')>-1)
    this.ie7 = (this.version.indexOf('MSIE 7')>-1)
    this.ie56 = (this.ie5||this.ie6)
    this.iewin = (this.ie56 && navigator.userAgent.indexOf('Windows')>-1 || this.ie7 && navigator.userAgent.indexOf('Windows')>-1)
    this.iemac = (this.ie56 && navigator.userAgent.indexOf('Mac')>-1)
    this.moz = (navigator.userAgent.indexOf('Mozilla')>-1)
    this.ff = (navigator.userAgent.indexOf('Firefox')>-1)
    this.moz13 = (navigator.userAgent.indexOf('Mozilla')>-1 && navigator.userAgent.indexOf('1.3')>-1) 
    this.oldmoz = (navigator.userAgent.indexOf('Mozilla')>-1 && navigator.userAgent.indexOf('1.4')>-1 && !this.ff ||navigator.userAgent.indexOf('Mozilla')>-1 && navigator.userAgent.indexOf('1.5')>-1 && !this.ff ||navigator.userAgent.indexOf('Mozilla')>-1 && navigator.userAgent.indexOf('1.6')>-1 && !this.ff)
    this.ns6 = (navigator.userAgent.indexOf('Netscape6')>-1)
    this.docom = (this.ie56||this.ns||this.iewin||this.op||this.iemac||this.safari||this.moz||this.oldmoz||this.ns6)
}

var preloaderOn = new Array();
var preloaderOff = new Array();
var preloaderActive = new Array();
var activeImg = new Array();

// PREP
function prepEvents(){
	if (is.docom){
		var an = document.getElementsByTagName('img');
		for (var i=0;i<an.length;i++){
			if (an[i].nodeName.toLowerCase() == 'img' && an[i].src.indexOf("_off.") > -1) {
				an[i].rsrc = an[i].src;
				preloaderOff[an[i].rsrc] = new Image();
				preloaderOff[an[i].rsrc].src = an[i].rsrc;
				if (hasClassName(an[i], "rollover")) {
					preloaderOn[an[i].rsrc] = new Image();
					preloaderOn[an[i].rsrc].src = an[i].src.replace(/_off./,"_on.");
					an[i].onmouseout = function(){
						if (activeImg[this.imgGroup] != this){
							this.src = preloaderOff[this.rsrc].src
						}
					};
					an[i].onmouseover = function(){
						if (activeImg[this.imgGroup] != this){
							this.src = preloaderOn[this.rsrc].src
						}
					};
				}    
				if (an[i].className.indexOf("active-") > -1) {
					an[i].imgGroup = an[i].className;
					an[i].imgGroup = an[i].imgGroup.replace(/.*active-(.*).*/,"$1");
					preloaderActive[an[i].rsrc] = new Image();
					preloaderActive[an[i].rsrc].src = an[i].src.replace(/_off./,"_active.");
					if (an[i].className.indexOf("setactive-") > -1) {
						activeImg[an[i].imgGroup] = an[i];
						an[i].src = preloaderActive[an[i].rsrc].src;
					}
					an[i].onclick = function(){
						if (this.src != preloaderActive[this.rsrc].src){
							this.src = preloaderActive[this.rsrc].src;
							activeImg[this.imgGroup].src = preloaderOff[activeImg[this.imgGroup].rsrc].src;
							activeImg[this.imgGroup] = this;
						}
					};
				}        
			}		
		}
	}
}

// ADD PREPEVENTS ONLOAD
// using onload.js instead
/*
if (is.docom){
    if (window.attachEvent){
        window.attachEvent('onload',prepEvents);
    }else if (window.addEventListener){
        window.addEventListener('load',prepEvents,false);
    }else if (is.iemac){
        document.onreadystatechange = function(){if (document.readyState == "interactive"){prepEvents()}};
    }
}
*/

// ADD CLASSES TO OBJECTS
function addClassName(element, className) {
	if (hasClassName(element, className)) { return false; }
	if (!element.className) { element.className = className; }
	else { element.className += ' '+className; }
	return true;
}

// REMOVE CLASSES FROM OBJECTS
function removeClassName(element, className) {
	if (!hasClassName(element, className)) { return false; }
	var classNames = element.className.split(' ');
	var newClassNames = [];
	for (var a=0; a<classNames.length; a++) {
		if (classNames[a] != className) { newClassNames[newClassNames.length] = classNames[a]; }
	}
	element.className = newClassNames.join(' ');
	return true;
}

// TEST FOR CLASS NAME
function hasClassName(element, className) {
    var exp = new RegExp("\\b"+className+"\\b");
    return (element.className && exp.exec(element.className))?true:false;
}