/**
 * Google Maps Modal
 * This jQuery plugin was inspired on jQuery.lightBox
 *
 * @name jquery.google-maps-modal.js
 * @author Igor Frias Vieira - http://igorvieira.com
 * @version 0.1
 * @date Feb 10, 2009
 * @copyright (c) 2008 Igor Frias Vieira
 * @license CC Attribution-No Derivative Works 2.5 Brazil - http://creativecommons.org/licenses/by-nd/2.5/br/deed.en_US
 * @example Visit http://igorvieira.com/blog/google-maps-modal/
 */

(function($)
{
	
	$.fn.teste = function(settings) {
		
		// Settings to configure the jQuery lightBox plugin how you like
		settings = jQuery.extend({
			
			//The overlay background
			bgColor: '#000', 		// Background color
			bgOpacity: 0.8,			// Background opacity
			
			//The map size
			mapWidth: 600,		// The map Width
			mapHeight: 350,		// The map Height
			
			//About the Map
			mapText: '',			// A little text
			mapUrl: ''				// You can find it on Google Maps iframe <iframe src="HERE"></iframe>
			
			/*
			 * ============================================================== You Should look for this src URL  \/ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- \/
			 * <iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0"	src="http://www.google.com/maps?f=q&amp;source=s_q&amp;hl=pt-BR&amp;geocode=&amp;q=Parque+ibirapuera&amp;sll=-23.623704,-46.561111&amp;sspn=0.092006,0.181961&amp;ie=UTF8&amp;s=AARTsJoZOnljttHb6BAp9fGn-ngks2fbFg&amp;ll=-23.588138,-46.657734&amp;spn=0.027531,0.036478&amp;z=14&amp;output=embed"></iframe>
			 */
			
		},settings);
	
	
		/*
		 * Initializing the plugin
		 * @return boolean false
		 */
		function _initialize(){			
			
			//Create the modal Interface
			_createInterface();
			
			return false;
		}
		
		
		
		/*
		 * Creating the Modal Interface
		 * @return boolean false
		 */
		function _createInterface(){			
			
			$('body').append("<div id='gMapModal-overlay'></div><div id='gMapModal-text'></div><div id='gMapModal-box'></div>");
			$('#gMapModal-box').append('<iframe width="' + settings.mapWidth + '" height="' + settings.mapHeight + '" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="' + settings.mapUrl + '"></iframe>');
			$('#gMapModal-text').append('<p>' + settings.mapText + '</p><a id="gMapModal-closeButton"></a>');
			
			objHidden = $('embed, object, select').css({ 'visibility' : 'hidden' });
			
			
			//Hidding the elements
			$('#gMapModal-overlay, #gMapModal-box, #gMapModal-text').hide();
			
			
			// The Background CSS
			$('#gMapModal-overlay').css({
				'position' 	: 'absolute',
				'top' 		: 0,
				'left' 		: 0,
				'width' 	: '100%',
				'height' 	: $('body').outerHeight(),
				
				'background-color' : settings.bgColor,
				'opacity' 			: settings.bgOpacity
			});
			
			
			
			mgLeft = ((settings.mapWidth/2) * -1);
			mgTop = $(window).scrollTop() + 50;
			
						
			// The Map Box CSS
			$('#gMapModal-box').css({
				'position'		: 'absolute',
				'left'			: '50%',
				'width'			: settings.mapWidth + "px",
				'height'		: settings.mapHeight + "px",
				'margin-left'	: mgLeft + "px",
				'top'			: mgTop + "px"
			});
			
			
			mgTop = mgTop + settings.mapHeight;
			
			// The text CSS
			$('#gMapModal-text').css({
				'position'		: 'absolute',
				'left'			: '50%',
				'width'			: settings.mapWidth + "px",
				'margin-left'	: mgLeft + "px",
				'top'			: mgTop + "px"	 
			});
			
			
			//Calling the setActions Function
			_setActions();
			
			
			$('#gMapModal-overlay, #gMapModal-box').show();
			setTimeout(function(){
				$('#gMapModal-text').slideDown();
			}, 500);
			
			return false;
		}
		
		
		
		/*
		 * Set the buttons actions
		 * @return boolean false
		 */
		function _setActions(){
			
			$('#gMapModal-overlay').bind('click', closeModal);
			$('#gMapModal-closeButton').bind('click', closeModal);
			
			return false;
		}
		
		
		
		
		/*
		 * Closing the Modal
		 * @return boolean false
		 */
		closeModal = function(){
			$('#gMapModal-overlay').remove();
			$('#gMapModal-box').remove();
			$('#gMapModal-text').remove();
			
			
			$(objHidden).css({ 'visibility' : 'visible' });
			
			return false;
		}
		
		var objHidden = [];
		return this.unbind('click').click(_initialize);
	}
		
})(jQuery);
