$(document).ready(function(){
    /* This code is executed after the DOM has been completely loaded */
    /* Script original adaptado pelo Maujor */
    /* Defining an array with the tab text and AJAX pages: */
    var TabsConversar = {
        ''	: 'paginas-ajax/conversar/nossos-clientes.php'
    /*'Nossos clientes'	: 'paginas-ajax/conversar/nossos-clientes.php' */
    /* 'MANDAR UMA MENSAGEM'	: 'paginas-ajax/conversar/mensagem.php', */
    /* 'FAZER UM ORÇAMENTO'	: 'paginas-ajax/conversar/orcamento.php', */
    /* 'ME TORNAR UM BREDIANO'	: 'paginas-ajax/conversar/brediano.php', */
    }

    /* The available colors for the tabs: */
    var colors = ['','','',''];

    /* The colors of the line above the tab when it is active:
	var topLineColor = {
		blue:'lightblue',
		green:'lightgreen',
		red:'red',
		orange:'orange'
	}*/

    /* Looping through the Tabs object: */
    var z=0;
    var c=0;
    $.each(TabsConversar,function(i,j){
        /* Sequentially creating the tabs and assigning a color from the array: */
        var tmpConversar = $('<li class="tab_conversar'+(++c)+'"><a href="#" class="tab tab-conversar '+colors[(z++%4)]+'"><span>'+i+'</span></a></li>');

        /* Setting the page data for each hyperlink: */
        tmpConversar.find('a').data('page_conversar',j);

        /* Adding the tab to the UL container: */
        $('ul.tabContainer-conversar').append(tmpConversar);
    })

    /* Caching the tabs into a variable for better performance: */
    var the_tabsConversar = $('.tab-conversar');

    the_tabsConversar.click(function(e){
        var element = $(this);
        element.parent('li').siblings('li').children('a').removeClass('corrente');
        element.addClass('corrente');

        /* Checking whether the AJAX fetched page has been cached: */

        if(!element.data('cache'))
        {
            /* If no cache is present, show the gif preloader and run an AJAX request: */
            $('#contentHolder-conversar').html('<img src="imagens/ajax_preloader.gif" width="64" height="64" class="preloader" />');

            $.get(element.data('page_conversar'),function(msg){
                $('#contentHolder-conversar').html(msg);

                /* After page was received, add it to the cache for the current hyperlink: */
                element.data('cache',msg);
            });
        }
        else $('#contentHolder-conversar').html(element.data('cache'));

        e.preventDefault();
    })

    /* Emulating a click on the first tab so that the content area is not empty: */
    the_tabsConversar.eq(0).click();
});

