/* 31-05 lightbox */
//$('.bg-lightbox').height($(document).height()).show();

function installlightboxClose() {
    $('.lightbox .close').click(closelightbox);
}

function openLightbox(video, image) {
    var html = "";
    
    if (!FlashDetect.installed) {
        resetBoxes();
        video = video.replace("flv", "m4v");
        alert(video);
        html += "<video width=\"545\" id=\"html5video\" height=\"314\" controls=\"controls\" autoplay>";
        html += "<source src=\"" + video + "\" type=\"video/mp4\" />";
        html += "</video>";
        $('.lb-video').html(html);
        document.getElementById("html5video").play();
    }
    else {
        html += '<object id="player" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" name="player" width="545" height="314">'
        html += '<param name="movie" value="swf/player-licensed.swf" />';
        html += '<param name="allowfullscreen" value="true" />';
        html += '<param name="allowscriptaccess" value="always" />';
        html += '<param name="flashvars" value="file=' + video + '&image=' + image + '" />';
        /*html+= '<object type="application/x-shockwave-flash" data="swf/player-licensed.swf" width="545" height="314">';
        html += '<param name="movie" value="swf/player-licensed.swf" />';
        html += '<param name="allowfullscreen" value="true" />';
        html += '<param name="allowscriptaccess" value="always" />';
        html += '<param name="flashvars" value="file=' + video + '&image=' + image + '" />';
        html += '<p><a href="http://get.adobe.com/flashplayer">Get Flash</a> to see this player.</p>';
        html += '</object>';*/
        html += "<embed type='application/x-shockwave-flash' src='swf/player-licensed.swf' width='545' height='314' bgcolor='undefined' allowscriptaccess='always' allowfullscreen='true' wmode='transparent' flashvars='file=" + video + '&image=' + image + "' />";
        html += '</object>';
        $('.lb-video').html(html);
    }


    $('.bg-lightbox').height($(document).height()).show();
    $('.lightbox').css('top', '-500px').animate({ top: 85 }, 2500);
    $.scrollTo($('.lightbox'), 800);
}

function closelightbox() {
    elipticBoxes();
    $('.lightbox').animate({ top: "-500px" }, 2500, function () { $('.bg-lightbox').hide(); $('.lb-video').html(''); });

}


/* /31-05 lightbox */

function installTextResize() {

    $(".sizeIncrease").click(function () {
        var currentFontSize = $('.resizableText').css('font-size');
        var currentFontSizeNum = parseFloat(currentFontSize, 10);
        var newFontSize = currentFontSizeNum + 1;
        if (newFontSize < 12)
            $('.resizableText').css('font-size', newFontSize);
        return false;
    });
    // Decrease Font Size
    $(".sizeDecrease").click(function () {
        var currentFontSize = $('.resizableText').css('font-size');
        var currentFontSizeNum = parseFloat(currentFontSize, 10);
        var newFontSize = currentFontSizeNum - 1;
        if (newFontSize > 8)
            $('.resizableText').css('font-size', newFontSize);
        return false;
    });
}

function installTabs() {
    $('.aContactTab').each(function () {
        $(this).find('.tab2').click(function () {
            $(this).parent().parent().find('fieldset').hide();
            $(this).parent().parent().find('.wantContact').show();
            $(this).parent().find('a').removeClass('on');
            $(this).addClass('on');
        });

        $(this).find('.tab3').click(function () {
            $(this).parent().parent().find('fieldset').hide();
            $(this).parent().parent().find('.sendMessage').show();
            $(this).parent().find('a').removeClass('on');
            $(this).addClass('on');
        });

    });
}

function initAgentList() {

    $('fieldset').hide();
    installTabs();
}



function installDetailTabs() {
    $('.tab2').click(function () {
        $('fieldset').hide();
        $('.wantContact').show();
        $('.aContactTab a').removeClass('on');
        $(this).addClass('on');
    });

    $('.tab3').click(function () {
        $('fieldset').hide();
        $('.sendMessage').show();
        $('.aContactTab a').removeClass('on');
        $(this).addClass('on');
    });
}


function initAgentDetail() {
    $('fieldset').hide();
    installDetailTabs();

}


