
function showShopsMap(region) {
	if(region!=''){
		$('#shopsMap').flash(function() {
			this.selectRegion(region);
		});
		;
	}else{
		$('#shopsMap').html('').flash({
			swf: '/images/www/swf/shopsMap.swf',
			width: 350,
			height: 350,
			id:'mapa',
			name:'mapa',
			wmode: 'transparent',
			allowscriptaccess: 'samedomain'
		 });
	}
}

function setupRegion(region) {
	trackShop('wojewodztwo-' + $('#selectRegion option[value='+region+']').attr('class'));
	if(region>-1){
		$('#selectRegion').val(region);
		$('.selectCity .jquery-selectbox-currentItem').text($('.selectCity select option[value='+region+']').text());
		getCities(region);
	}
}
function selectRegion(region) {
	trackShop('wojewodztwo-' + $('#selectRegion option[value='+region+']').attr('class'));
	if(region>-1){
		showShopsMap(region);
		getCities(region);
	}
}
function getCities(region) {
	$('#shopsArea').html('');
	$.ajax({
		url:'/shops-refresh-element.bhtml',
		method:'post', 
		data: {
			action: 'get_cities',
			province_code: region
		},
		success: function(html){
			$('#citiesArea').html(html);
			getBreadcrumb(region, '');
		}
	});
}
function getShops(city, name) {
	$('.selectCityList a').removeClass('activ');
	$('.selectCityList .city_'+city).addClass('activ');
	$.ajax({
		url:'/shops-refresh-element.bhtml',
		method:'post', 
		data: {
			action: 'get_shops',
			city_code: city
		},
		success: function(html){
			$('#shopsArea').html(html);
			$.scrollTo('#shopsArea', 800 );
			getBreadcrumb($('#selectRegion').val(), city);     				
		}
	});
	trackShop(name);
}
function getBreadcrumb(region, city) {
	$.ajax({
		url:'/shops-refresh-element.bhtml',
		method:'post', 
		data: {
			action: 'get_breadcrumb',
			province_code: region,
			city_code: city
		},
		success: function(html){
			$('#nav-path').html(html);
		}
	});
}

function trackShop(name) {
	var gaUrl = "/sklepy/" + name + ".bhtml";
	pageTracker._trackPageview(gaUrl);
}