(function($){
	
	
	
/*=========== Global Navigation ==========*/
//-> Athletes & Teams DropDown

function reInitScroll(){
	$('.sub-grid-aside ul').jScrollPane({
		'dragMinHeight':17,
		'dragMaxHeight':17,
		'scrollbarWidth':17
	});
}

/*function loadScrollData(){
	$('ul.sub-nav-grid .sub-grid-aside p.loading').css({'display': 'none'});
	$('ul.sub-nav-grid .sub-grid-aside ul').css({'display': 'block'}).jScrollPane({
		'dragMinHeight':17,
		'dragMaxHeight':17,
		'scrollbarWidth':17		
	});
}*/

/*$('#global-nav li#item-2').hover(
   function(e){ 
		$('ul.sub-nav-grid').stop().animate({'opacity':'1'}, 800, loadScrollData).show(); 
		console.log('fire and event on li', e.target());
	},
  function(e){
		$('ul.sub-nav-grid').stop().animate({'opacity':'0'}, 1000).hide(); 
});*/


//-> Fade non-hovered players
/*$('.sub-grid-items').find('a>img').each(function(){
	$this = $(this);
	
	$this.hover(
		function() {
			$('.sub-grid-items').find('a>img').not(this).each(function(){
				$(this).parent().stop().animate({'opacity': 0.2}, 500);
			})
		}, 
		function() {
			$('.sub-grid-items').find('a>img').each(function(){
				$(this).parent().stop().animate({'opacity': 1}, 500);
			})
	});
});*/

/*=========== MODULES [landing, sidebar ] ==========*/
//-> Landing | jScrollPane Options


 $('#module-feeds #bd ul').jScrollPane({
 	'scrollbarWidth': 18,
 	'dragMinHeight': 18,
 	'dragMaxHeight': 18,
 	'topCapHeight' : 10,
 	'bottomCapHeight': 10
 }); 

 /*$('#module-mediabrowser ul.assets').jScrollPane({
 	'scrollbarWidth': 18,
 	'dragMinHeight': 18,
 	'dragMaxHeight': 18,
 	'topCapHeight' : 20,
 	'bottomCapHeight': 10
 });*/


 $('.sidebarModule dd ul').jScrollPane({
 	'scrollbarWidth': 18,
 	'dragMinHeight': 18,
 	'dragMaxHeight': 18,
 	'topCapHeight' : 10,
 	'bottomCapHeight': 10
 });


$('#video .module-media-videos #category-list div.items ul').jScrollPane({
 	'scrollbarWidth': 30,
 	'dragMinHeight': 18,
 	'dragMaxHeight': 18,
 	'topCapHeight' : 10,
 	'bottomCapHeight': 10,
	'scrollbarMargin':0
 });

$('#photo .module-media-photos #category-list ul').jScrollPane({
 	'scrollbarWidth': 30,
 	'dragMinHeight': 18,
 	'dragMaxHeight': 18,
 	'topCapHeight' : 10,
 	'bottomCapHeight': 10,
	'scrollbarMargin':0
 });


$('#geosearch #results ul').jScrollPane({
  	'scrollbarWidth': 25,
  	'dragMinHeight': 18,
  	'dragMaxHeight': 18,
  	'topCapHeight' : 0,
  	'bottomCapHeight': 10,
 	'scrollbarMargin':0
  });


//-> Landing | Module::News Feeds
	var _bdContainer = $('#module-feeds #bd > div');
		_bdContainer.hide();

	$('#module-feeds ul.tabs li a').click(function(e){

			_bdContainer.hide().filter(this.hash).show();

			var _current = $(e.target).attr('href');
			$(this).parents('ul.tabs').css({'backgroundPosition': '0 0'});

			if( _current === '#teams-wrap'){
				$(this).parents('ul.tabs').css({'backgroundPosition': '0 -40px'});
			}		
			if( _current === '#athletes-wrap'){
				$(this).parents('ul.tabs').css({'backgroundPosition': '0 0'});
			}

			e.preventDefault();			
		}).filter(':first').click();

//-> Landing | Module::Media Browser
	var _mbContainer 	= $('#module-mediabrowser > div');
	var _mbTabs			= $('#module-mediabrowser-tabs ul.tabs li a');
	
	_mbContainer.find('ul>li').each(function(e){
		$(this).hover(function() {
			$(this).find('dd.media img').css({'border': '1px solid #2BEC2F'})
		}, function() {
		$(this).find('dd.media img').css({'border': 'none'})
		});
	})

	_mbContainer.hide();	
	_mbTabs.click(function(e){

		_mbContainer.hide().filter(this.hash).show();
		_mbTabs.removeClass('current');
		$(e.target).addClass('current');

		e.preventDefault()
	}).filter(':first').click();

//-> Landing | Module::Stats, Standings, Scores
	/*var _gsmContainer 	= $('#module-stats > div');
	var _gsmTabs 		= $('#module-stats ul li a');

	_gsmContainer.hide();
	_gsmTabs.click(function(e){
		alert('changing tabs1!!');
		_gsmContainer.hide().filter(this.hash).show();
		_gsmTabs.removeClass('current');
		$(e.target).addClass('current');

		e.preventDefault;
	}).filter(':first').click();*/

/*=========== Sidebar Modules ==========*/
//-> Sidebar | Module::Stats, Standings, Scores

	/*var _gsmContainer 	= $('.sidebarModule #module-stats > div');
	var _gsmTabs 		= $('.sidebarModule #module-stats ul.tabs li a');
	
	_gsmContainer.hide();
	_gsmTabs.click(function(e){
		alert('changing tabs2!!');
		_gsmContainer.hide().filter(this.hash).show();
		_gsmTabs.removeClass('current');
		$(e.target).addClass('current');

		e.preventDefault();
	}).filter(':first').click();*/

/*=========== Sidbar Media Tabs ==========*/	
//->  Photo sidebar tabs

var _photoTnContainer = $('.module-media-photos #category-list > div');
	_photoTnContainer.hide();

$('.module-media-photos ul.tabs li a').click(function(e){

		_photoTnContainer.hide().filter(this.hash).show();

		var _current = $(e.target).attr('href');
		
		$(this).parents('ul.tabs').css({'backgroundPosition': '0 0'});
		
		if( _current === '#athletes'){
			$(this).parents('ul.tabs').css({'backgroundPosition': '0 0'});
		}
		
		if( _current === '#teams'){
			$(this).parents('ul.tabs').css({'backgroundPosition': '0 -29px'});
		}		
		if( _current === '#events'){
			$(this).parents('ul.tabs').css({'backgroundPosition': '0 -58px'});
		}

		e.preventDefault();			
	}).filter(':first').click();


/*=========== Landing Accordion Marquee and Geo Search ==========*/	
// This is a global file but Kwick JS only esists on landing so 
// it wont load every time the if() checks for the selector. 
/*==============================================================*/
if($('#accordion').length){
	$('#accordion').kwicks({
		min : 100,
		spacing:1,
		sticky: true,
		defaultKwick:0,
		cb:function(){
			var $par = $(this).parent();	
			if($par.children().not('li.active')){
				$par.children('li').find('dd.max').css({'display': 'none'});
			}
		 
			$par.children(':not(li.active)').find('img').addClass('ctrOffset').fadeIn("fast");
					
			$(this).find('.chyron dd.min').fadeOut('fast',
				function(){
					$(this).parent().find('dd.max').fadeIn('fast');
				});	
			}
	
	}).find("li.isInit").mouseenter(function(e){
		//$(this).removeClass('isInit');
	});
}

$('area', 'map').hover(
	function(e){
		var that = $(e.target);
		$('span', '#regions').addClass(that.attr('title'));
		
		that.click(function(ev){					
			$("#regions").removeClass($('#regions').attr('class'));
			$("#regions").addClass('sticky-' + that.attr('title'));
		})
	}, 
	function(e){
		$('span', '#regions').removeClass();
	}	
);
/*=========== Fire! ==========*/
//-> Locale menu


	
})(jQuery);


