{% load i18n %}
<script type="text/javascript">
$(document).ready(function(){
	{% if edit_mode %}
    $("#coop-bar a.slide").pageSlide({width:'350px', direction:'right'});
	{% endif %}
	
    $("a.colorbox-form").live('click', function () {
        $.colorbox({
            href : $(this).attr('href'),
			title : '...',  
            onComplete : function(){
                $("form#template-form").ajaxForm({
                    success: function (html) {
						if (html.match(/^<script>.*<\/script>$/)) {
							$('body').append(html);
						} else if (html === 'close_popup') {
							$.colorbox.close();
						} else if (html === 'close_popup_and_media_slide') {
							$.colorbox.close();
							$("#coopbar_medialibrary").click();
						} else {
                            $.colorbox({html:html, title : '...'}); 
                        }
                    }
                })
            }
        });
        return false;
    });
	
	{% if article and edit_mode %}
	var toggle_save = function() {
	    if (!$(".edited").is(":visible")) {
			$(".edited").show();
			$("a.alert_on_click").bind('click', function(event) {
				return confirm("{% trans 'Your modifications are not saved and will be lost. Continue?' %}");
			});
		}
		{% if draft %}
		$(".publish").hide();
		{% endif %}
	}
	$(".edited").hide();
	GENTICS.Aloha.EventRegistry.subscribe(GENTICS.Aloha, "editableDeactivated",
        //Callback called when the fragment edition is done -> Push to the page
        function(event, eventProperties) {
            toggle_save();
        }
    );
	$("a.update-logo img").change(toggle_save);
	$(".article select").change(toggle_save);
	$(".article input").change(toggle_save);
	{% endif %}
});
</script>
