function formatText(index, panel) {
	return index + "";
}

var timer;
function fetchRightNow() {
	clearTimeout(timer);
	$.ajax({
		url: "/onair.php",
		cache: false,
		success: function(html){
			$(".on-air-schedule").html(html);
		}
	});
	//timer = setTimeout("fetchRightNow()", 30000);
}
//fetchRightNow();

$(document).ready(function() {
	$("ol#most-popular-media a").click(function() {
		LoadPlayer($(this).attr("href"));
		return false;
	});
	$("#breadcrumb ul li:last a").replaceWith("<span title='"+$("#breadcrumb ul li:last a").attr("title")+"'>"+$("#breadcrumb ul li:last a").text()+"</span>");
	$("ol.artist-tracks li.playlist-info-listen span a").click(function() {
		if($(this).parent().parent().parent().next().next(".audio-player:visible").length == 1) {
			$(this).parent().parent().parent().next().next(".audio-player").hide();
			$(this).parent().parent().parent().next().next(".audio-player").html("");
		} else {
			$(".audio-player").hide();
			$(".audio-player").html("");
			$(this).parent().parent().parent().next().next(".audio-player").show();
			$(this).parent().parent().parent().next().next(".audio-player").html("<object type='application/x-shockwave-flash' data='/swf/audio-player.swf' width='407' height='20'><param name='movie' value='/swf/audio-player.swf' /><param name='bgcolor' value='#40a500' /><param name='FlashVars' value='mp3="+$(this).attr("href")+"&amp;width=407&amp;volume=100&amp;showvolume=1&amp;showloading=never&amp;volumeheight=8&amp;loadingcolor=40a500&amp;bgcolor=40a500&amp;bgcolor1=40a500&amp;bgcolor2=40a500&amp;slidercolor1=ffffff&amp;slidercolor2=ffffff&amp;sliderovercolor=ffffff&amp;buttonovercolor=ffffff&amp;autoplay=1' /></object>");
			if($(this).attr("href").indexOf("nrj.se") != -1) {
				$(this).parent().parent().parent().next().next(".audio-player").css({'background-image' : 'none'});
			}
		}
		return false;
	});
	
	$("ol.playlist li.playlist-info-listen span a").click(function() {
		if($(this).parent().parent().parent().next().next(".audio-player:visible").length == 1) {
			$(this).parent().parent().parent().next().next(".audio-player").hide();
			$(this).parent().parent().parent().next().next(".audio-player").html("");
		} else {
			$(".audio-player").hide();
			$(".audio-player").html("");
			$(this).parent().parent().parent().next().next(".audio-player").show();
			$(this).parent().parent().parent().next().next(".audio-player").html("<object type='application/x-shockwave-flash' data='/swf/audio-player.swf' width='264' height='20'><param name='movie' value='/swf/audio-player.swf' /><param name='bgcolor' value='#40a500' /><param name='FlashVars' value='mp3="+$(this).attr("href")+"&amp;width=264&amp;volume=100&amp;showvolume=1&amp;showloading=never&amp;volumeheight=8&amp;loadingcolor=40a500&amp;bgcolor=40a500&amp;bgcolor1=40a500&amp;bgcolor2=40a500&amp;slidercolor1=ffffff&amp;slidercolor2=ffffff&amp;sliderovercolor=ffffff&amp;buttonovercolor=ffffff&amp;autoplay=1' /></object>");
			if($(this).attr("href").indexOf("nrj.se") != -1) {
				$(this).parent().parent().parent().next().next(".audio-player").css({'background-image' : 'none'});
			}
		}
		return false;
	});

	$(".togglemediaplayer").click(function() {
		$("#wrapper_media").slideToggle("normal");
		$("html, body").animate({
			scrollTop: 0
		}, "normal", "linear")
	});
	$(".showmediaplayer").click(function() {
		$("html, body").animate({
			scrollTop: 0
		}, "normal", "linear");
		$("#wrapper_media").slideDown("normal");
	});
	$(".scrolltotop").click(function() {
		$("html, body").animate({
			scrollTop: 0
		}, "normal");
	});

	//$("#tabs").tabs();
	$(".box-bottom").html("<"+"img src='/images/boxes/box-bottom-left-corner-4x4.gif' width='4' height='4' style='float: left;' /><"+"img src='/images/boxes/box-bottom-right-corner-4x4.gif' width='4' height='4' style='float: right;' />");
	$(".box-middle").each(function() {
		$(this).css({'height' : $(this).parent().parent().outerHeight()-50});
	});
	$(".box-middle-content").each(function() {
		$(this).css({'height' : $(this).parent().outerHeight()});
	});
	$("#search_box #input_keyword").css({'color' : '#a6a6a6'});
	$("#search_box #input_keyword").val("S\u00F6k p\u00E5 NRJ");
	$(".toggle").show();
	$(".scrolltotop").show();
	$(".featured").hide();
	$(".slider_wrapper .slider").show();
	$(".slider_wrapper_music .slider_music").show();
	$("<"+"div class='clear'><"+"span><!-- --><"+"/span><"+"/div>").insertAfter("ol.submenu");
	$("span.empty").html("&nbsp;");
	$("<"+"li class='seperator'><"+"span><!-- --><"+"/span><"+"/li>").insertBefore(".navigation");
	$("<"+"li class='seperator'><"+"span><!-- --><"+"/span><"+"/li>").insertAfter(".navigation:last");
	swapValues = [];
	$(".swap_value").each(function(i){
		swapValues[i] = $(this).val();
		$(this).focus(function(){
			if($(this).val() == swapValues[i]) {
				$(this).css({'color' : '#000'});
				$(this).val("");
			}
		}).blur(function(){
			if($.trim($(this).val()) == "") {
				$(this).css({'color' : '#a6a6a6'});
				$(this).val(swapValues[i]);
			}
		});
	});
	$('.slider_wrapper').anythingSlider({
		easing: "swing",        			// Anything other than "linear" or "swing" requires the easing plugin
		autoPlay: true,                 	// This turns off the entire FUNCTIONALY, not just if it starts running or not.
		delay: 5000,                    	// How long between slide transitions in AutoPlay mode
		startStopped: false,            	// If autoPlay is on, this can force it to start stopped
		animationTime: 650,             	// How long the slide transition takes
		hashTags: false,                 	// Should links change the hashtag in the URL?
		buildNavigation: true,          	// If true, builds and list of anchor links to link to each slide
		pauseOnHover: true,             	// If true, and autoPlay is enabled, the show will pause on hover
		startText: "&gt;",             		// Start text
		stopText: "||",               		// Stop text
		navigationFormatter: formatText		// Details at the top of the file on this use (advanced use)
	});
	$('.slider_wrapper_music').anythingSlider({
		easing: "swing",        			// Anything other than "linear" or "swing" requires the easing plugin
		autoPlay: true,                 	// This turns off the entire FUNCTIONALY, not just if it starts running or not.
		delay: 5000,                    	// How long between slide transitions in AutoPlay mode
		startStopped: false,            	// If autoPlay is on, this can force it to start stopped
		animationTime: 650,             	// How long the slide transition takes
		hashTags: false,                 	// Should links change the hashtag in the URL?
		buildNavigation: true,          	// If true, builds and list of anchor links to link to each slide
		pauseOnHover: true,             	// If true, and autoPlay is enabled, the show will pause on hover
		startText: "&gt;",             		// Start text
		stopText: "||",               		// Stop text
		navigationFormatter: formatText		// Details at the top of the file on this use (advanced use)
	});
	$("ol#navigation li.navigation").hover(function() {
		$(this).addClass("active");
	}, function() {
		$(this).removeClass("active");
	});
	$(".toggle").hover(function() {
		var toggleClass = $(this).attr("class").substr($(this).attr("class").indexOf(" ")+1);
		if($(".megamenu."+toggleClass).is(":hidden")) {
			$(this).attr({src: "/images/menu/arrow_hover.gif"});
		}
	}, function() {
		var toggleClass = $(this).attr("class").substr($(this).attr("class").indexOf(" ")+1);
		if($(".megamenu."+toggleClass).is(":hidden")) {
			$(this).attr({src: "/images/menu/arrow_down.gif"});
		}
	});
	$(".toggle").click(function() {
		var toggleClass = $(this).attr("class").substr($(this).attr("class").indexOf(" ")+1);
		if($(".megamenu."+toggleClass).is(":visible")) {
			$("li.navigation").removeClass("active");
			$("li.seperator").removeClass("active")
			$(this).parent("li").addClass("active");
			$("li.navigation").removeClass("open");
			$(this).parent("li").next("li.seperator").removeClass("seperator-active");
			$(this).attr({src: "/images/menu/arrow_down.gif"});
			$(".megamenu."+toggleClass).hide();
			$("#wrapper_megamenu").hide();
		} else {
			$("li.navigation").removeClass("active");
			$("li.seperator").removeClass("active")
			$("li.navigation").removeClass("open");
			$("li.navigation img").attr({src: "/images/menu/arrow_down.gif"});
			$(".megamenu").hide();
			$("#wrapper_megamenu").show();
			$(".megamenu."+toggleClass).show();
			$(this).parent("li").addClass("open");
			$(this).parent("li").next("li.seperator").addClass("seperator-active");
			$(this).attr({src: "/images/menu/arrow_up.gif"});
		}
	});
	$("ol.submenu").each(function() {
		$(this).find("li:first").css({'width' : '130px'});
	});
	/*$(".blogposts .content img:not(.sponsor)").lazyload({
		placeholder : "/images/grey.gif",
		effect: "fadeIn",
		threshold : 150
	});*/
	$(".btnVote").hover(function() {
		$(this).addClass("active");
	}, function() {
		$(this).removeClass("active");
	});
	$("#footer_favourites ol li>a").mouseover(function() {
		imgsrc = $(this).children("img").attr("src");
		matches = imgsrc.match(/_hover/);
		matches2 = imgsrc.match(/_active/);
		if(!matches && !matches2) {
			imgsrcHOVER = imgsrc.replace(/.png$/gi, "_hover.png");
			imgsrcACTIVE = imgsrc.replace(/.png$/gi, "_active.png");
			$(this).children("img").attr("src", imgsrcHOVER);
		} else if(matches2) {
			imgsrcACTIVE = imgsrc;
		}
	});
	$("#footer_favourites ol li>a").mouseout(function() {
		if(!matches && !matches2) {
			$(this).children("img").attr("src", imgsrc);
		}
	});
	$("#footer_favourites ol li>a").click(function() {
		var toggleClass = $(this).parent().attr("class");
		$(this).parent().siblings().each(function() {
			rollsrc = $("a>img", this).attr("src");
			rollON = rollsrc.replace(/_active.png$/gi, ".png");
			$("a>img", this).attr("src", rollON);
		});
		matches = imgsrc.match(/.png/);
		matches2 = imgsrc.match(/_active.png/);
		if(matches && !matches2) {
			$(this).children("img").attr("src", imgsrcACTIVE);
			$("#footer_featured ol").hide();
			$("#footer_featured ol#"+toggleClass).show();
		}
	});
	$("#footer_favourites ol li.favourites").siblings().show();
	$(".btnSendDark").hover(function() {
		$(this).addClass("active");
	}, function() {
		$(this).removeClass("active");
	});
	
	$("a.lightbox").lightBox();
	
	$(".pngfix-load").addClass("pngfix");
});

AudioPlayer.setup("http://nrj-beta.mtgradio.bahnhof.se/flash/audioplayer.swf", {
	width: 403
});

//	ALL YOUR BASE ARE BELONG TO US
var kkeys = [], konami = "38,38,40,40,37,39,37,39,66,65";
$(document).keydown(function(e) {
	kkeys.push(e.keyCode);
	if(kkeys.toString().indexOf( konami ) >= 0) {
		$(document).unbind('keydown',arguments.callee);
		window.location.href = "http://www.nrj.se/sok/konami+code";
	}
});