
function iniciar ( )
{
	// En que sitio estamos (blog,wiki,web)
	var sitio = obtenerSitio();
	
	// Nifty
	if (sitio == "web")
	{
		Nifty("li.actual","small");
		Nifty("div.contratarResumen","normal");
	}
	else if (sitio == "wiki")
	{
		Nifty("li.actual","small");
	}
	else if (sitio == "blog")
	{
		Nifty("div.wp-polls","big");
		Nifty("a.more-link","normal");
		Nifty("h3.tituloComentarios","big,tl,tr");
		Nifty("div.cajaComentario","big");
		Nifty("div.escribirComentario","big");
		Nifty("div.archivoTitulo","normal");
	}
	
	// Menues
	var cmMenuPrincipal = cmDrawFromText('menuPrincipal', 'hbr', cmThemePrincipal, 'ThemePrincipal');
	var cmMenuContacto  = cmDrawFromText('menuContacto', 'hbr', cmThemeContacto, 'ThemeContacto');
	
	// Cargar imagenes CSS
	//precargarImagenesCss();
	
	// LightBox
	initLightbox();
}

function precargarImagenesCss()
{
	if (document.all)
	{
		for (var s = 0; s < document.styleSheets.length; s++)
			for (var r = 0; r < document.styleSheets[s].rules.length; r++)
				if (document.styleSheets[s].rules[r].style.backgroundImage)
					precargarImagen(document.styleSheets[s].rules[r].style.backgroundImage);
	}
	else if (document.getElementById)
	{
		for (var s = 0; s < document.styleSheets.length; s++)
		{
			for (var r = 0; r < document.styleSheets[s].cssRules.length; r++)
			{
				document.styleSheets[s].cssRules[r].sheetIndex = s;
				document.styleSheets[s].cssRules[r].ruleIndex = s;
				if (document.styleSheets[s].cssRules[r].style.backgroundImage)
					precargarImagen(document.styleSheets[s].cssRules[r].style.backgroundImage);
			}
		}
	}
}
function precargarImagen ( uri )
{
	uri = uri.replace(/^url\(/,"").replace(/\)/,"");
	if (uri != "none" && uri != "")
	{
		var img = new Image();
		img.src = uri;
	}
}

function obtenerSitio()
{
	var uri = parseUri(document.location);
	var sitio;
	if (uri["path"].match(/^\/(wiki|mediawiki)/))
		sitio = "wiki";
	else if (uri["path"].match(/^\/blog\//))
		sitio = "blog";
	else
		sitio = "web";
	return sitio;
}

function mostrarOcultar ( id, force )
{
	var obj = document.getElementById(id);
	if (obj)
	{
		var mostrar = obj.style.display == "none" ? 1 : 0 ;
		if (force == 1 || force == 0)
			mostrar = force;
		if (mostrar)
		{
			obj.style.display = "block"
			//setCookie("mostrar_"+id, 1);
		}
		else
		{
			obj.style.display = "none"
			//setCookie("mostrar_"+id, 0);
		}
		return true;
	}
	else
		return false;
}

function setCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function getCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function delCookie(name)
{
	setCookie(name,"",-1);
}

function elegirContacto ( pais_id )
{
	alert(pais_id);
}

function localizacion ( prid, path )
{
	var uri = parseUri(document.location);
	document.location = "http://" + uri["authority"] + "/apps/localizacion.php?l=" + prid + "&p=" + path ;
	//document.location = "http://" + uri["authority"] + uri["path"] + "?l=" + prid ;
}

/* parseUri JS v0.1, by Steven Levithan (http://badassery.blogspot.com)
Splits any well-formed URI into the following parts (all are optional):
----------------------
• source (since the exec() method returns backreference 0 [i.e., the entire match] as key 0, we might as well use it)
• protocol (scheme)
• authority (includes both the domain and port)
    • domain (part of the authority; can be an IP address)
    • port (part of the authority)
• path (includes both the directory path and filename)
    • directoryPath (part of the path; supports directories with periods, and without a trailing backslash)
    • fileName (part of the path)
• query (does not include the leading question mark)
• anchor (fragment)
*/
function parseUri(sourceUri){
    var uriPartNames = ["source","protocol","authority","domain","port","path","directoryPath","fileName","query","anchor"];
    var uriParts = new RegExp("^(?:([^:/?#.]+):)?(?://)?(([^:/?#]*)(?::(\\d*))?)?((/(?:[^?#](?![^?#/]*\\.[^?#/.]+(?:[\\?#]|$)))*/?)?([^?#/]*))?(?:\\?([^#]*))?(?:#(.*))?").exec(sourceUri);
    var uri = {};
    
    for(var i = 0; i < 10; i++){
        uri[uriPartNames[i]] = (uriParts[i] ? uriParts[i] : "");
    }
    
    // Always end directoryPath with a trailing backslash if a path was present in the source URI
    // Note that a trailing backslash is NOT automatically inserted within or appended to the "path" key
    if(uri.directoryPath.length > 0){
        uri.directoryPath = uri.directoryPath.replace(/\/?$/, "/");
    }
    
    return uri;
}

// LOADING
function loadingPosicionar ( )
{
	/*
	var loading = document.getElementById("loading");
	var arrayScroll = getPageScroll();
	loading.style.top = arrayScroll[1] + "px";
	*/
}
function loadingMostrar ( )
{
	/*
	mostrarOcultar("loading",1);
	loadingPosicionar();
	*/
}
function loadingOcultar ( )
{
	/*
	mostrarOcultar("loading",0);
	*/
}

// Dump de variables! :-)
function dump(arr,level)
{
	var dumped_text = "";
	if(!level) level = 0;
	//The padding given at the beginning of the line.
	var level_padding = "";
	for(var j=0;j<level+1;j++) level_padding += "    ";
	
	if(typeof(arr) == 'object') { //Array/Hashes/Objects
		for(var item in arr) {
			var value = arr[item];
			
			if(typeof(value) == 'object') { //If it is an array,
				dumped_text += level_padding + "'" + item + "' ...\n";
				dumped_text += dump(value,level+1);
			} else {
				dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
			}
		}
		} else { //Stings/Chars/Numbers etc.
		dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
	}
	return dumped_text;
} 
