
/* cribbed from bv_utilities.js
 * (c) 2006 bivia.com
 * used with permission
 */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~/
 * Bivia Utilities, v2.1.1
 * (c) 2005 bivia.com
 * created by Ben Curtis of bivia.com, February 22 2005
 * objectified, Decemeber 22, 2005
 *   - event object largely inspired/ported from Dean Edwards's events
 *     http://dean.edwards.name/my/events.js
 * enhanced domready event handling, September 20, 2006
 *   - ref: http://dean.edwards.name/weblog/2006/06/again/
 *
 *~~~~*/



var Conf = {
	debug : false,
	js_path : '/templates/abs/js/',
	src_img_clear : '/templates/abs/img/clear.gif',
	complete : true
};



var bv = {
	tickBase : new Date(),
	initialized : false,
	init : function () {
		bv.initialized = new Date();
		bv.dom.init();
		bv.css.init();
	}, // END init

	bv_guid : 1,
	guid_counter : 2, // 0 is reserved, bv.bv_guid == 1
	getNewGuid : function() { return bv.guid_counter++; },
	getId : function (el,base) {
		if (!el.id) {
			var b = (base) ? base : "bv";
			el.id = b + bv.getNewGuid();
		}
		return el.id;
	},

	event : {
		add : function(el, evt, fn, prioritize) {
			if (evt == 'domready') el = window;
			if (typeof el == "string") el = document.getElementById(el);
			if (!el) return;
			if (evt == 'domready') {
				if (prioritize) bv.dom.readyList.unshift(fn);
				else bv.dom.readyList.push(fn);
				if (bv.dom.initialized)
					bv.dom.ready('event.add'); // do not call function directly, because you want it executed in order
			} else { // start Dean Edwards-port code
				if (!fn.bv_guid) fn.bv_guid = bv.getNewGuid();
				if (!el.bv_events) el.bv_events = {};
				if (!el.bv_events[evt]) {
					el.bv_events[evt] = {};
					if (el["on" + evt]) { // store any previously-assigned handlers
						el.bv_events[evt][0] = el["on" + evt];
					}
				}
				el.bv_events[evt][fn.bv_guid] = fn;
				el["on" + evt] = bv.event.handle;
			}
		}, // END event.add
		remove : function(el, evt, fn) {
			if (el.events && el.bv_events[evt] && fn.bv_guid)
				delete el.bv_events[evt][fn.bv_guid];
		}, // END event.remove
		handle : function(e) {
			var Rtn = true;
			e = e || bv.event.fixEvent(window.event);
			for (var ii in this.bv_events[e.type]) {
				this.bv_handleEvent = this.bv_events[e.type][ii];
				if (this.bv_handleEvent(e) === false)
					Rtn = false;
			}
			return Rtn;
		}, // END event.handle
		fixEvent : function (event) {
			if (!event) { // error thrown on unload?
				event = { type : 'unknown' };
			}
			// add W3C standard event methods
			event.preventDefault = bv.event.fixEvent_preventDefault;
			event.stopPropagation = bv.event.fixEvent_stopPropagation;
			return event;
		},
		fixEvent_preventDefault : function() {
			this.returnValue = false;
		},
		fixEvent_stopPropagation : function() {
			this.cancelBubble = true;
		}

	}, // END event

	dom : {
		initialized : false,
		init : function () {
			bv.dom.initialized = false; // not initialized until dom.ready is run
			if (document.addEventListener) {
				document.addEventListener('DOMContentLoaded', bv.dom.ready, false); // Gecko-based browsers, Opera 9+
			} else {
				/*@cc_on @*/
				/*@if (@_win32)
				document.write('<scr'+'ipt id="__ie_onload" defer="defer" src="javascript:false;"><\/script>');
				var script = document.getElementById("__ie_onload");
				script.onreadystatechange = function() {
					if (this.readyState == "complete") {
						bv.dom.ready(); // call the domready handler
					}
				};
				/*@end @*/
			}

			if (/WebKit/i.test(navigator.userAgent)) { // Safari
				var _timer = setInterval(function() {
					if (/loaded|complete/.test(document.readyState)) {
						bv.dom.ready(); // call the onload handler
						clearInterval(_timer);
					}
				}, 10);
			}

			bv.event.add(window, 'load', bv.dom.ready); // fail-safe fire onload, in case the above hangs
			bv.event.add(window, 'unload', function(){ window.bv = null; } ); // clean up after yourself
			if (!document.documentElement) document.documentElement = document.getElementsByTagName('html')[0];
			bv.css.addClass(document.documentElement, 'domCapable domLoading');
		}, // END dom.init

		readyList : [
			function () {
				bv.dom.initialized = new Date();
				if (bv.css && bv.css.addClass)
					bv.css.addClass(document.documentElement, 'domReady');
				if (bv.css && bv.css.removeClass)
					bv.css.removeClass(document.documentElement, 'domLoading');
			}
		],
		ready : function() {
			while (this.E = bv.dom.readyList.shift()) // deletes as it goes
				this.E(); // note: may safely support multiple, simultaneous firings
		}, // END dom.ready

		getElementsByClassName : function (el,TagsIn,Class) {
			var rtn = [];
			if (! el || ! el.getElementsByTagName) return rtn;
			var It = "\\b"+Class+"\\b";
			var Tags = TagsIn.split(",");
			for (var xx=0; xx<Tags.length; xx++) {
				var Els = (el.getElementsByTagName) ? el.getElementsByTagName(Tags[xx]) : el.all;
				for (var ii=0; ii<Els.length; ii++) {
					if (Els[ii].className.match(It))
						rtn[rtn.length] = Els[ii];
				}
			}
			return rtn;
		},
		getChildNodesOfType : function (el,TagsIn) {
			var rtn = [];
			TagsIn = TagsIn.toUpperCase();
			for (var xx=0; xx<el.childNodes.length; xx++)
				if ((","+TagsIn+",").indexOf(","+ el.childNodes[xx].nodeName +",") != -1)
					rtn[rtn.length] = el.childNodes[xx];
			return rtn;
		}
	}, // END dom
	
	css : {
		initialized : false,
		init : function () {
			bv.css.initialized = new Date();
		},
		
		addClass : function (el,nm) {
			var regex = new RegExp("\\b"+nm+"\\b");
			if (!el.className.match(regex))
				el.className = bv.string.trim(el.className +" "+ nm, true);
		}, // END style.addClass
		removeClass : function (el,nm) {
			var regex = new RegExp("\\b"+nm+"\\b", "g");
			el.className = bv.string.trim(el.className.replace(regex, ''), true);
		}, // END css.removeClass

		getValue : function (el,prop) {
			if (document.defaultView && document.defaultView.getComputedStyle) {
				return document.defaultView.getComputedStyle(el,'').getPropertyValue(prop);
			} else {
				var propCased = bv.string.camelCase(prop);
				if (el.currentStyle) {
					return el.currentStyle[propCased];
				} else return el.style[propCased];
			}
		},
		getOffset : function (el,base) { // no base = offset from parent
			// IE will treat the offset as to the parentNode; Moz refers all to the body element
			// so if we're not finding an offset relative to a base, take a shortcut for IE:
			if (!base && el.offsetParent == el.parentNode) {
				return { top : el.offsetTop, left : el.offsetLeft };
			} else if (!base) base = el.parentNode;
			return {
				top  : el.offsetTop  - base.offsetTop,
				left : el.offsetLeft - base.offsetLeft
			};
		},
		getOffsetFromRoot : function (el) {
			var offset = { top : 0, left : 0};
			while (el) {
				offset.top  += el.offsetTop;
				offset.left += el.offsetLeft;
				el = el.offsetParent;
			}
			return offset;
		}
	}, // END css

	string : {
		trim : function (s,dedupe) {
			// Mac IE chokes on the '?'; you can break this into two replaces for Mac IE compatibility
			s = s.replace(/^[\t\r\n\s]*(.*?)[\t\r\n\s]*$/, '$1');
			if (dedupe) // reduce internal runs of whitespace
				s = s.replace(/[\t\r\n\s]+/g, ' ');
			return s;
		},
		camelCase : function (s) {
			var bits = s.split("[- ]+");
			for (var xx=1; xx<bits.length; xx++)
				if (bits[xx].length)
					bits[xx] = bits[xx].charAt(0).toUpperCase() + bits[xx].substring(1);
			return bits.join('');
		}
	}, // END string

	complete : true
}; // END bv declaration
bv.init();
// /END bv_utilities.js clipping





