
/*** CENTER HAPPENING TAB COPY ***/

var happeningTabCopy = function(){
	var elToCenter = $$('div#scroller-happening ul li a span.title');

	for(var i=0; i<elToCenter.length; i++){
		var myHeight = elToCenter[i].getHeight(),
			parentHeight = elToCenter[i].up('li').getHeight();

		elToCenter[i].style.top = (parentHeight - myHeight) / 2 + 'px';
	}
};

/*** ANIMATING WHATS HOT SCROLLER ***/

var animateWhatsHot = function(){
	var elWhatsHotBtn = $$('div#scroller-controls-whats_hot li'),
		elWhatsHotItem = $$('div#scroller-whats_hot a');

	$$('div#scroller-whats_hot a span.event-details').invoke('hide');

	elWhatsHotBtn.invoke('observe', 'mouseenter', function(){
		mouseOver(this, 'width: 77px;', 0.1);
	}).invoke('observe', 'mouseleave', function(){
		mouseOut(this, 'width: 67px;', 0.1);
	});

	elWhatsHotItem.invoke('observe', 'mouseenter', function(e){
		var elHovered = e.element(),
			elAnchor = Event.findElement(e, 'a'),
			elDetails = elAnchor.down('span.event-details');

		mouseOver(this.down('img'), 'margin: 3px auto 4px; width: 180px;', 0.15, function(){
			$$('div#scroller-whats_hot a span.event-details').invoke('hide');
		}, function(){
			elDetails.appear({ duration: 0.25 });

			if(!ie6){
				if(elHovered.up('li').hasClassName('end-item-top')){
					$$('div#scroller-controls-whats_hot li.btn-previous a')[0].morph('opacity: 0.3', { duration: 0.15 });
				}
	
				if(elHovered.up('li').hasClassName('end-item-bottom')){
					$$('div#scroller-controls-whats_hot li.btn-next a')[0].morph('opacity: 0.3', { duration: 0.15 });
				}
			}
		});
	}).invoke('observe', 'mouseleave', function(e){
		var elHovered = e.element(),
			elAnchor = Event.findElement(e, 'a'),
			elDetails = elAnchor.down('span.event-details');

		mouseOut(this.down('img'), 'margin: 20px auto; width: 154px;', 0.15, function(){
			$$('div#scroller-whats_hot a span.event-details').invoke('hide');

			if(!ie6){
				if(elHovered.up('li').hasClassName('end-item-top')){
					$$('div#scroller-controls-whats_hot li.btn-previous a')[0].morph('opacity: 1', { duration: 0.15 });
				}
	
				if(elHovered.up('li').hasClassName('end-item-bottom')){
					$$('div#scroller-controls-whats_hot li.btn-next a')[0].morph('opacity: 1', { duration: 0.15 });
				}
			}

			Effect.Queues.get('mouseOverScope').invoke('cancel');
		}, function(){
			$$('div#scroller-whats_hot a span.event-details').invoke('hide');
		});
	});

	function mouseOver(el, styleEl, durationEl, callbackBefore, callbackFinish){
		new Effect.Morph(el, {
			style: styleEl,
			duration: durationEl,
			queue: {
				position: 'end',
				scope: 'mouseOverScope'
			},
			beforeStart: callbackBefore,
			afterFinish: callbackFinish
		});
	}

	function mouseOut(el, styleEl, durationEl, callbackBefore, callbackFinish){
		new Effect.Morph(el, {
			style: styleEl,
			duration: durationEl,
			queue: {
				position: 'end',
				scope: 'mouseOutScope'
			},
			beforeStart: callbackBefore,
			afterFinish: callbackFinish
		});
	}
};

document.observe('dom:loaded', function(){

	/*** HAPPENING NOW TAB INITIALIZATION ***/

	happeningTabContent = new MediaTabSwitcher('ul#nav-tab-happening > li > a', 'div#scroller-happening > div.tab-content div[id^=tab-].tab-happening', {
			initialTabIndex: 0,
			tabOnClassName: 'tab-happening-on',
			lazyLoadImages: true,
			callback: function(){
				happeningTabCopy();
			}
		},{
			elTabWrapper: $('tab-happening_now'),
			imageClass: 'media-img',
			audioVideoClass: 'media-av',
			flashTargetID: 'flash-target-media',
			flashPlaceholderClass: 'img-flash-placeholder',
			flashSettings: {
				path: '/_ui/swf/SOH-player-media.swf',
				width: '570',
				height: '320',
				version: '9.0.0',
				expressInstall: 'false'
			},
			flashVars: {
				loopBool: 'false',
				autoPlayBool: 'false',
				hideControlsBool: 'true'
			},
			flashParams: {
				allowscriptaccess: 'always',
				allowFullscreen: 'true',
				menu: 'false',
				scale: 'noscale',
				wmode:'transparent'
			},
			flashAttributes: {}
		}
	);


	/*** WHATS HOT SCROLLER INITIALIZATION ***/

	scrollerWhatsHot = new ScrollerPagingControl($('scroller-whats_hot'), {
			durationPerSlide: 0.25,
			restAlignment: 'left'
		},
		$('scroller-controls-whats_hot'), {
			itemsPerGroup: 5, 
			initialGroupIndex: 0,
			nextSlideTriggerID: 'btn-scroller-whats_hot_next',
			previousSlideTriggerID: 'btn-scroller-whats_hot_previous'
		}
	);


	/*** HAPPENING NOW SCROLLER INITIALIZATION ***/

	scrollerHappening = new ScrollerPagingControl($('scroller-happening'), {
			durationPerSlide: 0.15,
			restAlignment: 'top',
			orientation:'vertical'				
		},
		$('scroller-controls-happening'), {
			itemsPerGroup: 5,
			initialGroupIndex: 0,
			nextSlideTriggerID: 'btn-scroller-happening_next',
			previousSlideTriggerID: 'btn-scroller-happening_previous'
		}
	);


	/*** NEWS TICKER INITIALIZATION ***/

	homeNewsTicker = new newsTicker({
		elNewsList: $('news-ticker').down('ul'),
		changeDelay: 5000
	});


	/*** CENTER HAPPENING TAB COPY ***/

	happeningTabCopy();


	/*** WHATS ON SLIDER ***/

	whatsOnSelect = new selectSlider({
		elInputSelect: $('ctl00_ContentPlaceHolder1_uxWhatsOnSlider_uxBrowseItems'),
		elInputSubmit: $('ctl00_ContentPlaceHolder1_uxWhatsOnSlider_uxSubmit'),
		elSlideResults: $$('div#tab-whats_on div.column-search-results div.results')
	});


	/*** ANIMATING WHATS HOT SCROLLER ***/

	animateWhatsHot();
});
