/**
 * Disables the site (displays a layer)
 */
function disableSite(onExit)
{
	var div = document.createElement("div");
	div.className = 'site_overlay';
	
	document.body.appendChild(div);
	
	$('div.site_overlay').fadeTo(500, 0.33).click(
		function() 
		{
			$(this).fadeOut(500, onExit);
		} // end function
	);		
}


/**
 * Function for finding the position of a element
 * @param obj
 * @return
 */
function findPos(obj) 
{
  if( typeof( obj ) == 'string' )
  {
    obj     = document.getElementById(obj);
    
  }
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}	
	return [curleft,curtop];
}
 
 function toggleElementGroup(event)
 {
	 $(this).parent().children().filter('p,img,table,ul,div,span').toggle('blind');
	 event.preventDefault();
	 
	 if( $(legend).parent().hasClass('collapsed') )
	 {
		 // it is collapsed, expand it
		 $(legend).parent().removeClass('collapsed');		
		 
		 $(legend).parent().children().filter('p,img,table,ul,div,span').toggle('medium');
		 
		 
	 } else {
		 $(legend).parent().children().filter('p,img,table,ul,div,span').toggle('medium');
	 }
	
	 
	 // toggle the class
	 $(legend).parent().toggleClass('collapsed', !$(legend).parent().hasClass('collapsed'));
 }
 
 $(document).ready(function() {
	 
	// Initialize all collapsible fieldsets
	 initCollapsibleFieldSets();
	 
 });
 
 function initCollapsibleFieldSets()
 {
	 $('fieldset.collapsible').each(function()
	 {
		 if( $(this).hasClass('collapsed') )
		 {
			 $(this).children().filter('p,img,table,ul,div,span').toggle();
		 }
		 
		 // Add click handler
		 $(this).children('legend').click(toggleElementGroup);
	 });
			
 }
 
 function showSecurityBox(url)
 {
	 var layer = $('#securityEditorLayer');
	 var editorContainer = layer.find('#editorContainer');
	 
	 if( !layer.get(0) )
	 {
		 // create the layer and add it to the dom
		 layer = $('<div class="sitelayer" id="securityEditorLayer">');
		 layer.appendTo(document.body)
		 .css('display', 'none')
		 .css('opacity', '0.7');		
		 
		 layer.click(closeSecurityBoxEditor);
	 }
	 
	 if( !editorContainer.get(0) )
	 {
		 editorContainer = $('<div class="securityBoxEditorContainer" id="editorContainer">');
		 editorContainer.appendTo(document.body)
		 .css('opacity', '1');
		 
		 editorContainer.click(function(event) 
				 {
					 if (event.stopPropagation) {
						 event.stopPropagation();
					 } else {
						 event.cancelBubble = true;
					 } 
				 }
		 );
	 }
	 
	 editorContainer.html('<div style="padding: 10px; border: 1px solid black; background-color: #FFFFFF; text-align: center; margin-top: 225px;">Bezig met laden..</div>');
	 layer.fadeIn('slow', function() 
		 { 
		 	// start loading..
		 	editorContainer.load(url); 
		 }
	 );
	 
	 // show the layer
	 layer.css('display', 'block');
 }
 
 function closeSecurityBoxEditor()
 {
	 
	 var editor = $('#editorContainer');
	 
	 if(editor.get(0) )
		 editor.remove();
	 
	 var layer = $('#securityEditorLayer');
	 if( layer.get(0) )
	 {
		 layer.fadeOut('slow');
	 }
 }
 
 function updateDivSize(id, width, height)
 {
	 $("#" + id).width(width).height(height);
 }
 

