﻿
function ShowInsertImageDialog() {
	showModal("/InsertImage.aspx", 485, 575);
	return false;
}

function ShowUploadImageDialog() {
	showModal("/UploadImage.aspx", 130, 585);
}

$(document).ready(function() {
	$(".UserImage").click(selectImage);
	if ($(".markItUp").length > 0) {
		$(".markItUp").markItUp(mySettings);
	}
});

function showModal(url, height, width) {
	var dialog = $('#modalDialog')
        .jqm({
        	modal: true,
        	onShow: function(h) {
        		var $modal = $(h.w);
        		var $modalContent = $("iframe", $modal);
        		$modalContent.html('').attr('src', url);
        		if (height > 0) $modal.height(height);
        		if (width > 0) $modal.width(width);
        		$modalContent.height(height);
        		$modalContent.width(width);
        		h.w.show();
        	}
        }).jqmShow();
}

function returnFromUpload(image) {
	$('#modalDialog').jqmHide();
	if (image + "" != "") {
		//location.reload(true);
		parent.returnFromInsert(image);
	}
}

function returnFromInsert(image) {
	$('#modalDialog').jqmHide();
	if (image + "" != "") {
		$.markItUp({
			replaceWith: '[img]@' + image.toString() + '[/img]'
		});
	}
}

var currentImageId = 0;

function selectImage() {
	clearSelection();
	$(this).addClass("Selected");
	currentImageId = $(this).attr("id");
}

function clearSelection() {
	$(".UserImage").removeClass("Selected");
}

function insertImage(h) {
	ShowInsertImageDialog();
	return h.selection;
}

