var pageTracker;
Ext.onReady(function() {
    if (Ext.get('menu_principal')) {
        new Ext.ux.Menu('menu_principal', {
            transitionType: 'slide',
            direction: 'horizontal',
            delay: 0.2,
            autoWidth: true,
            transitionDuration: 0.3,
            animate: true
        })
    }
    if (Ext.get('banner')) {
        new Ext.ux.Carousel('banner', {
            itemSelector: 'div.banner',
            interval: 5,
            autoPlay: true,
            navigationOnHover: true
        })
    }
    if (Ext.get('hidden_menu_1')) {
        Ext.fly('hidden_menu_1').slideOut('t', {
            useDisplay: true
        });
        if (Ext.get('hidden_menu_2')) {
            Ext.fly('hidden_menu_2').slideOut('t', {
                useDisplay: true
            })
        }
        Ext.get('btn_menu_1').on('click', function() {
            if (Ext.fly('hidden_menu_1').hasClass('open')) {
                Ext.fly('hidden_menu_1').fadeIn();
                Ext.fly('hidden_menu_1').removeClass('open')
            } else {
                Ext.fly('hidden_menu_1').fadeOut({
                    remove: false,
                    useDisplay: true
                });
                Ext.fly('hidden_menu_1').addClass('open')
            }
            viewDepoimentos()
        });
        if (Ext.get('hidden_menu_2')) {
            Ext.get('btn_menu_2').on('click', function() {
                if (Ext.fly('hidden_menu_2').hasClass('open')) {
                    Ext.fly('hidden_menu_2').fadeIn();
                    Ext.fly('hidden_menu_2').removeClass('open')
                } else {
                    Ext.fly('hidden_menu_2').fadeOut({
                        remove: false,
                        useDisplay: true
                    });
                    Ext.fly('hidden_menu_2').addClass('open')
                }
                viewDepoimentos()
            })
        }
    }
    function viewDepoimentos() {
        if (Ext.get('depoimentos')) {
            if (Ext.fly('hidden_menu_1').hasClass('open')) {
                Ext.fly('depoimentos').fadeIn()
            } else {
                Ext.fly('depoimentos').fadeOut({
                    remove: false,
                    useDisplay: true
                })
            }
        }
    }
    if (Ext.get('youtube')) {
        if (Ext.get('btn_play')) {
            Ext.get('btn_play').on('click', function() {
                if (!Ext.get('btn_play').hasClass('pause')) playVideo();
                else pauseVideo()
            });
            function stopVideo() {
                if (ytplayer) {
                    ytplayer.stopVideo()
                }
            }
            Ext.get('btn_stop').on('click', stopVideo);
            Ext.get('btn_sound_on').on('click', function() {
                if (!Ext.get('btn_sound_on').hasClass('mute')) muteVideo();
                else unMuteVideo();
                Ext.get('btn_sound_on').toggleClass('mute')
            })
        }
    }
});
$(document).ready(function() {
    $('.rounded').corners();
    $('.menu').mouseover(function() {
        $(this).addClass('ahover');
        var a = $('#' + $(this).attr('id') + ' img').attr('src');
        a = a.replace('.gif', '_hover.gif');
        $('#' + $(this).attr('id') + ' img').attr('src', a)
    }).mouseout(function() {
        $(this).removeClass('ahover');
        var a = $('#' + $(this).attr('id') + ' img').attr('src');
        a = a.replace('_hover.gif', '.gif');
        $('#' + $(this).attr('id') + ' img').attr('src', a)
    }).css('cursor', 'pointer').click(function() {
        var a = $('#' + $(this).attr('id') + ' a').attr('href');
        if (a && a != '#') window.location.href = a
    });
	
    $('.chat').click(function() {
			
        analytics('Chat');
        var a = (screen.width - 626) / 2;
        var b = (screen.height - 560) / 2;
        settings = 'height=465,width=615,top=' + b + ',left=' + a + ',scrollsssbars=no,toolbar=no,location=no,status=no,menubar=no,resizable=no,dependent=no,titlebar=0';
        win = window.open('http://chat.impacta.com.br/chatv2/default.asp', 'chat', settings);
		
        if (parseInt(navigator.appVersion) >= 4) {
            win.window.focus()
        }
    });
	
    $('.analytics').click(function() {
        var a = $(this).attr('title');
        if (a) {
            analytics(a)
        } else {
            analytics(window.location)
        }
    });
	
    $('#form_top_busca').submit(function() {
        if ($('#desbusca').val() == '') {
            return false
        } else {
            return true
        }
    });
    $('.bloco span a').each(function() {
        var a = new Date();
        $(this).html($(this).text().replace(/\(diaHoje\)/g, a.getDate()));
        $(this).html($(this).text().replace(/\(mesHoje\)/g, monthName(a.getMonth()).toString().toLowerCase()))
    })
});
function right(a, n) {
    if (n <= 0) return "";
    else if (n > String(a).length) return a;
    else {
        var b = String(a).length;
        return String(a).substring(b, b - n)
    }
}
function addFavoritos() {
    var a = parent.location.href;
    var b = parent.frames.document.title;
    if (window.sidebar) window.sidebar.addPanel(b, a, "");
    else if (window.opera && window.print) {
        var c = document.createElement('a');
        c.setAttribute('rel', 'sidebar');
        c.setAttribute('href', a);
        c.setAttribute('title', b);
        c.click()
    } else if (document.all) {
        window.external.AddFavorite(a, b)
    }
}
function win(a, b, w, h) {
    var c = (screen.width - w) / 2;
    var d = (screen.height - h) / 2;
    settings = 'height=' + h + ',width=' + w + ',top=' + d + ',left=' + c + ',scrollsssbars=no,toolbar=no,location=no,status=no,menubar=no,resizable=no,dependent=no';
    win = window.open(a, b, settings);
    if (parseInt(navigator.appVersion) >= 4) {
        win.window.focus()
    }
}
function analytics(a) {
	_gaq.push(['_trackPageview', a]);
}
function monthName(a) {
    MonthNames = ['Janeiro', 'Fevereiro', 'Mar\u00e7o', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro'];
    return MonthNames[a]
}