var bnwRoll = {
	init : function () {
		var Img = bv.dom.getElementsByClassName(document,'img','bnwRoll');
		for (var xx=0; xx<Img.length; xx++) {
			var Src = Img[xx].src.match(/^(.+)_(on|off|down)(\.\w+)$/);
			Img[xx].bnwRoll_preload = { over:false, out:false, down:false };
			if (Src) {
				Img[xx].bnwRoll_preload.over = new Image();
				Img[xx].bnwRoll_preload.over.src = Src[1] +"_on"+ Src[3];
				bv.event.add(Img[xx], 'mouseover', bnwRoll.over);
				
				Img[xx].bnwRoll_preload.out = new Image();
				Img[xx].bnwRoll_preload.out.src = Src[1] +"_off"+ Src[3];
				bv.event.add(Img[xx], 'mouseout', bnwRoll.out);
				
				if ((/\bbnwRollDown\b/).test(Img[xx].className)) {
					Img[xx].bnwRoll_preload.down = new Image();
					Img[xx].bnwRoll_preload.down.src = Src[1] +"_down"+ Src[3];
					bv.event.add(Img[xx], 'mousedown', bnwRoll.down);
					bv.event.add(Img[xx], 'mouseup', bnwRoll.up);
				}
				
				if ((/\bbnwRollActive\b/).test(Img[xx].className)) {
					Img[xx].bnwRoll_preloadInActive = Img[xx].bnwRoll_preload;
					Img[xx].bnwRoll_preloadActive = { over:false, out:false, down:false };

					Img[xx].bnwRoll_preloadActive.over = new Image();
					Img[xx].bnwRoll_preloadActive.over.src = Src[1] +"_active_on"+ Src[3];
					
					Img[xx].bnwRoll_preloadActive.out = new Image();
					Img[xx].bnwRoll_preloadActive.out.src = Src[1] +"_active_off"+ Src[3];
					
					if ((/\bbnwRollDown\b/).test(Img[xx].className)) {
						Img[xx].bnwRoll_preloadActive.down = new Image();
						Img[xx].bnwRoll_preloadActive.down.src = Src[1] +"_active_down"+ Src[3];
					}
				}
			}
		}
	},
	over : function () {
		if (this.bnwRoll_preload && this.bnwRoll_preload.over)
			this.src = this.bnwRoll_preload.over.src;
	},
	out : function () {
		if (this.bnwRoll_preload && this.bnwRoll_preload.out)
			this.src = this.bnwRoll_preload.out.src;
	},
	down : function () {
		if (this.bnwRoll_preload && this.bnwRoll_preload.down)
			this.src = this.bnwRoll_preload.down.src;
	},
	up : function () {
		if (this.bnwRoll_preload && this.bnwRoll_preload.out)
			this.src = this.bnwRoll_preload.out.src;
	}
}; // END bnwRoll

