function notset_defaultsto(theVar, theDefault) {
	if (typeof(theVar)=="undefined") {
		theVar = theDefault;
		return theDefault;
	} else {
		return theVar;
	}
}

function popup_imprensa() {
	abrejanela(base_url + "novidades/imprensa_detalhes", 310, 220);
}

function popup_presskit() {
	abrejanela(base_url + "novidades/presskit", 310, 220);
}

function popup_horarios() {
	abrejanela(base_url + "home/horarios", 375, 265);
}

function popup_horario_van() {
	abrejanela(base_url + "home/horarios_van", 730, 480, 'scrollbars=yes');
}

function mostra_galeria_uri(uri, i) {
	// #id=show-jota-quest&num=1
	i = notset_defaultsto(i, "");
	uri = "#id=" + uri;
	if (i != "") uri += "&num=" + i;
	
	url = base_url + "ssp/galerias" + uri;
	abre_galeria(url);	
}

function mostra_galeria(id) {
	url = base_url + "ssp/id_to_uri/id/" + id;
	abre_galeria(url);
}

function abre_galeria(url) {
	abrejanela(url, 670, 480, "location=1");	
}

function abrejanela(theURL, width, height, features) {
	width = notset_defaultsto(width, 500);
	height = notset_defaultsto(height, 333);
	
	features = notset_defaultsto(features, "");
	if (features != "") features += ", ";	
	features += "width="+width + ", height=" + height;
	
	if ( (width != 0) || (height != 0) ) {
		features += ","+centerWindow(width, height);
	}
	window.open(theURL,"imagem",features);
}

//------------------------------------
//-- Funcao que centraliza a janela
//------------------------------------
function centerWindow(largura,altura)
{
    if (document.layers) {
        var xMax = window.outerWidth, yMax = window.outerHeight;
	} else {
	    var xMax = screen.width, yMax = screen.height;
	    if (isNaN(xMax)) xMax = 800;
	    if (isNaN(yMax)) yMax = 600;
	}

    var xOffset = (xMax - largura)/2, yOffset = (yMax - altura)/2;
	return ("top="+ yOffset +",left="+ xOffset +"");
}