nfl.global.InitializeSearch = (function () {
	var label, input, notBlank;
	
	notBlank = /\S/;
	
	function onInputFocus ( _evt ) {
		label.hide();
	}
	function onInputBlur ( _evt ) {
		if ( notBlank.test( input.value ) ) { return; }
		input.value = '';
		label.show();
	}
	function testInputBlankness() { 
		if ( $F(input).blank() ) {
			onInputBlur();
		}
		else {
			onInputFocus();
		}
	}
	return function( _config ) {
		input = $(_config.input);
		label = $(_config.label);
		if ( ! ( input && label )  ) { return; }

		input.observe('focus', onInputFocus ); 
		input.observe('blur', onInputBlur );
		testInputBlankness();
		// IE7 populates this value between DOM and window load 
		Event.observe(window, 'load', testInputBlankness);
	};
})();
nfl.global.prestitial			 = (function(){
	var __BODYELE			= 'com-nfl';
	var __CONTENTWRAPPER	= 'com-nfl-doc';
	var __PREELE			= 'com-nfl-prestitial'
	var __PREHDELE			= 'com-nfl-prestitial-header';
	var __TLIMIT			= 30000;
	var __CTIME				= 0;
	var __POLLINGRATE		= 1000;
	
	
	var __adIdLookup		= {
			'ebReportingFlash':'eyeDiv',
			'eyeDiv':'eyeDiv',
			'random':function(){ if(document.loaded){
				/* get last divs id */
				var __bodychildren	= $('com-nfl').select('div:last-child');
				if(__bodychildren.length > 0){
					//console.log('bchildren: '+__bodychildren.length,__bodychildren[(__bodychildren.length - 2)])
					var __dchild = __bodychildren[(__bodychildren.length - 2)];
					if(__dchild.tagName.toLowerCase() == 'div'){
						if((__dchild.id).indexOf('DIV_') > -1){
							return __dchild.id;
						}
					}
				}
				/* assume it failed other checks */
				return 'thisisnotthedroidyouwant'
			} return 'peanutbutternjellies' }
	}
		
	return {
		initialize: function(){
			if(document.loaded){
				try{$(__CONTENTWRAPPER).setStyle({'height':(document.viewport.getHeight()+'px')});}catch(e){}
				try{
					nfl.global.prestitial.poll();
					nfl.global.prestitial.background.poll();
				}catch(e){ console.warn('presitial error: ',e); }
				return
			}
			document.observe('prestitial:ready',function(){
				try{$(__CONTENTWRAPPER).setStyle({'height':(document.viewport.getHeight()+'px')});}catch(e){}
				try{
					nfl.global.prestitial.poll();
					nfl.global.prestitial.background.poll();
				}catch(e){ console.warn('presitial error: ',e); }
			});	
		},
		poll: function(){
			/* check to see if ad is still present */
			//console.log('nfl.global.prestitial.poll: n_prestitialAdId = '+ n_prestitialAdId +'\n\r $(__BODYELE).hasClassName(\'prestitial-active\') = '+ $(__BODYELE).hasClassName('prestitial-active') +'\n\r$(__BODYELE).hasClassName(\'prestitial\') = '+ $(__BODYELE).hasClassName('prestitial'));
			if(typeof n_prestitialAdId === 'undefined'){ return false; }
			if(!($(__BODYELE).hasClassName('prestitial-active')) && !($(__BODYELE).hasClassName('prestitial'))){ return false /* there's no prestitial, do alittle dance */ }
			if(this.isDummy()){return false}
			if($(this.getAdId())){
				/* code for checking whether or not the ad has finished displaying goes here */
				if(this.getAdId() == 'eyeDiv'){
					var eyefs		= this.getEyeFlash();
					if(eyefs){
						if(eyefs.style.top == '0px'){
							eyefs.style.top = ($(__PREHDELE).getHeight()+'px');
						}
						var stylesum	= parseInt(eyefs.style.width)+parseInt(eyefs.style.height);
						if(stylesum <= 0){
							this.remove()
						}
					}	
				}else{
					var __adiv	= $(this.getAdId());
					if(__adiv.getStyle('visibility') == 'hidden'){
						this.remove();
					}
				}
			}
			/* rinse and repeat */
			setTimeout("nfl.global.prestitial.poll()",__POLLINGRATE);
		},
		remove: function(){
			$(__BODYELE).removeClassName('prestitial-active');
			$(__BODYELE).removeClassName('prestitial');
			
			try{ document.getElementsByTagName('html')[0].style.overflow = 'scroll'; }catch(e){}
			console.log('removed prestitial-active/prestitial class.');
		},
		close: function(){
			try{
				this.remove();
				try{ $(__CONTENTWRAPPER).setStyle({'height':'auto'}); }catch(e){};
				
				if($(this.getAdId())){
					$(this.getAdId()).remove();
					console.log('removed '+this.getAdId()+' element.');
				}
			}catch(e){}
		},
		getAdIdLookup: function(){
			return __adIdLookup
		},
		getAdId: function(){
			var __adId	= __adIdLookup[n_prestitialAdId];
			if(n_prestitialAdId == 'random'){
				__adId = __adIdLookup[n_prestitialAdId]();
			}
			//console.log('getAdId: '+__adId,__adIdLookup);
			return __adId;
		},
		isDummy: function(){
			if($(n_prestitialAdId) || typeof __adIdLookup[n_prestitialAdId] !== 'undefined'){
				//console.log('isDummy: ad id');
				if($(this.getAdId())){
					//console.log('isDummy: ad container'+$(__adIdLookup[n_prestitialAdId]).innerHTML);
					if($(this.getAdId()).innerHTML == ''){ alert('nfl.global.prestitial.isDummy: 4'); return true}
					if($(this.getAdId()).tagName.toLowerCase() == 'img'){return true}
					//console.log('isDummy: ad container content:'+$(__adIdLookup[n_prestitialAdId]).innerHTML);
					return false
				}
			}
			return false
		},
		getEyeFlash: function(){
			if($(this.getAdId())){
				var __adDiv		= $(this.getAdId());
				var __adObjects	= __adDiv.select('object');
				return __adObjects[1]
			}
			return false
		},
		background: {
			poll: function(){
				__CTIME				= __CTIME+__POLLINGRATE;
				//console.log('background.poll: document loaded = '+document.loaded+' nfl.global.prestitial.getAdId() = '+ nfl.global.prestitial.getAdId());
				if(typeof n_prestitialAdId === 'undefined'){ return false; }
				if($(nfl.global.prestitial.getAdId()) || __CTIME > __TLIMIT){
					if(__CTIME > __TLIMIT){ console.log('nfl.global.prestitial.background.poll: removing due to time limit expiration'); }
					if(document.getElementsByTagName('html')[0].style.overflow != 'hidden'){
						document.getElementsByTagName('html')[0].style.overflow = 'hidden';
						return
					}
					this.remove();
				}else{
					setTimeout("nfl.global.prestitial.background.poll()",__POLLINGRATE);
				}
			}, 
			remove: function(){
				$(__BODYELE).removeClassName('prestitial');
				try{ document.getElementsByTagName('html')[0].style.overflow = 'hidden'; }catch(e){} /* faceplant, I'm actually mimicking their junk so that at least its consistent */
				if($(nfl.global.prestitial.getAdId()) && !nfl.global.prestitial.isDummy()){ $(__BODYELE).addClassName('prestitial-active'); }
				if(!nfl.global.prestitial.isDummy()){
					try{ 
						$(__CONTENTWRAPPER).setStyle({'height':'auto'}); 
					}catch(e){}
				}else{
					/* remove overflow = hidden that some bad ad programmer monkeys put in *faceplant* */
					try{ document.getElementsByTagName('html')[0].style.overflow = 'scroll'; }catch(e){}
				}
				console.log('removed prestitial class.');
			}
		}
	}
})();

