

$(function() { 
	
	$("#global_header .inner").DropDownMenu({itemSelector:'li'});

	$("#headermenu").DropDownMenu({itemSelector:'li'});

	$('#en_video_tab').removeClass('en');
	$('#en_video_tab .scrollerModule').nbaScroller();
	$('#en_video_tab > ul').tabs('#en_video_tab > div');
	$('<li class="lpbb"><a href="https://ilp.nba.com/nbalp/secure/registerform?utm_source=nbade&utm_medium=topnav&utm_content=text&utm_campaign=NBADE">LIVE GAMES</a></li>').appendTo($('#en_video_tab > ul'));
	$('#en_video_tab').addClass('en');

	$('#de_video_tab').removeClass('de');
	$('#de_video_tab .scrollerModule').nbaScroller();
	$('#de_video_tab > ul').tabs('#de_video_tab > div');
	$('<li class="lpbb"><a href="https://ilp.nba.com/nbalp/secure/registerform?utm_source=nbade&utm_medium=topnav&utm_content=text&utm_campaign=NBADE">LIVE SPIELE</a></li>').appendTo($('#de_video_tab > ul'));
	$('#de_video_tab').addClass('de');

	$('#two_tab > ul').tabs('#two_tab > div');

	$('#hp-scoreboard').nbaScroller();

	$('#stats .inner_module').load('http://www.nba.de/stats/widgets/league/statsLeader.xhtml .widget_main');

  $("#top_story .scrollerModule").nbaScroller();
  $("#top_story").nbaTopStory();

  $("#hp-takeover").nbaTakeover();


	//end of season scoreboard
	$("#hp-scoreboard .game").live("mouseenter", function(event) {
		$game = $(this);
		$(".links", $game).slideDown('fast', function() { $game.addClass("show_links"); });				
	}).live("mouseleave", function(event) {
		$game = $(this);
		$(".links", $game).slideUp('fast', function() { $game.removeClass("show_links"); });
	});

})


	//translation of elements that can translate
	$(function(){

		var country_codes = [];
		var country_names = {};
		
		$(".translator:eq(0) ul li").each(function() {
			var code = $(this).attr('class').toLowerCase();
				
			country_codes[country_codes.length] = code;
			country_names[code] = $(this).children("a").html();
		});

		var country_codes_string = country_codes.length > 0 ? country_codes.join(" ") : null;

		BrowserTimeZone.init();

		//write a cookie with the timezone and a value for whether the area observes daylight savings time
		$.setCookie("tz", "dst=" + BrowserTimeZone.dst +",tz=GMT" + BrowserTimeZone.offset, { duration : 0, path : '/' });


		function initScoreboard() {
			var locale = $.readCookie("userlocale") || "de";
        		var tz = escape("tz=GMT" + BrowserTimeZone.offset + "&dst=" + BrowserTimeZone.dst);


	         	$("#hp-scoreboard").hpscoreboard({tz : tz, locale : locale, showPrevious:false});
		}

		function setLanguage(language_code) {
			cookie_language_code = language_code;

			$("#container").removeClass(function() { return country_codes_string; });
			$("#container").addClass(language_code);

			$(".translator a.selection").html(country_names[language_code]);

			$.setCookie("userlocale", language_code, { duration : 365, path : '/' });
			
			// comment out scoreboard for end of season 6/13/2011
			// initScoreboard();
		}

		
		var cookie_language_code = $.readCookie("userlocale");
		if (cookie_language_code) {
			setLanguage(cookie_language_code);
		} else {
			cookie_language_code = "de";
			// comment out scoreboard for end of season 6/13/2011
			// initScoreboard();
		}
		
		$(".translator ul li").click(function() {
			setLanguage($(this).attr('class').toLowerCase());
		});

		$("a").each(function(i) {
			var xhtmlPos = this.href.indexOf(".xhtml");
			var firstQuery = this.href.indexOf("?");

			if (xhtmlPos > -1 && (xhtmlPos < firstQuery || firstQuery < 0) && !this.hash) {
			
				var locale = cookie_language_code;
				if ($(this).parents(".en:not(#container)").length > 0) { locale = "en"; }
				if ($(this).parents(".de:not(#container)").length > 0) { locale = "de"; }
				
				this.href = [this.href, (firstQuery > -1 ? "&" : "?"), "tz=GMT", BrowserTimeZone.offset, "&", "dst=", BrowserTimeZone.dst, "&", "locale=", locale].join("");
			}

		});

	});


// Kaltura

window.kplayers = [];

function jsCallbackReady (pid) { 
	var player = document.getElementById(pid);
	window.kplayers.push(player);
	player.addJsListener('mediaReady', 'kalPlayerPlayed');
}

function kalPlayerPlayed(pid) {
	nbaOmSuiteInfo.currentLeague = "Germany"
	w.nbaOmCurrentVideo = pid.entryId;
	nbaOmEvent.videoId = pid.entryId;
	nbaOmEvent.videoSource = 'I'; 
	nbaOmEvent.videoContext = 'E'; 
	nbaOmEvent.videoTitle = pid.entryId;
	nbaOmEvent.videoPlayerType = 'KAL'; 
	nbaOmEvent.videoCategory = nbaOmSuiteInfo.currentLeague + ':Kaltura';
	nbaOmEvent.onStreamStart();
}

