var PATH_TO_ROOT = "external/presidente/";
var PATH_TO_VIDEOS = PATH_TO_ROOT + "flash-files/swf/";
var PATH_TO_IMAGES = PATH_TO_ROOT + "flash-files/img/";
var PATH_TO_PLAYER = PATH_TO_ROOT + "flash-files/swf/player-licensed.swf";
var PATH_TO_MAIN_ANIM = PATH_TO_ROOT + "flash-files/SobreAXA1.swf";


function installlightboxClose()
{
	$('.lightbox .close').click(closelightbox);
}

function openLightbox(video, image)
{
	var html = "";
	if(!FlashDetect.installed)
	{
		video = video.replace("flv","m4v");
		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="' + PATH_TO_PLAYER + '" />';
		html += '<param name="allowfullscreen" value="true" />';
		html += '<param name="allowscriptaccess" value="always" />';
		html += '<param name="flashvars" value="file=' + video + '&image=' + PATH_TO_VIDEOS + image + '" />';
		html += "<embed type='application/x-shockwave-flash' src='" + PATH_TO_PLAYER + "' width='545' height='314' bgcolor='undefined' allowscriptaccess='always' allowfullscreen='true' wmode='transparent' flashvars='file=" + video + '&image=' + PATH_TO_VIDEOS + image + "' />";
		html += '</object>';
		$('.lb-video').html(html);	
	}
	
	$('.bg-lightbox').offset({ top: 0, left: 0}).height($(document).height()).width($(document).width()).show();
	$('.lightbox').css('top','-500px').animate({ top: 85 }, 2500);
	$.scrollTo( $('.lightbox'), 800 );
}

function closelightbox()
{
	$('.lightbox').animate({top: "-500px"}, 2500, function (){ $('.bg-lightbox').hide(); $('.lb-video').html(''); });
	
}

function installRightBoxes()
{

	var flash = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="349" height="471" id="SobreAXA">' +
				'<param name="movie" value="' + PATH_TO_MAIN_ANIM + '" />' +
				'<param name="wmode" value="opaque" />' +
                '<param name="flashvars" value="rootPath=' + PATH_TO_ROOT + '" />' +
				'<!--[if !IE]>-->' +
				'<object type="application/x-shockwave-flash" data="' + PATH_TO_MAIN_ANIM + '" width="349" height="471">' +
				'<param name="wmode" value="opaque" />' +
                '<param name="flashvars" value="rootPath=' + PATH_TO_ROOT + '" />' +
				'<!--<![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="' + PATH_TO_IMAGES + '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="' + PATH_TO_IMAGES + '04.png" /></a>' +
					'<a href="Marca_axa.aspx" title="Redefinimos standards" class="moving-box moving-box-3"><img src="' + PATH_TO_IMAGES + '/03.png" /></a>' +
					'<a href="porque-axa.aspx" title="Porqu a AXA?" class="moving-box moving-box-2"><img src="' + PATH_TO_IMAGES + '/02.png" /></a>' +
					'<a href="Responsabilidade-corporativa.aspx" title="Responsabilidade Corporativa" class="moving-box moving-box-1"><img src="' + PATH_TO_IMAGES + '01.png" /></a>' +
					'<p>Jo&atilde;o Leandro - CEO Axa Portugal</p>' +
				'</div>';
				
	if(!FlashDetect.installed)
	{
		document.write(html5);
		$(window).load(function () {
		    $('.moving-box-4').click(function (event) {
		        event.preventDefault();
		        openLightbox('JL.flv', 'preview_joaoleandro.jpg');
		    });
		});
	}
	else
	{
		document.write(flash);
	}
}

$(document).ready(function()
{
	if($('.bg-lightbox').length == 0)
	{
		$('body').append('<div class="bg-lightbox" style="display: none;">&nbsp;</div>');
	}
	
	if($('.lightbox').length == 0)
	{
		$('body').append('<div class="lightbox"><a title="Fechar" class="close">Fechar</a><img src="flash-files/img/lightbox_top.gif" alt="AXA - Redefinimos Standards" /><div class="lb-video"></div></div>');
	}
	
	var addCss=document.createElement("link");
	addCss.setAttribute("rel", "stylesheet");
	addCss.setAttribute("type", "text/css");
	addCss.setAttribute("href", PATH_TO_ROOT + "flash-files/hp-anim.css");
	document.getElementsByTagName("head")[0].appendChild(addCss);
	

});

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();
                });
            });
        });
    });
};