function installProdTab() {
    var last = $('.prodTab .tabs a').length;
    $('.prodTab .tabs a').each(function (index) {

        if ($(this).hasClass('on') && index == 0) {
            $(this).addClass('firstOn');
            $(this).prepend("<img src='img/x.gif' class='left' />");
        }
        else if (!$(this).hasClass('on') && index == 0) {
            $(this).addClass('firstOff');
            $(this).prepend("<img src='img/x.gif' class='left' />");
        }
        else if ($(this).hasClass('on') && index == last - 1) {
            $(this).addClass('lastOn');
            $(this).append("<img src='img/x.gif' class='right' />");
        }
        else if (!$(this).hasClass('on') && index == last - 1) {
            $(this).addClass('lastOff');
            $(this).append("<img src='img/x.gif' class='right' />");
        }

    });

    $('.prodTab .tabs .on').each(function () {
        $(this).prepend("<img src='img/x.gif' class='left' />");
        $(this).append("<img src='img/x.gif' class='right' />");

    });

}

function installBannerEffects() {
    $('.bannerEffect').mouseenter(function () { $(this).find('a').css('text-decoration', 'underline') });
    $('.bannerEffect').mouseleave(function () { $(this).find('a').css('text-decoration', 'none') });
}

function initContactForm() {
    $('.contactForm').hide();
    $('.internet').click(function () {
        if ($('.internet').hasClass('internetOn')) {
            $('.contactForm').hide();
            $(this).removeClass('internetOn');
        }
        else {
            $('.contactForm').show();
            $(this).addClass('internetOn');
        }
    });

}






/* tooltips */
function installTooltip(element, content) {
    var elementId = $(element).attr('id');
    var html = '<div class="tooltip" id="tooltip' + elementId + '"><a href="javascript: closeTooltips(\'#tooltip' + elementId + '\');" title="Fechar" class="close"><!-- --></a>';
    html += '<table><tr><td>' + content + '</td></tr></table>';

    $('body').append(html);

    $(element).css('cursor', 'pointer');
    $(element).click(function () {

        var position = $(this).offset();
        var tooltipLeft = position.left - 10;
        var tooltipTop = position.top - 165;
        $('#tooltip' + elementId).css({ 'top': tooltipTop, 'left': tooltipLeft });

        $('#tooltip' + elementId + ':visible').fadeOut();
        $('#tooltip' + elementId + ':hidden').fadeIn();
    });
}

function closeTooltips(me) {
    $(me).fadeOut();
}




function partnerChildListeners() {
    $('#addPartner').click(getPartnerVal);
    $('#removePartner').click(getPartnerVal);
}

function getPartnerVal() {
    if ($("input[name='addRemovePartner']:checked").attr('id') == 'addPartner')
        $('#partnerData').show();
    else
        $('#partnerData').hide();
}



function childrenListeners() {
    $('#addChild').click(getChildrenVal);
    $('#removeChild').click(getChildrenVal);
}

function getChildrenVal() {
    if ($("input[name='addRemoveChild']:checked").attr('id') == 'addChild')
        $('#childrenData').show();
    else
        $('#childrenData').hide();
}

/* Assistente Interactivo */

/* first step variabels */
function getFirstFormChoice() {
    var area = $('input[name="q1"]:checked').val();
    //alert(area);
    //alert(area);
    if (area == undefined) {
        showError(true);
        markFirstPanelWithError();
    }
    else {
        loadForm(area);
    }
}

function resetButtons() {
    $('#btn-continuar, #btn-voltar').unbind();
}

function initAI() {
    resetButtons();
    $('#btn-continuar').click(getFirstFormChoice);
    $('ul li input').each(function () {
        $(this).click(function () {
            removeErrorFromFirstPanel();
        });
    });

    if ($('#ai-right img').attr('src').indexOf('start') < 0) {
        var img = new Image();
        img.src = "img/AI/right_start.jpg";
        img.style.display = "none";
        img.className = "new";
        $('.ai-right img').addClass('to-remove');
        document.getElementById('ai-right').appendChild(img);
        /*$('#ai-right .new').load(function()
        {
        $(this).fadeIn();
        $('#ai-right .to-remove').fadeOut(1000, function()
        { 
        $(this).remove();
        });
        });*/
        loadRightImage();
    }


}

function loadRightImage() {
    $('#ai-right .new').load(function () {
        $('#ai-right .to-remove').fadeOut(1000, function () {
            $('#ai-right .new').fadeIn();
            $(this).remove();
        });

    });
}

