/*
Contact JS pour Goupe Dubreuil
Copyright(c) 2008, Skalpel.

Author : Michael
michael@skalpel.fr

Note : 
	-
ToDo :
	- 
*/
window.addEvent('domready', function() {
	// Gmap
	if($('gmap')) new SKjs.GMap();
});

/* 
Class : GMap
	- Gestion de l'affichage de la GMAP
Arguments : 
	options {object} - Objet Options

Options :
	elmGMap {String} - Id du conteneur de la GMAP
	gmapKey {String} - Key GMap
*/
SKjs.GMap = new Class ({
	Implements: [Events, Options],
	options: {
		elmGMap: 'gmap',
		elmProAdress: new Array(46.74627168462244, -1.4295530319213867),
		
		gmapZoom: 13,
    // Key pour www.groupedubreuil.com
    gmapKey: 'ABQIAAAAl2xBfBfD1lyZFD84QY3dpRSizUmYvjOlnJ5xUzOS4wwloWfUxRRk5hFiooklQVfnJLLYixvBrlWPbw'
    // Key pour www.skalpel-solutions.com
    //gmapKey: 'ABQIAAAAl2xBfBfD1lyZFD84QY3dpRTF4wNfxZV0ePSVTHW8ybL94iavgBSJLoNV2L76qcDGk7Ka975NA-gPhQ'
		// Key pour skalpel-dev/groupedubreuil
    //gmapKey: 'ABQIAAAAcfvht2QPWzjaBc2MkZBtPBTnHYOKtRls7bmm8SSZx4uAiXFKZhQXcxAEoIHEJttMOw22oVrdIoNDkg',
	},
	
	initialize: function(options) {
		this.setOptions(options);
		
		this.setGMapApi();
	},
	
	/*
	Property :
		Initialisation et inclusion de l'API de Google Maps
	*/
	setGMapApi: function() {
		var self = this;
		var source = 'http://maps.google.com/maps?file=api&v=2.x&key='+ this.options.gmapKey +'&async=2';
		var script = new Element('script', {'src': source, 'type': 'text/javascript'}).inject(document.head);
		
		waitForExistence();
		function waitForExistence() {
			if(typeof(GMap2) != 'undefined') self.create();
			else setTimeout(waitForExistence, 10);
		}
	},
	
	/*
	Property :
		Creation de la Map
	*/
	create: function() {
		if(GBrowserIsCompatible()) {
			var map = new GMap2($(this.options.elmGMap));
			
			map.setCenter(new GLatLng(0, 0), 12);
			map.addControl(new GSmallMapControl());
			map.addControl(new GMapTypeControl());
			
			point = new GLatLng(this.options.elmProAdress[0], this.options.elmProAdress[1]);
			map.setCenter(point, this.options.gmapZoom);
			
			var marker = new GMarker(point);
			map.addOverlay(marker);
		}
	}
});