function initialize_band_pictures(){
	$("#show_image_library").click(function(){
		$("#image_media_conf").removeClass("hidden");
	});
	initialize_image_gallery();
	import_pictures_from_library();
	$("#picture_drop").droppable();
	$("#picture_drop").bind("drop",picture_dropped);
}

function initialize_image_gallery(){
	pictures_thumbnail_gallery = create_thumbnail_gallery($("#displayed_pics"));
}

function import_pictures_from_library(){
	pictures_thumbnail_gallery.clear();
	$("#display_pics .pic").remove();
	$(".pic .custom_actions").remove();
	if(typeof image_library != "undefined")
	for(var i = 0; i < image_library.length; i++){
		var pic = image_library[i];
		if(typeof pic.displayed != "undefined")
		if(pic.displayed == "true"){
			 var pic_obj = add_pic(i);
			 pictures_thumbnail_gallery.add_thumbnail(pic_obj);
		}
	}
	$(".pic:first", $("#displayed_pics")).removeClass("hidden");
}

function add_pic(index){
	var pic = image_library[index];
	var pic_obj = $("#" + pic.id).clone();
	$(pic_obj).attr("id", "clone_" + $(pic_obj).attr("id"));
	$(pic_obj).css({"left":0,"right":0,"top":0,"bottom":0});
	$("img",pic_obj).css({"border":"2px solid #fff"});
	var custom_actions_obj = $("<div class='custom_actions'><a class='remove_displayed'>Remove</a></div>");
	$(pic_obj).append(custom_actions_obj);
	$(".remove_displayed",pic_obj).bind("click",{obj:pic_obj,index:index},return_to_media_library);
	$(pic_obj).draggable("disable");
	$(".default_image_actions",pic_obj).addClass("hidden");	
	$("#displayed_pics").append(pic_obj);
	return pic_obj;
}

function return_to_media_library(event){
	var img_index = event.data.index;
	band_data.pics[img_index].displayed = "false";
	image_library = band_data.pics;
	api.update_band_data(band_data["_id"], function(){
		var pic_obj = event.data.obj;
		$("img[links_to='"+$(pic_obj).attr("id")+"']").remove();
		$(pic_obj).remove();
	});
}

function picture_dropped(event,ui){
	var drop_zone = $(this);
	var image_dropped = ui.draggable;
	var img_index = selected_image.index;
	band_data.pics[img_index]["displayed"] = "true"
	image_library = band_data.pics;
	api.update_band_data(band_data["_id"],function(){var pic_obj = add_pic(img_index);  pictures_thumbnail_gallery.add_thumbnail(pic_obj);});
}