function loadMap()
{
    // initialize our contact map      
    var latlng = new google.maps.LatLng(39.768326,-77.620128);
    var opts = {zoom: 8, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP};
    var map = new google.maps.Map(document.getElementById("mapdiv"), opts);
    var marker = new google.maps.Marker({position: latlng,
                                         map: map,
                                         title:"AAIM Controls Inc."});
    var aaim_map_content = '<div style="height:120px;">' +
        'AAIM Controls Inc.<br/>' +
        '11885 Mutual Drive<br/>' +
        'Waynesboro, PA 17268<br/><br/>' +
        '<a style="color:blue;" href="http://maps.google.com/maps?saddr=11885+Mutual+Drive+Waynesboro%2C+PA">Get Directions</a>' +
        '</div>';


    var info_window = new google.maps.InfoWindow({content:aaim_map_content,
                                                  maxHeight:400});
    google.maps.event.addListener(marker, 'click', function() { info_window.open(map, marker); });
      
    window.map_opts = opts;
    window.map = map;
}


// Jquery DOM Ready function
$(function()
  {
      var ie = $.browser.msie;
      // var slider_width = null;

      // if (ie)
      //     slider_width = screen.width * .65;
      
      // $('#slider').anythingSlider({buildNavigation:false, delay:4000, buildArrows:true,
      //                             width:slider_width});

      // if (ie)
      //     {
      //         $('.anythingWindow').removeAttr('overflow').removeAttr('position');
      //         $('.anythingSlider').removeAttr('overflow').removeAttr('position');
      //     }

      $(".peKenBurns").peKenburnsSlider();
      

      var links = ['.home_link', '.about_link', '.solutions_link', '.portfolio_link',
                   '.partners_link', '.contact_link', '#starters1_link', '#starters2_link',
                   '#vfd1_link', '#vfd2_link', '#micro1_link', '#micro2_link', '#plc1_link',
                   '#plc2_link', '#motor1_link', '#motor2_link'];
      for (i=0; i<links.length; i++)
          {
              var link = links[i];
              $(link).click(function(event)
                            {
                                var scroll = true;
                                var full_url = '';
                                //prevent the default action for the click event
                                event.preventDefault();

                                // hide all of our content divs
                                //$('.content').removeClass('show').addClass('hide');
                                var anim1 = $('.content').hide('slow').delay(250);

                                var show_div_id = this.id.split('_')[0];
                                if (show_div_id[0] != '#')
                                    // add id if were working with a class, otherwise
                                    // we already have '#' at the front                
                                    show_div_id = '#' + show_div_id; 

                                // if we're clicking on a '2' link, it's to toggle
                                // between a solutions item expand/collapse div and
                                // we want to toggle back to the entire solutions div
                                var solution_scroll_div = '';
                                if (show_div_id.indexOf("2") != -1)
                                    {
                                        solution_scroll_div = show_div_id.substring(0, show_div_id.length-1) + '1_link';
                                        show_div_id = '#solutions';
                                    }

                                //alert('show_div = ' + show_div_id + ', scroll_div = ' + solution_scroll_div);
                                
                                // if we scroll from our solution page to our individual
                                // content page (link 1), we get some jagged ass animation,
                                // looks much better if we don't
                                if (show_div_id.indexOf("1") != -1)
                                    scroll = false;
                                
                                // and then show the one we want
                                //$(show_div_id).removeClass('hide').addClass('show');
                                anim2 = $(show_div_id).show('slow', function() 
                                                            {
                                                                if (show_div_id == '#contact') // reset map
                                                                    {
                                                                        loadMap();
                                                                        google.maps.event.trigger(window.map, 'resize');
                                                                        window.map.setOptions(window.map_opts);
                                                                        window.map.setZoom(map.getZoom());
                                                                    }
                                                            });
                       
                                // The following gives a nice scroll effect to our content href
                                // without placing that ugly '/#target' shit in the address bar

                                //get the full url - like mysitecom/index.htm#home
                                full_url = this.href;
                                //alert('full_url = ' + full_url + ', show_div = ' + show_div_id);
                                
                                //split the url by # and get the anchor target name - home in mysitecom/index.htm#home
                                var trgt = solution_scroll_div;
                                if (trgt == '')
                                    {
                                        var part = full_url.split('#');
                                        trgt = '#' + part[1];
                                    }

                                //get the top offset of the target anchor
                                var target_offset = $(trgt).offset();
                                var target_top = target_offset.top;
                                
                                //goto that anchor by setting the body scroll top to anchor top
                                //if (scroll)
                                $.when(anim1, anim2).done(function()
                                                          { $('html, body').animate({scrollTop:target_top}, 500); });
                            });
          }
  });

