google.load('maps', '2.x');
$(function(){

	var group = new ImageGroup();
	group.AddImage("/gfx/g_icosh.png");
	group.AddImage("/gfx/g_icotrn.png");
	group.AddImage("/gfx/g_ico2.png");
	group.AddImage("/gfx/g_ico3.png");
	group.AddImage("/gfx/g_ico4.png");
	group.AddImage("/gfx/g_ico8.png");

	group.imageupdate = function(group) {

		if (!group.IsComplete())
			return;
	};
	LoadGroup(group);
		//var img_name = group.items[i];
		//var img_obj = GetImage(img_name);

		// Make the image visible, and set its .src attribute
		//eval("document.images['" + img_name + "'].style.display = ''");
		//eval("document.images['" + img_name + "']").src = img_obj.src;

	  $('#map').css('height',$('#locations').height()+'px').pmap('init', {
  			'mapCenter':[51.917168,19.138184],
				'mapZoom': 8,
				//'debugMode': false
				'mapControl': 'large'
			}, function(el, options){
			$('#map').pmap('getLocations', {'link':window.location.href,'mode':'read'}, function(response) {
				$.each(response.locations, function(i, loc) {
					//var coords = $(loc).attr('title').split(';');
					//alert($(loc).attr("title"));
					$('#map').pmap('AddMarker', {
							'pointID': loc.location_id,
							'pointModule': loc.module,
							'pointItem': loc.item,
							'pointLatLng': [loc.latitude,loc.longitude],
							'pointHTML': loc.description,
							'pointIcon': loc.module,
							'pointIsDraggable': true,
							'pointIsRemovable': true
						}, function(marker, options) {
	    		  //$('.removeme').click(function(){ $(el).jmap('removeMarker', marker) });
  	    	});
    		});
    		//$('#map').pmap("ZoomAndCenter", {});
    		$('#map').pmap("ZoomToFit", {});
			});
			//$('.clickme').click(function(el) {})
  	});

		$('#mapform').bind("submit", function(event){
			event.preventDefault();
			var items = {};
			$('#mapform :input').each( function(i, el) {
				items[$(el).attr('name')] = $(el).attr('value');
			});
			$('#map').pmap('FindLocation',{'query':items.query,'user':items.user,'module':items.module,'item':items.item} );
			//$('#map').pmap('AddLocation',{'query':items.query,'user':items.user,'module':items.module,'item':items.item} );
		});
	//};

	

});
