$(document).ready( function() { 
	$('#ulNav li ul').css({display: "none"}); 
	$('#ulNav li:has(ul)').each( function() {
		$(this).hover(
			function(e) { 
				 $(this).find('ul:first').css({display: "block"}); 
			}
			,function(e) { 
				 $(this).find('ul').css({display: "none"}); 
			}
		);
	} ); 
	$('#ulNav li.Level2:has(ul) span.Level2').unwrap();
	$('div.col_slides_description_sin_js').each( function() {
		new ArrowsScroll($(this), $(this).find('div.col_slides_description, div.col_slides_details'));
	} );
	$('div#leadership_col_right .scroll').each( function() {
		new ArrowsScroll($(this), $(this).find('div.ScrollIn'));
	} );
} ); 

function ElementPaging(sPagesJq, sPrevJq, sNextJq) {
	this.next = function() {
		if(this.iSelected < this.jqPages.length - 1) {
			this.iSelected++;
			this.showCurrent(true);
		}
	}
	this.prev = function() {
		if(this.iSelected > 0) {
			this.iSelected--;
			this.showCurrent(true);
		}
	}
	this.showCurrent = function(bTrans) {
		var nTransTime = bTrans ? this.nTransTime : 0;
		var iSelected = this.iSelected;
		this.jqPages.each( function(index) {
			if(index == iSelected) $(this).delay(nTransTime + 100).fadeIn(nTransTime); // These extra 50ms avoid being two
			else $(this).fadeOut(nTransTime);										   // visible elements at the same time
		});
		// Hide both prev and next
		if(this.jqPrev.css('display') == 'none') this.jqPrev.delay(nTransTime);
		else this.jqPrev.fadeOut(nTransTime);
		if(this.jqNext.css('display') == 'none') this.jqNext.delay(nTransTime);
		else this.jqNext.fadeOut(nTransTime);
		// Show if needed
		if(this.iSelected > 0) this.jqPrev.fadeIn(nTransTime);
		if(this.iSelected < this.jqPages.length -1) this.jqNext.fadeIn(nTransTime);
	}
	this.nTransTime = 300;
	this.iSelected = 0;
	this.jqPages = $(sPagesJq);
	this.jqPrev = $(sPrevJq);
	this.jqNext = $(sNextJq);
	thisObject = this;
	this.jqPrev.click( function() { thisObject.prev(); } );
	this.jqNext.click( function() { thisObject.next(); } );
	this.showCurrent(false);
}
function ElementPaging2(sPagesJq, sPrevJq, sNextJq) {
	this.next = function() {
		if(this.iSelected < this.jqPages.length - 1) {
			this.iSelected++;
			this.showCurrent(true);
		}
	}
	this.prev = function() {
		if(this.iSelected > 0) {
			this.iSelected--;
			this.showCurrent(true);
		}
	}
	this.showCurrent = function(bTrans) {
		var nTransTime = bTrans ? this.nTransTime : 0;
		var iSelected = this.iSelected;
		this.jqPages.each( function(index) {
			if(index == iSelected) $(this).delay(nTransTime + 100).fadeIn(nTransTime); // These extra 50ms avoid being two
			else $(this).fadeOut(nTransTime);										   // visible elements at the same time
		});
		// Hide both prev and next
		if(this.jqPrev.css('display') == 'none') this.jqPrev.delay(nTransTime);
		else this.jqPrev.fadeOut(nTransTime);
		if(this.jqNext.css('display') == 'none') this.jqNext.delay(nTransTime);
		else this.jqNext.fadeOut(nTransTime);
		// Show if needed
		if(this.iSelected > 0) this.jqPrev.fadeIn(nTransTime);
		if(this.iSelected < this.jqPages.length -1) this.jqNext.fadeIn(nTransTime);
	}
	this.nTransTime = 300;
	this.iSelected = 0;
	this.jqPages = $(sPagesJq);
	this.jqPrev = $(sPrevJq);
	this.jqNext = $(sNextJq);
	thisObject2 = this;
	this.jqPrev.click( function() { thisObject2.prev(); } );
	this.jqNext.click( function() { thisObject2.next(); } );
	this.showCurrent(false);
}

