/* ACORDEON SIMPLE */
var Acordeon = window.Acordeon || {};
Acordeon.example = function() {
    var YUD = YAHOO.util.Dom;
    var YUE = YAHOO.util.Event;
    var YUA = YAHOO.util.Anim;
    var onMenuCollapse = new YAHOO.util.CustomEvent('menu collapse');
    var onMenuOpen = new YAHOO.util.CustomEvent('menu open');
    var last = [];
    var ua = navigator.userAgent.toLowerCase();
    var isOpera = (ua.indexOf('opera') != -1);
    var isIE = (ua.indexOf('msie') != -1 && !isOpera);
    return {
        init : function(identificador) {
            //this.id = identificador;
            var oLi = YUD.getElementsByClassName('filtro','div',identificador);
            for ( var i=0, j=oLi.length; i<j; ++i ) {
                YUE.on(oLi[i], 'click', this.collapse, oLi[i].parentNode.offsetHeight);
            }
            YUD.batch(oLi, function(oEl) {
                    if ( YUD.hasClass(oEl, 'close') ) {
                        oEl.parentNode.getElementsByTagName('ul')[0].style.height = '0';
                    }
                }
            );
        },
        collapse : function(e, iH) {
            last.push(this);
            if ( last.length > 3 ) {
                last.shift();
            }
            if ( YUD.hasClass(this, 'close') ) {
                YUD.removeClass(this, 'close');
                var oEl = this.parentNode.getElementsByTagName('ul')[0];
                oEl.style.height = '0';
                var iHeight = (isIE ? parseInt(iH)-22 : parseInt(iH)-25);
                var attributes = {
                    height : {
                        from : 0,
                        to : iHeight
                    }
                };
                var anim = new YAHOO.util.Anim(oEl, attributes, 0.5, YAHOO.util.Easing.easeOut);
                anim.animate();
                onMenuOpen.fire();
            }
            else {
                YUD.addClass(this, 'close');

                var oEl = this.parentNode.getElementsByTagName('ul')[0];

                var attributes = {
                    height : {
                        to : 0
                    }
                };
                var anim = new YUA(oEl, attributes, 0.5, YAHOO.util.Easing.easeIn);
                anim.animate();
                onMenuCollapse.fire();
            }
        }
    };
}();

/* MAS INFORMACION */
var DEDmasinfo = window.DEDmasinfo || {};
DEDmasinfo.example = function() {
    var YUD = YAHOO.util.Dom;
    var YUE = YAHOO.util.Event;
    var YUA = YAHOO.util.Anim;
    var onMenuCollapse = new YAHOO.util.CustomEvent('menu collapse');
    var onMenuOpen = new YAHOO.util.CustomEvent('menu open');
    var last = [];
    var ua = navigator.userAgent.toLowerCase();
    var isOpera = (ua.indexOf('opera') != -1);
    var isIE = (ua.indexOf('msie') != -1 && !isOpera);
    return {
        init : function() {
            var oLi = YUD.getElementsByClassName('filtro','div','aco_masinfo');
            for ( var i=0, j=oLi.length; i<j; ++i ) {
                YUE.on(oLi[i], 'click', this.collapse, oLi[i].parentNode.offsetHeight);
            }
            YUD.batch(oLi, function(oEl) {
                    if ( YUD.hasClass(oEl, 'close') ) {
                        oEl.parentNode.getElementsByTagName('ul')[0].style.height = '0';
                    }
                }
            );
        },
        collapse : function(e, iH) {
            last.push(this);
            if ( last.length > 3 ) {
                last.shift();
            }
            if ( YUD.hasClass(this, 'close') ) {
                YUD.removeClass(this, 'close');
                var oEl = this.parentNode.getElementsByTagName('ul')[0];
                var switchMostrar = this.parentNode.getElementsByTagName('span')[0];
                switchMostrar.innerHTML = 'Ocultar';
                oEl.style.height = '0';
                var iHeight = (isIE ? parseInt(iH)-22 : parseInt(iH)-25);
                var attributes = {
                    height : {
                        from : 0,
                        to : iHeight
                    }
                };
                var anim = new YAHOO.util.Anim(oEl, attributes, 0.5, YAHOO.util.Easing.easeOut);
                anim.animate();
                onMenuOpen.fire();
            }
            else {
                YUD.addClass(this, 'close');

                var oEl = this.parentNode.getElementsByTagName('ul')[0];
                var switchMostrar = this.parentNode.getElementsByTagName('span')[0];
                switchMostrar.innerHTML = 'Ver';

                var attributes = {
                    height : {
                        to : 0
                    }
                };
                var anim = new YUA(oEl, attributes, 0.5, YAHOO.util.Easing.easeIn);
                anim.animate();
                onMenuCollapse.fire();
            }
        }
    };
}();


