function BAcommon() {
	this.env  = {};
	this.ns   = {};

	this.env.ua       = navigator.userAgent;
	this.env.isWin    = this.env.ua.match(/Win/);
	this.env.isMac    = this.env.ua.match(/Mac/);
	this.env.isOpera  = (window.opera);
	this.env.isIE     = (document.all && !this.env.isOpera);
	this.env.isMoz    = this.env.ua.match(/Gecko\//);
	this.env.isN7     = this.env.ua.match(/Netscape\/7/);
	this.env.isN6     = this.env.ua.match(/Netscape\/6/);
	this.env.isSafari = this.env.ua.match(/AppleWebKit/);
	this.env.ver      = navigator.appVersion;
	this.env.ver      = this.getUAVer();

};

BAcommon.prototype = {
	getUAVer : function() {
		if(RegExp){
			if(this.env.isIE){
				return this.env.ua.match(/MSIE (\d(.\d+)?)/)[1];
			}
			if(this.env.isMoz){
				return this.env.ua.match(/(\d(.\d+)?) \(/)[1];
			}
			if(this.env.isOpera){
				return this.env.ua.match(/Opera\/? ?(\d(\.\d+)?)/)[1];
			}
			if(this.env.isNN || this.env.isN6 || this.env.isN7){
				return this.env.ua.match(/Netscape\/(\d(.\d+)?)/)[1];
			}
			return parseFloat(this.env.ver);
		}else{
			return undefined;
		}
	}
};
var BA = new BAcommon;

Array.prototype.indexOf = function(value){
	var i = 0;
	while(i < this.length){
		if(this[i] == value) return i;
		i++;
	}
	return -1;
};

if(!Array.push){
	Array.prototype.push = function(elem){
		this[this.length] = elem;
	}
};

function ClassNames(obj){
	this.obj = obj;
	this._cns_ = obj.className.split(/\s+/);
};

ClassNames.prototype.has = function(value){
	if(this._cns_.indexOf(value) == -1){
		return false;
	}
	return true;
};

ClassNames.set = function(node,cname){
	if(!node.classNames){
		node.classNames = new ClassNames(node);
	}
	if(cname){
		node.classNames.add(cname);
	}
};

BA.getElementsByTagName = function(tagName, baseNode) {
	if (!tagName) tagName = '*';
	if (tagName.toLowerCase() == 'body' && document.body) return [document.body]; // measure for Netscape7.1
	if (!baseNode || !baseNode.nodeType || baseNode.nodeType != 1) baseNode = document;

	if (baseNode == document && tagName == '*' && document.all) {
		var elms = document.all, ret = [];
		for (var i = 0; i < elms.length; i++) {
			if (elms[i].nodeType == 1) {
				ret[ret.length] = elms[i];
			}
		}
		return ret;
	}

	if(!baseNode.getElementsByTagName) {
		return null;
	}else if(BA.ns.rootNS && document.getElementsByTagNameNS){
		return document.getElementsByTagNameNS(BA.ns.xhtml1, tagName);
	}else{
		return baseNode.getElementsByTagName(tagName);
	}
};

BA.getElementsByClassName = function(className, tagName, baseNode) {
	if (!className) return null;
	var ret  = new Array();
	var objs = BA.getElementsByTagName(tagName, baseNode);
	for (var i = 0; i < objs.length; i++) {
		if (!objs[i].className) continue;
		ClassNames.set(objs[i]);
		if(objs[i].classNames.has(className)){
			ret.push(objs[i]);
		}
	}
	return ret;
};

BA.concatNodeList = function() {
	var ret = new Array();
	if (typeof arguments[0] != 'object' && typeof arguments[0] != 'function'){ // Safari returns 'function' when arg is [NodeList]
		return ret;
	}
	for (var i = 0; i < arguments.length; i++){
		for (var j = 0; j < arguments[i].length; j++) {
			ret[ret.length] = arguments[i][j];
		}
	}
	return ret;
};

BA.addEvent = function(obj, type, listener) {
	if(!obj || !type || !listener) return;
	if (obj.addEventListener) {  // Std DOM Events
		obj.addEventListener(type, listener, false);
	} else {
		if (obj.attachEvent) {   // WinIE
				obj.attachEvent(
					'on' + type,
					function() { listener( {
						type            : window.event.type,
						target          : window.event.srcElement,
						currentTarget   : obj,
						clientX         : window.event.clientX,
						clientY         : window.event.clientY,
						pageX           : (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft) + window.event.clientX,
						pageY           : (document.documentElement.scrollTop  ? document.documentElement.scrollTop  : document.body.scrollTop ) + window.event.clientY,
						stopPropagation : function() { window.event.cancelBubble = true  },
						preventDefault  : function() { window.event.returnValue  = false }
					} ) }
				);
		} else {                 // MacIE
			var exists = obj['on' + type];
		    obj['on' + type]  = (exists) ?
				function() {
					exists();
					listener( {
						type            : window.event.type,
						target          : window.event.srcElement,
						currentTarget   : obj,
						clientX         : window.event.clientX,
						clientY         : window.event.clientY,
						pageX           : (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft) + window.event.clientX,
						pageY           : (document.documentElement.scrollTop  ? document.documentElement.scrollTop  : document.body.scrollTop ) + window.event.clientY,
						stopPropagation : function() { window.event.cancelBubble = true  },
						preventDefault  : function() { window.event.returnValue  = false }
					} );
				} : function() {
					listener( {
						type            : window.event.type,
						target          : window.event.srcElement,
						currentTarget   : obj,
						clientX         : window.event.clientX,
						clientY         : window.event.clientY,
						pageX           : (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft) + window.event.clientX,
						pageY           : (document.documentElement.scrollTop  ? document.documentElement.scrollTop  : document.body.scrollTop ) + window.event.clientY,
						stopPropagation : function() { window.event.cancelBubble = true  },
						preventDefault  : function() { window.event.returnValue  = false }
					} )
				};
		}
	}
};

BA.addOnload = function(listener) {
	BA.addEvent(window, 'load', listener)
};

BA.addOnLoading = function(fn, wait) {
	// add. MAGICAL
	if(BA.env.isOpera && BA.env.ver < 7){
		return;
	}

	if (!BA.psLoading) BA.psLoading = new Array();
	if (!wait) var wait = 500;
	fn();
	BA.psLoading[BA.psLoading.length] = setInterval(fn, wait);
	BA.addOnload(fn);
	BA.addOnload(BA.clearOnLoading);
};

BA.clearOnLoading = function(){
	if (!BA.psLoading) return;
	for (var i = 0; i < BA.psLoading.length; i++)
		clearInterval(BA.psLoading[i]);
};

function RollOverImages(targetClass,ois,ais){
	if(!document.BARO) document.BARO = this;
	this.targetClass = targetClass;
	this.ois = ois;
	this.ais = ais;
	this.pli = new Array();
	if(targetClass && (ois || ais)) this.init();
};

RollOverImages.prototype.preloadImg = function(srcs){
	var ret = new Array();
	if(!document.images || !srcs) return;
	for(var i=0;i<srcs.length;i++){
		(new Image()).src = srcs[i];
		ret.push(srcs[i]);
	}
};

RollOverImages.prototype.swap = function(names,status){
	for(var i=0;i<names.length;i++){
		var tempobj = (document.all)? document.all[names[i]] : document.getElementById(names[i]);
		if(tempobj[status]) tempobj.src = tempobj[status];
	}
};

RollOverImages.prototype.setEvent = function(tn){
	var tn = tn;
	var ois = this.ois;
	var ais = this.ais;
	if(ois && !tn.onmouseover) tn.onmouseover = function(){
		if(ais){
			this._onfocus = this.onfocus;
			this.onfocus = '';
		}
		document.BARO.swap(this.BAROti,'o');
	};
	if(ois && !tn.onmouseout) tn.onmouseout = function(){
		if(ais){
			this.onfocus = this._onfocus;
		}
		document.BARO.swap(this.BAROti,'u');
	};
	if(ais && !tn.onmousedown) tn.onmousedown = function(){document.BARO.swap(this.BAROti,'a');};
	if(ois && ais && !tn.onmouseup) tn.onmouseup = function(){document.BARO.swap(this.BAROti,'o');};
	
	if(ois && !tn.onfocus) tn.onfocus = function(){document.BARO.swap(this.BAROti,'o');};
	if(!tn.onblur) tn.onblur = function(){document.BARO.swap(this.BAROti,'u');};
	if(ais && !tn.onkeypress) tn.onkeypress = function(){document.BARO.swap(this.BAROti,'a');};
	if(ois && ais && !tn.onkeyup) tn.onkeyup = function(){document.BARO.swap(this.BAROti,'o');};
};

RollOverImages.prototype.init = function(){
	if(!document.getElementById && document.all) return;
	if(!document.images) return;
	var pli = this.pli;
	var ois = this.ois;
	var ais = this.ais;
	var idprefix = 'BARO_';
	
	var objinput = BA.getElementsByClassName(this.targetClass,'input');
	var objimg = BA.getElementsByClassName(this.targetClass,'img');
	var objs = BA.concatNodeList(objinput,objimg);
	
	for(var i=0;i<objs.length;i++){
		var tempimg = objs[i];
		
		tempimg.id = (tempimg.id)? tempimg.id : (idprefix + this.targetClass + '_' + i);
		
		var basesrc = tempimg.src;
		var imgtype = basesrc.substring(basesrc.lastIndexOf('.'));
		var basename = basesrc.substring(0,basesrc.length - imgtype.length);
		var temppli = new Object();
		tempimg.u = basesrc;
		if(ois){
			tempimg.o = temppli.o = basename + ois + imgtype;
			if(pli.indexOf(temppli.o) == -1) pli.push(temppli.o);
		}
		if(ais){
			tempimg.a = temppli.a = basename + ais + imgtype;
			if(pli.indexOf(temppli.a) == -1) pli.push(temppli.a);
		}
		
		if(tempimg.tagName.toLowerCase() == 'img'){
			var pa = tempimg.parentNode;
			for(var j=0;j<10;j++){
				if(pa && pa.tagName.toLowerCase() == 'a'){
					if(!pa.BAROti) pa.BAROti = new Array();
					pa.BAROti.push(tempimg.id);
					this.setEvent(pa);
					break;
				}else if(pa.parentNode){
					pa = pa.parentNode;
				}else{
					break;
				}
			}
		}else if(tempimg.tagName.toLowerCase() == 'input'){
			tempimg.BAROti = new Array(tempimg.id);
			this.setEvent(tempimg);
		}
	}
	this.preloadImg(pli);
};

BA.addOnLoading(function(){new RollOverImages('ps','_x')}, 5000);


function printPage() {
  if (window.print)
    window.print()
  else
    alert("Sorry, your browser doesn't support this feature.");
}

