var default_cant_use_PNGs = 0;



var g_prevSize;
function editor_finishLoading()
{
	init_ResizeMonitor(0);
	if (typeof browser_IE_version != "undefined")
		document.body.scroll = 'no';
	else browser_IE_version = 0;

	testAjax();
	createUploaderObject();


	CreateLeftNav("toolBar");
	if (typeof CreateLeftNav_second == "function") CreateLeftNav_second("toolBar");

//	leftMenu_onClick(document.getElementById("tool_tools"));
	leftMenu_onClick(document.getElementById("tool_text"));
	leftMenu_onClick(document.getElementById("tool_extra_comm"));

	createLeftMenu("toolBar");
	
	
	var m_el = document.body.firstChild;
	while (m_el)
	{
		if (m_el && m_el.id && m_el.className && m_el.className == 'topEditBar')
		{
			sayDebugMessage("Tool edit: "+m_el.id);
			defineTopEditbar(m_el.id);
		}

		m_el = m_el.nextSibling;
	}

	init_ResizeMonitor(1);

	ajaxComm_readPage("");

	if (editor_pageLoaded)
		editor_pageLoaded();
}

function resizeWindow()
{
	var sizeX = g_prevSize.w, sizeY = g_prevSize.h;

	var modalDlg = document.getElementById('modal-owner');
	if (modalDlg && modalDlg.style.display == "block")
	{
		var div1 = document.getElementById('modal-overlay');
		if (div1) div1.style.top = g_prevSize.s + "px";
	
		modalDlg.style.left = (sizeX - parseInt(modalDlg.offsetWidth ))/2 + "px";
		modalDlg.style.top  = (sizeY - parseInt(modalDlg.offsetHeight))/2 + g_prevSize.s + "px";

	}

	var load = document.getElementById('loading-overlay-main');
	if (load)
	{
		load.style.margin = "";
		if (typeof resizeWindow_skipLoadingBox == "undefined" || !resizeWindow_skipLoadingBox)
		{
			load.style.left = (sizeX - parseInt(load.offsetWidth ))/2 + "px";
			load.style.top  = (sizeY - parseInt(load.offsetHeight))/2 + "px";
		} else {
			load.style.left = (sizeX - parseInt(load.offsetWidth ))/2 + "px";
			load.style.top  = (sizeY - parseInt(load.offsetHeight) - 40) + "px";
		}
	}
	
	if (sizeX < 100 || sizeY < 100 || !document.getElementById("footerBar"))
		return;

	sayDebugMessage("Body: " + sizeX + "x" + sizeY);

	var footerHeight = parseInt(document.getElementById("footerBar").offsetHeight);
	var leftMenu = document.getElementById("toolBar");
	leftMenu.style.height = (sizeY - parseInt(leftMenu.offsetTop)-footerHeight) + "px";


	var editLocation  = document.getElementById('main_edit_area' );
	editLocation .style.top    = parseInt(leftMenu.offsetTop)+"px";
	editLocation .style.width  = (sizeX - parseInt(leftMenu.offsetWidth)) + "px";
	editLocation .style.height = (sizeY - parseInt(editLocation.offsetTop)-footerHeight) + "px";

	var m_el = document.getElementById('main_edit_area_holder').firstChild;
	while (m_el)
	{
		if (m_el.tagName == "DIV")
		{
			m_el.style.minHeight = editLocation.style.height;
			break;
		}

		m_el = m_el.nextSibling;
	}

	if (m_editBars)
		for (i=0; i<m_editBars.length; i++)
		{
			var cur = document.getElementById(m_editBars[i]);

			cur.style.top   = parseInt(leftMenu.offsetTop)+"px";
			cur.style.left  = parseInt(leftMenu.offsetWidth)+"px";
			cur.style.width = (sizeX - parseInt(editLocation.offsetLeft)) + "px";
		}

	return false;
}



var m_showhideDivs = new Array(),
	m_showhideDivsInterval = 0;
var showhideAnim_growY = 1,
	showhideAnim_alpha = 2;

