// tinyMCE stuff
$$('html')[0].onclick = function() { hide_ul() };
var ul_click = false;
var ul_logo_click = false;

function hide_ul() {
	if (ul_click == true) {
		ul_click = false;
	} else if ($('editor_image') && $('editor_image').style.display == '') {
			$('editor_image').toggle();
	}
	if (ul_logo_click == true) {
		ul_logo_click = false;
	}
}


// tinyMCE handlers -----------------------------------------------------------

function insertImage(host, filename, width, height) {
	tinyMCE.execCommand('mceInsertContent', false, "<img src='http://" + host +  filename + "'>");
	Element.hide("editor_image");
}

function insertFile(host, filename, short_filename) {
	tinyMCE.execCommand('mceInsertContent', false, "<a href='http://" + host + filename + "'>" + short_filename + "</a>");
	Element.hide("editor_file");
}

function makeDraggable(elmnt_id) {
  new Draggable(elmnt_id, {ghosting:true, revert:true});
}

function openLogin() {
  Shadowbox.open({player:'inline',content:'#overlay-form-login',width:300,height:375,options:{enableKeys:false}});
}

function showAgendaOverlay(e) {
  var el = e.element().ancestors()[0];
	var id = el.readAttribute('id');
	if (!id) {
		id = el.up().identify();
	}
  element = $("overlay_" + id);
  
  element.setStyle({
    top: (Event.pointerY(e) - 125) + 'px',
    left: '-220px', // (Event.pointerX(e) - 220) + 'px',
    display: 'block',
	zIndex: 1000001
  })
}

function hideAgendaOverlay(e) {
  var el = e.element().ancestors()[0];
	var id = el.readAttribute('id');
	if (!id) {
		id = el.up().identify();
	}
  $("overlay_" + id).hide();
}

function showExpectedAgendaOverlay(e) {
	var el = e.element();
	var id = el.readAttribute('id');
	if (!id) {
		id = el.up().identify();
	}
	var element = $('overlay_' + id);
	
	element.setStyle({
		top: Event.pointerY(e) + 'px',
		left: (Event.pointerX(e) - 220) + 'px',
		display: 'block',
		zIndex: 1000001
	})
}

function hideExpectedAgendaOverlay(e) {
	var el = e.element();
	var id = el.readAttribute('id');
	if (!id) {
		id = el.up().identify();
	}
	$('overlay_' + id).hide();
}