/* SERVICIOS ADICIONALES */
var DEDservicios = window.DEDservicios || {};
DEDservicios.example = function() {
    var YUD = YAHOO.util.Dom;
    var YUE = YAHOO.util.Event;
    var YUA = YAHOO.util.Anim;
    var onMenuCollapse = new YAHOO.util.CustomEvent('menu collapse');
    var onMenuOpen = new YAHOO.util.CustomEvent('menu open');
    var last = [];
    var ua = navigator.userAgent.toLowerCase();
    var isOpera = (ua.indexOf('opera') != -1);
    var isIE = (ua.indexOf('msie') != -1 && !isOpera);
    return {
        init : function() {
            var oLi = YUD.getElementsByClassName('filtro','div','aco_servicios');
            for ( var i=0, j=oLi.length; i<j; ++i ) {
                YUE.on(oLi[i], 'click', this.collapse, oLi[i].parentNode.offsetHeight);
            }
            YUD.batch(oLi, function(oEl) {
                    if ( YUD.hasClass(oEl, 'close') ) {
                        oEl.parentNode.getElementsByTagName('ul')[0].style.height = '0';
                    }
                }
            );
        },
        collapse : function(e, iH) {
            last.push(this);
            if ( last.length > 3 ) {
                last.shift();
            }
            if ( YUD.hasClass(this, 'close') ) {
                YUD.removeClass(this, 'close');
                var oEl = this.parentNode.getElementsByTagName('ul')[0];
                var switchMostrar = this.parentNode.getElementsByTagName('span')[0];
                switchMostrar.innerHTML = 'Ocultar';
                oEl.style.height = '0';
                var iHeight = (isIE ? parseInt(iH)-22 : parseInt(iH)-25);
                var attributes = {
                    height : {
                        from : 0,
                        to : iHeight
                    }
                };
                var anim = new YAHOO.util.Anim(oEl, attributes, 0.5, YAHOO.util.Easing.easeOut);
                anim.animate();
                onMenuOpen.fire();
            }
            else {
                YUD.addClass(this, 'close');

                var oEl = this.parentNode.getElementsByTagName('ul')[0];
                var switchMostrar = this.parentNode.getElementsByTagName('span')[0];
                switchMostrar.innerHTML = 'Ver';

                var attributes = {
                    height : {
                        to : 0
                    }
                };
                var anim = new YUA(oEl, attributes, 0.5, YAHOO.util.Easing.easeIn);
                anim.animate();
                onMenuCollapse.fire();
            }
        }
    };
}();