function addShowHideAnimation(id, to_show, anim_type, param, timeoutBeforeStart)
{
	var i;
	for (i=0; i<m_showhideDivs.length; i++)
		if (m_showhideDivs[i][0] == id)
		{
			if (to_show != m_showhideDivs[i][1])
			{
				m_showhideDivs[i][1] = !m_showhideDivs[i][1];
				m_showhideDivs[i][3] = 10 - m_showhideDivs[i][3];
			}

			m_showhideDivs[i][5] = timeoutBeforeStart;

			break;
		}

	if (i == m_showhideDivs.length)
	{
		if (to_show)
		{
			var curEl = document.getElementById(id);

			if (id == 'loading-overlay' && parseInt(curEl.style.zIndex) > 0) return;

			if (anim_type == showhideAnim_growY) curEl.style.heigth = "0px";
			if (anim_type == showhideAnim_alpha)
			{
				try { curEl.style.filter  = "alpha(opacity=0)"; } catch (e) {}
				try { curEl.style.opacity = 0;                  } catch (e) {}
			}
	
			if (id == 'loading-overlay')
			{
				curEl.style.zIndex     = 1200;
				curEl.style.visibility = "visible";
			} else
				curEl.style.display = "block";
		}

		m_showhideDivs.push( new Array(id, to_show, anim_type, 0, param, timeoutBeforeStart) );
	}


	if (!m_showhideDivsInterval)
		m_showhideDivsInterval = window.setInterval(intervalShowHide, 25);

	return true;
}

function intervalShowHide()
{
	try {
		for (i=0; i<m_showhideDivs.length; i++)
		{
			var cur_info = m_showhideDivs[i], curEl = document.getElementById(cur_info[0]);
			var cur_step = (cur_info[1]) ? cur_info[3] : 10-cur_info[3];
			
			if (cur_info[5] > 0) cur_info[5] -= 25;
			else {
				switch (cur_info[2])
				{
					case (showhideAnim_growY):
						curEl.style.height = Math.round(cur_step*cur_info[4]/10) + "px";
					break;

					default:
					case (showhideAnim_alpha):
						try { curEl.style.filter  = "alpha(opacity=" + (cur_step*10) + ")"; } catch (e) {}
						try { curEl.style.opacity = cur_step/10.0; } catch (e) {}
					break;
				}		
				
				m_showhideDivs[i][3] += 1;
				if (m_showhideDivs[i][3] >= 11)
				{
					if (!cur_info[1])
					{
						if (cur_info[0] == 'loading-overlay')
						{
							   curEl.style.zIndex  = -1200;
							   curEl.style.visible = "hidden";
						} else curEl.style.display = "none";
					} else {
						if ( cur_info[2] == showhideAnim_growY) curEl.style.height = "auto";
					}

					if (cur_info[2] == showhideAnim_alpha)
					{
						try { curEl.style.filter  = "" ; } catch (e) {}
						try { curEl.style.opacity = "1"; } catch (e) {}
					}

					m_showhideDivs.splice(i--, 1);
				}
			}
		}
	} catch (e) { m_showhideDivs = new Array(); }

	if (m_showhideDivs.length == 0)
	{
		window.clearInterval(m_showhideDivsInterval);
		m_showhideDivsInterval = 0;
	}
}

function selectSelectOption(sel, value, defValue)
{
	if (typeof(sel) == "string"   ) sel = document.getElementById(sel);
	if (typeof(val) == "undefined") val = defValue;
	if (!sel || !value) return -1;

	for (i=0; i<sel.options.length; i++)
		if (sel.options[i].value == value)
		{
			try { sel.selectedIndex = i; } catch (e) {}
			return i;
		}

	return -1;
}

if (typeof window.offscreenBuffering != "undefined")
	window.offscreenBuffering = true;


function new_window_open(href, target, m_size)
{
	if (typeof m_size != "number")
		m_size = 240;

	window.open(href, target, "directories=no,fullscreen=no,width=600,height="+m_size+",left=100,top=100,location=no,menubar=no,resizable=no,scrollbars=yes,status=yes,titlebar=no,toolbar=no,centerscreen=yes,chrome=yes", false);
	return false;
}