charts=true;
var wxoverlay=null;
var latlngpt=document.createElement('DIV');

function make(dt){
    var centerPos=null;
    var zoom=null;
    var latlng=null;
    var countryChange=parseInt(getCookie('countrychange'));
    zoom = 5;
    centerPos = g_latlng;
    var mapOptions = {
        zoom: zoom,
        center: centerPos,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        mapTypeControl: false,
        navigationControl: true,
        streetViewControl: false,
        navigationControlOptions: { style: google.maps.NavigationControlStyle.ZOOM_PAN }
    };
    map = new google.maps.Map(document.getElementById("map"), mapOptions);
    latlngpt.id='latlngpt';
    latlngpt.style.top='8px';
    map.controls[google.maps.ControlPosition.RIGHT_TOP].push(latlngpt);
    google.maps.event.addListener(map, "mousemove", function(pt) { 
        document.getElementById("latlngpt").innerHTML = Math.round(pt.latLng.lng()*1000)/1000+", "+Math.round(pt.latLng.lat()*1000)/1000; 
    });
    wxoverlay=new WXTiles({'withnone':false,'autoupdate':false,'cview':dt, 'updateCallback': updateTSelect });
    wxoverlay.setToffset(g_tzoffset);
    wxoverlay.addToMap(map);
    wxoverlay.addColorBar('small','horiz');
    document.getElementById('tSelect').appendChild(wxoverlay.getTSelect());
    setCookie('defaultactivity', g_aname, 365);
    
    $("[name=undefined_tSelect]").change(function() {
        update_selected_item($(this).val());
    });
}

function updateView(dt) {
    wxoverlay.setView(dt);
    updateTSelect();
}

function updateTime(time, up) {
    var t=parseInt(time);
    t = (up) ? (t+1600000) : (t-1600000);
    wxoverlay.setTime(t);
}
function updateTSelect() {
    var itime=-1;
    var tar=[];
    var ftime=null;
    var thtml="";   
    var timesel = $("#times");
    var ctime=wxoverlay.ctime;
    wxoverlay.tselect.length=0;
    var alltimes=wxoverlay.getTimes(wxoverlay.cview, false);
    if (alltimes) {
        for (i=0;i<alltimes.length;i++){
            var t=alltimes[i];
            var nd=new Date(t+wxoverlay.toff*3600000);
            var jstime=datedays[nd.getUTCDay()]+' '+nd.getUTCDate()+' '+datemonths[nd.getUTCMonth()]+' '+zer0(nd.getUTCHours())+':'+zer0(nd.getUTCMinutes());
            wxoverlay.tselect.options[wxoverlay.tselect.options.length] = new Option(jstime,t,(t==wxoverlay.ctime),(t==wxoverlay.ctime));
            if (t==ctime) {
                itime=wxoverlay.tselect.options.length;
                tar[i]='<li class="sel"><a class="time-link time-sel" rel="'+t+'">'+jstime+'</a></li>';
                ftime=alltimes[i];
            }
            else {
                tar[i]='<li><a class="time-link" rel="'+t+'">'+jstime+'</a></li>';
            }
        }
        if (itime > -1) {
            wxoverlay.setTime(wxoverlay.tselect.options[itime-1].value);
            wxoverlay.tselect.selectedIndex=itime-1;
        }
        else {
            wxoverlay.setTime(wxoverlay.tselect.options[wxoverlay.tselect.options.length-1].value);
            wxoverlay.tselect.selectedIndex=wxoverlay.tselect.options.length-1;
        }
        
        if (!ftime) {
            tar[tar.length-1]='<li class="sel"><a class="time-link time-sel" rel="'+t+'">'+jstime+'</a></li>';
            ftime=alltimes[tar.length-1];
        }
        
        $.each(tar, function(index, value) { thtml+=value; });
        timesel.html(thtml);
        
        $(".time-link").bind("click", function() {
            remove_selected_item();
            add_selected_item($(this).attr('rel'));
            wx_change_time($(this).attr('rel'));
            $("[name=undefined_tSelect]").val($(this).attr('rel'));
        });
        wx_change_time(ftime);
    }
}

function wx_change_time(t) { wxoverlay.setTime(t); }

function remove_selected_item() {
    $(".time-link").each(function() {
        if ($(this).hasClass('time-sel')) {
            $(this).removeClass('time-sel');
            $(this).parent().removeClass('sel');   
        }
    });
}

function add_selected_item(t) { $('[rel='+t+']').addClass('time-sel').parent().addClass('sel'); }

function update_selected_item(t) {
    remove_selected_item();
    add_selected_item(t);
}

function step_time_forward() {
    var el=$('.sel').next().children('.time-link');
    var t = el.attr('rel');
    step_time(t);
}

function step_time_back() {
    var el=$('.sel').prev().children('.time-link');
    var t = el.attr('rel');
    step_time(t);
}

function step_time(t) {
    if (t) {
        wx_change_time(t);
        update_selected_item(t);
        $("[name=undefined_tSelect]").val(t);
    }
}





