var $j = jQuery.noConflict();
var endereco_portal = '';
var endereco_jornal = '';

var imgload = '<div style="text-align: center"><img src="http://www.imprensaregional.com.pt/~cms/templates/images/loader.gif" alt="loading..." /></div>';


$j(document).ready(function()
{
	try
	{
		endereco_portal = $j('#endereco_portal').html();
		endereco_jornal = $j('#endereco_jornal').html();
	}
	catch(o){}
});


function fo_muda_edicao(accao)
{
	var edicao_sel = $j('#fo_edicoes').val();

	if(edicao_sel == '--arquivo--')
	{
		accao = 'edicao-arquivo';
		edicao_sel = '';
	}
	else if(edicao_sel == '--activas--')
	{
		accao = 'edicao';
		edicao_sel = '';
	}

	window.location.href = endereco_jornal+'/pagina/'+accao+'/'+edicao_sel;
}

function fo_calendario_v2(data_evento)
{
	if(endereco_portal == ''){
		endereco_portal = $j('#endereco_portal').html();
		endereco_jornal = $j('#endereco_jornal').html();
	}

	var id_elem = "#calendario_holder_v2";
	var inf = '';

	$j.ajaxSetup ({cache: false});

    $j.post(
        endereco_portal+"/~cms/modulos/agenda/class.eventos_proc.php",
        {get_calendario_v2: "1", data: data_evento},
        function(responseText){$j(id_elem).html(responseText);},
        "html"
    );
}

function get_mes(data)
{
	var new_data = data;
	if(data.length == 10){
		new_data = data.substring(0,7);
	}
	$j('#botao_eventos_mes').attr("href", endereco_jornal+'/pagina/eventos/'+new_data);
	fo_calendario_v2(data);
}

function pick_data(data)
{
	window.location.href = endereco_jornal+'/pagina/eventos/'+data;
}

//METEOROLOGIA inicio//
function ajax_get_meteo(inf)
{
	var id_elem = "#meteorologia";
	$j.ajaxSetup ({cache: false});

    $j(id_elem).html(imgload);

    $j.post(
        endereco_portal+"/~informa_centralizada/index.php",
        {accao: "get_meteo", info: inf, versao: 'v2'},
        function(responseText){$j(id_elem).html(responseText);},
        "html"
    );
}

function ajax_get_meteo_cidades(inf)
{
	var id_elem = "#meteorologia_cidades";

	$j.ajaxSetup ({cache: false});

    $j(id_elem).html(imgload);

    $j.post(
        endereco_portal+"/~informa_centralizada/index.php",
        {accao: "get_meteo_cidades", info: inf, versao: 'v2'},
        function(responseText){$j(id_elem).html(responseText);},
        "html"
    );
}
//METEOROLOGIA fim//

//FARMACIAS inicio//
function ajax_get_farmacias(inf)
{
	var id_elem = "#farmacias";
	$j.ajaxSetup ({cache: false});

    $j(id_elem).html(imgload);

    $j.post(
        endereco_portal+"/~informa_centralizada/index.php",
        {accao: "get_farmacias", info: inf, versao: 'v2'},
        function(responseText){$j(id_elem).html(responseText);},
        "html"
    );
}

function ajax_get_farmacias_cidades(inf)
{
	var id_elem = "#farmacias_cidades";

	$j.ajaxSetup ({cache: false});

    $j(id_elem).html(imgload);

    $j.post(
        endereco_portal+"/~informa_centralizada/index.php",
        {accao: "get_farmacias_cidades", info: inf, versao: 'v2'},
        function(responseText){$j(id_elem).html(responseText);},
        "html"
    );
}
//FARMACIAS fim//

//MARES inicio//
function ajax_get_mares(inf)
{
	var id_elem = "#mares";
	$j.ajaxSetup ({cache: false});

    $j(id_elem).html(imgload);

    $j.post(
        endereco_portal+"/~informa_centralizada/index.php",
        {accao: "get_mares", info: inf, versao: 'v2'},
        function(responseText){$j(id_elem).html(responseText);},
        "html"
    );
}

function ajax_get_mares_cidades(inf)
{
	var id_elem = "#mares_cidades";

	$j.ajaxSetup ({cache: false});

    $j(id_elem).html(imgload);

    $j.post(
        endereco_portal+"/~informa_centralizada/index.php",
        {accao: "get_mares_cidades", info: inf, versao: 'v2'},
        function(responseText){$j(id_elem).html(responseText);},
        "html"
    );
}
//MARES fim//

//BOLSA vertical inicio//
function ajax_get_bolsa_v(inf)
{
	var id_elem = "#bolsa_v";
	$j.ajaxSetup ({cache: false});

    $j(id_elem).html(imgload);

    $j.post(
        endereco_portal+"/~informa_centralizada/index.php",
        {accao: "get_bolsa_v", info: inf, versao: 'v2'},
        function(responseText){$j(id_elem).html(responseText);bolsa_ticker_v();},
        "html"
    );
}

