// JavaScript Document
$(document).ready(function() {
ur = window.location.hash.toString();
if (ur == '') {
	location.href = '/#' + window.location.pathname.toString();
}

hash = window.location.hash.toString();
if (hash != '') { 
	$('#content').load(hash.substr(1), 'ajax=1');	
}


	alf = ['А', 'Б', 'В', 'Г', 'Д', 'Е', 'Ж', 'З', 'И', 'Й', 'К', 'Л', 'М', 'Н', 'О', 'П', 'Р', 'С', 'Т', 'У', 'Ф', 'Х', 'Ц', 'Ч', 'Ш', 'Щ', 'Ы', 'Ю', 'Я',  
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'W', 'Z',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
	alphabet = '<ul id="rus">';
	for (l in alf) {
		if (alf[l] == 'A') alphabet += '</ul><ul id="eng">';
		alphabet += '<li><a href="/artist/rub/' + encodeURIComponent(alf[l]) + '.htm">' + alf[l] + '</a></li>';
	}
	alphabet += '</ul>';
	var curalf;
	$('#alphabet').html(alphabet).delegate('a', 'click', function(){
		if (curalf) curalf.removeClass('on');
		curalf = $(this).parent();
		curalf.addClass('on');
	});
	
	$('html').delegate('a', 'click', function(){
	//$('a').live('click', function(){
		url = $(this).attr('href');
		
		if ($(this).hasClass('listen')) {
			EP_setAutoPlay('ep_player1', true);
			EP_loadPlaylist('ep_player1', '/album/pl/'+$(this).attr('href')+'.xml');
			return false;
		}
		
		if (url.indexOf('/') === 0) {
			if ($(this).hasClass('dlyr')) {
				alert(1);
				return false;
			}
			else {
				$('#blue_block').html('<img src="/images/ajax-loader.gif" alt="загрузка" />');
				$('#content').load(url, 'ajax=1');
			}
			//location.href = '#page';
			location.href = '#' + url;
			
			           //     window.document.body.scrollTop = 0;
               // window.document.documentElement.scrollTop = 0;
				
				//$('body').scrollTop(0); 
				$("html:not(:animated)"+( ! $.browser.opera ? ",body:not(:animated)" : "")).animate({scrollTop: 0}, 1000);
			return false;
		}
	});

	$('#search_form').submit(function(){
		url = '/search/?' + $(this).serialize();
		$('#blue_block').html('<img src="/images/ajax-loader.gif" alt="загрузка" />');
		$('#content').load(url, 'ajax=1');
		location.href = '#page';
		location.href = '#' + url;
		if (curalf) curalf.removeClass('on');
		return false;
	});

});
