chooseDepartment = function(id) {
    ids = id.split(':');
    
    jQuery("#dealerId").val(ids[0]);
    
    if(jQuery('select#department'+ids[0]).length) {
        jQuery('select#department').find("option").remove();
        jQuery('select#department').append(jQuery('select#department'+ids[0]).find('option').clone());
    }
    
    jQuery("select.department").val(ids[1]==''?'main':ids[1]);
    
    jQuery('textarea#message').focus()
    
    return false;
}

jQuery("#dealerId").change(function() {
    el = jQuery(this);
    
    jQuery('select#department').find("option").remove();
    jQuery('select#department').append(jQuery('select#department'+el.val()).find('option').clone());
})

$(document).ready(function(){
    $(".hours-box").hover(
        function(){
            $(this).addClass("over");
        },
        function(){
            $(this).removeClass("over");
        }
    );

    $('.mod-form-contact-us-multi .dealer-info .heading').toggle( function(){
            $(this).next().slideDown("slow", function(){
                $(this).prev().addClass('expanded');
  
            });
            if(!$(this).hasClass("onceExpanded")){
                map_canvas = $(this).next().find(".map_canvas");
                map_postfix = map_canvas.attr("id");
                map_postfix = map_postfix.substring(11);
                
                google.maps.event.trigger(window["map"+map_postfix], 'resize');

                window["map"+map_postfix].setCenter(window["marker"+map_postfix].getPosition());
                
                window["infowindow"+map_postfix] = new google.maps.InfoWindow({  
                              content: window["infowindow"+map_postfix].getContent() 
                          });

                window["infowindow"+map_postfix].open(window["map"+map_postfix], window["marker"+map_postfix]);
            } 
            
            

        }, function() { 
            $(this).next().slideUp("slow", function(){
                $(this).prev().removeClass('expanded');
            });
            $(this).addClass("onceExpanded");
        }
        );
    
});
