/*
 * jQuery Plugins:
 *
 * - Twitter Widget
 * - Testimonial Widget
 * - Toggle
 * - Accordion
 * - Back to top
 * - Contact Form
 * - Google Map
 *
 * Copyright 2011, MTD
 * http://themeforest.net/user/MTD
 */
(function($){
	$.fn.extend({
   google_maps: function(){
      if( $(this).length ){
        $.google_maps = $(this);
        $.getScript("http://maps.google.com/maps/api/js?sensor=false&callback=jQuery.fn.google_maps_callback&async=2");
      }
    },

    google_maps_callback: function(){
    	$.google_maps.each(function(){
    		var map			= $(this),
    			details		= $(this).find(".mapDetails").html(),
    			latitude	= map.data("latitude"),
    			longitude	= map.data("longitude"),
    			coord		= new google.maps.LatLng( latitude, longitude ),
    			param		= {
    				zoom				: map.data("zoom") || 6,
    				zoomControlOptions	: {
    					style: google.maps.ZoomControlStyle.SMALL
    				},
    				panControl			: false,
    				streetViewControl	: false,
    				center				: coord,
    				html				: map.data("title"),
    				popup				: true,
    				mapTypeId			: google.maps.MapTypeId.ROADMAP
    			},
    			gmap		= new google.maps.Map( map.get(0), param ),
    			bubble		= new google.maps.InfoWindow({
    				content		: details,
    				maxWidth	: 600
    			}),
    			icon		= new google.maps.MarkerImage("/themes/site_themes/aiguamedia/img/map-marker.png",
    				new google.maps.Size(210,80),
    				new google.maps.Point(0,0),
    				new google.maps.Point(110,80)
    			),
    			marker		= new google.maps.Marker({
    				position	: coord,
    				map			: gmap,
    				icon		: icon,
    				flat		: true,
    				title		: map.data("title")
    			});
    		google.maps.event.addListener(marker, "click", function () {
    			bubble.open(gmap, marker);
    		});
    	
    	});
    }
  });
})(jQuery);