function ArrowsScroll(jqDivOut, jqDivIn) {
	this.onMouseOverUp = function() {
		this.iVel = -this.iYInc;
	}
	this.onMouseOverDown = function() {
		this.iVel = +this.iYInc;
	}
	this.onMovement = function() {
		var iYPosAct = this.jqDivOut.find('div.' + this.sDivWrapClass).scrollTop();
		this.iYPos += this.iVel;
		if(this.iYPos > this.iMaxScroll) this.iYPos = this.iMaxScroll;
		else if(this.iYPos < 0) this.iYPos = 0;
		this.jqDivOut.find('div.'+this.sDivWrapClass).scrollTo(iYPosAct + (this.iYPos - iYPosAct) * this.nEasingFactor, 0, { axis: 'y' } );
		var oThis = this;
		this.timeout = setTimeout(function() { oThis.onMovement(); }, this.iDelay);
	}
	this.onMouseOut = function() {
		this.iVel = 0;
		//clearTimeout(this.timeout);
	}
	this.onResize = function() {
		if(this.bFirstTime) {
			this.bFirstTime = false;
			this.jqDivOut.css('overflow', 'hidden')
			this.jqDivIn.wrap('<div class="'+this.sDivWrapClass+'">')
			jqDivWrap = this.jqDivOut.find('div.' + this.sDivWrapClass);
			if(this.jqDivOut.css('position') != 'absolute') this.jqDivOut.css('position', 'relative');
			this.jqDivOut.append('<img class="ScrollArrowUp" src="images/scroll-arrow-up.png" alt="up" /><img class="ScrollArrowDown" src="images/scroll-arrow-down.png" alt="down" />');
			this.jqDivIn.append('<div style="height: '+this.iMarginBottom+'px; background: none;"></div>');
			jqDivWrap.css('position', 'absolute');
			jqDivWrap.css('width', '100%');
			jqDivWrap.css('height', this.jqDivOut.height() + 'px');
			jqDivWrap.css('overflow', 'hidden');
		}
		this.jqDivOut.find('div.' + this.sDivWrapClass).scrollTo(0, { axis: 'y' } );
		this.iYPos = 0;
		this.iMaxScroll = this.jqDivIn.height() - this.jqDivOut.height();
		if(this.iMaxScroll > 0) {
			var oThis = this;
			this.jqDivOut.find('img.ScrollArrowUp, img.ScrollArrowDown').show();
			this.jqDivOut.find('img.ScrollArrowUp').mouseover( function() {
				oThis.onMouseOverUp();
			} );
			this.jqDivOut.find('img.ScrollArrowDown').mouseover( function() {
				oThis.onMouseOverDown();
			} );
			this.jqDivOut.find('img.ScrollArrowUp,img.ScrollArrowDown').mouseout( function() {
				oThis.onMouseOut();
			} );
			if(this.timeout) clearTimeout(this.timeout);
			this.onMovement();
		} else {
			this.jqDivOut.find('img.ScrollArrowUp, img.ScrollArrowDown').hide();
		}
	}
	this.iDelay = 50;
	this.iYInc = 10;
	this.nEasingFactor = 0.4;
	this.iMarginBottom = 6;
	this.sDivWrapClass = 'col_slides_description_wrap';
	this.bFirstTime = true;
	this.iVel = 0;
	this.iYPos = 0;
	this.jqDivOut = jqDivOut;
	this.jqDivIn = jqDivIn;
	this.onResize();
}

function TextPaging(sPagesJq, sPrevJq, sNextJq, sBarr) {
	this.next = function() {
		if(this.iSelected < this.jqPages.length - 1) {
			this.iSelected++;
			this.showCurrent(true);
		}
	}
	this.prev = function() {
		if(this.iSelected > 0) {
			this.iSelected--;
			this.showCurrent(true);
		}
	}
	this.showCurrent = function(bTrans) {
		var nTransTime = bTrans ? this.nTransTime : 0;
		var iSelected = this.iSelected;
		this.jqPages.each( function(index) {
			if(index == iSelected) $(this).delay(nTransTime + 100).fadeIn(nTransTime); // These extra 100ms avoid being two
			else $(this).fadeOut(nTransTime);										   // visible elements at the same time
		});
		// Hide both prev and next and barr
		if(this.jqBarr.css('display') == 'none') this.jqBarr.delay(nTransTime);
		else this.jqBarr.fadeOut(nTransTime);
		if(this.jqPrev.css('display') == 'none') this.jqPrev.delay(nTransTime);
		else this.jqPrev.fadeOut(nTransTime);
		if(this.jqNext.css('display') == 'none') this.jqNext.delay(nTransTime);
		else this.jqNext.fadeOut(nTransTime);
		//if(this.jqBarr.css('display') == 'none') $('#divDebug').append('<p>jqBar display was none</p>');
		//else $('#divDebug').append('<p>jqBar display was block</p>')
		/*this.jqPrev.hide();
		this.jqNext.hide();
		this.jqBarr.hide();*/
		// Show if needed
		if(this.iSelected > 0 && this.iSelected < this.jqPages.length - 1) {
			this.jqBarr.fadeIn(nTransTime);
		}
		if(this.iSelected > 0) {
			this.jqPrev.fadeIn(nTransTime);
		}	
		if(this.iSelected < this.jqPages.length -1) {
			this.jqNext.fadeIn(nTransTime)
		}
	}
	this.nTransTime = 300;
	this.iSelected = 0;
	this.jqBarr= $(sBarr);
	this.jqPages = $(sPagesJq);
	this.jqPrev = $(sPrevJq);
	this.jqNext = $(sNextJq);
	thisObject = this;
	this.jqPrev.click( function() { thisObject.prev(); } );
	this.jqNext.click( function() { thisObject.next(); } );
	this.showCurrent(false);
}