/* VENTAJAS EXCLUSIVAS */
var DEDventajas = window.DEDventajas || {};
DEDventajas.example = function() {
    var YUD = YAHOO.util.Dom;
    var YUE = YAHOO.util.Event;
    var YUA = YAHOO.util.Anim;
    var onMenuCollapse = new YAHOO.util.CustomEvent('menu collapse');
    var onMenuOpen = new YAHOO.util.CustomEvent('menu open');
    var last = [];
    var ua = navigator.userAgent.toLowerCase();
    var isOpera = (ua.indexOf('opera') != -1);
    var isIE = (ua.indexOf('msie') != -1 && !isOpera);
    return {
        init : function() {
            var oLi = YUD.getElementsByClassName('filtro','div','aco_ventajas');
            for ( var i=0, j=oLi.length; i<j; ++i ) {
                YUE.on(oLi[i], 'click', this.collapse, oLi[i].parentNode.offsetHeight);
            }
            YUD.batch(oLi, function(oEl) {
                    if ( YUD.hasClass(oEl, 'close') ) {
                        oEl.parentNode.getElementsByTagName('ul')[0].style.height = '0';
                    }
                }
            );
        },
        collapse : function(e, iH) {
            last.push(this);
            if ( last.length > 3 ) {
                last.shift();
            }
            if ( YUD.hasClass(this, 'close') ) {
                YUD.removeClass(this, 'close');
                var oEl = this.parentNode.getElementsByTagName('ul')[0];
                var switchMostrar = this.parentNode.getElementsByTagName('span')[0];
                switchMostrar.innerHTML = 'Ocultar';
                oEl.style.height = '0';
                var iHeight = (isIE ? parseInt(iH)-22 : parseInt(iH)-25);
                var attributes = {
                    height : {
                        from : 0,
                        to : iHeight
                    }
                };
                var anim = new YAHOO.util.Anim(oEl, attributes, 0.5, YAHOO.util.Easing.easeOut);
                anim.animate();
                onMenuOpen.fire();
            }
            else {
                YUD.addClass(this, 'close');

                var oEl = this.parentNode.getElementsByTagName('ul')[0];
                var switchMostrar = this.parentNode.getElementsByTagName('span')[0];
                switchMostrar.innerHTML = 'Ver';

                var attributes = {
                    height : {
                        to : 0
                    }
                };
                var anim = new YUA(oEl, attributes, 0.5, YAHOO.util.Easing.easeIn);
                anim.animate();
                onMenuCollapse.fire();
            }
        }
    };
}();


/* INFORMACION EXTRA */
var DEDnotas = window.DEDnotas || {};
DEDnotas.example = function() {
    var YUD = YAHOO.util.Dom;
    var YUE = YAHOO.util.Event;
    var YUA = YAHOO.util.Anim;
    var onMenuCollapse = new YAHOO.util.CustomEvent('menu collapse');
    var onMenuOpen = new YAHOO.util.CustomEvent('menu open');
    var last = [];
    var ua = navigator.userAgent.toLowerCase();
    var isOpera = (ua.indexOf('opera') != -1);
    var isIE = (ua.indexOf('msie') != -1 && !isOpera);
    return {
        init : function() {
            var oLi = YUD.getElementsByClassName('filtro','div','aco_notas');
            for ( var i=0, j=oLi.length; i<j; ++i ) {
                YUE.on(oLi[i], 'click', this.collapse, oLi[i].parentNode.offsetHeight);
            }
            YUD.batch(oLi, function(oEl) {
                    if ( YUD.hasClass(oEl, 'close') ) {
                        oEl.parentNode.getElementsByTagName('ul')[0].style.height = '0';
                    }
                }
            );
        },
        collapse : function(e, iH) {
            last.push(this);
            if ( last.length > 3 ) {
                last.shift();
            }
            if ( YUD.hasClass(this, 'close') ) {
                YUD.removeClass(this, 'close');
                var oEl = this.parentNode.getElementsByTagName('ul')[0];
                var switchMostrar = this.parentNode.getElementsByTagName('span')[0];
                switchMostrar.innerHTML = 'Ocultar';
                oEl.style.height = '0';
                var iHeight = (isIE ? parseInt(iH)-22 : parseInt(iH)-25);
                var attributes = {
                    height : {
                        from : 0,
                        to : iHeight
                    }
                };
                var anim = new YAHOO.util.Anim(oEl, attributes, 0.5, YAHOO.util.Easing.easeOut);
                anim.animate();
                onMenuOpen.fire();
            }
            else {
                YUD.addClass(this, 'close');

                var oEl = this.parentNode.getElementsByTagName('ul')[0];
                var switchMostrar = this.parentNode.getElementsByTagName('span')[0];
                switchMostrar.innerHTML = 'Ver';

                var attributes = {
                    height : {
                        to : 0
                    }
                };
                var anim = new YUA(oEl, attributes, 0.5, YAHOO.util.Easing.easeIn);
                anim.animate();
                onMenuCollapse.fire();
            }
        }
    };
}();