var bolsa_first = 0;
var bolsa_speed = 700;
var bolsa_pause = 2000;

var bolsa_first2 = 0;
var bolsa_speed2 = 700;
var bolsa_pause2 = 2000;

function bolsa_ticker_v()
{
	bolsa_v_removeFirst()
	interval = setInterval(bolsa_v_removeFirst, bolsa_pause);
}

function bolsa_v_removeFirst(){
	bolsa_first = $j('ul#listticker_bolsa_v li:first').html();

	$j('ul#listticker_bolsa_v li:first').animate({opacity: 0}, bolsa_pause).fadeOut('fast',function() {$j('ul#listticker_bolsa_v li:first').remove();bolsa_v_addLast(bolsa_first)});
}

function bolsa_v_addLast(first){
	last = '<li style="display:none">'+first+'</li>';

	$j('ul#listticker_bolsa_v').append(last);

	$j('ul#listticker_bolsa_v li:last').animate({opacity: 1}, bolsa_speed).fadeIn('slow');
}

///////////

function ajax_get_bolsa_h(inf)
{
	var id_elem = "#bolsa_h";
	$j.ajaxSetup ({cache: false});

    //$j(id_elem).html(imgload);
    $j.post(
        endereco_portal+"/~informa_centralizada/index.php",
        {accao: "get_bolsa_h", info: inf, versao: 'v2'},
        function(responseText){
        	$j(id_elem).html(responseText);
        	bolsa_ticker_h();
        },
        "html"
    );
}

function bolsa_ticker_h()
{
	bolsa_h_removeFirst()
	interval = setInterval(bolsa_h_removeFirst, bolsa_pause2);
}

function bolsa_h_removeFirst(){
	bolsa_first2 = $j('ul#listticker_bolsa_h li:first').html();

	$j('ul#listticker_bolsa_h li:first').animate({opacity: 0}, bolsa_pause2).fadeOut('fast',function() {$j('ul#listticker_bolsa_h li:first').remove();bolsa_h_addLast(bolsa_first2)});
}

function bolsa_h_addLast(first){
	last = '<li style="display:none">'+first+'</li>';

	$j('ul#listticker_bolsa_h').append(last);

	$j('ul#listticker_bolsa_h li:last').animate({opacity: 1}, bolsa_speed2).fadeIn('slow');
}
//BOLSA vertical  fim//

// Galeria Multimedia inicio //
function get_gm()
{
	window.location.href = endereco_jornal+'/pagina/galeria-multimedia/'+$j("#list_gm_cat").val()+'?filtro='+$j("#tipo_gm_cat").val();
}

function get_gm_destaque(width, height)
{
	var id_elem = "#fo_gm_destaque";
	$j.ajaxSetup ({cache: false});

    $j(id_elem).html(imgload);

    $j.post(
        endereco_portal+"/~cms/modulos/galeria_multimedia/galeria_multimedia_proc.php",
        {accao: "fo_get_galeria_multimedia_destaque_v2", versao: 'v2', endereco_portal: endereco_portal, endereco_jornal: endereco_jornal, tpl_obj_width: width, tpl_obj_height: height },
        function(responseText){
        	var temp_html = responseText.split("#SEPARADOR#");
        	$j(id_elem).html(temp_html[0]);
        	$j("#fo_gm_destaque_titulo").html(temp_html[1]);
        },
        "html"
    );
}

// Galeria Multimedia fim //

//PAPEL DIGITAL inicio//
function trocar_papel_digital(id_elem,nr_elem)
{
	if(id_elem && nr_elem)
	{
		for(var i=0; i<nr_elem; i++)
		{
			var papel = document.getElementById('id_papeldigital'+i);
			if(id_elem == i)
			{
				papel.style.display = 'block';
				thumb_papel_digital(id_elem);
			}
			else
			{
				papel.style.display = 'none';
			}
		}
	}
}


function thumb_papel_digital(id_elem)
{
	var caminho_papel = $j('#papeldigital_op1_'+id_elem).val();
	var id_swfpapeldigital = $j('#papeldigital_op2_'+id_elem).val();
	var p_width = $j('#papeldigital_op3_'+id_elem).val();
	var p_height = $j('#papeldigital_op4_'+id_elem).val();

	var flashvars = {};

	var params = {};
	params.menu = "false";
	params.wmode = "transparent";
	params.align = 'center';
	params.salign = 'TL';
	var attributes = {};

	swfobject.embedSWF(caminho_papel, id_swfpapeldigital, p_width, p_height, "9.0.0", "../~cms/comuns/swfobject/expressInstall.swf",flashvars,params,attributes);
}