function unbindFirstForm() {
    $('ul li input').each(function () {
        $(this).unbind();
    });
}


/*function setStep(step)
{
$('.step-chooser').removeClass().addClass('step-' + step);
}

function showFirstForm()
{
$('.panel-title').show();
$('.first-panel').show();
}

function hideFirstForm()
{
$('.panel-title').hide();
$('.first-panel').hide();
}*/

var firstFormErrorMsg = 'Por favor fa&ccedil;a a sua selec&ccedil;&atilde;o.';
var formErrorMsg = 'Verifique os campos assinalados a vermelho.';
function showError(firstFormError) {
    if (firstFormError) {
        $('.form-error label').html(firstFormErrorMsg);
    }
    else {
        $('.form-error label').html(formErrorMsg);
    }
    $('.form-error').show();
}

function hideError() {
    $('.form-error').hide();
}

function markFirstPanelWithError() {
    $('.title-q1, .title-q2, .title-q3').addClass('title-error');
}

function removeErrorFromFirstPanel() {
    $('.title-q1, .title-q2, .title-q3').removeClass('title-error');
    unbindFirstForm();
    hideError();
}


/* LOAD FORMS */
function loadForm(formName) {
    $('#loading-form').height($(document).height());
    $('#loading-form').fadeIn();
    var pageLoad = "forms/";
    if (formName == "automovel") {
        pageLoad += "form_automovel";
    }
    else if (formName == "start") {
        pageLoad += "form_start";
    }
    else if (formName == "mota") {
        pageLoad += "form_mota";
    }
    else if (formName == "casa") {
        pageLoad += "form_casa";
    }


    pageLoad += ".html";

    $.ajax({
        url: pageLoad,
        cache: false,
        success: function (html) {
            //alert("sucess");
            $('#form-loader').html(html);
            $('#loading-form').stop().fadeOut();

        },
        error: function () {
            alert("AJAX error");
        }
    });

}
/****************************************/
/* 				AUTOMOVEL 				*/
/****************************************/
function automovelInit() {
    $('#car-license-plate-date').datepicker(
	{
	    showOn: "button",
	    buttonImage: "img/ico_calendar.gif",
	    buttonImageOnly: true,
	    dateFormat: 'mm/yy',
	    defaultDate: Date.parse('January 1st 2006')
	});

    $('#driver-birthday').datepicker(
	{
	    showOn: "button",
	    buttonImage: "img/ico_calendar.gif",
	    buttonImageOnly: true,
	    dateFormat: 'dd/mm/yy',
	    defaultDate: Date.parse('January 1st 1949')
	});

    $('#voltar').click(function () { loadForm("start"); });
    $('#continuar').click(function () { automovelResult() });

    var img = new Image();
    img.src = "img/AI/right_automovel.jpg";
    img.style.display = "none";
    img.className = "new";
    $('.ai-right img').addClass('to-remove');
    document.getElementById('ai-right').appendChild(img);
    loadRightImage();

}

