var Numero = 0;

/* LIGHTBOX */
hs.graphicsDir = 'images/graphics/';
hs.align = 'center';
hs.transitions = ['expand', 'crossfade'];
hs.outlineType = 'rounded-white';
hs.fadeInOut = true;
hs.headingEval = 'this.thumb.alt';
hs.headingOverlay.position = 'below';
hs.addSlideshow({
	interval: 5000,
	repeat: false,
	useControls: true,
	fixedControls: 'fit',
	overlayOptions: {
		opacity: .75,
		position: 'bottom center',
		hideOnMouseOut: true
	}
});
/* FIM LIGHBOX */
$(document).ready(function() {

    $('.formulario input[type="text"]').overText();
    $("#container > img").parent().children("#left").css("width", "520px");
    $("#anim").parent().parent().parent("body").css("background-image", "none");

    /* MENU */
    $("#menu > li > ul > li > ul").parent().children("a").css("background-position", "164px 15px");
    $("#menu li a").click(function() {
        $(this).focus();
        /*	if(!$(this).parent().hasClass("show")){
        $(this).parent().addClass("show");
        }else{
        $(this).parent().removeClass("show");
        $(this).parent().children("ul").css("display", "none");
        };*/
    });
    var dropdown_intervalId;
    var dropdown_ulId = (!dropdown_ulId) ? 'menu' : dropdown_ulId;
    var dropdown_delay = (!dropdown_delay) ? 0 : dropdown_delay;

    function dropdown_init() {
        try {
            var as = document.getElementById(dropdown_ulId).getElementsByTagName('a');

            for (var a = 0; a < as.length; a++) {
                as[a].onfocus = function() { dropdown_expand(this) }
                as[a].onblur = function() { dropdown_colapse(dropdown_delay) }
            }

            dropdown_colapse(0);

        } catch (e) { }

    }

    function dropdown_expand(caller) {
        try {
            clearInterval(dropdown_intervalId);

            var uls = caller.parentNode.parentNode.getElementsByTagName('ul');

            for (var ul = 0; ul < uls.length; ul++)
                uls[ul].style.display = "none";

            caller.parentNode.getElementsByTagName('ul')[0].style.display = "block";

        } catch (e) { }

    }

    function dropdown_colapse(milliseconds) {
        try {
            clearInterval(dropdown_intervalId);

            dropdown_intervalId = setInterval(function() {
                var uls = document.getElementById(dropdown_ulId).getElementsByTagName('ul');

                for (var ul = 0; ul < uls.length; ul++)
                    uls[ul].style.display = "none";

                clearInterval(dropdown_intervalId);

            }, milliseconds, null);

        } catch (e) { }

    }

    window.onload = dropdown_init;






    $("#menu li a").focus(function() {
        $("#menu li a").parent().children("ul").parent().children("a").css("background-position", "164px 15px");
        $("#menu li.show > a").css("background-position", "164px -80px");
        $("#lang li").css("opacity", "0.45");
        $("#lang li.selected").css("opacity", "1");
        $("#menu-produtos li").css("z-index", "-1");
        $("#menu").css("z-index", "1000");
        $(this).parent().children("ul").parent().children("a").css("background-position", "164px -80px");
        $("#busca div").css("display", "none");
    });

    $("#menu li a").blur(function() {
        $(this).parent().children("ul").parent().children("a").css("background-position", "164px 15px");
        $("#lang li").css("opacity", "0.45");
        $("#lang li.selected").css("opacity", "1");
        $("#menu-produtos li").css("z-index", "1000");
    });
    /* FIM MENU */

    /* BUSCA */
    $("#busca a, #menu li:first-child + li + li + li + li + li + li + li a").click(function() {
        $(this).parent().children("div").css("display", "block");
        $("#lang li").css("opacity", "1");
        $(this).parent().children("div").children("input[type='text']").focus();
    });

    $("#busca div label").click(function() {
        $(this).parent().css("display", "none");
        $("#lang li").css("opacity", "0.45");
        $("#lang li.selected").css("opacity", "1");
    });

    /* SUBMENU */
    $("#submenu > a").click(function() {
        if (!$(this).parent().hasClass("selected")) {
            $(this).parent().removeClass("selected");
            $(this).parent().addClass("selected");
        } else {
            $(this).parent().removeClass("selected");
        };
    });
    $("#intro > div > ul > li > a").click(function() {
        if (!$(this).parent().hasClass("selected")) {
            $(this).parent().removeClass("selected");
            $(this).parent().addClass("selected");
        } else {
            $(this).parent().removeClass("selected");
        };
    });
    $("#menu-produtos > li:first-child + li > a").click(function() {
        if (!$(this).parent().hasClass("selected")) {
            $(this).parent().removeClass("selected");
            $("#images").css("z-index", "-1");
            $(".scrollable").css("z-index", "-1");

            $(this).parent().addClass("selected");
        } else {
            $(this).parent().removeClass("selected");
            $("#images").css("z-index", "1");
            $(".scrollable").css("z-index", "1");
        };
    });
    /* IMAGENS */
    $("#images .scrollable").scrollable();
    $("#images .items img").click(function() {
        if ($(this).hasClass("active")) { return; }
        var url = $(this).attr("src").replace("_thumb", "_dest");
        
        var lnkAmpliar = $("#lnkAmpliar");
        lnkAmpliar.attr("href", $(this).attr("src").replace("_thumb", "_nor"));
        
        var wrap = $("#image_wrap").fadeTo("medium", 0.5);
        var alt = $(this).attr("alt");
        $("#image_wrap p").text(alt);
        var img = new Image();
        img.onload = function() {
            wrap.fadeTo("fast", 1);
            wrap.find("img").attr("src", url);
        };
        img.src = url;
        $(".items img").removeClass("active");
        $(this).addClass("active");
    }).filter(":first").click();
    /* GALERIA */
    var quanTelas = ($("#gallery ul li").length);
    var i = 4;
    if (quanTelas > 4) {
        $("#gallery ul").css("width", quanTelas * 87);
        var largura = $("#gallery ul").outerWidth();
        var anim = largura / quanTelas
        $("#arrow-right").show();
        $("#arrow-left").click(function() {
            if (i > 4) {
                $('#arrow-right').show();
                $("#arrow-right").animate({ opacity: 1 }, 250);
                i = i - 1;
                $('#gallery ul').animate({ left: -(i - 4) * anim }, 500, function() {
                    if (i == 4)
                        $("#arrow-left").animate({ opacity: 0 }, 250, function() {
                            $(this).hide();
                        });

                });
            }
        });
        $("#arrow-right").click(function() {
            if (i < quanTelas) {
                $('#arrow-left').show();
                $("#arrow-left").animate({ opacity: 1 }, 250);
                i = i + 1;
                $('#gallery ul').animate({ left: -(i - 4) * anim }, 500, function() {
                    if (i == quanTelas)
                        $("#arrow-right").animate({ opacity: 0 }, 250, function() {
                            $(this).hide();
                        });
                });
            }
        });
    };
    /* ANIMACAO */
    $("#chamadas li").mouseover(function() {
        $("img + img + img", this).animate({ width: "11px", height: "18px", top: 148 }, 250);
        $("img:first-child + img", this).animate({ top: 157, left: 204, width: "0", height: "0" }, 250);
    });
    $("#chamadas li").mouseout(function() {
        $("img + img + img", this).animate({ width: "8px", height: "14px", top: 150 }, 250);
        $("img:first-child + img", this).animate({ width: "29px", height: "29px", top: 142, left: 189 }, 250);
    });
    $("#noticias-home h2").mouseover(function() {
        $("img + img + img", this).animate({ width: "11px", height: "18px", top: 22, right: 23 }, 25);
        $("img:first-child + img", this).animate({ top: 31, right: 30, width: "0", height: "0" }, 250);
    });
    $("#noticias-home h2").mouseout(function() {
        $("img + img + img", this).animate({ width: "8px", height: "14px", top: 24, right: 25 }, 250);
        $("img:first-child + img", this).animate({ width: "29px", height: "29px", top: 16, right: 15 }, 250);
    });
    
    /* BANNER */
    $(".images > div").each(function(){
		Numero = Numero + 1;
		$(".slidetabs").append("<a href='javascript:;'>" + Numero + "<img src='images/blank.png' width='30' height='30' alt='' /></a>");
		
	});
	$(".slidetabs").tabs(".images > div", {
		effect: 'fade',
		fadeOutSpeed: "slow",
		rotate: true
	}).slideshow({ autoplay: true, interval: 7000});
});
    
   
    function nomeiaCampo(pCampo, pValor, pAcao) {
        if (pAcao == 0) {
            if (pCampo.value == pValor)
                pCampo.value = '';
        }

        if (pAcao == 1) {
            if (pCampo.value == '')
                pCampo.value = pValor;
        }
    }

    function mostraEsconde(qual) {
        if (document.getElementById(qual).style.display == "none") {
            document.getElementById(qual).style.display = "";
        }
        else {
            document.getElementById(qual).style.display = "none";
        }
    }
