Array.prototype.unique = function()	{
	var a = [];
	var l = this.length;
	for(var i = 0; i < l; i++)
	{
		for(var j = i + 1; j < l; j++)
		{
			// If this[i] is found later in the array
			if (this[i] === this[j])
				j = ++i;
		}
		a.push(this[i]);
	}
	return a;
}

$(function() {
	var urls = [];
	var prefixes = [ 'www.', 'corp.', 'company.', 'www.corp.', 'www.company.', 'www.pda.' ];
	
	$("#regions a").each(function() {
		var baseUrl = $(this).attr('href')
			.replace('http://', '').replace('www.', '').replace('corp.', '').replace('company.', '').replace('pda.', '');
		
		for (var key in prefixes)
			urls.push(prefixes[key] + baseUrl);
		
		if (baseUrl.indexOf('stage.mts.qsupport.') >= 0)
		{
			for (var key in prefixes)
				urls.push(prefixes[key] + baseUrl.replace('mtsmain.', 'mts.').replace('stage.mts.qsupport.', ''));
		}
	});
	
	urls.push('mtsweb.adcast.ru/');
	urls.push('www.mtsgsm.com/');
	urls.push('www.vis.mtsgsm.com/');
	urls.push('www.corp.mtsgsm.com/');
	
	urls.unique();
	
	$('.sitemap a').each(function() {
		var href = $(this).attr('href');
		if ($(this).attr('target') == '_blank')
			$(this).append('<img class="externalBlock" src="/upload/images/externallinks.png" />');
		else if (href.length > 0 && href.match(/^http:\/\/.*$/) && $.inArray(href.split('/')[2] + '/', urls) < 0)
			$(this).attr('target', '_blank').attr('title', 'Страница откроется в новом окне').append('<img class="externalBlock" src="/upload/images/externallinks.png" />');
	});
});
