window.onloadOriginal = window.onload;

window.onload = function() {
	
	window.onloadOriginal();

	function carousel(dir, buttons, currentCarousel, divUnits, xMoveBy) {
		var carouselCountainer = currentCarousel.getElementsByClassName('carouselNhlContainer', 'div')[0];
		
		// if there's no stageScroll on the page or
		// there's already an animation in the queue then exit
		if(!carouselCountainer || Effect.Queue.effects.length > 0)
			return;
	
		// setup variables
		var curX = Position.positionedOffset(carouselCountainer)[0];
	
		var xMove = carouselCountainer.parentNode.getWidth();
		var divUnits = typeof(divUnits) == "undefined" ? 5 : divUnits;
		
		//alert(xMove + ":" + divUnits);
		
		//if we're one of the smaller scrolls we need to tweak the xMove a little bit.
		if(xMove == 508)
		{
			xMove += 38;
			divUnits = 3;
		}
		else if(xMove == 700)
		{
			xMove += 28;
			divUnits = 4;
		}
		/* nhl */
		else if(xMove == 720)
		{
			xMove += 10;
			divUnits = 5;
		}

		var numScrolls = Math.ceil(carouselCountainer.immediateDescendants().length / divUnits) - 1;
		var xMoveBy = typeof(xMoveBy) == "undefined" ? (xMove * dir) : xMoveBy;
		var xMoveTo = curX + (xMoveBy);
		var xMax = -Math.abs((numScrolls) * xMove);
		var curScroll = Math.abs(xMoveTo / xMove);
		
		// exit if conditions aren't perfect
		if(!(xMoveTo <= 0 && xMoveTo >= xMax))
			return;
			
		if(buttons)
		{
			// setup left / right buttons
			buttons[0].src = xMoveTo >= 0 ? "../img/scrollBackOff.gif" : "../img/scrollBackOn.gif";
			buttons[1].src = xMoveTo <= xMax ? "../img/scrollForwardOff.gif" : "../img/scrollForwardOn.gif";
		}
	
		// do the move
		if(dir != 0)
		//{
		//	if(typeof(finalPos)=="undefined")
				new Effect.MoveBy(carouselCountainer, 0, xMoveBy);
		//	else
		//		new Effect.Move(carouselCountainer, { x: finalPos, mode: 'absolute'});
		//}
		
		// setup status indicators
		var indicatorCount = -1;
		var indicators = currentCarousel.getElementsByClassName('indicatorsWrapper', 'div')[0];
	
		if(indicators)
		{
			// delete the old indicators
			while (indicators.firstChild)
				indicators.removeChild(indicators.firstChild);
		
			// add them back in
			while(indicatorCount++ < numScrolls) {
				indicators.appendChild(Builder.node('div', {className:((indicatorCount == curScroll) ? 'on' : 'off')}));
			}
		}
	}
	
	try{

	$('content').select('.carouselNhlContainer .items', '.carouselNhlContainer .itemsLast').each(function(carouselItem) {
		Event.observe(carouselItem, 'mouseover', function() {
			carouselItem.select('.thumbnailspacer').each(function(play) {
				play.setStyle({border:'solid 3px #f90'});
			});
			carouselItem.select('.thumbnailplay').each(function(play) {
				play.setStyle({display:'block'});
			});
			carouselItem.select('.itemTitle a').each(function(image) {
				image.setStyle({color:'#f90'});
			});
		});
		Event.observe(carouselItem, 'mouseout', function() {
			carouselItem.select('.thumbnailspacer').each(function(play) {
				play.setStyle({border:'solid 3px #000'});
			});
			carouselItem.select('.thumbnailplay').each(function(play) {
				play.setStyle({display:'none'});
			});
			carouselItem.select('.itemTitle a').each(function(image) {
				image.setStyle({color:'#fff'});
			});
		});
	});

	$('content').select('.evThumbsContainer .items div.thumbnail').each(function(thumbItem) {
		Event.observe(thumbItem, 'mouseover', function() {
			thumbItem.select('.thumbnailplay').each(function(play) {
				play.setStyle({display:'block'});
			});
			thumbItem.ancestors()[0].setStyle({background:'url(../img/expressvu/ev_thumbnailbg_play.gif) left top no-repeat'});
		});
		Event.observe(thumbItem, 'mouseout', function() {
			thumbItem.select('.thumbnailplay').each(function(play) {
				play.setStyle({display:'none'});
			});
			thumbItem.ancestors()[0].setStyle({background:'url(../img/expressvu/ev_thumbnailbg.gif) left top no-repeat'});
		});
	});

	// Carousel Scrolling
	$$('.carouselNhlBody').each(function(currentCarousel) {
		currentCarousel.getElementsByClassName('slideButtons').each(function(buttons) {
			buttons = buttons.descendants();

			Event.observe(buttons[1], 'click', function() {
				carousel(-1, buttons, currentCarousel);
			});
			Event.observe(buttons[0], 'click', function() {		
				carousel(1, buttons, currentCarousel);
			});

			carousel(0, buttons, currentCarousel);
		});
	});
	}catch(e){}

}

function decorateEvThumbs() {
	$('content').select('.evThumbsContainer .items div.thumbnail').each(function(thumbItem) {
		Event.observe(thumbItem, 'mouseover', function() {
			thumbItem.select('.thumbnailplay').each(function(play) {
				play.setStyle({display:'block'});
			});
			thumbItem.ancestors()[0].setStyle({background:'url(../img/expressvu/ev_thumbnailbg_play.gif) left top no-repeat'});
		});
		Event.observe(thumbItem, 'mouseout', function() {
			thumbItem.select('.thumbnailplay').each(function(play) {
				play.setStyle({display:'none'});
			});
			thumbItem.ancestors()[0].setStyle({background:'url(../img/expressvu/ev_thumbnailbg.gif) left top no-repeat'});
		});
	});
}




