jQuery(document).ready(function() {
	
    eletroChamadasDestaques = function(instanceName) {
        this.init(instanceName);
    }
    
    jQuery.extend(eletroChamadasDestaques.prototype, {
        current: 1, 
        total: 0,
        delay: 10000,
        name: '',
        videos: new Array(),
        
        init: function(instanceName) {
            var th = this;
            this.name = instanceName;
            
            this.total = jQuery('a.chamadas_home_abas').length;
            jQuery('#chamadas_home_abas .chamadas_home_content').hide();
            jQuery('a.chamadas_home_abas').each(function() {
                jQuery(this).click(function() {
                	var number = jQuery(this).parents('li').attr('id');
                    number = number.substr(number.length - 1, 1);
                    if (number != th.current) th.goTo(number);
                });
            });
            
            this.goTo(this.current);
        }, 
        
        next: function() {
            var target;
            if (this.current < this.total) {
                target = this.current + 1;
            } else {
                target = 1;
            }
            this.goTo(target);
        }, 
        
        goTo: function(target) {

        	
        	jQuery('#chamadas_home_aba_' + this.current).fadeOut();
        	jQuery('#chamadas_home_aba_' + target).fadeIn();
            //jQuery('#destaques_navigation a').removeClass('destaques_navigation_selected');
            //jQuery('#destaques_navigation a:contains("' + target + '")').addClass('destaques_navigation_selected');
            this.current = parseInt(target);

            if (this.total > 1) {
	            clearTimeout(this.slideshow);
	            this.slideshow = setTimeout(this.name + '.next()', this.delay);
            }
        }

    });
    
    eletro_chamadas = new eletroChamadasDestaques('eletro_chamadas');
});