/* simplemodal addon for extended use
 *
 * A modal (lightbox) should appear the same within each project. This extra functionality
 * will try to aid in that. 
 *
 * modalGetHref	 	use Jquery ajax get to load content into the modal
 * renderModal		render the modal onto the screen
 *
 * todo make an jquery object that extends simpleModal.
 *
 */

/* minimal height */
var ui_modalMinHeight = 150;

/* close button img location (some info on preffered sizes) */
var ui_modalImageLocation = '';


/* modalGetHref()
 * Use Jquery ajax get mothod to load content 
 * param e refers too an <a> tab object 
 *
 * usage:
 *
 * <a href="/mediabeheer/beheercategorieen" target="_blank" onclick="modalGetHref(this); return false;">link name</a>
 *
 * - use target="_blank" to open the modal window on browsers without javascript support
 * - always use return false; on the onclick function, that way browsers with javascript support won't use the normal <a> functionality
 */

function modalGetHref(e){

	$.get($(e).attr('href'), function(data) {
		renderModal(data);
	});
}

/* renderModal()
 * Render the modal onto the screen 
 * param data (string) with html or text content ..
 *
 * height and widths:
 * var minModalHeight: the minimum height
 *
 * home: by default the modal will be rendered at 80% of the current screen height
 */

function renderModal(data){
	
	$.modal('<div id="simplemodal-flowcontroller" style="width:100%; height:'+ui_modalMinHeight+'px;  overflow-y:auto;"></div>',
			{containerCss: {
				height: ui_modalMinHeight+'px'
			},
			onShow: function () {
				/* Load the data in the modal */				
				$('#simplemodal-flowcontroller').html(data);

				/* Do some specific Jquery or normal javascript for rendering UI elements that are possibly within the modal*/
				
				if("#ui_modalCategorylist"){

					$("#ui_modalCategorylist").treeview({
						collapsed: true,
						unique: true,
						persist: "location"
					});
				}

			}
	});
	
}

