/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~/
 * enableScrollBars, v1.1
 * (c) 2005 bivia.com
 * created by Ben Curtis of bivia.com, February 27 2005
 *   - revised for _bv_utilities, March 25, 2006
 *
 * Creates CSS-defined custom scrollbars for divs, 
 * for when overflow:auto|scroll is bad looking.
 *~~~~*/

var enableScrollBars = {

	model : document.createElement('div'),

	init : function () {
		if (navigator.appName == "Microsoft Internet Explorer" && navigator.platform == "MacPPC") return;
	// Safari issues with overflow:hidden not hiding scrollbars;
		if (navigator.userAgent.indexOf('Safari') != -1)
			document.write('<style type="text/css">div.bvScrollBars { overflow:hidden !important; }</style>');
		bv.event.add(window, 'domready', enableScrollBars.find);
	}, // END: init
	
	find : function () {
		var Sc = bv.dom.getElementsByClassName(document, "div,span,ol,ul", "bvScrollBars");
		if (Sc.length) { // since there are scrollbars needed, create the model node
			enableScrollBars.model.className = "bvScrollGui";
			var ThumbTrack       = document.createElement('div');
			ThumbTrack.className = "bvScrollTrack";
			enableScrollBars.model.appendChild(ThumbTrack);
			var ThumbSlide       = document.createElement('div');
			ThumbSlide.className = "bvScrollThumb";
			var ThumbDetails       = document.createElement('div');
			ThumbDetails.className = "bvScrollThumbDetails";
			ThumbSlide.appendChild(ThumbDetails);
			enableScrollBars.model.appendChild(ThumbSlide);
			var ArrowUp       = document.createElement('div');
			ArrowUp.className = "bvScrollUp";
			enableScrollBars.model.appendChild(ArrowUp);
			var ArrowDown       = document.createElement('div');
			ArrowDown.className = "bvScrollDown";
			enableScrollBars.model.appendChild(ArrowDown);
	
			bv.event.add(document, "mousemove", enableScrollBars.act.slide.Move);
			bv.event.add(document, "mousedown", enableScrollBars.act.check);
			bv.event.add(document, "mouseup", enableScrollBars.act.slide.ClickUp);
		}
		for (var xx=0; xx<Sc.length; xx++) enableScrollBars.make(Sc[xx]);
	}, // END: find
	
	make : function (Div) {
		Div.bv_scrollContent = bv.dom.getElementsByClassName(Div,'div','bvScrollContainer')[0];
		Div.bv_scrollContent.style.top = "0px";
		Div.bv_scrollMax = Div.bv_scrollContent.offsetHeight - Div.offsetHeight;
		Div.bv_scrollUnit = Div.offsetHeight *0.9;
//		Div.style.overflow = "hidden";
		bv.css.addClass(Div,"hideOverflow");
	
		var Gui = enableScrollBars.model.cloneNode(true);
			Div.appendChild(Gui);
			Div.bv_scrollContent.style.marginRight = (Gui.offsetWidth +5) +"px";
			Div.bv_scrollGui = Gui;
		
	// the addition of scrollbars can cause the content to squash and grow taller
		Div.bv_scrollMax = Div.bv_scrollContent.offsetHeight - Div.offsetHeight;
	
		if (Div.bv_scrollMax <= 0) bv.css.addClass(Gui, "bvScrollDisabled");
		else {
			
		// Track
			Div.bv_scrollTrack = bv.dom.getElementsByClassName(Div,'div','bvScrollTrack')[0];
			Div.bv_scrollTrack.bv_scroller   = Div;
			bv.event.add(Div.bv_scrollTrack, 'mousedown', enableScrollBars.act.track.ClickDown);
			bv.event.add(Div.bv_scrollTrack, 'mouseup', enableScrollBars.act.track.ClickUp);
			Div.bv_scrollTrack.bv_waitTimer  = null;
			Div.bv_scrollTrack.bv_cycleTimer = null;
		
		// Thumb
			Div.bv_scrollThumb = bv.dom.getElementsByClassName(Div,'div','bvScrollThumb')[0];
			Div.bv_scrollThumb.bv_scroller = Div;
			bv.event.add(Div.bv_scrollThumb, 'mousedown', enableScrollBars.act.slide.ClickDown);
			bv.event.add(Div.bv_scrollThumb, 'mouseup',   enableScrollBars.act.slide.ClickUp);
		
		// ArrowUp
			Div.bv_scrollArrowUp = bv.dom.getElementsByClassName(Div,'div','bvScrollUp')[0];
			Div.bv_scrollArrowUp.bv_scroller   = Div;
			bv.event.add(Div.bv_scrollArrowUp, 'click',     enableScrollBars.act.arrow.UpClick);
			bv.event.add(Div.bv_scrollArrowUp, 'mousedown', enableScrollBars.act.arrow.UpClickDown);
			bv.event.add(Div.bv_scrollArrowUp, 'mouseup',   enableScrollBars.act.arrow.UpClickUp);
			bv.event.add(Div.bv_scrollArrowUp, 'mouseout',  enableScrollBars.act.arrow.UpClickUp);
			Div.bv_scrollArrowUp.bv_waitTimer  = null;
			Div.bv_scrollArrowUp.bv_cycleTimer = null;
		
		// ArrowDown
			Div.bv_scrollArrowDown = bv.dom.getElementsByClassName(Div,'div','bvScrollDown')[0];
			Div.bv_scrollArrowDown.bv_scroller   = Div;
			bv.event.add(Div.bv_scrollArrowDown, 'click',     enableScrollBars.act.arrow.DownClick);
			bv.event.add(Div.bv_scrollArrowDown, 'mousedown', enableScrollBars.act.arrow.DownClickDown);
			bv.event.add(Div.bv_scrollArrowDown, 'mouseup',   enableScrollBars.act.arrow.DownClickUp);
			bv.event.add(Div.bv_scrollArrowDown, 'mouseout',  enableScrollBars.act.arrow.DownClickUp);
			Div.bv_scrollArrowDown.bv_waitTimer  = null;
			Div.bv_scrollArrowDown.bv_cycleTimer = null;
	
			var TrackLength = Gui.offsetHeight - Div.bv_scrollArrowUp.offsetHeight - Div.bv_scrollArrowDown.offsetHeight;
			Div.bv_scrollThumb.style.height = Math.max(
						parseInt(Div.bv_scrollThumb.offsetWidth) /1.5, 
						Div.offsetHeight *(TrackLength / Div.bv_scrollContent.offsetHeight)
					) +"px";
			Div.bv_scrollThumb.getElementsByTagName('div')[0].style.height = "100%";
			Div.bv_scrollThumb.bv_top = Div.bv_scrollArrowUp.offsetHeight;
			Div.bv_scrollThumb.style.top = Div.bv_scrollThumb.bv_top +"px";
			Div.bv_scrollThumb.bv_excursion = TrackLength - Div.bv_scrollThumb.offsetHeight;
			
		} // end disabled check
	}, // END: make
	
	scroll : {
		to : function (Which, Pos) {
			if (Pos < 0) Pos = 0;
			if (Pos > Which.bv_scrollMax) Pos = Which.bv_scrollMax;
			Which.bv_scrollContent.style.top = (-1* Pos) +"px";
			enableScrollBars.scroll.thumb(Which);
		}, // END: scroll.to
		by : function (Which, Amt) {
			enableScrollBars.scroll.to(Which, -1* (parseInt(Which.bv_scrollContent.style.top) - Amt));
		}, // END: scroll.by
		thumb : function (Which) {
			var T = Which.bv_scrollThumb;
			T.style.top = (Math.round(T.bv_excursion *(-1* parseInt(Which.bv_scrollContent.style.top)/Which.bv_scrollMax)) + T.bv_top) +"px";
		} // END: scroll.thumb
	}, // END: scroll
	
	act : {
		check : function (evt) {
			if (evt.target && evt.target.className.indexOf('Scroll') != -1) {
				evt.stopPropagation();
				return false;
			}
		}, //END: act.check

		track : {
			ClickDown : function (evt) {
				var ClickAt = evt.offsetY || evt.layerY;
				var Mod = (ClickAt > parseInt(this.bv_scroller.bv_scrollThumb.style.top)) ? 1 : -1;
				if (this.bv_cycleTimer) clearInterval(this.bv_cycleTimer);
				this.bv_waitTimer  = setTimeout("",350);
				this.bv_cycleTimer = setInterval("enableScrollBars.act.track.Budge(document.getElementById('"+ bv.getId(this.bv_scroller) +"'),"+ Mod +");",350);
			}, // END: act.track.ClickDown
			ClickUp : function (evt) {
				if (this.bv_cycleTimer) clearInterval(this.bv_cycleTimer);
				if (this.bv_waitTimer) {
					clearTimeout(this.bv_waitTimer);
					var ClickAt = evt.offsetY || evt.layerY;
					var Mod = (ClickAt > parseInt(this.bv_scroller.bv_scrollThumb.style.top)) ? 1 : -1;
					enableScrollBars.act.track.Budge(this.bv_scroller, Mod);
				}
			}, // END: act.track.ClickUp
			Budge : function (Which, Mod) {
				if (Which.bv_scrollTrack.bv_waitTimer) clearTimeout(Which.bv_scrollTrack.bv_waitTimer);
				Which.bv_scrollTrack.bv_waitTimer = null;
				enableScrollBars.scroll.by(Which, Mod * Which.bv_scrollUnit);
			} // END: act.track.Budge
		}, // END: act.track

		slide : {
			Move : function (evt) {
				if (!window.bvScrollBarGrabbed) return true;
				else {
					enableScrollBars.scroll.to(
							window.bvScrollBarGrabbed.bv_scroller,
							window.bvScrollBarGrabbed.bv_scroller.bv_scrollMax *(
								(evt.clientY - window.bvScrollBarGrabbed.bv_scrollZeroPoint) / 
								window.bvScrollBarGrabbed.bv_excursion
							)
						);
					return true;
				}
			}, // END: act.slide.Move
			ClickDown : function (evt) {
				window.bvScrollBarGrabbed = this;
				this.bv_scrollZeroPoint = evt.clientY - parseInt(this.style.top) + this.bv_top;
			}, // END: act.slide.ClickDown
			ClickUp : function () {
				window.bvScrollBarGrabbed = null;
			} // END: act.slide.ClickUp
		}, // END: act.slide

		arrow : {
			UpClick : function () {
				if (this.bv_waitTimer) clearTimeout(this.bv_waitTimer);
				if (this.bv_cycleTimer) clearInterval(this.bv_cycleTimer);
				else enableScrollBars.scroll.by(this.bv_scroller, -15);
			}, // END: act.arrow.UpClick
			UpClickDown : function () {
				if (this.bv_waitTimer) clearTimeout(this.bv_waitTimer);
				if (this.bv_cycleTimer) clearInterval(this.bv_cycleTimer);
				this.bv_waitTimer = setTimeout("enableScrollBars.act.arrow.UpClickDownCycle('"+ bv.getId(this.bv_scroller) +"');",500);
			}, // END: act.arrow.UpClickDown
			UpClickDownCycle : function (Id) {
				document.getElementById(Id).bv_scrollArrowUp.bv_cycleTimer = setInterval("enableScrollBars.scroll.by(document.getElementById('"+ Id +"'), -5);",25);
			}, // END: act.arrow.UpClickDownCycle
			UpClickUp : function () {
				if (this.bv_waitTimer) clearTimeout(this.bv_waitTimer);
				if (this.bv_cycleTimer) clearInterval(this.bv_cycleTimer);
			}, // END: act.arrow.UpClickUp
			DownClick : function () {
				if (this.bv_waitTimer) clearTimeout(this.bv_waitTimer);
				if (this.bv_cycleTimer) clearInterval(this.bv_cycleTimer);
				else enableScrollBars.scroll.by(this.bv_scroller, +15);
			}, // END: act.arrow.DownClick
			DownClickDown : function () {
				if (this.bv_waitTimer) clearTimeout(this.bv_waitTimer);
				if (this.bv_cycleTimer) clearInterval(this.bv_cycleTimer);
				this.bv_waitTimer = setTimeout("enableScrollBars.act.arrow.DownClickDownCycle('"+ bv.getId(this.bv_scroller) +"');",500);
			}, // END: act.arrow.DownClickDown
			DownClickDownCycle : function (Id) {
				document.getElementById(Id).bv_scrollArrowDown.bv_cycleTimer = setInterval("enableScrollBars.scroll.by(document.getElementById('"+ Id +"'), +5);",25);
			}, // END: act.arrow.DownClickDownCycle
			DownClickUp : function () {
				if (this.bv_waitTimer) clearTimeout(this.bv_waitTimer);
				if (this.bv_cycleTimer) clearInterval(this.bv_cycleTimer);
			} // END: act.arrow.DownClickUp
		} // END: act.arrow
	}, // END: act
	
	complete : true
};
enableScrollBars.init();


var bvBreakFrame = {

	init : function () {
		var Trg = document.getElementById('spdeIframe');
		if (!Trg) Trg = document.getElementById('spdeNavTrg');
		if (Trg) {
			var Q = bvBreakFrame.getQuery();
			if (Q.src) Trg.src = Q.src;
		}
	},
	
	getQuery : function() {
		var Q = {};
		if (location.search.length) {
			var src = location.search.substring(location.search.lastIndexOf('?') +1);
			var Pairs = src.split('&');
			for (var xx=0; xx<Pairs.length; xx++) {
				var KV = Pairs[xx].split('=');
				if (KV.length == 2) Q[unescape(KV[0])] = unescape(KV[1]);
			}
		}
		return Q;
	},
	
	complete : true

}

if (window.bv && bv.event) bv.event.add(window, 'domready', bvBreakFrame.init );
