// JavaScript Document
var alertb = 0;

function alertbox(text, fadeout) {
	clearTimeout(alertb);
	$("#alertbox").remove();
	$("body").append("<div id='alertbox' title='Click to hide'></div>");
	$('#alertbox').html(text);
	$("#alertbox")
		.css("top",-($("#alertbox").outerHeight(true)) + "px")
		.css("left", (($(window).width() / 2) - ($("#alertbox").width() / 2)) + "px");
	$("#alertbox").animate({top: "0"});
	if(fadeout || fadeout == null)
		alertb = setTimeout("$('#alertbox').fadeOut(1000, function(){ $('#alertbox').remove(); })",4000);
};

$(document).ready(function() {
	$('.hugeScrollArea').jScrollPane({dragMaxHeight: 24, scrollbarWidth: 12 });
	$('.playTrack').click(function(){callRemix(this.id, "miniPlayer"); return false;});   	
	
   	$('body').click(function(event){
		if($(event.target).is('.downloadremix')){
			var id = $(event.target).attr("id");
			id = id.split("-");
			id = id[1];
			
			$("#downloadmp3-"+id).slideToggle(150);
			return false;
		}
	});
	
	$('#contentWrap').submit(function(event){
		var id = $(event.target).attr("id");
		var idsplit = id.split("-");
		if(idsplit[0] == "downloadtrackform"){
			$.post("/ext.php", $(event.target).serialize(),
				function(data){
					if(data.ok){
						alertbox(data.message);
						$("#downloadmp3-"+idsplit[1]).slideUp(150);
					}else{
						alertbox(data.message);
					}
					
			},"json");
			return false;
		}
	});
});