//window.onloadOriginal = window.onload;

//window.onload = function() {
//	
//	window.onloadOriginal();

//	function carousel(dir, buttons, currentCarousel, divUnits, xMoveBy) {
//		var carouselCountainer = currentCarousel.select('carouselNhlContainer', 'div')[0];
//		
//		// if there's no stageScroll on the page or
//		// there's already an animation in the queue then exit
//		if(!carouselCountainer || Effect.Queue.effects.length > 0)
//			return;
//	
//		// setup variables
//		var curX = Position.positionedOffset(carouselCountainer)[0];
//	
//		var xMove = carouselCountainer.parentNode.getWidth();
//		var divUnits = typeof(divUnits) == "undefined" ? 5 : divUnits;
//		
//		//alert(xMove + ":" + divUnits);
//		
//		//if we're one of the smaller scrolls we need to tweak the xMove a little bit.
//		if(xMove == 508)
//		{
//			xMove += 38;
//			divUnits = 3;
//		}
//		else if(xMove == 700)
//		{
//			xMove += 28;
//			divUnits = 4;
//		}
//		/* nhl */
//		else if(xMove == 720)
//		{
//			xMove += 10;
//			divUnits = 5;
//		}

//		var numScrolls = Math.ceil(carouselCountainer.immediateDescendants().length / divUnits) - 1;
//		var xMoveBy = typeof(xMoveBy) == "undefined" ? (xMove * dir) : xMoveBy;
//		var xMoveTo = curX + (xMoveBy);
//		var xMax = -Math.abs((numScrolls) * xMove);
//		var curScroll = Math.abs(xMoveTo / xMove);
//		
//		// exit if conditions aren't perfect
//		if(!(xMoveTo <= 0 && xMoveTo >= xMax))
//			return;
//			
//		if(buttons)
//		{
//			// setup left / right buttons
//			buttons[0].src = xMoveTo >= 0 ? "../img/scrollBackOff.gif" : "../img/scrollBackOn.gif";
//			buttons[1].src = xMoveTo <= xMax ? "../img/scrollForwardOff.gif" : "../img/scrollForwardOn.gif";
//		}
//	
//		// do the move
//		if(dir != 0)
//		//{
//		//	if(typeof(finalPos)=="undefined")
//				new Effect.MoveBy(carouselCountainer, 0, xMoveBy);
//		//	else
//		//		new Effect.Move(carouselCountainer, { x: finalPos, mode: 'absolute'});
//		//}
//		
//		// setup status indicators
//		var indicatorCount = -1;
//		var indicators = currentCarousel.select('indicatorsWrapper', 'div')[0];
//	
//		if(indicators)
//		{
//			// delete the old indicators
//			while (indicators.firstChild)
//				indicators.removeChild(indicators.firstChild);
//		
//			// add them back in
//			while(indicatorCount++ < numScrolls) {
//				indicators.appendChild(Builder.node('div', {className:((indicatorCount == curScroll) ? 'on' : 'off')}));
//			}
//		}
//	}

//	$('content').select('.carouselNhlContainer .items', '.carouselNhlContainer .itemsLast').each(function(carouselItem) {
//		Event.observe(carouselItem, 'mouseover', function() {
//			carouselItem.select('.thumbnailspacer').each(function(play) {
//				play.setStyle({border:'solid 3px #f90'});
//			});
//			carouselItem.select('.thumbnailplay').each(function(play) {
//				play.setStyle({display:'block'});
//			});
//			carouselItem.select('.itemTitle a').each(function(image) {
//				image.setStyle({color:'#f90'});
//			});
//		});
//		Event.observe(carouselItem, 'mouseout', function() {
//			carouselItem.select('.thumbnailspacer').each(function(play) {
//				play.setStyle({border:'solid 3px #000'});
//			});
//			carouselItem.select('.thumbnailplay').each(function(play) {
//				play.setStyle({display:'none'});
//			});
//			carouselItem.select('.itemTitle a').each(function(image) {
//				image.setStyle({color:'#fff'});
//			});
//		});
//	});
//	
//	decorateEvThumbs();

//	// Carousel Scrolling
//	$$('.carouselNhlBody').each(function(currentCarousel) {
//		//currentCarousel.select('.slideButtons').each(function(buttons) {		
//		currentCarousel.getElementsByClassName('slideButtons').each(function(buttons) {
//			buttons = buttons.descendants();

//			if(buttons.length > 1) {
//				Event.observe(buttons[1], 'click', function() {
//					carousel(-1, buttons, currentCarousel);
//				});
//				Event.observe(buttons[0], 'click', function() {
//					carousel(1, buttons, currentCarousel);
//				});
//				carousel(0, buttons, currentCarousel);
//			}
//		});
//	});

//}

//function decorateEvThumbs() {
//	$('content').select('.evThumbsContainer .items div.thumbnail').each(function(thumbItem) {
//		Event.observe(thumbItem, 'mouseover', function() {
//			thumbItem.select('.thumbnailplay').each(function(play) {
//				play.setStyle({display:'block'});
//			});
//			thumbItem.ancestors()[0].setStyle({background:'url(../img/expressvu/ev_thumbnailbg_play.gif) left top no-repeat'});
//		});
//		Event.observe(thumbItem, 'mouseout', function() {
//			thumbItem.select('.thumbnailplay').each(function(play) {
//				play.setStyle({display:'none'});
//			});
//			thumbItem.ancestors()[0].setStyle({background:'url(../img/expressvu/ev_thumbnailbg.gif) left top no-repeat'});
//		});
//	});
//}