/**
 * @author Dirk Eidam (dirk.eidam@gmx.de)
 */

$(document).ready(function() {	
	
	// AJAX für das Hinzufügen von Dateien zur DAM-Sammlung
	$("a.collection-add").click(function(p) {
		
		cl = $(this).attr('class');
		cls = cl.split(' ');
		
		for (var i = 0; i < cls.length; i++) {
			if(cls[i].substr(0,3) == 'uid') {
				uid = cls[i].substr(3);
			}
		}
		$("a.collection-add.uid" + uid).fadeOut();
		$.ajax({
			url: $(this).attr("href"),
			type: "GET",
			data: "eID=de_dam_collection&de_dam_collection[plugin]=pi1",
			dataType: "json",
			success: function(response) {
				count = $(".file-counter .count").text();
				count = Number(count) + 1;
				$(".file-counter .count").text(count).css("background-color","#f00").animate( { backgroundColor: '#fff' }, 1000);
				$("a.collection-add.uid" + uid).replaceWith("<div class=\"no-collect-icon\">&nbsp;</div>");
				$(".title.uid" + uid).addClass('select');
				alert(response.uid);
			},
			error: function(error) {
				$("a.collection-add.uid" + uid).fadeIn();
				alert("Datei konnte nicht gespeichert werden.");
			}
		});
		return false;
	});
});