function in_array(needle, haystack, strict)
{
var found = false, key, strict = !!strict;
for (key in haystack) {if ((strict && haystack[key] === needle) || (!strict && haystack[key] == needle)) {found = true;break;}}
return found;
}
/**/
function metromapGroup(groupID)
{
$("#metromap-loader").stop().animate({opacity: "1"}, 500, function()
{
var iC = parseInt(metromap_stationgroups[groupID].length),
i = 0;
$.each(metromap_stationgroups[groupID], function(k,id)
{
i++;
if (!in_array(id, metromap_selected))
{
$("#metromap-map .station[data-id="+id+"]").addClass('selected');
metromap_selected.push(id);
}
if (iC==i)
{
metromapSync();
$("#metromap-loader").animate({opacity: "0"}, 500);
}
});
});
return false;
}
function metromapShow()
{
$('body').addClass('metromap-body')
$("#metromap").show();
return false;
}
function metromapHide()
{
$('body').removeClass('metromap-body')
$("#metromap").hide();
return false;
}
function metromapClear()
{
metromap_selected = [];
$("#metromap-cont").html('');
$("#metromap-clear").hide();
$("#metromap-map .station").removeClass('selected');
$("#metromap-count").text(0);
}
function metromapSync()
{
_metromapVisual();
if (parseInt(metromap_selected.length)>0)
{
$("#metromap-clear").show();
if (!$("#filter-btn-more").hasClass('hided')) $("#filter-btn-more").trigger('click');
}
else $("#metromap-clear").hide();
$("#metromap-count").text(parseInt(metromap_selected.length));
}
function metromapInit(url)
{
$.ajax({url: url, crossDomain:true, dataType:'html', cache: false}).done(function(html)
{
$("#metromap").html(html);
metromapSync();
$.each(metromap_stations,function(id,station)
{
var html_class = !in_array(id, metromap_selected) ? "station" : "station selected";
$('<div class="'+html_class+'" style="top:'+station.y+'px;left:'+station.x+'px" data-id="'+id+'">'+station.html+'</div>').appendTo("#metromap-map");
});
});
}
$(document).on('keydown', function(e) { if(e.keyCode==27) metromapHide(); });
$(document).on('click', '#metromap-bg', function() { return metromapHide(); });
$(document).on('click', '#metromap-map .station', function()
{
$(this).toggleClass('selected');
metromap_selected.push($(this).attr('data-id'));
metromapSync();
return false;
});