$(document).ready(function() {
	$("#datepicker").hide();
	$("#datepicker").datepicker({
	   onSelect: function(dateText, inst) {
	   	$("#datepicker").animate({ height: 'hide', opacity: 'hide' }, 'slow');
	   	// console.log("dateText: " + dateText); // debug Adrian
	   	var year = dateText.substring(0,4);
	   	var month = dateText.substring(5,7);
	   	var day = dateText.substring(8,10);
	   	// console.log("year: " + year); // debug Adrian
	   	// console.log("month: " + month); // debug Adrian
	   	// console.log("day: " + day); // debug Adrian
	   	// window.location = "http://www.google.com";
	   	var url = "http://p3spotify.adagio.se/" + year + "/" + month + "/" + day + "/";    
			$(location).attr('href',url);
	   }
	});
	$("#datepicker").datepicker($.datepicker.regional['sv']);
	var currentDate = $("#date").val();
	// console.log("currentDate: " + currentDate); // debug Adrian
	currentDateOjb = new Date(currentDate);	
	// console.log("currentDateOjb: " + currentDateOjb); // debug Adrian
	$("#datepicker").datepicker('setDate', currentDateOjb);
	$("a.choosedate").click(function(){
		var thisTarget = $(this).attr('href');
		// console.log("thisTarget: " + thisTarget); // debug Adrian
		var visability = $(thisTarget).css("display");
		if (visability == "none") {
			$(thisTarget).animate({ height: 'show', opacity: 'show' }, 'slow');
			$("#choosedate a").text('Göm datumväljare');
		} else {
			$(thisTarget).animate({ height: 'hide', opacity: 'hide' }, 'slow');
			$("#choosedate a").text('Välj datum');
		}
		return false;
	});
	// $("#tracklisttable").tablesorter(); 
	$("#tracklisttable").tablesorter({ 
		// sortForce: [[0,0]]
		sortList: [[0,0]],
		// headers: {2: {sorter:false}, 3: {sorter:false}}
		headers: {2: {sorter:false}}
	}); 
	// $("#tracklisttable tr.newhour").prev().css("background", "yellow"); // debug Adrian
	$("#tracklisttable tr.newhour").prev().addClass("beforenewhour"); 

	$("#tracklisttable tbody tr").hover(
		function () {
			$(this).addClass("hover");
			// $(this).find("span.searchlink").fadeIn(100);
			$(this).find("span.searchlink").show();
		}, 
		function () {
			$(this).removeClass("hover");
			// $(this).find("span.searchlink").fadeOut(100);
			$(this).find("span.searchlink").hide();
		}
	);

});


