/* Altura da tela aonde começa o conteúdo */
var bodyContent_Top  = 420; // px
var bodyContent_Time = 500; // ms
/* ----- */

/*
 * listLog
 */
function listLogInit (number) {
    var divWidth = $('#listLog div').css('width');
    $('#listLog div div').css('width', parseInt(divWidth) * number);
    $('#listLog div').scrollTo(0);
}

function listLogScroll (signal) {
    $('#listLog div:first').scrollTo(signal + '=' + $('#listLog div').css('width'), 500);
}
/* END - listLog */


/*
 * bodyTop - Ir para o topo do site
 */
function bodyTop (value) {
    $(document).scrollTo(value, 500);
}
/* END - bodyTop */


/*
 * outrasNot
 */
function outrasNotInit (number) {
    var divHeight = $('#outrasNot').css('height');
    $('#outrasNot div').css('height', parseInt(divHeight) * number);
    $('#outrasNot').scrollTo(0);
}

function outrasNotScroll (signal) {
    $('#outrasNot').scrollTo(signal + '=' + $('#outrasNot').css('height'), 500);
}
/* END - outrasNot */

/*
 * setLightBox
 */
$(document).ready(function () {
    setLightBox('a[rel="lightbox"]');
});

function setLightBox (elem) {
    if (elem) {
        $(elem).lightBox({
            imageLoading: 'img/lightbox/loading.gif',
            imageBtnClose: 'img/lightbox/close.gif',
            imageBtnPrev: 'img/lightbox/prev.gif',
            imageBtnNext: 'img/lightbox/next.gif',
            imageBlank: 'img/lightbox/blank.gif',
            txtImage: 'Imagem',
            txtOf: 'de'
        });
    }
}
// END - setLightBox

/*
 * galeriasList
 */
function galeriasListInit (number) {
    var divWidth = $('#galeriasList div').css('width');
    $('#galeriasList div div').css('width', parseInt(divWidth) * number);
    $('#galeriasList div').scrollTo(0);
}

function galeriasListScroll (signal) {
    $('#galeriasList div:first').scrollTo(signal + '=' + $('#galeriasList div').css('width'), 500);
}
/* END - galeriasList */

/*
 * fileUpPreview
 */
function inputFileImageChange (elem, field) {
    if (elem && field) {
        fileUpPreview(elem, document.getElementById('IMG_' + field));
    }
}

function inputFileImageClear (field) {
    if (field) {    
        $('#IMG_' + field).html('');
        $('input[name="' + field + '"]').val('');
        $('input[name="FILE_' + field + '"]').val('');
    }
}

function fileUpPreview (objFile, previewer) {
    if(!/(\.gif|\.jpg|\.jpeg|\.png)$/i.test(objFile.value)) {
        alert("Arquivo inválido.");
        objFile.value = null;
        return;
    }
    if (window.navigator.userAgent.indexOf("MSIE 7") != -1) {
        previewer.innerHTML = "";
        previewer.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='file://" + String(objFile.value) +"', sizingMethod='scale')";
    }
    else {
        previewer.innerHTML = "";
        var W = previewer.offsetWidth - 2;
        var H = previewer.offsetHeight - 2;
        var tmpImage = document.createElement('img');
        previewer.appendChild(tmpImage);
        tmpImage.onerror = function () {
            alert("Erro.");
            previewer.innerHTML = "";
            return;
        }
        tmpImage.onload = function () {
            if (this.width > W) {
                this.height = this.height / (this.width / W);
                this.width = W;
            }
            if (this.height > H) {
                this.width = this.width / (this.height / H);
                this.height = H;
            }
        }
        if (window.navigator.userAgent.indexOf("Firefox/3") != -1) {
            var picData = objFile.files.item(0).getAsDataURL();
            tmpImage.src = picData;
            // tmpImage.writeAttribute("title", "ImageSize: "+ objFile.files.item(0).fileSize +" byte");
        }
        else {
            tmpImage.src = "file://" + objFile.value;
        }
    }
}
/* END - fileUpPreview */

/*
 * Mapa
 */
function mapa () {
	var PopUp_W = 1000;
    var PopUp_H =  590;
    var PopUp_L = (screen.width - PopUp_W) / 2;
    var PopUp_T = ((screen.height - PopUp_H) / 2) - 50;
    PopUp_T = (PopUp_T > 0 ? PopUp_T : 0);
    var PopUp_Win = (window.open('mapa.php', 'Farol_Shopping_Mapa', 'width=' + PopUp_W + ', height=' + PopUp_H + ', left=' + PopUp_L + ', top=' + PopUp_T + ', resizable=no, scrollbars=no, toolbar=no, location=no, directories=no, status=no, menubar=no, copyhistory=no'));
    if (parseInt(navigator.appVersion) >= 4) {
        PopUp_Win.window.focus();
    }
}
/* END - Mapa */

// Lightbox me
$(document).ready(function () {
    $(".abre_flutuante_depoimentos").click (function() {
        abre_flutuante();
    });
});

function abre_flutuante ()
{
    $("#enviar_depoimento").lightbox_me({centered: true});
}

/* Ticker */

$(document).ready(function () {
    function newsticket_next() {
        // Anima
        $('.newsticker ul.lista li:first-child').fadeOut(200).detach().appendTo('.newsticker ul.lista');
        $('.newsticker ul.lista li:first-child').delay(200).fadeIn(200);
    }    
    $('.newsticker .depoimentosPrev').click(function(){
        // Limpa o intervalo e seta de novo
        clearInterval(newsticker_intervalo);
        newsticker_intervalo = setInterval(newsticket_next, 12000);
        // Anima
        $('.newsticker ul.lista li:first-child').fadeOut(200);
        $('.newsticker ul.lista li:last-child').delay(200).detach().prependTo('.newsticker ul.lista').fadeIn(200);
    });
    $('.newsticker .depoimentosNext').click(function(){
        // Limpa o intervalo e seta de novo
        clearInterval(newsticker_intervalo);
        newsticker_intervalo = setInterval(newsticket_next, 12000);
        // Anima
        newsticket_next();
    });
    // Seta o intervalo
    newsticker_intervalo = setInterval(newsticket_next, 12000);
});

/**
 * Limitador interativo de caracteres (Twitter-like).
 *
 * @author Caio Moritz Ronchi <caiomoritz@gmail.com>
 */
jQuery.fn.interactiveCharLimit = function(countDownElementSelector, options) {
    return this.each(function() {

        var $ = jQuery;

        var $countDownElement = $(countDownElementSelector);
        if ($countDownElement.length == 0) return;

        if (!options) options = {};

        options = $.extend({
            stylesOnLimitNotReached: { color: 'black' },
            stylesOnLimitReached: { color: 'red' },
            lockOnLimitReached: true
        }, options);

        var $textElement = $(this);
        var limit = parseInt($countDownElement.text());

        $(this).keyup(function() {

            var text = $textElement.val(); 
            var textLength = text.length;
            var totalCharsLeft = limit - textLength;

            if ((totalCharsLeft + 1) <= 0 && options.lockOnLimitReached) {
                $textElement.val(text.substr(0, limit));
                return false;
            }

            $countDownElement.text(totalCharsLeft);

            var styles = (totalCharsLeft >= 0)
                ? options.stylesOnLimitNotReached
                : options.stylesOnLimitReached;

            $countDownElement.css(styles);

            return true;
        });
    });
};

$(function(){
    $('.redes_sociais .share').hover(function(){
        $(this).find('.addthis').show();
    },function(){
        $(this).find('.addthis').hide();
    });
})
