$(document).ready(addRadioLogoHandlers);
$(document).ready(addYoutubeSearchHandler);
$(document).ready(function(){	
	$("#artist").autocomplete("/artist/search", {max: 10, scroll: false, width: 225});
	$("#song").autocomplete("/song/search", {extraParams: {artist: function(){return $("#artist").val();}}, max: 10, scroll: false, width: 225});	
});





function addRadioLogoHandlers()
{
	$("img.radioLogo", this).click(function(){
			$(this).highlightFade();
			
			$.post("/radio/url", {name: $(this).attr("alt")}, function(xml){
				$("#player").html("<embed type=\"application/x-mplayer2\" src=\"" + xml + "\" width=345 height=64 showstatusbar=1 autostart=1 invokeurls=0 style=\"margin-top: 7px\"></embed>");
			});
			
			$.post("/radio/image", {name: $(this).attr("alt")}, function(xml){
				$("#currentRadioLogo").attr({src: "images/logos/" + xml});
			});
	});
	
	$("img.radioLogo", this).hover(function(){
		$(this).css({"z-index" : "10"})
			   .stop().animate({marginTop: "-3px", marginLeft: "-3px", width: "96px", height: "66px"}, 100);
	}, function(){
		$(this).css({"z-index" : "0"})
			   .stop().animate({marginTop: "0", marginLeft: "0", width: "90px", height: "60px"}, 200);
	});	

}

function addYoutubeSearchHandler()
{
	$("#youtubeSearch", this).click(function(){
			$("#youtubeProgress").progressbar({value: 33});
			
			$.getJSON("/youtube/search/?track=" + escape($("#song").val()), function(data){

				setYoutubeProgress(50);
				showYoutubeResults(data);
						
			});
	});
	
}

function setYoutubeProgress(percentage)
{
	$("#youtubeProgress").progressbar({value: percentage});
}
