/* 
 Rutinas para las páginas index.
 */
var publicityUrl = 'yellowPageSearch?action=publicity';
var categoryTable = 'yellowPageSearch?action=categoryT';
$(document).ready(function() {
    //Colocando estilos en la Cabecera
    if($('#pageType').val() == 'restPage'){
        $('#rest_ind').addClass('active');
    }else if($('#pageType').val() == 'yellowPage'){
        $('#yellow_ind').addClass('active');
    }else if($('#pageType').val() == 'hotelPage'){
        $('#hotel_ind').addClass('active');
    }else if($('#pageType').val() == 'callejeroPage'){
        $('#callejero_ind').addClass('active');
    }
    
    $("#categoryCombo").load('yellowPageSearch?action=categoryC');
    
    $("#deptoT").autocomplete(deptoList);
    $("#deptoT").bind("change", function(e){
        var temp = '';//almacenará arrays de autofillData.js
        switch($("#deptoT").val()){
            case 'La Paz':
                temp = LA_PAZ; 
                break;
            case 'Oruro':
                temp = ORURO;
                break;
            case 'Potosi':
                temp = POTOSI;
                break;
            case 'Cochabamba':
                temp = COCHABAMBA;
                break;
            case 'Chuquisaca':
                temp = CHUQUISACA;
                break;
            case 'Tarija':
                temp = TARIJA;
                break;
            case 'Pando':
                temp = PANDO;
                break;
            case 'Santa Cruz':
                temp = SANTA_CRUZ;
                break;
            case 'Beni':
                temp = BENI;
                break;
        }
        $("#cityT").val('');
        $("#cityT").autocomplete(temp);
    });
    var d = new Date();
    $("#top_publicity").load(publicityUrl+'&type1=true&date='+d.getTime().toString());
    $("#sectionList").load(categoryTable+'&depto='+$("#deptoT").val());
    //Publicidad central independiente.
    $("#publicidad_Index_P").load('yellowPageSearch?action=publicity&type10=true&date='+d.getTime().toString());        
    if($("#agenda_news").val() != undefined){
        loadAgenda();
    }
    setInterval("changeWeatherLoc()",25000);//cambiando de ciudad.
})

//Cambia la ciudad del clima cierto tiempo.
var locCod = ['SAM|BO|BL007|POTOSI','SAM|BO|BL004|SANTA CRUZ|','SAM|BO|BL009|ORURO','SAM|BO|BL001|SUCRE','SAM|BO|BL009|TARIJA','SAM|BO|BL002|COCHABAMBA','SAM|BO|BL004|LA PAZ|'];
var weatherIndex = 0;
function changeWeatherLoc(){
    var WEATHER_FLASH;
    if($('#Clima_index_p').length > 0){
        WEATHER_FLASH = '<div style=\'width: 180px; height: 150px; background-image: url( http://vortex.accuweather.com/adcbin/netweather_v2/backgrounds/winter2_180x150_bg.jpg ); background-repeat: no-repeat; background-color: #7CADEE;\' ><div id=\'NetweatherContainer\' style=\'height: 138px;\' >'+
            '<script src=\'http://netweather.accuweather.com/adcbin/netweather_v2/netweatherV2ex.asp?partner=netweather&tStyle=normal&logo=1&zipcode='+ locCod[weatherIndex]+'&lang=esp&size=8&theme=winter2&metric=1&target=_self\'></script></div>'+
            '<div style=\'text-align: center; font-family: arial, helvetica, verdana, sans-serif; font-size: 10px; line-height: 12px; color: #0000FF;\' ><a style=\'color: #0000FF\' href=\'http://www.accuweather.com/world-index-forecast.asp?partner=netweather&locCode=SAM|BO|BL004|LA PAZ|&metric=1\' >Weather Forecast</a> | <a style=\'color: #0000FF\' href=\'http://www.accuweather.com/maps-satellite.asp\' >Weather Maps</a></div></div>'
        $('#Clima_index_p').html(WEATHER_FLASH);
    }else{
        WEATHER_FLASH = '<div style=\'width: 300px; height: 150px; background-image: url( http://vortex.accuweather.com/adcbin/netweather_v2/backgrounds/spring1_300x250_bg.jpg ); background-repeat: no-repeat; background-color: #607041;\' ><div id=\'NetweatherContainer\' style=\'height: 238px;\' >'+
            '<script src=\'http://netweather.accuweather.com/adcbin/netweather_v2/netweatherV2ex.asp?partner=netweather&tStyle=normal&logo=1&zipcode='+ locCod[weatherIndex]+'&lang=esp&size=8&metric=1&target=_self\'></script></div>'+
            '<div style=\'text-align: center; font-family: arial, helvetica, verdana, sans-serif; font-size: 10px; line-height: 12px; color: #0000FF;\' ><a style=\'color: #0000FF\' href=\'http://www.accuweather.com/world-index-forecast.asp?partner=netweather&locCode=SAM|BO|BL004|LA PAZ|&metric=1\' >Weather Forecast</a> | <a style=\'color: #0000FF\' href=\'http://www.accuweather.com/maps-satellite.asp\' >Weather Maps</a></div></div>'
        $('#Clima_index_p2').html(WEATHER_FLASH);
    }
    if(weatherIndex < locCod.length-1){
        weatherIndex++;
    }else {
        weatherIndex = 0;
    }
}

function loadAgenda(){
    $.post('yellowPageSearch?action=agendaNews',{        
    },
    function(data) {        
        $("#agenda_news").append(data);
        $("#agenda_news").jCarouselLite({  
            vertical: true,  
            visible: 1,  
            auto:10000,  
            speed:1000  
        });        
    });
}



