var dashboardObj = null;
var wrapper = null;
var close_button = null;
var login = null; //provisional
var imageURL = "";
var resizeWidth = null;

function dashboardLoader()
{
	dashboardHeight = ie ? document.documentElement.clientHeight : self.innerHeight;
	dashboardWidth = document.documentElement.clientWidth;
}

function openDashboard()
{
	if (!dashboardObj) dashboardObj = $("dashboard");
	if (!wrapper) wrapper = $("wrapper");
	if (!close_button) close_button = $("close_button");
	if ($("login")) openLogin(); //provisional
	
	dashboardObj["style"]["height"] = dashboardHeight + "px";
	dashboardObj["style"]["display"] = "block";
	
	wrapper["style"]["height"] = dashboardHeight + "px";
	wrapper["style"]["overflow"] = "hidden";
	
	close_button["style"]["display"] = "block";
	
}

//provisional
function openLogin()
{
	if (!login) login = $("login");
	login["style"]["display"] = "block";
	login["style"]["top"] = (dashboardHeight - login.offsetHeight) / 2 + "px";
	login["style"]["left"] = (dashboardWidth - login.clientWidth) / 2 + "px";
	setTimeout("document.loginForm.username.focus()", 500);
}

function openImageIframe()
{
	var imageFrame = $("image_frame");
	imageFrame["style"]["display"] = "block";
	imageFrame["style"]["top"] = (dashboardHeight - imageFrame.offsetHeight) / 2 + "px";
	imageFrame["style"]["left"] = (dashboardWidth - imageFrame.offsetWidth) / 2 + "px";
}
//--------------------------

function closeDashboard()
{
	if (login) login["style"]["display"] = "none"; //provisional
	if ($("image_frame")) $("image_frame")["style"]["display"] = "none"; //provisional
	if ($("image_preview")) $("image_preview")["style"]["display"] = "none"; //provisional
	
	dashboardObj["style"]["display"] = "none";
	
	wrapper["style"]["height"] = "auto";
	wrapper["style"]["overflow"] = "auto";
	
	close_button["style"]["display"] = "none";
}

function setUploadedImage()
{
	//Creo el <b> donde va la imagen
	var imgB = document.createElement("b");
	imgB["onclick"] = insertImage;
	//Creo el <img> donde va a estar el "thumb" de la imagen
	var imgThumb = document.createElement("img");
	imgThumb["src"] = imageURL;
	imgThumb["className"] = resizeWidth ? "wImg" : "hImg";
	//Le hago el append de [imgThumb] a [imgB]
	imgB.appendChild(imgThumb);
	
	//Creo el <img> del icono de preview
	var imgPreview = document.createElement("img");
	imgPreview["src"] = PATH + "/images/fill.gif";
	imgPreview["className"] = "preview";
	imgPreview["onclick"] = previewImage;
	
	//Creo el <span> donde guardare todo
	var imgSpan = document.createElement("span");
	//Le hago un append de [imgB] y [imgPreview] a [imgSpan]
	imgSpan.appendChild(imgB);
	imgSpan.appendChild(imgPreview);
	//alert(imgSpan["innerHTML"]);
	
	//Ahora le hacemos el append de ambas cosas al <div id="blog_images">
	$("images_cont").insertBefore(imgSpan, $("bi_node"));
	//alert($("blog_images")["innerHTML"]);
}

function previewImage()
{
	var imgObj = this.previousSibling.childNodes[0];
	//alert($("image_preview").childNodes[0]);
	var image_preview = $("image_preview");
	image_preview.childNodes[0]["src"] = imgObj["src"];
	image_preview["style"][ "display"] = "block";
	
	openDashboard();
}

function insertImage()
{
	if (txtAreaName)
	{
		var imgObj = this.childNodes[0];
		$(txtAreaName)["value"] += " [img]" + imgObj["src"] + "[/img] ";
	}
	else
	{
		alert("No has seleccionado un área donde insertar la imagen.");
	}
	//txtAreaName
}

/*var closeX, login;
var dashboard;

function dashboardLoader()
{
	dashboard.style.height = bodyHeight + "px";
}

function openLogin()
{
	login.style.display = "block";
	login.style.top = (bodyHeight - login.clientHeight) / 2 + "px";
	login.style.left = (bodyWidth - login.clientWidth) / 2 + "px";
	setTimeout("document.loginForm.username.focus()", 500);
}

function openDashboard()
{
	dashboardStatus = "open";
	dashboard.style.display = "block";
	closeX.style.display = "block";
	
	if (login)
	{
		openLogin();
	}
	
	setDocumentScroll("hidden");
}

function closeDashboard()
{
	dashboardStatus = "closed";
	for (obj = 0; obj < objectArray.length; obj++)
	{
		if (objectArray[obj])
		{
			objectArray[obj].style.display = "none";
		}
	}
	
	setDocumentScroll("");
}

function setDocumentScroll(scrollValue)
{
	ie ? document.getElementsByTagName("html")[0].style.overflow = scrollValue : "";
	ff ? document.body.style.overflow = scrollValue : "";
}*/