var Oferty = Class.create({
		
	initialize: function() {
		this._running = false;
		this._specjalne = null;
	},
	
	reloadList: function(params, clear) {

		if (this._running)
			return;

		Common.Loader.startAjax();
		this._running = true;

		params = Object.clone(params);

		// mapa
		params['mapa'] = $('oferty_mapa').visible() ? '1' : '_none';

		// czyszczenie danych
		params['clear'] = clear ? 2 : 0;

		var _this = this;
		var ajaxObj = new Ajax.Request('/oferty,ajax-oferty',
		{
			method: 'post',
			parameters: params,
			onSuccess: function(transport) {
				var response = transport.responseText;
				$('oferty').replace(response);
				$('oferty_liczba').update($('oferty_liczba_div').innerHTML);
				Common.Loader.stopAjax();
				_this._running = false;
			},
			onFailure: function() { 
				alert(Lang.generic_error);
				Common.Loader.stopAjax();
				_this._running = false;
			}
		});
	},

	showMap: function() {
		pageTracker._trackPageview('/oferty/zakladka_lista');
		$('oferty_mapa').show();
		$('oferty_tabs_lista').removeClassName('selected');
		$('oferty_tabs_mapa').addClassName('selected');
		GMap.construct();
		this.reloadList({}, false);
	},

	hideMap: function() {
		pageTracker._trackPageview('/oferty/zakladka_mapa');
		$('oferty_mapa').hide();
		$('oferty_tabs_lista').addClassName('selected');
		$('oferty_tabs_mapa').removeClassName('selected');
		this.reloadList({}, false);
	},

	setScrollPosition: function(element) {
		var ajaxObj = new Ajax.Request('/oferty,ajax-scroll-position',
		{
			method: 'post',
			parameters: {scrollPosition: document.viewport.getScrollOffsets().top},
			onSuccess: function(transport) {
				document.location.href = element.href;
			},
			onFailure: function() { 
				document.location.href = element.href;
			}
		});
	}

});

