﻿var f = {
    //////////////////////////////////////////////////////////////////////////////////////
    // VARIAVEIS GLOBAIS
    idioma: {},
    //////////////////////////////////////////////////////////////////////////////////////
    // INIT
    init: function () {
        f.topCenter();
        f.wrap();
        setTimeout(function () { 
            Cufon.set('fontFamily', 'Gill Sans').replace('#slide-list li a , #slide-list2 li a , .lsForm .btForm ', { hover: true }); 
            Cufon.set('fontFamily', 'Gill Sans').replace('h2'); 
            }, 10);
        f.click();
        f.idiomaGet();
        f.supersized(f.idioma);
        f.btClose();
        f.minMax();
        f.formOk();

        // fecha o menu inferior
        $('#progress-back').animate({ bottom: "-8px" }, 10);
        $('#controls-wrapper').animate({ bottom: "-42px" }, 10);
    },
    //////////////////////////////////////////////////////////////////////////////////////
    // define o idioma para o script
    idiomaGet: function () {
        f.idioma = $("#flag > ul").attr('class')
    },
    wrap : function(){
        $('#wrap').css('width' , $(document).width()).css('height' ,  $(document).height())
    },
    //////////////////////////////////////////////////////////////////////////////////////
    // carrosel background
    supersized: function (l) {
        var images;
        if (l == "br") { // BR
            images = [	// Slideshow Images
					    //{image: '_produtos/box-brush.jpg', title: 'Box/Brush Off   <span>Box/Brush Off  </span>', thumb: '_produtos/thumbs/box-brush.jpg' },
					    { image: '_produtos/caseinado.jpg', title: 'Caseinado <span>Caseinado</span>', thumb: '_produtos/thumbs/caseinado.jpg' },
					    { image: '_produtos/cerosos.jpg', title: 'Cerosos <span>Cerosos</span>', thumb: '_produtos/thumbs/cerosos.jpg' },
					    { image: '_produtos/estampas.jpg', title: 'Estampas <span>Estampas</span>', thumb: '_produtos/thumbs/estampas.jpg' },
					    { image: '_produtos/floater.jpg', title: 'Floater <span>Floater</span>', thumb: '_produtos/thumbs/floater.jpg' },
					    { image: '_produtos/nubuck.jpg', title: 'Nubuck <span>Nubuck</span>', thumb: '_produtos/thumbs/nubuck.jpg' },
					    { image: '_produtos/papel.jpg', title: 'Papel <span>Papel</span>', thumb: '_produtos/thumbs/papel.jpg' },
                        { image: '_produtos/verniz.jpg', title: 'Verniz <span>Verniz</span>', thumb: '_produtos/thumbs/verniz.jpg' }
				    ];
        } else if (l == "en") {
            images = [	// Slideshow Images
						//{image: '_produtos/box-brush.jpg', title: 'Box/Brush Off   <span>Box/Brush Off  </span>', thumb: '_produtos/thumbs/box-brush.jpg' },
					    { image: '_produtos/caseinado.jpg', title: 'Casein finishing <span>Casein finishing </span>', thumb: '_produtos/thumbs/caseinado.jpg' },
					    { image: '_produtos/cerosos.jpg', title: 'Waxy <span>Waxy</span>', thumb: '_produtos/thumbs/cerosos.jpg' },
					    { image: '_produtos/estampas.jpg', title: 'Prints <span>Prints</span>', thumb: '_produtos/thumbs/estampas.jpg' },
					    { image: '_produtos/floater.jpg', title: 'Floater <span>Floater</span>', thumb: '_produtos/thumbs/floater.jpg' },
					    { image: '_produtos/nubuck.jpg', title: 'Nubuck <span>Nubuck</span>', thumb: '_produtos/thumbs/nubuck.jpg' },
					    { image: '_produtos/papel.jpg', title: 'Foil <span>Foil</span>', thumb: '_produtos/thumbs/papel.jpg' },
                        { image: '_produtos/verniz.jpg', title: 'Patent <span>Patent</span>', thumb: '_produtos/thumbs/verniz.jpg' }
					];
        };
        // CARREGA O CARROSEL
        $.supersized({
            // Functionality
            slide_interval: 5000, 	// Length between transitions
            performance: 1,
            transition: 6, 			// 0-None, 1-Fade, 2-Slide Top, 3-Slide Right, 4-Slide Bottom, 5-Slide Left, 6-Carousel Right, 7-Carousel Left
            transition_speed: 1000, 	// Speed of transition
            autoplay: 0,
            // Components							
            slide_links: 'name', // Individual links for each slide (Options: false, 'num', 'name', 'blank')
            slides: images,
            
        });
        theme.afterAnimation()

    },
    //////////////////////////////////////////////////////////////////////////////////////
    // alinha menu superior / central
    topCenter: function () {
        var w = $('#slide-list2').outerWidth();
        $('#slide-list2').css('margin-left', -(w / 2));
    },
    //////////////////////////////////////////////////////////////////////////////////////
    // EVENTOS DE CLIQUE
    click: function () {
        var j;
        $('#controlsTop li a , .conteudo p a').click(function () {
            _t = $(this);
            j = $(this).attr('href');
            a = $(this).hasClass('atv');
            acao(j)
            
        });
        function acao(i) {
            switch (i) {
                //produtos
                case "#produtos":
                    if (!a) {
                        _t.addClass('atv');
                        $('#controls-wrapper').animate({ bottom: "0px" }, 1000, 'easeOutQuint', function () {
                            $('#progress-back').animate({ bottom: "42px" }, 300, 'linear' , function(){
                                $('#tray-arrow').trigger('click');
                            
                            });
                        });

                    } else {
                        _t.removeClass('atv');

                        b = $('#thumb-tray').css('bottom');
                        b = b.replace('px','');
                        if (b == 0){
                            $('#tray-arrow').trigger('click');
                        }
                        $('#progress-back').animate({ bottom: "-8px" }, 300, 'linear', function () {
                            $('#controls-wrapper').animate({ bottom: "-42px" }, 1000, 'easeOutQuint');
                        });
                    }
                break;
                // empresa
                case "#empresa":
                    if (!a){
                        _t.addClass('atv');
                        f.showItem(i);
                    }else{
                        f.hideItem($('#empresa'),'empresa');                        
                    }  
                break;
                // meio ambiente
                case "#meioAmbiente":
                    if (!a) {
                        _t.addClass('atv');
                        f.showItem(i , "left");
                    }else{
                        f.hideItem($('#meioAmbiente'),'meioAmbiente');                        
                    }  
                break;
                // contato
                case "#contato":
                    if (!a) {
                        _t.addClass('atv');
                        f.showItem(i, 'right');
                    }else{
                        f.hideItem($('#contato'),'contato');                        
                    }  
                break;
        
                default:
            };
        };
    },
    // função do botao de fechar
    btClose : function(a){
        $('.boxFloat .close').click(function(a){
            o = $(this).parents('.boxFloat');
            l = o.attr('id');
            f.hideItem(o,l);
        })
    },
    // funcao de minimizar e maximizar janela
    minMax : function(){
        $('.boxFloat .min').click(function(){
            _t = $(this)
            o = _t.parents('.boxFloat');
            if (_t.hasClass("hide")){
                a1 = _t.parent().outerHeight(true);
                a2 = _t.parent().next().outerHeight(true);
                at = a1 + a2;
                o.animate({height: at}, 500 , 'easeOutBack' , function(){ _t.removeClass('hide').find('img').attr('src' , '_img/ico-min.png')  });
            }else{
                o.animate({height: '43'}, 500 , 'easeInBack' , function(){ _t.addClass('hide').find('img').attr('src' , '_img/ico-max.png')  });
            };            
        });
    },
    // animacao para abrir o box
    showItem : function(o , d){
       lt = $(window).width() / 2;
       l = $(o).width() / 2;
       // posiciona o bloco

       if (d != undefined){
            if (d == "right"){
                tl = (lt*2) - ((l * 2) + 65);
                
            }else if (d == "left"){
                tl = 65;
            }
       }else{
          tl = lt - l;
       }
       
       at = $(window).height() / 2;
       a = $(o).height() / 2;
       ta = at - a; 

       $(o).css('top' , ta);
       $(o).animate({ left: tl }  , 500 , 'easeOutCirc');
       $(o).draggable({handle: ".move" , containment: '#wrap' , scroll : false});

       $('.boxFloat').css('z-index','90');
       $(o).css('z-index','100');

       $(o).mousedown(function(){
        $('.boxFloat').css('z-index','90');
        $(o).css('z-index','100');
       })

    },
    // animacao para fechar o box
    hideItem : function(o , l){
       at = $(window).height() / 2;
       a = $(o).height() / 2;
       ta = at - a;
       lt = $(window).width();
       o.animate({ left: -(lt) } , 500 , 'easeInCirc' ,
            function(){ $(this).css('top', ta); 
            $("#slide-list2 ."+l).removeClass('atv'); 
            Cufon.refresh(); 
       });
    
    },
    // animação para o formulario de contato ok
    formOk : function(){
        v= $('#formOk').is(':visible');
        if (v){
            f.showItem('#contato');
            $('.contato').addClass('atv');
            setTimeout(function(){
                f.hideItem($('#contato'),'contato');
                setTimeout(function(){ $('#formOk').hide(); $('#contato').css('top',"50px"); $('#form').show();},2000);                              
            },4000);
        }
    }
}

$(document).ready(function () { f.init(); }); 

// refresh cufon