function automovelResult() {

    if (checkAutomovelHasErrors() > 0) {
        showError(false);
        return;
    }
    hideError();

    var tipo_veiculo = $('input[name="q4"]:checked').val();
    var data_matricula = $('#car-license-plate-date').val();
    //alert(convertTimeToYears(data_matricula.getTime()));
    data_matricula = Date.parse(data_matricula);
    data_matricula = checkDateMatricula(data_matricula);

    var anos_carta = $('input[name="q6"]:checked').val();
    var anos_sem_sinistros = $('input[name="q7"]:checked').val();
    var proteccao_desejada = $('input[name="q8"]:checked').val();
    var data_nascimento = $('#driver-birthday').datepicker("getDate");
    data_nascimento = checkDataDeNascimento(data_nascimento);


    /* ARVORE */
    var produto = "";
    if (tipo_veiculo == "ligeiro_passageiros" && data_nascimento == "30-60" && anos_carta == "carta_mais_4_anos" && anos_sem_sinistros == "sem_sinistros_mais_4_anos" && data_matricula == "2-" && proteccao_desejada == "proteccao_base") {
        produto = "ice3-advantage";
    }

    if (tipo_veiculo == "ligeiro_passageiros" && data_nascimento == "30-60" && anos_carta == "carta_mais_4_anos" && anos_sem_sinistros == "sem_sinistros_mais_4_anos" && data_matricula == "2-" && (proteccao_desejada == "proteccao_elevada" || proteccao_desejada == "proteccao_intermedia")) {
        if (checkPlateYear(data_matricula) == 1) {
            produto = "ice3-premium";
        }
        else {
            produto = "ice3-premium-24";
        }
    }

    if (tipo_veiculo == "ligeiro_passageiros" && data_nascimento == "30-60" && anos_carta == "carta_mais_4_anos" && anos_sem_sinistros == "sem_sinistros_mais_4_anos" && data_matricula != "2-") {
        produto = "ice3-advantage";
    }

    if (tipo_veiculo == "ligeiro_passageiros" && data_nascimento == "30-60" && anos_carta == "carta_mais_4_anos" && anos_sem_sinistros == "sem_sinistros_menos_4_anos" && data_matricula != "8+" && proteccao_desejada == "proteccao_base") {
        produto = "protec-1";
    }

    if (tipo_veiculo == "ligeiro_passageiros" && data_nascimento == "30-60" && anos_carta == "carta_mais_4_anos" && anos_sem_sinistros == "sem_sinistros_menos_4_anos" && data_matricula != "8+" && proteccao_desejada == "proteccao_intermedia") {
        produto = "protec-extra";
    }

    // FALTA AQUI UM

    // / FALTA AQUI UM

    if (tipo_veiculo == "ligeiro_passageiros" && data_nascimento == "30-60" && anos_carta == "carta_mais_4_anos" && anos_sem_sinistros == "sem_sinistros_menos_4_anos" && data_matricula == "8+" && proteccao_desejada == "proteccao_intermedia") {
        produto = "protec-1";
    }

    if (tipo_veiculo == "ligeiro_passageiros" && data_nascimento == "30-60" && anos_carta == "carta_menos_4_anos" && data_matricula != "8+" && proteccao_desejada == "proteccao_base") {
        produto = "protec-1";
    }

    if (tipo_veiculo == "ligeiro_passageiros" && data_nascimento == "30-60" && anos_carta == "carta_menos_4_anos" && data_matricula != "8+" && proteccao_desejada == "proteccao_intermedia") {
        produto = "protec-extra";
    }

    // FALTA AQUI UM

    // / FALTA AQUI UM

    if (tipo_veiculo == "ligeiro_passageiros" && data_nascimento == "30-60" && anos_carta == "carta_menos_4_anos" && data_matricula == "8+") {
        produto = "protec-1";
    }

    if (tipo_veiculo == "ligeiro_passageiros" && (data_nascimento == "18-30" || data_nascimento == "60+") && data_matricula != "8+" && proteccao_desejada == "proteccao_base") {
        produto = "protec-1";
    }

    if (tipo_veiculo == "ligeiro_passageiros" && (data_nascimento == "18-30" || data_nascimento == "60+") && data_matricula != "8+" && proteccao_desejada == "proteccao_intermedia") {
        produto = "protec-extra";
    }

    if (tipo_veiculo == "ligeiro_passageiros" && (data_nascimento == "18-30" || data_nascimento == "60+") && data_matricula != "8+" && proteccao_desejada == "proteccao_elevada") {
        produto = "protec-confort-plus";
    }

    if (tipo_veiculo == "ligeiro_passageiros" && (data_nascimento == "18-30" || data_nascimento == "60+") && data_matricula == "8+") {
        produto = "protec-1";
    }


    /* MERCADORIAS */
    if (tipo_veiculo == "ligeiro_mercadorias" && data_nascimento != "" && data_matricula != "8+" && proteccao_desejada == "proteccao_base") {
        produto = "protec-1";
    }

    if (tipo_veiculo == "ligeiro_mercadorias" && data_nascimento != "" && data_matricula != "8+" && proteccao_desejada == "proteccao_intermedia") {
        produto = "protec-extra";
    }

    if (tipo_veiculo == "ligeiro_mercadorias" && data_nascimento != "" && data_matricula != "8+" && proteccao_desejada == "proteccao_elevada") {
        produto = "protec-confort-plus";
    }

    if (tipo_veiculo == "ligeiro_mercadorias" && data_nascimento != "" && data_matricula == "8+") {
        produto = "protec-1";
    }



    if (!$('#' + produto).is(':visible')) {
        if ($('.insurance-info').is(':visible')) {
            $('.insurance-info:visible').slideUp(1000, function () {
                $('#' + produto).slideDown();
            });
        }
        else {
            $('#' + produto).slideDown();
        }
    }

}

