/*=============================
	LOADING GRAPHIC
=============================*/
var loading_graphic = new Image();
loading_graphic.src = '/images/loading.gif';

function displayLoadingGraphic( button ) {
	
	var loading_block = document.createElement('div');
	loading_block.className = 'loading';
	loading_block.appendChild( loading_graphic );
	button.parentNode.appendChild( loading_block );
	button.style.display = 'none';
	button.style.visibility = 'hidden';
}

function sleep(milliseconds) {
  var start = new Date().getTime();
  for (var i = 0; i < 1e7; i++) {
    if ((new Date().getTime() - start) > milliseconds){
      break;
    }
  }
}

/*============================================
	DISPLAY PAGE HIGHLIGHT HANDLERS.
============================================*/
var page_highlights_handlers = new Array();

// REGISTER YOUR HANDLER HERE.
function registerPageHighlightsHandler( handler )
{
	page_highlights_handlers;

	page_highlights_handlers[page_highlights_handlers.length] = handler;
}
// CALL EACH HANDLER
function displayPageHighlights( page_id )
{
	page_highlights_handlers;

	var c;
	for ( c = 0; c < page_highlights_handlers.length; c++ )
	{
		page_highlights_handlers[c].displayPageHighlights( page_id );
	}

	return true;
}

/*====================================================================
	UPDATE PADDING, MARGIN, AND BORDER SETTINGS DYNAMICALLY
====================================================================*/
function set_background_color( module, module_instance_id, hexcolor )
{
	document.getElementById( module + module_instance_id ).style.backgroundColor = hexcolor;
}
function set_border_left_color( module, module_instance_id, hexcolor )
{
	document.getElementById( module + module_instance_id ).style.borderLeftColor = hexcolor;
}
function set_border_left_width( module, module_instance_id, border_width )
{
	document.getElementById( module + module_instance_id ).style.borderLeftWidth = border_width + 'px';
}
function set_border_left_style( module, module_instance_id, style )
{
	document.getElementById( module + module_instance_id ).style.borderLeftStyle = style;
}
function set_border_right_color( module, module_instance_id, hexcolor )
{
	document.getElementById( module + module_instance_id ).style.borderRightColor = hexcolor;
}
function set_border_right_width( module, module_instance_id, border_width )
{
	document.getElementById( module + module_instance_id ).style.borderRightWidth = border_width + 'px';
}
function set_border_right_style( module, module_instance_id, style )
{
	document.getElementById( module + module_instance_id ).style.borderRightStyle = style;
}
function set_border_top_color( module, module_instance_id, hexcolor )
{
	document.getElementById( module + module_instance_id ).style.borderTopColor = hexcolor;
}
function set_border_top_width( module, module_instance_id, border_width )
{
	document.getElementById( module + module_instance_id ).style.borderTopWidth = border_width + 'px';
}
function set_border_top_style( module, module_instance_id, style )
{
	document.getElementById( module + module_instance_id ).style.borderTopStyle = style;
}
function set_border_bottom_color( module, module_instance_id, hexcolor )
{
	document.getElementById( module + module_instance_id ).style.borderBottomColor = hexcolor;
}
function set_border_bottom_width( module, module_instance_id, border_width )
{
	document.getElementById( module + module_instance_id ).style.borderBottomWidth = border_width + 'px';
}
function set_border_bottom_style( module, module_instance_id, style )
{
	document.getElementById( module + module_instance_id ).style.borderBottomStyle = style;
}


function set_padding_left( module, module_instance_id, padding_width )
{
	document.getElementById( module + module_instance_id ).style.paddingLeft = padding_width + 'px';
}
function set_padding_right( module, module_instance_id, padding_width )
{
	document.getElementById( module + module_instance_id ).style.paddingRight = padding_width + 'px';
}
function set_padding_top( module, module_instance_id, padding_width )
{
	document.getElementById( module + module_instance_id ).style.paddingTop = padding_width + 'px';
}
function set_padding_bottom( module, module_instance_id, padding_width )
{
	document.getElementById( module + module_instance_id ).style.paddingBottom = padding_width + 'px';
}

function set_margin_left( module, module_instance_id, margin_width )
{
	document.getElementById( module + module_instance_id ).style.marginLeft = margin_width + 'px';
}
function set_margin_right( module, module_instance_id, margin_width )
{
	document.getElementById( module + module_instance_id ).style.marginRight = margin_width + 'px';
}
function set_margin_top( module, module_instance_id, margin_width )
{
	document.getElementById( module + module_instance_id ).style.marginTop = margin_width + 'px';
}
function set_margin_bottom( module, module_instance_id, margin_width )
{
	document.getElementById( module + module_instance_id ).style.marginBottom = margin_width + 'px';
}

/*================================
	PREVIEW MODE TOGGLE
=================================*/
var preview = false;
$(document).ready(function(){

	$('#previewMode').click(function() {
		preview;
		if(preview == false)
		{
			$('div.cmsEditingBox').hide(100);
			preview = true;
		}
		else
		{
			$('div.cmsEditingBox').show(100);
			preview = false;
		}
	});
});
