$(document).ready(function() {

$("#seed_search_form").submit(function() {
	if ($("#seed_song").val() == $("#seed_song").attr('message') && $("#seed_artist").val() == $("#seed_artist").attr('message'))
		return false;
	find_song($("#seed_song").val(), $("#seed_artist").val());
	return false;
});

$("#seed_search_btn").click(function() {
	if ($("#seed_song").val() == $("#seed_song").attr('message') && $("#seed_artist").val() == $("#seed_artist").attr('message'))
		return false;
	find_song($("#seed_song").val(), $("#seed_artist").val());
	return false;
});

$(".search_song").focus(function() {
	if ($(this).val() == $(this).attr('default') || $(this).val() == $(this).attr('message')) {
		$(this).val("")
	}
	$(this).css("color", "black");
});

$(".search_song").blur(function() {
	if ($(this).val() == "") {
		$(this).val($(this).attr('message'))
		$(this).css("color", "#B8B8B8");
	}
});

//find_song($("#seed_song").val(), $("#seed_artist").val());
$(".search_song").blur();

/*** start store recommendation ***/
$("#home_seed_btn").click(function() {
	home_seed_song();
});

$("#home_seed_song").keydown(function(e) {
	if(e.keyCode==13) home_seed_song();
});

$("#home_seed_song").click(function() {
	if ($(this).val() == $(this).attr('default')) {
		$(this).val('');
		$(this).css('color', '#000000');
	}
});
$("#home_seed_song").blur(function() {
	if ($(this).val() == '') {
		$(this).val($(this).attr('default'));
		$(this).css('color', '#999999');
	}
});
/*** end recommendation ***/

});

function home_seed_song()
{
	var inp = $("#home_seed_song");
	var res = $("#home_store_discover");

	if (inp.val() == '' || inp.val() == inp.attr('default')) return false;

	$.ajax({
		type: "POST",
		url: "/member/discover-store/",
		data: {
			query: inp.val()
		},
		beforeSend: function(){
			res.show().html('<div class="loading" style="padding:10px;">'+ajax_loading+'</div>');
		},
		success: function(xml){
			res.html(xml);
			setup_niftyplayer('#store_recommendation_list [id^=inline-player-]');
		}
	});

	return false;
}
function find_song(seed_song, seed_artist, skip) {
	if (seed_song == $("#seed_song").attr('message')) seed_song = "";
	if (seed_artist == $("#seed_artist").attr('message')) seed_artist = "";
	if (seed_song == "" && seed_artist == "") return false;

	$.ajax({
		type: "POST",
		url: "/discover/ajax/recommend-seed-song/",
		data: {
			song: seed_song,
			artist: seed_artist
		},
		beforeSend: function(){
			$("#recommendation_list_box").show();
			$("#recommendation_list").html('<img src="/images/common/loading.gif" align="absmiddle" style="padding-right: 5px;" />Loading');
		},
		success: function(xml){
			$("#recommendation_list").html(xml);
			setup_playlist();
			setup_niftyplayer('#recommendation_list [id^=inline-player-]');
			$("#gn-logo").show();
		}
	});

	return false;
}