function checkAutomovelHasErrors() {
    var errors = 0;
    $('.title-error').removeClass('title-error');
    var tipo_veiculo = $('input[name="q4"]:checked').val();
    if (tipo_veiculo == undefined) {
        $('.title-q4').addClass('title-error');
        errors++;
    }

    var data_matricula = $('#car-license-plate-date').val();
    if (data_matricula == "") {
        $('.title-q5').addClass('title-error');
        errors++;
    }

    var anos_carta = $('input[name="q6"]:checked').val();
    if (anos_carta == undefined) {
        $('.title-q6').addClass('title-error');
        errors++;
    }

    var anos_sem_sinistros = $('input[name="q7"]:checked').val();
    if (anos_sem_sinistros == undefined) {
        $('.title-q7').addClass('title-error');
        errors++;
    }

    var proteccao_desejada = $('input[name="q8"]:checked').val();
    if (proteccao_desejada == undefined) {
        $('.title-q8').addClass('title-error');
        errors++;
    }

    var data_nascimento = $('#driver-birthday').val();
    if (data_nascimento == "") {
        $('.title-q9').addClass('title-error');
        errors++;
    }

    return errors;
}

function checkDataDeNascimento(birthdate) {

    var yearsAgo30 = Date.parse('t - 30 y');
    var yearsAgo60 = Date.parse('t - 60 y');
    if (birthdate.between(yearsAgo60, yearsAgo30)) {
        return "30-60";
    }

    var yearsAgo18 = Date.parse('t - 18 y');
    if (birthdate.between(yearsAgo30, yearsAgo18)) {
        return "18-30";
    }

    if (birthdate.compareTo(yearsAgo60) == -1) {
        return "60+";
    }

    return "";
}

function checkDateMatricula(platedate) {
    var yearsAgo2 = Date.parse('t - 2 y');
    var now = new Date();
    if (platedate.between(yearsAgo2, now)) {
        return "2-";
    }

    var yearsAgo8 = Date.parse('t - 8 y');
    if (platedate.between(yearsAgo8, yearsAgo2)) {
        return "2-8";
    }

    if (platedate.compareTo(yearsAgo8) == -1) {
        return "8+";
    }
    return "";
}

function checkPlateYear(platedate) {
    var now = new Date()
    var yearAgo1 = Date.parse('t - 1 y');
    if (platedate.between(yearAgo1, now)) {
        return 1;
    }
    return 2;
}


/****************************************/
/* 				MOTA	 				*/
/****************************************/
function motaInit() {
    $('#voltar').click(function () { loadForm("start"); });
    $('#continuar').click(function () { motaResult() });

    var img = new Image();
    img.src = "img/AI/right_mota.jpg";
    img.style.display = "none";
    img.className = "new";
    $('.ai-right img').addClass('to-remove');
    document.getElementById('ai-right').appendChild(img);
    loadRightImage();
}

function motaResult() {
    if (checkMotaHasErrors() > 0) {
        showError(false);
        return;
    }
    hideError();

    var tipo_mota = $('input[name="q10"]:checked').val();
    var proteccao_desejada = $('input[name="q11"]:checked').val();
    var produto = "";
    /* ARVORE */
    if (tipo_mota == "tipo_motociclo" && proteccao_desejada == "proteccao_base") {
        produto = "protec-2r-rc";
    }

    if (tipo_mota == "tipo_motociclo" && proteccao_desejada == "proteccao_elevada") {
        produto = "protec-2r-moto";
    }

    if (tipo_mota == "tipo_ciclomotor" && proteccao_desejada == "proteccao_base") {
        produto = "protec-2r-rc";
    }

    if (tipo_mota == "tipo_ciclomotor" && proteccao_desejada == "proteccao_elevada") {
        produto = "protec-2r-ciclo";
    }

    if (!$('#' + produto).is(':visible')) {
        if ($('.insurance-info').is(':visible')) {
            $('.insurance-info:visible').slideUp(1000, function () {
                $('#' + produto).slideDown();
            });
        }
        else {
            $('#' + produto).slideDown();
        }
    }
}