/* Copyright (c) 2006 Brandon Aaron (brandon.aaron@gmail.com || http://brandonaaron.net)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 * Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers.
 * Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix.
 *
 * $LastChangedDate: 2007-12-20 09:02:08 -0600 (Thu, 20 Dec 2007) $
 * $Rev: 4265 $
 *
 * Version: 3.0
 * 
 * Requires: $ 1.2.2+
 */

(function($) {

$.event.special.mousewheel = {
	setup: function() {
		var handler = $.event.special.mousewheel.handler;
		
		// Fix pageX, pageY, clientX and clientY for mozilla
		if ( $.browser.mozilla )
			$(this).bind('mousemove.mousewheel', function(event) {
				$.data(this, 'mwcursorposdata', {
					pageX: event.pageX,
					pageY: event.pageY,
					clientX: event.clientX,
					clientY: event.clientY
				});
			});
	
		if ( this.addEventListener )
			this.addEventListener( ($.browser.mozilla ? 'DOMMouseScroll' : 'mousewheel'), handler, false);
		else
			this.onmousewheel = handler;
	},
	
	teardown: function() {
		var handler = $.event.special.mousewheel.handler;
		
		$(this).unbind('mousemove.mousewheel');
		
		if ( this.removeEventListener )
			this.removeEventListener( ($.browser.mozilla ? 'DOMMouseScroll' : 'mousewheel'), handler, false);
		else
			this.onmousewheel = function(){};
		
		$.removeData(this, 'mwcursorposdata');
	},
	
	handler: function(event) {
		var args = Array.prototype.slice.call( arguments, 1 );
		
		event = $.event.fix(event || window.event);
		// Get correct pageX, pageY, clientX and clientY for mozilla
		$.extend( event, $.data(this, 'mwcursorposdata') || {} );
		var delta = 0, returnValue = true;
		
		if ( event.wheelDelta ) delta = event.wheelDelta/120;
		if ( event.detail     ) delta = -event.detail/3;
//		if ( $.browser.opera  ) delta = -event.wheelDelta;
		
		event.data  = event.data || {};
		event.type  = "mousewheel";
		
		// Add delta to the front of the arguments
		args.unshift(delta);
		// Add event to the front of the arguments
		args.unshift(event);

		return $.event.handle.apply(this, args);
	}
};

$.fn.extend({
	mousewheel: function(fn) {
		return fn ? this.bind("mousewheel", fn) : this.trigger("mousewheel");
	},
	
	unmousewheel: function(fn) {
		return this.unbind("mousewheel", fn);
	}
});

})(jQuery);
