/* if the id is found we're going to adjust the width of the footer bar from the default
100% to the actual figure, this is to pacify ie6 really, since 100% really isn't 100% to MS */

function resizeFooter() {
	if ( $('FooterBox') ) {
		var WindowWidth  = window.getScrollWidth();
		var WindowHeight = window.getScrollHeight();
		var FooterSize 	 = $('FooterBox').getSize();
		

		$('FooterBox').setStyle('width', WindowWidth) ;
		$('FooterBox').setStyle('top',  WindowHeight - 45  ) ;
		$('FooterBox').setStyle('display', 'block' ) ;

		// to do, ie6 specific set here 
		if (typeof document.body.style.maxHeight == "undefined") {
		
			if ( WindowHeight < 730 ) {
				$('FooterBox').setStyle('top',  WindowHeight - 54  ) ;
				
			}else {
				$('FooterBox').setStyle('top',  WindowHeight  - 58 ) ;
			}
			$('FooterBox').setStyle('width', WindowWidth - 14 ) ;
		}
			
	}
}


window.addEvent('resize', function(){
	// footer needs to be updated
	resizeFooter();

});

window.addEvent('load', function(){
	// footer needs to be updated
	resizeFooter();

	Element.Events.extend({
		'wheelup': {
			type: Element.Events.mousewheel.type,
			map: function(event){
				event = new Event(event);
				if (event.wheel >= 0) this.fireEvent('wheelup', event)
			}
		},
	 
		'wheeldown': {
			type: Element.Events.mousewheel.type,
			map: function(event){
				event = new Event(event);
				if (event.wheel <= 0) this.fireEvent('wheeldown', event)
			}
		}
	});


	
	if ( $('ContentDiv') ) 
	{
		var scroll = new Fx.Scroll('ContentDiv', {
			wait: false,
			duration:10,
			transition: Fx.Transitions.linear
		});			
			  
		var ContentSize   = $('ContentDiv').getSize();
		var ContentHeight = ContentSize['scrollSize']['y'];
		var ContentWindow = ContentSize['size']['y'];
		var ContentCords  = $('ContentDiv').getCoordinates();
		var ContentBottomLoc = ContentCords['bottom'] ;
		//alert(ContentWindow);
		//alert(ContentHeight);
		
		if ( ContentHeight > 237 && $('SoftJoinFormWrapper') ) {
			var ShowScroll = true ;
		} 

		else if ( ContentHeight > 300 && !$('SoftJoinFormWrapper') ) {
			var ShowScroll = true ;
		} 
		
		else {
			var ShowScroll = false ;
		}
		
		function ScrollContent () {
		
			var fx = new Fx.Style($('ScrollKnob'), 'top', {duration: 10, wait: false});
			var mySlide2 = new Slider($('ScrollBarShort'), $('ScrollKnob'), {
				
				mode: 'vertical',	
				
				onChange: function(pos){
					scroll.scrollTo(0, pos) ;
				},
							
				onTick: function(pos){
					fx.custom(pos);
				},
				
				steps: ContentHeight
			}).set(0);	
		
		
		}
		
		function ManualScrollContent( Direction )
		{
			var fx = new Fx.Style($('ScrollKnob'), 'top', {duration: 10, wait: false});
			var KnobySteps = 10 ; /* how many pix to jump by for knoby */
			var WindowKnobPos = $('ScrollKnob').getPosition();
			var StartKnobPos = $('ScrollBarShort').getPosition();
			var KnobPos = WindowKnobPos['y'] - StartKnobPos['y'] ;
			var SliderSize = $('ScrollBarShort').getSize();  // how tall is the slider ( calc here so bar can change height w/o udpate here ) 
			var StepsTaken = ( KnobPos / KnobySteps ) ;  

			/* here we find out how many steps are in the scroll bar, and return how many px the content needs to jump on each step  */			
			var ContentSteps = ( ContentHeight  / ( SliderSize['size']['y'] / KnobySteps ) )   ;  		

			if ( Direction == 'up' ) {
				if ( StepsTaken == 1 ) {
					StepsTaken = 0 ;
				}
			
				if ( KnobPos > 0 ) {
					fx.custom( KnobPos - KnobySteps );
					scroll.scrollTo( 0, ( ContentSteps * StepsTaken ) - KnobPos ) ;
				}
			} else if ( Direction == 'down' ) {
			
				if ( StepsTaken == 0 ) {
					StepsTaken = 1 ;
				}
				
				/* if the height of the scroll bar changes, please re-calc here, or the knob won't scroll all the way */
				if ( KnobPos <= 180 ) {
					fx.custom( KnobPos + KnobySteps ) ;
					scroll.scrollTo( 0, KnobPos + ( ContentSteps * StepsTaken) ) ;
				}
			}
		
		}
		/* check if div scrollable content is larger then the div height */
		if ( ShowScroll )
		{
			if ( $('ScrollContainer') ) {
				$('ScrollContainer').setStyle('display', 'block') ;
			}
			
			ScrollContent();
		
			$('ContentDiv').addEvents({
				
				'wheelup': function(e) {
					e = new Event(e).stop();
					ManualScrollContent( 'up' ) ;
				},
			 
				'wheeldown': function(e) {
					e = new Event(e).stop();
					ManualScrollContent( 'down' ) ;
				}
			});
			
			/* removed arrows per request 
			$('slider_arrow_up').addEvent('click', function(){
				ManualScrollContent( 'up' ) ;
			});

			$('slider_arrow_down').addEvent('click', function(){
				ManualScrollContent( 'down' ) ;
			});
			*/
		
		/* if the scroller isn't needed, lets not show the dang thing */
		} else {
			if ( $('ScrollContainer') ) {
				$('ScrollContainer').setStyle('display', 'none') ;
			}
		}

		
	}

}); /*end addEvent */