function checkMotaHasErrors() {
    var errors = 0;
    $('.title-error').removeClass('title-error');
    var tipo_mota = $('input[name="q10"]:checked').val();
    if (tipo_mota == undefined) {
        $('.title-q10').addClass('title-error');
        errors++;
    }

    var proteccao_desejada = $('input[name="q11"]:checked').val();
    if (proteccao_desejada == undefined) {
        $('.title-q11').addClass('title-error');
        errors++;
    }
    return errors;
}

/****************************************/
/* 				CASA	 				*/
/****************************************/
function casaInit() {
    $('#voltar').click(function () { loadForm("start"); });
    $('#continuar').click(function () { casaResult() });

    var checkboxes = $("input[name='q12']");
    $(checkboxes).change(function () {
        checkIdadeConstrucao();
    });


    var img = new Image();
    img.src = "img/AI/right_casa.jpg";
    img.style.display = "none";
    img.className = "new";
    $('.ai-right img').addClass('to-remove');
    document.getElementById('ai-right').appendChild(img);
    loadRightImage();
}

function casaResult() {
    if (checkCasaHasErrors() > 0) {
        showError(false);
        return;
    }
    hideError();

    /* ARVORE */
    var produto = "";
    var idade_construcao = $('input[name="q12"]:checked').val();
    var cobertura = $('input[name="q13"]:checked').val();
    var proteccao_desejada = $('input[name="q14"]:checked').val();
    if (cobertura == "cobertura_edificio_recheio" && proteccao_desejada == "proteccao_base") {
        produto = "domus-mesus";
    }

    if (cobertura == "cobertura_edificio_recheio" && proteccao_desejada == "proteccao_intermedia") {
        produto = "domus-mesus";
    }

    if (cobertura == "cobertura_edificio_recheio" && proteccao_desejada == "proteccao_elevada") {
        produto = "domus-topus";
    }

    if (cobertura == "cobertura_edificio" && proteccao_desejada == "proteccao_base") {
        produto = "domus-mesus";
    }

    if (cobertura == "cobertura_edificio" && proteccao_desejada == "proteccao_intermedia") {
        produto = "domus-mesus";
    }

    if (cobertura == "cobertura_edificio" && proteccao_desejada == "proteccao_elevada") {
        produto = "domus-topus";
    }

    if (!$('#' + produto).is(':visible')) {
        if ($('.insurance-info').is(':visible')) {
            $('.insurance-info:visible').slideUp(1000, function () {
                $('#' + produto).slideDown();
            });
        }
        else {
            $('#' + produto).slideDown();
        }
    }

}

function checkIdadeConstrucao() {

    var idade_construcao = $('input[name="q12"]:checked').val();
    if (idade_construcao == "idade_mais_30") {
        $('.title-error').removeClass('title-error');
        hideError();
        $('#fs-cobertura, #fs-proteccao, #continuar').fadeOut();
        $('.insurance-house-contact').fadeIn();

    }
    else {
        $('#fs-cobertura, #fs-proteccao, #continuar').fadeIn();
        $('.insurance-house-contact').fadeOut();
    }
}

function checkCasaHasErrors() {
    var errors = 0;
    $('.title-error').removeClass('title-error');
    var idade_construcao = $('input[name="q12"]:checked').val();
    if (idade_construcao == undefined) {
        $('.title-q12').addClass('title-error');
        errors++;
    }

    var cobertura = $('input[name="q13"]:checked').val();
    if (cobertura == undefined) {
        $('.title-q13').addClass('title-error');
        errors++;
    }

    var proteccao_desejada = $('input[name="q14"]:checked').val();
    if (proteccao_desejada == undefined) {
        $('.title-q14').addClass('title-error');
        errors++;
    }
    return errors;
}








