﻿/**************************************************************
*
* CLASSE JAVASCRIPT RANDEMP BANNERS
*
* CRIADO POR: CRISTIANO TAVELLA 
* DATA: 17/08/2010
* OBS:
* EDITADO POR: CRISTIANO TAVELLA
* DATA: 17/08/2010
* OBS:
*
*************************************************************/
function set(posicao, campo, value) {
    eval("this." + campo + "[" + posicao + "] ='" + value.replace(/\'/g, "\\\'") + "';");
}

function get(posicao, campo) {
    eval("var var_return =  this." + campo + "[" + posicao + "];");
    return var_return;
}

function print() {
    
    for (var x = 0; x < this.qtdRegistros; x++) {

        $(this.destino).append(this.layout.replace(/\[x\]/g, x));
    }

    var count = 0;
    for (var x = 0; x < this.qtdRegistros; x++) {
        $("#" + this.id + "pkcadempre_" + x).val(this.pkcadempre[x]);
        $("#" + this.id + "nome_" + x).html(this.nome[x]);
        $("#" + this.id + "banner_" + x).val(this.banner[x]);

        //$("#" + this.id + "foto_" + x).attr("src", "");
        //$("#" + this.id + "foto_" + x).attr("src", this.urlfoto[x] + "mini_" + this.foto[x]);

        if ($("#" + this.id + "pkcadempre_" + x).val() == "")
            $("#box_lancamentos_" + x).hide();
        else {
            count++;
           
            var id = this.id;
            $("#box_lancamentos_"+x).click(function () {
                $('#counteudo_banner').html($($("#" + id + "banner_" + $(this).attr("num")).val()));
                $(".box_lancamentos").attr('class', 'box_lancamentos2');
                $(this).attr('class', 'box_lancamentos');

            });
        }
    }

    if (count != 0) {
        if (count < 4) {
            for (var x = 0; x < count; x++) {
                $("#box_lancamentos_" + x).show();
            }
        }
        else {
            $("#box_lancamentos_0, #box_lancamentos_1, #box_lancamentos_2, #box_lancamentos_3, #box_lancamentos_4").show();
            if(count > 5)
                $('#banners_seta2').attr('class', 'box_setah2')
        }

        $("#box_lancamentos_0").attr('class', 'box_lancamentos');
        $('#counteudo_banner').html(this.banner[0]);
    }

    document.getElementById('banners_seta1').onclick = function () {
        ScrollEsquerda(count);
    }

    document.getElementById('banners_seta2').onclick = function () {
        ScrollDireita(count);
    }

    
}


var scroll_banner = 0;

function ScrollDireita(count) {

    if ((scroll_banner+4) < (count-1)) {
           
        for (var x = 0; x < count; x++) {
            $("#box_lancamentos_" + x).hide();
        } 

        scroll_banner++;

        $("#box_lancamentos_" + scroll_banner).show();
        $("#box_lancamentos_" + (parseInt(scroll_banner) + 1)).show();
        $("#box_lancamentos_" + (parseInt(scroll_banner) + 2)).show();
        $("#box_lancamentos_" + (parseInt(scroll_banner) + 3)).show();
        $("#box_lancamentos_" + (parseInt(scroll_banner) + 4)).show();


        
    }

    if ((scroll_banner + 4) == (count - 1))
        $('#banners_seta2').attr('class', 'box_seta2');

    if(scroll_banner > 0)
        $('#banners_seta1').attr('class', 'box_setah1');
 }

 function ScrollEsquerda(count) {

     if (scroll_banner > 0) {
         for (var x = 0; x < count; x++) {
             $("#box_lancamentos_" + x).hide();
         }

         scroll_banner--;

         $("#box_lancamentos_" + scroll_banner).show();
         $("#box_lancamentos_" + (parseInt(scroll_banner) + 1)).show();
         $("#box_lancamentos_" + (parseInt(scroll_banner) + 2)).show();
         $("#box_lancamentos_" + (parseInt(scroll_banner) + 3)).show();
         $("#box_lancamentos_" + (parseInt(scroll_banner) + 4)).show();


         
     }

     if (scroll_banner == 0)
         $('#banners_seta1').attr('class', 'box_seta1');

     if ((scroll_banner + 4) < (count - 1))
         $('#banners_seta2').attr('class', 'box_setah2');
 }

function LancamentosBanners(parametros) {

    //Número de registros
    this.qtdRegistros = parametros.qtdregistros;
    //destino no qual será imprimido
    this.destino = parametros.destino;
    //Id opcional antes dos nomes dos campos
    this.id = (typeof (parametros.id) == "undefined" ? " " : parametros.id);


    /*
    Métodos impressão 
    */
    //layout do randimo
    this.layout = parametros.layout;
    this.print = print;
    /*
    Métodos GET e SET da classe
    */
    this.set = set;
    this.get = get;

    /*
    Campos da tabela
    */
    this.pkcadempre = new Array();
    this.nome = new Array();
    this.banner = new Array();

}

