<!--

var geocoder;
var map;
var theImages = new Array();

theImages[0] = '/images/sub-content-header-bg-1.jpg';
theImages[1] = '/images/sub-content-header-bg-2.jpg';
theImages[2] = '/images/sub-content-header-bg-3.jpg';
theImages[3] = '/images/sub-content-header-bg-4.jpg';
theImages[4] = '/images/sub-content-header-bg-5.jpg';
theImages[5] = '/images/sub-content-header-bg-6.jpg';

var j = 0;
var p = theImages.length;
var preBuffer = new Array();
for (i = 0; i < p; i++) {
	preBuffer[i] = new Image();
	preBuffer[i].src = theImages[i];
}
var whichImage = Math.round(Math.random()*(p-1));

function rotateImage() {
	document.getElementById('content-header').style.background = 'url(\'' + theImages[whichImage] + '\')';
}

function initialize() {
  geocoder = new google.maps.Geocoder();
	var image = 'images/clipart-gmaps-marker.png';
  var latlng = new google.maps.LatLng(-34.397, 150.644);
  var myOptions = {
    zoom: 14,
    center: latlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP,
		mapTypeControl: true,
		mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
		navigationControl: true,
		navigationControlOptions: {
		    style: google.maps.NavigationControlStyle.DEFAULT,
		    position: google.maps.ControlPosition.TOP_LEFT
		}
  }
  var map_norfolk = new google.maps.Map(document.getElementById("map_norfolk"), myOptions);
  var map_ches = new google.maps.Map(document.getElementById("map_ches"), myOptions);
  var map_vb = new google.maps.Map(document.getElementById("map_vb"), myOptions);

  if (geocoder) {
		var addr_norfolk = '1200 North Military Highway, Norfolk, VA 23502-2227';
		var addr_ches = '1510 Sam\'s Circle Chesapeake, VA 23320-4693';
		var addr_vb = '1400 South Independence Boulevard Virginia Beach, VA 23462-5331';

    geocoder.geocode( { 'address': addr_norfolk}, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
        map_norfolk.setCenter(results[0].geometry.location);
        var marker = new google.maps.Marker({
            map: map_norfolk,
            position: results[0].geometry.location,
						icon: image
        });

				var infowindow = new google.maps.InfoWindow({ 
					content: '<img src="/images/clipart-gmaps-marker.png" /><br />1200 North Military Highway<br />Norfolk, VA. 23502<br /><strong>(757) 351-6894</strong>',
					size: new google.maps.Size(25,25)
				});

				google.maps.event.addListener(marker, 'click', function() {
				    infowindow.open(map_norfolk,marker);
				});
      }
    });

    geocoder.geocode( { 'address': addr_ches}, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
        map_ches.setCenter(results[0].geometry.location);
        var marker = new google.maps.Marker({
            map: map_ches, 
            position: results[0].geometry.location,
						icon: image
        });

				var infowindow = new google.maps.InfoWindow({ 
					content: '<img src="/images/clipart-gmaps-marker.png" /><br />1510 Sam\'s Circle<br />Chesapeake, VA 23320<br /><strong>(757) 410-4009</strong>',
					size: new google.maps.Size(25,25)
				});

				google.maps.event.addListener(marker, 'click', function() {
				    infowindow.open(map_ches,marker);
				});
      }
    });

    geocoder.geocode( { 'address': addr_vb}, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
        map_vb.setCenter(results[0].geometry.location);
        var marker = new google.maps.Marker({
            map: map_vb, 
            position: results[0].geometry.location,
						icon: image
        });

				var infowindow = new google.maps.InfoWindow({ 
					content: '<img src="/images/clipart-gmaps-marker.png" /><br />1400 South Independence Boulevard<br />Virginia Beach, VA 23462<br /><strong>(757) 233-7610</strong>',
					size: new google.maps.Size(25,25)
				});

				google.maps.event.addListener(marker, 'click', function() {
				    infowindow.open(map_vb,marker);
				});
      }
    });
  }
}

function popup(url, w, h) {
   var xMin = 50;
   var yMin = 50;

    var xMax = screen.availWidth * 0.7;
    var yMax = screen.availHeight * 0.7;

    if (w < xMin || w > xMax)
    {
        w = xMax;
    }

    if (h < yMin || h > yMax)
    {
        h = yMax;
    }

    // Center on screen.
    var x = screen.availWidth / 2 - w / 2;
    var y = screen.availHeight / 2 - h / 2;

    var options = "";

    options += "toolbar=no, location=no, directories=no, status=yes, ";
    options += "menubar=no, scrollbars=yes, resizable=yes, copyhistory=no, ";
    options += "dependent=yes, ";

    options +=    "width=" + w + ", height=" + h + ", left=" + x + ", top=" + y;

    var popupWindow = window.open(url, "PopUp", options);
}

function theRotator() {
	//Set the opacity of all images to 0
	$('div#rotator ul li').css({opacity: 0.0});
	
	//Get the first image and display it (gets set to full opacity)
	$('div#rotator ul li:first').css({opacity: 1.0});
		
	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('rotate()',9000);
	
}

function rotate() {	
	//Get the first image
	var current = ($('div#rotator ul li.show')?  $('div#rotator ul li.show') : $('div#rotator ul li:first'));

	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#rotator ul li:first') :current.next()) : $('div#rotator ul li:first'));	
	
	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	
};

// -->
