jQuery(document).ready(function($){
    $('.lightbox-link').fancybox();
	$('.fancybox').fancybox();
    $('.validate-form').validate();
	
	//Initialize Google Maps
	if ($('.block.maps .content .map_canvas').length >0 ){
	 var map = new google.maps.Map(document.getElementById('map_canvas'), {
      zoom: 14,
	  center: new google.maps.LatLng(-33.92, 151.25),
     mapTypeId: google.maps.MapTypeId.ROADMAP
    });
	
	 var infowindow = new google.maps.InfoWindow();

    var marker, i;
}

	
	
	//Loop through stockists locations
	$maps = $('.block.maps .content .map_canvas');
    $maps.each(function(index, Element) {
        $infotext = $(Element).children('.infotext');

       /* var myOptions = {
            'zoom': parseInt($infotext.children('.zoom').text()),
			center: new google.maps.LatLng(-33.92, 151.25),
            'mapTypeId': google.maps.MapTypeId.ROADMAP
        };*/
        //var map;
        var geocoder;
       // var marker;
        var infowindow;
        var address = $infotext.children('.address').text() + ', '
                + $infotext.children('.city').text() + ', '
                + $infotext.children('.state').text() + ' '
                + $infotext.children('.zip').text() + ', '
                + $infotext.children('.country').text()
        ;
        var content = '<strong>' + $infotext.children('.location').text() + '</strong><br />'
                + $infotext.children('.address').text() + '<br />'
                + $infotext.children('.city').text() + ', '
                + $infotext.children('.state').text() + ' '
                + $infotext.children('.zip').text()
        ;
        if (0 < $infotext.children('.phone').text().length) {
            content += '<br />' + $infotext.children('.phone').text();
        }

        geocoder = new google.maps.Geocoder();
        geocoder.geocode({'address': address}, function(results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
               // myOptions.center = results[0].geometry.location;
               // map = new google.maps.Map(Element, myOptions);
			    map.setCenter(results[0].geometry.location);

			    marker = new google.maps.Marker({
					position: results[0].geometry.location,
					map: map
				  });
				   infowindow = new google.maps.InfoWindow({'content': content});
				  /* google.maps.event.addListener(map, 'tilesloaded', function(event) {
                    infowindow.open(map, marker);
                });*/

				  google.maps.event.addListener(marker, 'click', (function(marker, i) {
					return function() {
					  infowindow.setContent(content);
					  infowindow.open(map, marker);
					}
				  })(marker, i));


			   
			   }
             
     

                });
				  i++;
            
        });
    });
	
	
function openlink(task){
	var task	=	task;
	window.location.href="index.php?task="+task;
}
