var isie6;

function hideImg() {
	$('#overlay').remove();
	$('#preloader').remove();
	$('#photoCont').remove();
	if (isie6) {
		$('html').css('overflow', 'auto');
		$('#overlaySelect').remove();
	}
	return !1;
}

function showPhoto(pict_src, pict_desc) {
	if (isie6) {
		$('html').css('overflow', 'hidden');
		$('#container').css('height', '100%');
		$('#container').append('<iframe id="overlaySelect"></iframe>');
	}
	$('#container').append($('<div id="overlay"></div>'), $('<div id="preloader"></div>'), $('<div id="photoCont"><div><a href="#" class="close">Закрыть</a><p>'+pict_desc+'</p></div></div>'));
	
	var preloadImg = new Image();
	preloadImg.onload = function() {
		preloadImg.onload = null;		
		var w = preloadImg.width;
		var h = preloadImg.height;
		
		$('#photoCont div').prepend('<img src="'+pict_src+'" width="'+w+'" height="'+h+'">').parent('div').css(
			{
				'width': w+32+'px',
				'margin': '-'+Math.round(h/2)+'px 0 0 -'+Math.round(w/2)+'px',
				'display': 'block'
			}
		);
		$('#preloader').hide();
		$('#photoCont').show();
		
	}
	preloadImg.src = pict_src;
	$('#photoCont a.close').click( hideImg);
	
	$('#overlay').click( hideImg);
	
}

function showFlags(){
$('#spectators li>span, #flags li>span').each(
			function(i) {
				$(this).append('<span class="countryName"><strong>'+$(this).attr('title')+'</strong><i class="cnr lc"/><i class="cnr rc"/><i class="tail"/></span>');
				$(this).attr('title', '');
			}
		);

}

$(
	function() {
		isie6 = (document.getElementById('container').style.minWidth == undefined) ? true : false;
	
		$('#leftCol #mainMenu li').append('<i>»</i>');
		$('#spectators').before('<div id="eamap"/>');
		
		showFlags();

		$('#searchBlock input:text').val($('#searchBlock label').text())
			.focus(
				function() {
					if ($(this).val() == $('#searchBlock label').text())
						$(this).val('');
				}
			).blur(
				function() {
					if ($(this).val() == '')
						$(this).val($('#searchBlock label').text());
				}
			);
		if($.browser.msie && $.browser.version <= 6) {
			$('#spectators  li i, #flags li i').append('<i/>')
			$('#spectators li>span, #flags li>span').hover(
				function() { $(this).addClass('hover');},
				function() { $(this).removeClass('hover');}
			);
		}
		
		$('.albumInside:eq(0) li a').click(
			function() {
				showPhoto($(this).attr('href'), $('span', $(this)).text());
				return !1;
			}
		);
		
	}
);