function doUpdateAnimation(btn) {
	btn.name = "update";
	btn.value="UPDATING...";
}

function handleWishlistSong(btn,ids) {
	var i;
	var idstring = "";
	var btnFunction = btn.getAttribute("name");
	
	for (i=0;i<ids.length;++i) {
		doUpdateAnimation(document.getElementById("songButton_" + ids[i]));
		idstring = idstring + "," + ids[i];
	}
	
	if (btn.id == "allButton") {
		doUpdateAnimation(btn);
	}
	idstring = idstring.substring(1, idstring.length);
	
	if (btnFunction == "add") {
		new Ajax.Request(ROOT + "/wishlist.xml?wishlist_do=add&wishlist_song_id=" + idstring , {
			onSuccess: function(response) {
				if (response.responseXML.getElementsByTagName("full").length == 0 && response.responseXML.getElementsByTagName("added").length > 0) {
					for (i=0;i<ids.length;++i) {
						document.getElementById("songButton_" + ids[i]).name="remove";
						document.getElementById("songButton_" + ids[i]).value="Entfernen";
					}
					if (btn.id == "allButton") {
						btn.name="remove";
						btn.value="Will nichts!";
					}
				}
				else
				{
					if (response.responseXML.getElementsByTagName("full").length > 0) {
						alert('Deine Wunschliste ist voll!\nBitte entferne Songs aus deiner Wunschliste um neue aufnehmen zu können.');
					}
					for (i=0;i<ids.length;++i) {
						document.getElementById("songButton_" + ids[i]).name="add";
						document.getElementById("songButton_" + ids[i]).value="Will ich!";
					}
					if (btn.id == "allButton") {
						btn.name="add";
						btn.value="Will alle!";
					}
				}
			},
			onFailure: function(response) {
				for (i=0;i<ids.length;++i) {
					document.getElementById("songButton_" + ids[i]).name="add";
					document.getElementById("songButton_" + ids[i]).value="Will ich!";
				}
				if (btn.id == "allButton") {
					btn.name="add";
					btn.value="Will alle!";
				}
			}
		}
		);
		btn.setAttribute("class", 'btn70_grey');
	}
	else if (btnFunction == "remove") {
		new Ajax.Request(ROOT + "/wishlist.xml?wishlist_do=remove&wishlist_song_id=" + idstring , {
			onSuccess: function(response) {
				if (response.responseXML.getElementsByTagName("removed").length > 0) {
					for (i=0;i<ids.length;++i) {
						document.getElementById("songButton_" + ids[i]).name="add";
						document.getElementById("songButton_" + ids[i]).value="Will ich!";
					}
					if (btn.id == "allButton") {
						btn.name="add";
						btn.value="Will alle!";
					}
				}
				else
				{
					for (i=0;i<ids.length;++i) {
						document.getElementById("songButton_" + ids[i]).name="remove";
						document.getElementById("songButton_" + ids[i]).value="Entfernen";
					}
					if (btn.id == "allButton") {
						btn.name="remove";
						btn.value="Will nichts!";
					}
				}
			},
			onFailure: function(response) {
				for (i=0;i<ids.length;++i) {
					document.getElementById("songButton_" + ids[i]).name="add";
					document.getElementById("songButton_" + ids[i]).value="Will ich!";
				}
				if (btn.id == "allButton") {
					btn.name="remove";
					btn.value="Will nichts!";
				}
			}

		}
		);
		btn.setAttribute("class", 'btn70');
	}
}

function setDownloaded(btn, className) {
	btn.setAttribute("class", className);
}

