$(document).ready(function() {
	
	// получаем звезды
	star = $('img[src*=en_logo]:eq(0)').attr('src');
    star = star.match(/en_logo(\d+)/)[1];
	
	// выводим звезды
	$('#block-head .star div').animate({width: (star * 30) + 'px'}, 2500);

	// двигаем панораму мышкой =)
	$('#block-head').mousemove(function(e) {
		move = e.pageX * 100 / $('#block-head .back').width();
		$('#block-head .back').css({backgroundPosition: move + '% 0'});
	});

	// быстрый вход	
	if( $('#lnkUserName').length ) { 		
	} else {	
		var fast_form = $('#block-fastlogin');
		var fast_form_src = $('a[id$=lnkLogin]').attr('href');
		$('#block-fastlogin form').attr('action', fast_form_src);    	
		$('td.leftMenu td:eq(0)').prepend(fast_form);	
		$(fast_form).show();	
	}
	
	// баян всея руси	
	$('#menu-accordion .head').click(function(){			
		if ( $(this).is('.selected') ) { $(this).removeClass('selected').next('.item').slideUp(250); }
		else { 
			$(this).addClass('selected').siblings('.head').removeClass('selected');
			$('#menu-accordion .item:visible').slideUp(500);
			$(this).next('.item').slideDown(250);
		}	
	});
	
	// подсказки
	$('#org-list li').each(function(){        
        var tip = $(this).find('.about');
        $(this).hover(
            function(){ tip.show(); },
            function(){ tip.hide(); }
        );         
    });
		
	// заголовки полей
	$('input.onfocus_pass').parent().prepend('<input class="label" type="text" value="Пароль" title="Пароль" />'); // пока так
	$('input.onfocus').focus(function(){ value = $(this).attr('title'); if($(this).val() == value) $(this).val(''); });		
	$('input.onfocus').blur(function(){ value = $(this).attr('title'); if($(this).val() == '') $(this).val(value); });					
	$('input.label').focus(function(){ $(this).hide().siblings('input').focus(); });		
	$('input.onfocus_pass').blur(function(){ if($(this).val() == '') $(this).siblings('input').show(); });

	// Сибирь
	var siberia = $('tr.forumRow').has('a[href="/Guestbook.aspx?section=8077"]');
	$(siberia).addClass('siberia');
		
	// %username%
	username = $('a[href="/UserDetails.aspx"]:first').text();
	userid = $('a[href="/UserDetails.aspx"]:first').next('span').text();	
	allElements = document.getElementsByTagName('*');
	for (i = 0, s = allElements.length; i < s; i++) {
		if(allElements[i].tagName != 'script') {
			for(j = 0, s_ = allElements[i].childNodes.length; j < s_; j++) {
				if(allElements[i].childNodes[j].nodeType == 3) {
					allElements[i].childNodes[j].textContent = allElements[i].childNodes[j].textContent.replace(/%username%/g, username);
				}
			}
		}
	}
	
	// user
	currentLocation = location.pathname + location.search;	
	if (userid == '') {
		$(siberia).hide();
		if (currentLocation == '/Guestbook.aspx?section=8077') {
			location.replace('http://ulan.en.cx');
		}
	}

});
