$(document).ready(function() {
	thumbHover();
	initialize();
	slideShow('#slide');
});

function thumbHover() {
	$('.thumb').hover(function() {
		$(this).animate({opacity: '1'});
	}, function() {
		$(this).animate({opacity: '0.7'});		
	});
}

var geocoder;
  var map;
  function initialize() {
	 if($('#map').length>0){
    geocoder = new google.maps.Geocoder();
    var latlng = new google.maps.LatLng(51, -4);
    var myOptions = {
      zoom: 15,
      center: latlng,
      mapTypeControl: false,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    map = new google.maps.Map(document.getElementById("map"), myOptions);
    codeAddress();
	}
  }

  function codeAddress() {
    var address = document.getElementById("address").innerHTML;
    if (geocoder) {
      geocoder.geocode( { 'address': address}, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
          map.setCenter(results[0].geometry.location);
          var marker = new google.maps.Marker({
              map: map, 
              position: results[0].geometry.location
          });
          /* open info window */
          var balloontext = document.getElementById('balloon').innerHTML;
            var infowindow = new google.maps.InfoWindow({
				content: balloontext,
				maxWidth: 150
		    });
          infowindow.open(map,marker);
        } else {
          //alert("Geocode was not successful for the following reason: " + status);
        }
      });
    }
  }

function slideShow(element) {
	if($(element).length>0){
		setInterval(function() {
			if($(element).children('img:visible:eq(0)').prev().size()>0) {
				$(element).children('img:visible:eq(0)').prev().show();
				$(element).children('img:visible:eq(1)').fadeOut(2000);
			}
			else {
				$(element).children('img:last').fadeIn(2000, function() {
					$(element).children('img:visible').not(':last').fadeOut(2000);
				});
			}
		}, 5000);
	}
}

