$().ready(
    function() {       	
    	initMap();      	
        address1 = new addressModule({lat: config.lat, lng: config.lng, countryCode: config.countryCode, position: '#locationHouse', zip: '#locationZip', city: '#locationCity', street: '#locationStreet', house: '#locationHouse', country : '#locationCountry', geo : '#locationGeo', pointAcceptText: config.pointAccept, mapCloseText: config.mapClose, addressNotFoundText: config.addressNotFound, geoCodeNotFoundText: config.geoCodeNotFound});
    }
);

function initMap()
{		
        var latlng = new google.maps.LatLng(config.lat,config.lng);            
        var myOptions = {
            zoom: 12,
            center: latlng,
            mapTypeControl: false,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        config.map = new google.maps.Map(document.getElementById("mapCanvasSearch"), myOptions);
        setMarkers(config.map, config.builders);
        
        $(".jobsListLight, .jobsListDark").hover(
            function (e) {
              goMarker($(this).attr('counter'));
            },
            function (e) {}
        );
       


}
function setMarkers(map, locations)
{
    var image = new google.maps.MarkerImage(config.imageDir+'/image/tool.png',
        new google.maps.Size(12, 34),
        new google.maps.Point(0,0),
        new google.maps.Point(7, 34));    
    for (var i = 0; i < locations.length; i++) {
        var hq = locations[i];        
        var myLatLng = new google.maps.LatLng(hq.lat, hq.lng);        
        if (i == 0)
        {
            config.bounds=new google.maps.LatLngBounds(myLatLng, myLatLng);
        }
        else
        {
            config.bounds.extend(myLatLng);
        }
        hq.i=i;
        config.markers[i] = new google.maps.Marker({
            position: myLatLng,
            map: map,
            icon: image,            
            title: hq.name,
            zIndex : hq.zIndex,
            specData: hq
        });
        /*google.maps.event.addListener(config.markers[i], 'click', function(e, o) {
            var otherChecked=$('input[name=check_'+this.specData.id+']').attr('checked');
            $('#demonstrator .jobsListData a').html(this.specData.name);
            $('#demonstrator .jobsListData a').attr('href', '/'+this.specData.link);
            $('#demonstrator .jobsListData input').attr('name', 'check_'+this.specData.id);
            $('#demonstrator .jobsListData input').attr('checked', otherChecked);
            $('#demonstrator .jobsListPhoneNumber').html(this.specData.phone);
            //$('#demonstrator a.listLink').html(this.specData.name);
            //$('#demonstrator a.listLink').attr('href', '/'+this.specData.link);
            $('#demonstrator .jobsListVoteBox').html($('#jobsListVoteBox_'+this.specData.id).html());
            $('#demonstrator').attr('counter', this.specData.i);
            $('input[name=check_'+this.specData.id+']').attr('checked')
            $('#demonstrator').show();
        });*/

    }
    config.map.fitBounds(config.bounds);
}
function goMarker(i)
{	
    config.map.panTo(config.markers[i].position);    
}
