$(function(){
	if($("#map").length > 0) initMap()
	$('#main form input[type=file]').bind('change focus click', fileInputHandler);
	melto();
	})
function melto(){
	var lnkMail = $('a.melto')
	$(lnkMail).each(function (i){
			dom = $(this).attr("href")
			domUrl = dom.substring(11,dom.length);
			lnkMelto = "mailto:" + $(this).text() +'@'+ domUrl;				  
			$(this).attr('href',lnkMelto)
			$(this).text($(this).text() +'@'+ domUrl)
							  })
}
	
function fileInputHandler(){
	$this = $(this)
      $val = $this.val()
	  $(".fake").val($val)
	  }
	
function initMap() {
		var myOptions = {
		  zoom: 14,
		  disableDefaultUI: true,
		  scaleControl: true,
		   navigationControl: true,
		  navigationControlOptions: {
			style: google.maps.NavigationControlStyle.SMALL
		  },
		  mapTypeId: google.maps.MapTypeId.ROADMAP
		};
		var Gmap = new google.maps.Map(document.getElementById("map"),myOptions);
		if(lng ==0 || lat==0){
			var  geocoder = new google.maps.Geocoder();
			geocoder.geocode( { 'address': adr}, function(results, status) {
			      if (status == google.maps.GeocoderStatus.OK) {
			    	Gmap.setCenter(results[0].geometry.location);
			    	var image = '/css/gfx/marker.png';
					var marker = new google.maps.Marker({
						position: results[0].geometry.location,
						icon: image
						});
					marker.setMap(Gmap); 
			      } else {
			        alert("Geocode was not successful for the following reason: " + status);
			      }
			    });	
		}else{
			var point = new google.maps.LatLng(lat,lng);
			Gmap.setCenter(point);
			var marker = new google.maps.Marker({
		        position: point, 
		        map: Gmap
		    });

		}
			
		 
    }
