<ul id="" class="srv_solidBox srv_filePane scroll">
  	{% for g in galleries %}
		<li>
			<a href="#srv_place_gallery" data-id="{{ g.pk }}">
				<h5>{{ g.title }}</h5>
				<p>{{ g.description }}</p>
			</a>
		</li>
	{% endfor %}
</ul>
<div id="" class="srv_solidBox srv_insertOptions scroll">
<h4>Insert a Gallery</h4>
	<div id="srv_insert_gallery_display"></div>
	<h5 id="srv_insert_gallery_title"></h5>
	<p id="srv_insert_gallery_description"></p>
	<p><select id="#srv_insert_gallery_template"><option>Auto</option></select></p>
	<input type="hidden" name="srv_insert_gallery_pk" id="srv_insert_gallery_pk" value="0">
	<input type="button" class="srv_button insert" id="srv_insert_gallery_action" value="Place image at Cursor">
<!--<p>Narrow the list with tags:</p>

<div id="tagCloud" class="clearfix">
  <span class="tags">Tags:</span> <span id="clearTags" class="selected"><a>Show all
  files</a></span> <span><a>instructions</a></span> 
</div>-->
</div>
<script type="text/javascript">
$("a[href=#srv_place_gallery]").click(function(e){
	var chosen = this
	$(chosen).parent().parent().children().removeClass('backgroundHighlight');
	$(chosen).parent().addClass('backgroundHighlight');
	$("#srv_insert_gallery_title").html( $(chosen).children('h5').html() );
	$("#srv_insert_gallery_description").html($(chosen).children('p').html());
	$("#srv_insert_gallery_pk").val($(chosen).attr('data-id'));
	e.preventDefault();
	return false;
});
$("input#srv_insert_gallery_action").click(function(e){
	var template, pk;
	pk = parseInt($("#srv_insert_gallery_pk").val())
	if(pk > 0){
		template = $("select#srv_insert_gallery_template").val();
		if(template == 'auto') template = null;
		srv_insert_gallery_by_pk(pk, template)
	}
	e.preventDefault();
	return false;
});
function srv_insert_gallery_by_pk(pk, template){
	var markup = '<inline type="gallery.gallery" id="'+pk+'"';
	if(template){
		markup += ' template="'+template+'"'
	}
	markup += '/>'
	srv_wysiwyg_insert_html_at_cursor(markup)
}
</script>