var st = 0; //variable para lo de scroll top

var ff = !document.all && self.innerWidth;
var ie = !ff;
var op = window.opera;

/*var ie = document.all && !self.innerHeight;
var ff = !document.all && document.getElementById;
var op = document.all && self.innerHeight;*/

var dashboardObj = null;
var wrapper = null;
var close_button = null;
var canRefresh = true;

function dashboardObjects()
{
	if (!dashboardObj) dashboardObj = $("dashboard");
	if (!wrapper) wrapper = $("wrapper");
	if (!close_button) close_button = $("close_button");
}

function openDashboard(what)
{
	st = document.documentElement.scrollTop;
	dashboardHeight = ie ? document.documentElement.offsetHeight - 4 : self.innerHeight;
	dashboardObjects();
	
	dashboardObj["style"]["height"] = dashboardHeight + "px";
	dashboardObj["style"]["display"] = "block";
	
	wrapper["style"]["height"] = dashboardHeight - 2 + "px";
	wrapper["style"]["overflow"] = "hidden";
	
	close_button["style"]["display"] = "block";
	$("search_panel").className = "hide";
	
	if (what != "lists" && what != "upload")
		getDashboardFeeds();
}

function closeDashboard()
{
	dashboardObjects();
	$("feedsForo")["style"]["display"] = "none";
	
	if ($("editTitle") && $("editTitle").className == "show")
	{
		var w = ie ? document.documentElement.offsetWidth : self.innerWidth;
		var editTitle = $("editTitle");
		editTitle.style.height = "auto";
		editTitle.style.width = "auto";
		editTitle.style.left = ((w - 76) / 2) + "px";
		editTitle.style.top = ((dashboardHeight - 82) / 2) + "px";
		editTitle.className = "hide";
		
		$("editContent").innerHTML = '<img src="http://images.mcanime.net/images/loading.gif" width="48" height="54" alt="Loading..." />';
	}
	
	dashboardObj["style"]["display"] = "none";
	
	wrapper["style"]["height"] = "auto";
	wrapper["style"]["overflow"] = "auto";
	window.scrollTo(0, st);
	
	close_button["style"]["display"] = "none";
}

function getDashboardFeeds()
{
	if (canRefresh)
	{
		$("feedsContent")["innerHTML"] = '<div align="center"><img src="http://images.mcanime.net/images/loading.gif" width="48" height="54" alt="Loading..." /></div>';
		$("feedsForo")["style"]["display"] = "block";
		var myConn = new XHConn();
		myConn.connect("/mcanimeFeeds/dashboard/", "GET", "", displayFeeds);
		myConn = null;
		canRefresh = false;
	}
}

var displayFeeds = function (oXML)
{
	$("feedsContent")["innerHTML"] = oXML.responseText;
	$("feedsContent")["style"]["maxHeight"] = dashboardHeight - 110 + "px";
	if (ie) $("feedsContent")["style"]["height"] = dashboardHeight - 110 + "px";
	
	canRefresh = true;
}

function processOnkeyup(e)
{
	ie ? key = window.event.keyCode : "";
	ff ? key = e.which : "";
	
	var ctrlPressed = ff ? e.ctrlKey : event.ctrlKey;
	
	if (key == 27 && $("dashboard")["style"]["display"] == "block")
	{
		closeDashboard();
		$("search_panel").className = "hide";
		$("user_lists").className = "hide";
	}
		
	if (key == 120 && ctrlPressed) // F9
		openDashboard();
}

function minMax(spanObj, divId)
{
	if (spanObj["title"] == "min")
	{
		spanObj["title"] = "max";
		spanObj.childNodes[0]["innerHTML"] = "[+]";
		$(divId)["style"]["display"] = "none";
	}
	else
	{
		spanObj["title"] = "min";
		spanObj.childNodes[0]["innerHTML"] = "[-]";
		$(divId)["style"]["display"] = "block";
	}
}

document.onkeyup = processOnkeyup;