/* 27-08 */
function installRightBoxes() {
    
    var flash = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="349" height="471" id="SobreAXA">' +
				'<param name="movie" value="external/presidente/SobreAXA1.swf" />' +
				'<param name="wmode" value="opaque" />' +
				'<!--[if !IE]>-->' +
				'<object type="application/x-shockwave-flash" data="external/presidente/SobreAXA1.swf" width="349" height="471">' +
				'<param name="wmode" value="opaque" />' +
				'<!--<![endif]-->' +
				'<a href="http://www.adobe.com/go/getflashplayer">' +
				'<img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />' +
				'</a>' +
				'<!--[if !IE]>-->' +
				'</object>' +
				'<!--<![endif]-->' +
				'</object>';

    var html5 = '<div class="hpFlash">' +
					'<img src="external/presidente/img/man2.png" class="man" alt="Jo‹o Leandro - CEO Axa Portugal" />' +
					'<a href="#" title="Mensagem do CEO" class="moving-box moving-box-4"><img src="external/presidente/img/box4.png" /></a>' +
					'<a href="http://bsure.webhop.org/AxaPT2011/Marca_axa.aspx" title="Redefinimos standards" class="moving-box moving-box-3"><img src="external/presidente/img/box3.png" /></a>' +
					'<a href="http://bsure.webhop.org/AxaPT2011/porque-axa.aspx" title="Porqu a AXA?" class="moving-box moving-box-2"><img src="external/presidente/img/box2.png" /></a>' +
					'<a href="http://bsure.webhop.org/AxaPT2011/Responsabilidade-corporativa.aspx" title="Responsabilidade Corporativa" class="moving-box moving-box-1"><img src="external/presidente/img/box1.png" /></a>' +
					'<p>Jo&atilde;o Leandro - CEO Axa Portugal</p>' +
				'</div>';

    if (!FlashDetect.installed) {
        
        document.write(html5);
        $(window).load(function () {
            elipticBoxes();
            $('.moving-box-4').click(function (event) {
                event.preventDefault();
                openLightbox('external/presidente/swf/JL.flv', 'external/presidente/swf/preview_joaoleandro.jpg');
            });
        });
    } else {
        document.write(flash);
    }
}

function resetBoxes() {
    $('.moving-box').stop().css(
	{
	    top: "169px",
	    left: "20px",
	    "z-index": 150
	});
    flag2 = flag3 = flag4 = true;
}

function elipticBoxes() {
    movingbox1();
}
var flag2 = true, flag3 = true, flag4 = true;
function movingbox1() {

    $('.moving-box-1').animate({ top: 180, left: 125 }, 1000, function ()	// bottom
    {
        if (flag2) { flag2 = !flag2; movingbox2(); }
        $(this).animate({ top: 169, left: 250 }, 1000, function ()					// right
        {
            $(this).css('z-index', 50);
            $(this).animate({ top: 150, left: 125 }, 1000, function ()				// top
            {
                $(this).animate({ top: 169, left: 20 }, 1000, function ()			// left
                {
                    $(this).css('z-index', 100);
                    movingbox1();
                });
            });
        });
    });
};

function movingbox2() {
    $('.moving-box-2').animate({ top: 180, left: 125 }, 1000, function ()	// bottom
    {
        if (flag3) { flag3 = !flag3; movingbox3(); }
        $(this).animate({ top: 169, left: 250 }, 1000, function ()					// right
        {
            $(this).css('z-index', 50);
            $(this).animate({ top: 150, left: 125 }, 1000, function ()				// top
            {
                $(this).animate({ top: 169, left: 20 }, 1000, function ()			// left
                {
                    $(this).css('z-index', 100);
                    movingbox2();
                });
            });
        });
    });
};

function movingbox3() {
    $('.moving-box-3').animate({ top: 180, left: 125 }, 1000, function ()	// bottom
    {
        if (flag4) { flag4 = !flag4; movingbox4(); }
        $(this).animate({ top: 169, left: 250 }, 1000, function ()					// right
        {
            $(this).css('z-index', 50);
            $(this).animate({ top: 150, left: 125 }, 1000, function ()				// top
            {
                $(this).animate({ top: 169, left: 20 }, 1000, function ()			// left
                {
                    $(this).css('z-index', 100);
                    movingbox3();
                });
            });
        });
    });
};

function movingbox4() {
    $('.moving-box-4').animate({ top: 180, left: 125 }, 1000, function ()	// bottom
    {
        $(this).animate({ top: 169, left: 250 }, 1000, function ()					// right
        {
            $(this).css('z-index', 50);
            $(this).animate({ top: 150, left: 125 }, 1000, function ()				// top
            {
                $(this).animate({ top: 169, left: 20 }, 1000, function ()			// left
                {
                    $(this).css('z-index', 100);
                    movingbox4();
                });
            });
        });
    });
};


