var mapa;
var directions;

function kontakt() {
	if ($('kontaktowy')) {
		

		$('kontaktowy').addEvent('submit',function(){
			var wynik=true; 		
			$$('form#kontaktowy input[type="text"]').each(function(item){
				if (item.value=='') {
					$wynik=false;
					item.setStyle('background-color', '#C03C3C');
				}
				else {
					item.setStyle('background-color', '#ffffff');					
				}
			});

			if ($('tresc').value=='') {
				$('tresc').setStyle('background-color', '#C03C3C');
				wynik=false;
			}				
			else {
				$('tresc').setStyle('background-color', '#ffffff');					
			}
			return wynik;
		});
	} 
}

function mapLink() {
	$$('dl.kontakt a').each(function(item, index){
	   item.addEvent('click', function(){
			setPosition(item.getProperty('href'))
			return false;
			});
	}); 
}

function setPosition(adres) {
	mapa.setMapType(G_NORMAL_MAP);
	// ustalenie pozycji dla danego adresu
	if (adres=='/kontakt/kartuzy/') {
	//54.333173,18.206642
	 mapa.setCenter(new GLatLng(54.333173,18.206642),13);
	
	}
	else if (adres=='/kontakt/pruszcz/') {
	
	//"54.269059,18.64337"
	mapa.setCenter(new GLatLng(54.269059,18.64337),13);		
	}
	else if (adres=='/kontakt/starogard/') {
	//"53.950836;18.514760"
	mapa.setCenter(new GLatLng(53.950836,18.514760),13); 	
	}
	else if (adres=='/kontakt/wejherowo/') {
	//54.600322;18.233049	
	mapa.setCenter(new GLatLng(54.600322,18.233049),13); 
	}
	else if (adres=='/kontakt/wladyslawowo/') {
	//54.790674;18.399509"
	mapa.setCenter(new GLatLng(54.790674,18.399509),13);	
	}
	else if (adres=='/kontakt/slupsk/') {
	//"54.450832;17.059355" 	
	mapa.setCenter(new GLatLng(54.450832,17.059355),13);	
	}
	else if (adres=='/kontakt/kwidzyn/') {
	//53.717205, 18.941840	
	mapa.setCenter(new GLatLng(53.717205,18.941840),13);	
	}
	
	
}

function setDirections(fromAddress) {
      directions.load("from: " + fromAddress + ", Kartuski, Pomorskie, Polska to: @54.326673, 18.196900");
	  mapa.setMapType(G_NORMAL_MAP );
	  return false;
    }

 function load() {
	if (document.getElementById('mapa')) {
		if (GBrowserIsCompatible()) {
			mapa = new GMap2(document.getElementById('mapa'));

			mapa.setCenter(new GLatLng(54.274848,18.179626), 8);
			mapa.addControl(new GLargeMapControl());
			mapa.addControl(new GMapTypeControl());

	
			mapa.addMapType(G_PHYSICAL_MAP); 
			mapa.setMapType(G_NORMAL_MAP);	
			
			mapa.enableDoubleClickZoom();
			mapa.enableContinuousZoom();
			mapa.enableScrollWheelZoom(); 
	
			var mkr1 = new GMarker(new GLatLng(54.333173,18.206642));
	        GEvent.addListener(mkr1, "click", function() {
	              mkr1.openInfoWindowHtml('<p><strong>SEZAM</strong></p><p>Kartuzy<br/>ul. Węglowa 1<br/>tel. 058 685 33 18</p>');
	          });
			mapa.addOverlay(mkr1);

			var mkr2 = new GMarker(new GLatLng(54.269059,18.64337));
	        GEvent.addListener(mkr2, "click", function() {
	              mkr2.openInfoWindowHtml('<p><strong>SEZAM</strong></p><p>Pruszcz Gdański<br/>ul. Podmiejska 5<br/>tel. 058 773 00 10, 773 00 11</p>');
	          });			  
			mapa.addOverlay(mkr2);

			var mkr3 = new GMarker(new GLatLng(53.950836,18.514760));
	        GEvent.addListener(mkr3, "click", function() {
	              mkr3.openInfoWindowHtml('<p><strong>SEZAM</strong></p><p>Starogard Gdański<br/>ul. Lubichowska 178<br/>tel. 058 56 33 110, 56 14 714</p>');
	          });			  
			mapa.addOverlay(mkr3);

			var mkr4 = new GMarker(new GLatLng(54.600322,18.233049));
	        GEvent.addListener(mkr4, "click", function() {
	              mkr4.openInfoWindowHtml('<p><strong>SEZAM</strong></p><p>Wejherowo<br/>ul. I Brygady Pancernej WP 84<br/>tel. 058 677 03 33, 677 44 33</p>');
	          });				
			mapa.addOverlay(mkr4);

			var mkr5 = new GMarker(new GLatLng(54.790674,18.399509));
	        GEvent.addListener(mkr5, "click", function() {
	              mkr5.openInfoWindowHtml('<p><strong>SEZAM</strong></p><p>Władysławowo<br/>ul. Żwirowa 7<br/>tel. 058 774 79 60 – 61</p>');
	          });				
			mapa.addOverlay(mkr5);

			var mkr6 = new GMarker(new GLatLng(54.450832,17.059355));
	        GEvent.addListener(mkr6, "click", function() {
	              mkr6.openInfoWindowHtml('<p><strong>SEZAM</strong></p><p>Słupsk<br/>ul. Hubalczyków 12<br/>tel. 059 848 22 18, 848 22 19</p>');
	          });				
			mapa.addOverlay(mkr6);
			
			var mkr7 = new GMarker(new GLatLng(53.717205,18.941840));
	        GEvent.addListener(mkr7, "click", function() {
	              mkr7.openInfoWindowHtml('<p><strong>SEZAM</strong></p><p>Kwidzyn<br/>ul. ul.Zielna 2<br/>tel. 055 261 04 98 </p>');
	          });				
			mapa.addOverlay(mkr7);									
			new GKeyboardHandler(mapa);						
		  }
	}
}
