/* 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 = 500;

/* 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){
	if($(e).attr('href')){
		$.get($(e).attr('href'), function(data) {
			renderModal(data);
		});
	}else if($(e).attr('action')){
		$.get($(e).attr('action'), 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*/
				
				initInterface();
			
				/* zorg dat alle forms weer worden geinitialiseerd */

				
			},
			onClose: function(){
				/* overschrijf de close methode, iets in treeview gaat niet helemaal goed waardoor dit nodig is */
				
				$.modal.close(); // must call this!
				humanAction = true;
				
				/* herlaad de verschillende elementen, anders activeerd de tree niet */
				reloadInterfaceComponent('#left_content','/media/ajax','ui_left_menu');
				   
			}
			
	});
	
}