nfl.global.Navigation = (function () {
	var ID = {
			CONTAINER: 'alt-nv-main',
			SCORESTRIP: 'hd-scorestrip'
		},
		ATTR = { ORIGINAL_HEIGHT: 'data-oheight' },
		CSS = {
			CONTENT: 'div.channel-content',
			GROUP: 'li.alt-nv-group',
			SHADOW: 'shadow',
			PREPARED: 'prepared'
		},
		CLOSE_HEIGHT = { height: '0px' },
		DURATION = 0.5,
	    sexy = false,
	    ss,
	    timeout,
	    mousedOver,
	    TO_DURATION = 750;
	
	function prepareChannel ( _el ) {
		var group, iframe, newStyle, oHeight, div;

		newStyle  = { display: 'none' };
		
		group    = _el.up( 'li' );
		group.channels = _el;

		oHeight = _el.offsetHeight - parseFloat( _el.getStyle('paddingBottom') ) - parseFloat( _el.getStyle('paddingTop') );
		_el.setAttribute( ATTR.ORIGINAL_HEIGHT, oHeight + 'px' );
		_el.addClassName( CSS.PREPARED );
		
		// Fixes select see-through in IE6
		if ( Prototype.Browser.IE ) {
			iframe    = document.createElement( 'iframe' );
			iframe.id = "DivShim";
			iframe.setAttribute("scrolling","no");
			iframe.setAttribute("frameborder","0");
			_el.insertBefore( iframe, _el.firstChild );
		}
		
		div = document.createElement('div');
		div.className = CSS.SHADOW;
		_el.appendChild( div );
		
		if ( sexy ) {
			newStyle.backgroundPosition = '0 ' + oHeight + 'px';
			newStyle.height = '0px';
		}
		_el.setStyle( newStyle );
	}
	
	function beforeOpenStart(_effect) {
		_effect.element.show().setStyle({ zIndex: 1000 });
	}
	function afterOpenFinish(_effect) {
		_effect.element.setStyle({ zIndex: 1000 }).transitionEffect = null;
	}
	function afterCloseFinish(_effect) {
		_effect.element.hide().transitionEffect = null;
	}
	
	function toggleChannels( _channels, _open) {
		// if we're sexy, do a slide
		if ( sexy ) {
			// cancel any current effects on this element
			if ( _channels.transitionEffect ) {
				_channels.transitionEffect.cancel();
			}
			// create an effect with different options based on whether or not we're opening
			_channels.transitionEffect = new Effect.Morph( _channels, _open ?
				{ style: { height: _channels.getAttribute( ATTR.ORIGINAL_HEIGHT ) }, duration: DURATION,
				  beforeStart: beforeOpenStart, afterFinish: afterOpenFinish } :
				{ style: CLOSE_HEIGHT, duration: DURATION, afterFinish: afterCloseFinish }
			);
			return;
		}
		// otherwise just show or hide based on the direction
		_channels[ _open ? 'show' : 'hide' ]();
	}
	
	function onMouseOver ( _e ) {
		var group, from, channels;
		_e.stop();

		// figure out your context
		group    = _e.findElement( CSS.GROUP );
		if ( ! group ) { return; }
		channels = group.channels;
		from     = $( _e.relatedTarget || _e.fromElement );
		
		// if you're not over the correct element, exit
		if ( (! channels) || (! from) || ( from && from.descendantOf && from.descendantOf( group ) ) ) { return; }
		
		// if we come from the scorestrip, hold off on sliding out
		if ( ss && ( ss === from || ( from.descendantOf && from.descendantOf(ss) )) ) {
			mousedOver = true;
			// if we're locked, cancel the old timeout
			if ( channels.timeout ) { clearTimeout(channels.timeout); }
			// set a timeout to slide the current channel out after a decent wait
			channels.timeout = setTimeout(function() {
				// clear the lock
				channels.timeout = null;
				// if we're still moused over, exit
				if ( ! mousedOver ) { return; }
				// toggle the channels open
				toggleChannels( channels, true );
			}, TO_DURATION);
			return;
		}
		// otherwise toggle the channels open
		toggleChannels( channels, true );
	}
	function onMouseOut ( _e ) {
		var group, to, channels;

		// stop the event
		_e.stop();

		// figure out your context
		group    = _e.findElement( CSS.GROUP );
		if ( ! group ) { return; }
		channels = group.channels;
		to       = $( _e.relatedTarget || _e.toElement );

		// if you're not over the correct element, exit
		if ( (! channels) || ( to  && ( to === group || ( to.descendantOf && to.descendantOf( group ) ) ) ) ) { return }

		// set a flag alerting that we've moused out, in case someone is waiting
		mousedOver = false;

		// if we're locked, don't slide out
		if (channels.timeout) { return;}
		
		// toggle the channels open
		toggleChannels( channels, false );
	}
	
	function removeReferences(group) {
		if ( ! group.channels ) { return; }
		delete group.channels.transitionEffect;
		delete group.channels.timeout;
		delete group.channels;
	}
	
	function cleanUp(e) {
		$(ID.CONTAINER).
			stopObserving('mouseover', onMouseOver).
			stopObserving('mouseout', onMouseOut);
		try {
			$$(CSS.GROUP).each(removeReferences);
		} catch (e) {}
		ss = null;
	}

	return {
		initialize: function() {
			var el = $(ID.CONTAINER);
			if ( ! el ) { return; }

			// If we have scriptaculous, go the extra mile
			if ( typeof Effect !== "undefined" ) { sexy = true; }
			
			el.
				observe('mouseover', onMouseOver ).
				observe('mouseout', onMouseOut ).
				select( CSS.CONTENT ).
					each( prepareChannel );
			Event.observe(window, 'unload', cleanUp);
			document.observe('dom:loaded', function() { ss = $(ID.SCORESTRIP); });
		},
		setAnimation: function( _value ) {
			if ( sexy === _value ) { return; }
			sexy = _value;
			$$('#' + ID.CONTAINER + ' ' + CSS.CONTENT).each(
				_value ? function( _el ) {
					_el.setStyle({ backgroundPosition: '0 ' + _el.getAttribute( ATTR.ORIGINAL_HEIGHT ) + 'px', height: '0px', paddingBottom: null });
					_el.addClassName( CSS.PREPARED );
				} : function( _el ) {
					_el.setStyle({ backgroundPosition: 'left top', height: 'auto', paddingBottom: '0px' });
					_el.removeClassName( CSS.PREPARED );
				});
		}
	};
})();
