
nreal_popup_ = new Class({
	configure:function(){
		this.popup_width  		= 800; //szer. wyskakujacego okienka 
		this.popup_height 		= 550; //wysokosc wyskakujacego okienka
		this.map_width			= 700; //szerokosc mapy
		this.map_height			= 400; //wysokosc mapy
		this.default_distance 	= 5; //domyslnie w km odleglosc 
		this.start_map_zoom  	= 12; //zoom na start
		this.max_markers		= 200; //ile markerow
		this.marker_types = new Array();
		this.marker_types['main_marker'] 	= 'http://talarczyk.com.pl/user_themes/tis/style/images/mark_aktualny.png'; //glowny obiekt w srodku
		this.marker_types['def'] 			= 'http://talarczyk.com.pl/user_themes/tis/style/images/mark_aktualny.png'; //domyslny gdy typ nie rozpoznany
		this.marker_types['mieszkanie'] 	= 'http://talarczyk.com.pl/user_themes/tis/style/images/mark_mieszkania.png'; //mieszkanie
		this.marker_types['dom'] 			= 'http://talarczyk.com.pl/user_themes/tis/style/images/mark_domy.png'; //dom
		this.marker_types['dzialka'] 		= 'http://talarczyk.com.pl/user_themes/tis/style/images/mark_dzialki.png'; //dzialka
		this.marker_types['lokal'] 			= 'http://talarczyk.com.pl/user_themes/tis/style/images/mark_lokale.png'; //lokal
		this.marker_types['obiekt'] 		= 'http://talarczyk.com.pl/user_themes/tis/style/images/mark_obiekty.png'; //obiekt
	},
	
	initialize:function(){
		this.configure();
		this.markers = new Array();
		this.loaded_positions = false; //zaladowany obiekt z elementami w poblizu ( JSON )
		SqueezeBox.initialize({ size: {x: this.popup_width, y: this.popup_height} });
	},
	popup:function(object_id){
		this.object_id = object_id;
		SqueezeBox.open('display.php?mu_user_realty=w_poblizu&sid_realty='+object_id+'&mw='+this.map_width+'&mh='+this.map_height);
	},
	initialize_map:function(){
		if(GBrowserIsCompatible())  
			{
				this.mapa = new GMap2($('popup_map_w_poblizu'),{mapTypes: [G_PHYSICAL_MAP,G_HYBRID_MAP,G_NORMAL_MAP,G_SATELLITE_MAP]});
				this.mapa.setMapType(G_NORMAL_MAP);
				this.mapa.addControl(new GLargeMapControl3D());
				this.mapa.enableScrollWheelZoom();
				this.mapa.clearOverlays();
				this.position_start = new GLatLng($('geoy').value,$('geox').value);
				this.mapa.setCenter(this.position_start,this.start_map_zoom);
				this.load_data(this.object_id,this.default_distance);
			}		
	},
	//wczytuje dane do obiektu json o najblizszych obiektach w okregu distance km
	load_data:function(object_id,distance){
		
		$$('.popup_w_poblizu_ul a').each(function(item){
			item.removeClass('kmSelected');
		});
		var v = 'km_'+distance;
		   	$(v).addClass('kmSelected');
		var jsonRequest = new Request.JSON({url: "display.php?mu_user_realty=w_poblizu_json", onSuccess: function(obj){
		    nreal_popup.load_markers_from_json(obj);
		    nreal_popup.loaded_positions = obj;
		}}).get({'sid_realty': object_id, 'distance': distance,'max_markers':nreal_popup.max_markers});
	},
	load_markers_from_json:function(jsondata){
		
		this.add_main_marker();
		nreal_popup.markers = new Array();
		var index = 0;
		$each(jsondata,function(i){
			var marker_image = nreal_popup.marker_types['def'];
			
			//if (nreal_popup.marker_types.contains(i.type)) 
			marker_image = nreal_popup.marker_types[i.type];
			
			var mark_point = new GLatLng(i.x,i.y);
			var marker_icon = new GIcon(G_DEFAULT_ICON,marker_image);
			var marker_options = {icon:marker_icon};
			nreal_popup.markers[index] =  new GMarker(mark_point,marker_options);
			nreal_popup.markers[index].tny_index = index;
			nreal_popup.markers[index].tny_html = i.html_popup;
			nreal_popup.mapa.addOverlay(nreal_popup.markers[index]);
			GEvent.addListener(nreal_popup.markers[index],'click',function(){ 
				nreal_popup.markers[this.tny_index].openInfoWindowHtml(this.tny_html);
			});
			index++;
		});
	}, 
	add_main_marker:function(){
		nreal_popup.mapa.clearOverlays();
		main_icon = new GIcon(G_DEFAULT_ICON,nreal_popup.marker_types['main_marker']);
		main_marker = new GMarker(nreal_popup.position_start,{icon:main_icon});
		nreal_popup.mapa.addOverlay(main_marker);
	}
}); 
 
var nreal_popup = null;
window.addEvent('domready', function(){
	nreal_popup = new nreal_popup_();
});
