function jquery_loading_indicator() {
   loading_indicator('hide');

   jQuery("#loading_indicator").ajaxStart(function(){
           loading_indicator('show');
           jQuery('select').css({ visibility: 'hidden' });
   });

   jQuery("#loading_indicator").ajaxStop(function(){
           loading_indicator('hide');
           jQuery('select').css({ visibility: 'visible' });
   });
}

function loading_indicator(state) {
	if (jQuery("#loading_indicator").length == 0) {
		jQuery("body").append('<div id="loading_indicator"></div>');
	}
	
	if (state == 'show') {
		posTop = get_top();
		
		jQuery("#loading_indicator").css('marginTop', (get_top() + 'px'));
		jQuery("#loading_indicator").html('<div style="background-color:#f4e3b6; color: #e19f01; font-weight: bold; font-size: 12px; padding: 10px; height:40px; border: 2px solid #e19f01; z-index: 10010;">Even geduld a.u.b.<br /><img src="/img/loader.gif" border="0" alt="" /></div>');
		
	} else if (state == 'hide' && jQuery("#loading_indicator").length > 0) {
		jQuery("#loading_indicator").empty();;
	}
}


function get_top() {
	if (window.innerHeight) {
		posTop = window.pageYOffset
	} else if (document.documentElement &&
		document.documentElement.scrollTop) {
		posTop = document.documentElement.scrollTop;
	} else if (document.body) {
		posTop = document.body.scrollTop;
	}
	
	posTop = parseInt(posTop);
	
	return posTop;
}

// wait for the DOM to be loaded 
jQuery(document).ready(function() {
	jquery_loading_indicator();	
});
