//  interval[]: is an array of id's to be used
//  by clearInterval(id) and clearTimeout(id) 
//  to stop certain events from firing
var interval = new Array();

// gaia_map: creates a map object
var gaia_map = function() {
  var that;
  that = {
    current : 1,
    total :10,
    change_region : function(id){
        $('.map_update').not('#map_update_'+id).fadeOut(400);
        $('#map_update_'+id).fadeIn(400).siblings().fadeOut(400);
                    },
    increment : function(){
        that.change_region(that.current);
        if(that.current >= that.total) {
            that.current = 1;
        }else{
            that.current++;
        }
    }
  };
  return that;
};

//  map: an instance of the gaia_map() object described above
var map = gaia_map();

//  map_over(map_over_id): changes the active region
//  on the map, if the user hovers over a link
//  for a long enough period of time.
var map_over = function(map_over_id){
    var id  = map_over_id;
    map.change_region(id);
}

// map_details(map_details_id): opens the location details
// over the map
var map_details = function(map_details_id){
    var id = map_details_id;
    $('#map_details_'+id).fadeIn(400).siblings().fadeOut(400);
}

// map_close(map_details_id): closes the details for a location
var map_close = function(map_details_id){
    var id = map_details_id;
    $('#map_details_'+id).fadeOut(400);
}

// initialize_map: sets up the auto-rotator,
// and hook up the mouseover and mouseout events
// fot the regions to the map object.
var initialize_map = function(){

    //  initialize the auto-rotatar, which
    //  cycles through the regions one at a time
    //  until the user begins interacting with the map


    $('[title="Seattle, WA"]').mouseover(function(){
        map_over(811);
    });
    $('[title ="Phoenix, AZ"]').mouseover(function(){
        map_over(798);
    });
    $('[title ="Denver, CO"]').mouseover(function(){
            map_over(803);
    });
    $('[title ="Milwaukee, WI"]').mouseover(function(){
            map_over(806);
    });
    $('[title ="Atlanta, GA"]').mouseover(function(){
            map_over(805);
    });
    $('[title ="Pittsburgh, PA"]').mouseover(function(){
            map_over(810);
    });
    $('[title ="Newark/Jersey City, NJ"]').mouseover(function(){
            map_over(804);
    });
    $('[title ="New Haven, CT"]').mouseover(function(){
            map_over(801);
    });
    $('[title ="Boston, MA"]').mouseover(function(){
            map_over(800);
    });
    $('[title ="Syracuse, NY"]').mouseover(function(){
            map_over(812);
    });
   $('[title ="california"]').mouseover(function(){
            map_over(11);
    });
    $('[title ="Sonoma County, CA"]').mouseover(function(){
            map_over(808);
    });
    $('[title ="Oakland, CA"]').mouseover(function(){
            map_over(802);
    });
    $('[title ="San Jose, CA"]').mouseover(function(){
            map_over(813);
    });
        $('[title ="Ventura County, CA"]').mouseover(function(){
            map_over(799);
    });
        $('[title ="Los Angeles, CA"]').mouseover(function(){
            map_over(807);
    });
        $('[title ="Orange County, CA"]').mouseover(function(){
            map_over(809);
    });
        $('[title ="San Diego, CA"]').mouseover(function(){
            map_over(797);
    });


    //  make the click event for each region
    //  be linked to the map_details($region) function

    $('[title="Seattle, WA"]').click(function(){
        map_details(811);
    });
    $('[title ="Phoenix, AZ"]').click(function(){
        map_details(798);
    });
    $('[title ="Denver, CO"]').click(function(){
            map_details(803);
    });
    $('[title ="Milwaukee, WI"]').click(function(){
            map_details(806);
    });
    $('[title ="Atlanta, GA"]').click(function(){
            map_details(805);
    });
    $('[title ="Pittsburgh, PA"]').click(function(){
            map_details(810);
    });
    $('[title ="Newark/Jersey City, NJ"]').click(function(){
            map_details(804);
    });
    $('[title ="New Haven, CT"]').click(function(){
            map_details(801);
    });
    $('[title ="Boston, MA"]').click(function(){
            map_details(800);
    });
    $('[title ="Syracuse, NY"]').click(function(){
            map_details(812);
    });
    $('[title ="Sonoma County, CA"]').click(function(){
            map_details(808);
    });
    $('[title ="Oakland, CA"]').click(function(){
            map_details(802);
    });
    $('[title ="San Jose, CA"]').click(function(){
            map_details(813);
    });
        $('[title ="Ventura County, CA"]').click(function(){
            map_details(799);
    });
        $('[title ="Los Angeles, CA"]').click(function(){
            map_details(807);
    });
        $('[title ="Orange County, CA"]').click(function(){
            map_details(809);
    });
        $('[title ="San Diego, CA"]').click(function(){
            map_details(797);
    });
    $('[title ="california"]').click(function(){
          $('#ca-map').fadeIn(400);
    }); 
    $('.detailsclose').click(function(){
      $('.map_details').fadeOut(400);
    });
    $('.caclose').click(function(){
      $('#ca-map').fadeOut(400);
    });
 };
 
 //  Sanitize the environment
 //  and run the code when the browser loads!
jQuery(function($){
    if (!$.browser.msie) $('body').css('opacity', 0.9999);
    initialize_map();
});
