
 var map;
 var geocoder;
 var marker;
 var withMarker
 var currentImg = 0;
 var totalImgs = 0;
 
 function initializePropertyMap(elid, address,  wMarker) {
   if (GBrowserIsCompatible()) {
     map = new GMap2(document.getElementById(elid));
     map.setCenter(new GLatLng(0, 0), 12);

     //map.setUIToDefault();
     
     map.addControl(new GSmallZoomControl());
     
     geocoder = new GClientGeocoder();
     geocoder.getLocations(address, addAddressToMap);
     
     withMarker = wMarker;
   }
 }
 
 function addAddressToMap(response) {
 	map.clearOverlays();
    if (!response || response.Status.code != 200) {
      alert("Status Code:" + response.Status.code);
    } else {
      var place = response.Placemark[0];
      point = new GLatLng(place.Point.coordinates[1],
                          place.Point.coordinates[0]);
     
      if(withMarker){
      	marker = new GMarker(point, {draggable: false});
      	map.addOverlay(marker);
      }
      
      map.setCenter(point, 12);
      

  }
}

function changeImages()
{
	if(currentImg < totalImgs){
		$("#camp_img_" + currentImg).addClass('secundarias');
	 	$("#camp_img_" + currentImg).fadeOut('slow');
	 	var next = (currentImg + 1);
	 	$("#camp_img_" + next).removeClass('secundarias');
	 	$("#camp_img_" + next).fadeIn('slow');
	 	currentImg = next;
	}else{
		$("#camp_img_" + currentImg).addClass('secundarias');
	 	$("#camp_img_" + currentImg).fadeOut('slow');
	 	var next = 0;
	 	$("#camp_img_" + next).removeClass('secundarias');
	 	$("#camp_img_" + next).fadeIn('slow');
	 	currentImg = next;
		
	}
}
 
 $(document).ready(function(){
 
 	totalImgs = $(".secundarias").length;
	if(totalImgs > 0){
 		setInterval ( changeImages, 5000 );
 	}
 
 });