bv.event.add(window, 'domready', bnwRoll.init);






var bnwSlideShow = {

	slides : [],
	currSlide : null,
	slideDuration : 10,
	slideTimer : null,
	pauseBtn : {},
	
	init : function () {
		var Show = document.getElementById('bnwSlideShow');
		if (Delay = Show.className.match(/\bbnwSlideShowSlideDuration(\d+)\b/)) {
			bnwSlideShow.slideDuration = parseInt(Delay[1]);
		}
		
		var Slides = bv.dom.getChildNodesOfType(Show, 'li');
		for (var xx=0; xx<Slides.length; xx++) {
			Slides[xx].bnwSlideShow_index = bnwSlideShow.slides.length;
			bnwSlideShow.slides.push(Slides[xx]);
			if ((/\bbnwActiveSlide\b/).test(Slides[xx].className))
				bnwSlideShow.swapSlide(Slides[xx].bnwSlideShow_index);
		}
		
		bv.event.add(document.getElementById('controlBtnPrev'), 'click', bnwSlideShow.prevSlide);
		bv.event.add(document.getElementById('controlBtnPause'), 'mousedown', bnwSlideShow.pausePlay);
		bv.event.add(document.getElementById('controlBtnNext'), 'click', bnwSlideShow.nextSlide);

		bnwSlideShow.pauseBtn = document.getElementById('controlBtnPause');
		bnwSlideShow.playShow();
	},

	swapSlide : function (Which) {
		if (bnwSlideShow.slideTimer) clearTimeout(bnwSlideShow.slideTimer);
		if (bnwSlideShow.currSlide)
			bv.css.removeClass(bnwSlideShow.currSlide, 'bnwActiveSlide');
		bnwSlideShow.currSlide = bnwSlideShow.slides[Which];
		bv.css.addClass(bnwSlideShow.currSlide, 'bnwActiveSlide');
		bnwSlideShow.slideTimer = setTimeout('bnwSlideShow.nextSlide()', bnwSlideShow.slideDuration *1000);
	},
	nextSlide : function () {
		var Idx = bnwSlideShow.currSlide.bnwSlideShow_index;
		Idx++;
		if (Idx >= bnwSlideShow.slides.length) Idx = 0;
		bnwSlideShow.swapSlide(Idx);
	},
	prevSlide : function () {
		var Idx = bnwSlideShow.currSlide.bnwSlideShow_index;
		Idx--;
		if (Idx < 0) Idx = bnwSlideShow.slides.length -1;
		bnwSlideShow.swapSlide(Idx);
	},
	
	pauseShow : function () {
		if (bnwSlideShow.slideTimer) clearTimeout(bnwSlideShow.slideTimer);
		bnwSlideShow.slideTimer = null;
		bnwSlideShow.pauseBtn.bnwRoll_preload = bnwSlideShow.pauseBtn.bnwRoll_preloadActive;
	},
	playShow : function () {
		bnwSlideShow.pauseShow();
		bnwSlideShow.slideTimer = setTimeout('bnwSlideShow.nextSlide()', bnwSlideShow.slideDuration *1000);
		bnwSlideShow.pauseBtn.bnwRoll_preload = bnwSlideShow.pauseBtn.bnwRoll_preloadInActive;
	},
	pausePlay : function () {
		if (bnwSlideShow.slideTimer) {
			bnwSlideShow.pauseShow();
		} else {
			bnwSlideShow.playShow();
		}
		return false;
	}
}; // END bnwSlideShow

bv.event.add(window, 'domready', bnwSlideShow.init);


