$(document).ready(function() {
	$('#fclc').click(function() { shFilters(0); });
	$('#fclo').click(function() { shFilters(1); });
	$('#fmore').click(function() { moreFilters(); });
	$('#fless').click(function() { moreFilters(); });
});

function shFilters(open) {
	if(open) {
		$('#fmore').show(); 
	} else {
		$('#fmore').hide();
	}
	document.cookie = "filters_visible="+ open +"; path=/";
	
	$('#fless').hide();
	$('.faddit').hide();
	
	$('#fcl').toggle(); $('#fclo').toggle();
	$('#fcont').toggle(); $('#ftags').toggle();
}

function moreFilters() {
	$('.faddit').toggle();
	$('#fmore').toggle(); $('#fless').toggle();
}

function radiusSlider() {
	var A_TPL2h = {
		'b_vertical' : false,
		'b_watch': true,
		'n_controlWidth': 140,
		'n_controlHeight': 16,
		'n_sliderWidth': 19,
		'n_sliderHeight': 16,
		'n_pathLeft' : 0,
		'n_pathTop' : 0,
		'n_pathLength' : 121,
		's_imgControl': '/pics/slider/sldr1v_bg.gif',
		's_imgSlider': '/pics/slider/sldr1v_sl.gif',
		'n_zIndex': 1
	}
	var A_INIT2h = {
		's_form' : null,
		's_name': 'siro',
		'n_minValue' : 0,
		'n_maxValue' : 100,
		'n_value' : 30,
		'n_step' : 10
	}
	new slider(A_INIT2h, A_TPL2h);
	
	$('#sl0slider').click(function() {
		//submitForm();
		var t = window.location.href.split('//')[1];//removes protocol
		var p = t.indexOf('/');
		t = t.substr(p, t.length);//removes domain
		p = t.indexOf('?');
		if(p > 0) t = t.substr(0, p);//removes get params
		
		if(cityUrlName.length < 1) {
			cityUrlName = $('#quickW').val();
			cityID = gup('rid');
		}
		var what = $('#quickC').val();
		for(w in lbls) {
			if(what == lbls[w]) {
				what = '';
				break;
			}
		}
		
		t += '?cmd=search&tab=1&q=' + what + '&w=' + cityUrlName + '&rid=' + cityID + '&rad=' + $('#siro').val();
		if(lang != 'pl') t += '&lang=' + lang;
		
		document.location = t;
	});
}

function showRegionsLayer(type, content) {
	var bWidth, bHeight;
	
	switch(type) {
		case 0: bWidth = 200; bHeight = 100; break;
		case 1: bWidth = 1000; bHeight = 500; break;
		case 2: bWidth = 500; bHeight = 200; break;
		case 3: bWidth = 410; bHeight = 389; break;
		case 4: bWidth = 400; bHeight = 400; break;
	}
	
	var centerY = true;
	var centerX = true;
	
	var top, left;
	var wWidth = $(window).width();
	var wHeight = $(window).height();
	left = (wWidth - bWidth)/2;
	top = (wHeight - bHeight)/2;
	if( wWidth <= bWidth ){
		left =  0;
		centerX = false;
	}
	if( wHeight <= bHeight ){
		top =  0;
		centerY = false;
	}
	
	$.blockUI({
		message: content,
		centerY: centerY,	
		centerX: centerX,
		css: {
			backgroundColor: '#FFF', border: 'none', position: 'absolute',
			top:  top + 'px', 
            left: left + 'px',
			width: bWidth+'px',
			height: bHeight+'px',
			padding: '0'
		},
		overlayCSS: {
			position: 'absolute',
			overflow: 'visible',		
			backgroundColor: '#000',
			opacity: '0.6'
		}
	});
}

function getRegions(type) {
	var regions = $('#regionsLayer').html();
	if(regions.length > 0) {
		showRegionsLayer(type, regions);
		return false;
	}
	
	showRegionsLayer(0, $('#regionsLayerWait').html());
	
	var t = window.location.href.split('//')[1];//removes protocol
	var p = t.indexOf('/');
	t = t.substr(p, t.length);//removes domain
	p = t.indexOf('?');
	if(p > 0) t = t.substr(0, p);//removes get params
	t = staticDomain + '/ajax/firmsListRegions' + t + '?jsoncallback=?';
	
	var params = {};
	var search = gup('cmd');
	if(search != '') {
		var tab = gup('tab'); var q = gup('q'); var w = gup('w');
		params = { 'cmd':'search', 'tab':tab, 'q':q, 'w':w, 'lang':lang };
	} else {
		params = { 'lang':lang };
	}
	
	$.getJSON(t, params, function(res) {
		$('#regionsLayer').html(res);
		$.unblockUI();
		showRegionsLayer(type, res);
	});
	
	return false;
}

function showItemsForLetter(me, letter) {
	$(me).parent().parent().children('.ifr').hide();
	$(me).parent().parent().children('#itemsFor' + letter).show();
}