/* MENUS DESPLEGABLES */
var DEDmenus = window.DEDmenus || {};
DEDmenus.example = function() {
    var YUD = YAHOO.util.Dom;
    var YUE = YAHOO.util.Event;
    var YUA = YAHOO.util.Anim;
    var onMenuCollapse = new YAHOO.util.CustomEvent('menu collapse');
    var onMenuOpen = new YAHOO.util.CustomEvent('menu open');
    var last = [];
    var ua = navigator.userAgent.toLowerCase();
    var isOpera = (ua.indexOf('opera') != -1);
    var isIE = (ua.indexOf('msie') != -1 && !isOpera);
    return {
        init : function(identificador) {
            var oLi = YUD.getElementsByClassName('filtro','div',identificador);
            YUE.on(oLi[0], 'click', this.collapse, oLi[0].parentNode.offsetHeight);
            YUD.batch(oLi, function(oEl) {
                    if ( YUD.hasClass(oEl, 'close') ) {
                        oEl.parentNode.getElementsByTagName('ul')[0].style.height = '0';
                    }
                }
            );
        },
        collapse : function(e, iH) {
            last.push(this);
            if ( last.length > 3 ) {
                last.shift();
            }
            if ( YUD.hasClass(this, 'close') ) {
                YUD.removeClass(this, 'close');
                var oEl = this.parentNode.getElementsByTagName('ul')[0];
                oEl.style.height = '0';
                var iHeight = (isIE ? parseInt(iH)-15 : parseInt(iH)-15);
                var attributes = {
                    height : {
                        from : 0,
                        to : iHeight
                    }
                };
                var anim = new YAHOO.util.Anim(oEl, attributes, 0.5, YAHOO.util.Easing.easeOut);
                anim.animate();
                onMenuOpen.fire();
                
                /** Gestión bullet **/
                try{ 
	                var bullet  = this.parentNode.getElementsByTagName('img')[0];
	                bullet.className = "sprite_general flecha_roja_abajo"; 
                } catch (e) {}
            }
            else {
                YUD.addClass(this, 'close');

                var oEl = this.parentNode.getElementsByTagName('ul')[0];
               
                var attributes = {
                    height : {
                        to : 0
                    }
                };
                var anim = new YUA(oEl, attributes, 0.5, YAHOO.util.Easing.easeIn);
                anim.animate();
                onMenuCollapse.fire();
                
                /** Gestión bullet **/      
                try{          
                    var bullet  = this.parentNode.getElementsByTagName('img')[0];
                    bullet.className = "sprite_general flecha_roja";
                } catch (e) {}
            }
        }
    };
}();



function inicioAcordeon(){
    YAHOO.util.Event.onContentReady('aco_masinfo',DEDmasinfo.example.init, DEDmasinfo.example, true);
    YAHOO.util.Event.onContentReady('aco_servicios',DEDservicios.example.init, DEDservicios.example, true);
    YAHOO.util.Event.onContentReady('aco_ventajas',DEDventajas.example.init, DEDventajas.example, true);
    YAHOO.util.Event.onContentReady('aco_notas',DEDnotas.example.init, DEDnotas.example, true);
}
