﻿

///* *****Funcion desplazamiento menu y content***** */
//window.addEvent('domready', function () {
//    // This var define the increment value (+ or - 212 px). In the line below is initialited to 0. 
//    var increment = 0;

//    // FX var 
//    var fx = new Fx.Style('carousel', 'margin-left', {
//        duration: 500,
//        transition: Fx.Transitions.Back.easeInOut,
//        wait: true
//    });

//    // Previous Button
//    $('.volver').addEvents({
//        'click': function (event) {
//            increment = increment + 212;
//            fx.stop()
//            fx.start(increment);
//        }
//    });

//    // Next Button
//    $('.itemMenu').addEvents({
//        'click': function (event) {
//            increment = increment - 212;
//            fx.stop()
//            fx.start(increment);
//        }
//    })
//});



    /* *****panel de conexion***** */
    function imageButton() {
        $("#menuConexion").slideToggle("slow");
    };
    /*-------------------------------*/

    /* -----------carousel------------ */
    var CH = {
        ds: '',
        dA: 0,
        sD: 0,
        tD: 0,
        an: 0,
        fotogramas: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],
        idD: 'diapos',
        nID: 'diapos-on',
        idCn: 'controles',
        intv: '',
        act: true,
        $: function (id) { var elem = document.getElementById(id); return elem; },
        desp: function (x) {
            if (CH.act == true) {
                if (((x == -1) && (CH.dA != CH.tD)) || ((x == 1) && (CH.dA != 0))) {
                    CH.act = false;
                    var pos = 0;
                    CH.intv = setInterval(function () {
                        if (pos < CH.fotogramas.length) {
                            var inicio = parseInt(CH.$(CH.idD).style.left.replace('px', ''));
                            CH.$(CH.idD).style.left = (inicio + (Math.round(CH.an * (CH.fotogramas[pos] / 100)) * x)) + 'px';
                            pos++;
                        } else {
                            (x == -1) ? CH.dA++ : CH.dA--;
                            CH.$(CH.idD).style.left = ((CH.an * CH.dA) * (-1)) + 'px';
                            pos = 0;
                            CH.act = true;
                            clearInterval(CH.intv);
                        }
                    }, 50);
                } else if (((x == -2) && (CH.dA != CH.tD)) || ((x == 2) && (CH.dA != 0))) {
                    CH.act = false;
                    var pos = 0;
                    CH.intv = setInterval(function () {
                        if (pos < CH.fotogramas.length) {
                            var inicio = parseInt(CH.$(CH.idD).style.left.replace('px', ''));
                            CH.$(CH.idD).style.left = (inicio + (Math.round(CH.an * (CH.fotogramas[pos] / 100)) * x)) + 'px';
                            pos++;
                        } else {
                            (x == -2) ? CH.dA++ : CH.dA--;
                            CH.$(CH.idD).style.left = ((CH.an * CH.dA) * (-2)) + 'px';
                            pos = 0;
                            CH.act = true;
                            clearInterval(CH.intv);
                        }
                    }, 50);
                }
            }
        },
        dims: function () {
            var alF = 0;
            CH.an = (CH.$(CH.nID).offsetWidth) ? CH.$(CH.nID).offsetWidth : CH.$(CH.nID).style.pixelWidth;
            for (var i = 0; i <= CH.tD; i++) {
                var al = (CH.ds[i].offsetHeight) ? CH.ds[i].offsetHeight : CH.ds[i].style.pixelHeight;
                (al > alF) ? alF = al : alF = alF;
            }
            CH.$(CH.nID).setAttribute('style', 'height:' + alF + 'px;width:' + CH.an + 'px;position:relative;overflow:hidden;');
            CH.$(CH.idD).setAttribute('style', 'height:' + alF + 'px;width:' + (CH.an * CH.ds.length) + 'px;position:absolute;top:0;left:0;');
            for (var i = 0; i <= CH.tD; i++) {
                CH.ds[i].setAttribute('style', 'height:' + alF + 'px;width:' + CH.an + 'px;float:left;');
            }
        },
        inicio: function () {
            var div = document.createElement('div');
            div.id = CH.nID;
            var clon = CH.$(CH.idD).cloneNode(true);
            div.appendChild(clon);
            CH.$(CH.idD).parentNode.replaceChild(div, CH.$(CH.idD));
            CH.ds = CH.$(CH.idD).getElementsByTagName('div');
            CH.tD = CH.ds.length - 1;
            CH.dims();
            var cntr = document.createElement('div');
            cntr.id = CH.idCn;
            (CH.$(CH.nID).nextSibling) ? (CH.$(CH.nID).parentNode).insertBefore(cntr, CH.$(CH.nID).nextSibling) : (CH.$(CH.nID).parentNode).appendChild(cntr);
            var ct = document.createElement('div');
            (CH.$(CH.nID).nextSibling) ? (CH.$(CH.nID).parentNode).insertBefore(ct, CH.$(CH.nID).nextSibling) : (CH.$(CH.nID).parentNode).appendChild(ct);
            for (var i = 0; i <= CH.tD; i++) {
            }
        }
    }

    window.onload = CH.inicio;

    function siguiente(paso) {
        CH.desp(paso);  //CH.desp(-1)
        pasoAtras = paso.substring(1, 2);
    }
    function anterior() {
        CH.desp(pasoAtras) //CH.desp(1)
    }
    /* -------------------------------- */



