$(function(){
    $('.comments .comment:even').addClass('comment_even');
});

$(function(){
	$('.other').hover(function(){
        $('.other-block').slideToggle('fast');
        $('.other').addClass('current_other');
	}, function(){
        $('.other-block').hide();
        $('.other').removeClass('current_other');
	});
});

$(function(){
	$('.userbar_design div').click(function(){
		$('.userbar_design div').not(this).removeClass('current_userbar');
		$(this).addClass('current_userbar');
		$('.current_userbar input').attr('checked', 'checked');
	});
});


$(function(){
    $('.select_game a').click(function(){
        $('.select_game a').removeClass('current_game');
        $(this).addClass('current_game');
        var game_id = $(this).attr('rel');
        var game_url = '/userbars/create/'+ game_id +'/';
        $('.userbar_form').attr('action',game_url);

        $.post(
            '/userbars/load_form/',
            {'game_id':game_id},
            function(html){
                $('.userbar_fields').html(html);
                $('.userbar_level1').spinner({ min: 1, max: 85 });
                $('.userbar_level2').spinner({ min: 1, max: 150 });
                $('.userbar_level4').spinner({ min: 1, max: 65 });
                $('.userbar_level5').spinner({ min: 1, max: 55 });
                $('.userbar_level6').spinner({ min: 1, max: 150 });
                $('.userbar_level7').spinner({ min: 1, max: 85 });
                $('.userbar_ID11').spinner({ min: 1, max: 999999999});
                $('.userbar_points11').spinner({ min: 1, max: 10000 });

            }
        );
        
        $.post(
            '/userbars/load_bars_for_game/',
            {'game_id':game_id},
            function(html){
                $('.userbar_design').html(html);
                $('.userbar_design div:first').addClass('current_userbar');


            }
        );
    });

    $('#userbar_nation4').live('change',function(){
        if ($(this).val()=='Акрет'){
            $('#userbar_class4').replaceWith('<select id="userbar_class4"><option>воин</option><option>специалист</option><option>стрелок</option></select>');
        }
        else{
            $('#userbar_class4').replaceWith('<select id="userbar_class4"><option>воин</option><option>специалист</option><option>стрелок</option><option>колдун</option></select>');
        }

    });


});

//Люди=>Воитель,Рыцарь,Разбойник;
//Светлые Эльфы=>Светлый Рыцарь,Разведчик,Светлый Маг,Оракул Евы;
//Темные Эльфы=>Темный Рыцарь,Ассасин,Темный маг,Оракул Шилен;
//Камаэль=>Солдат,Надзиратель;
//Орки=>Налетчик,Монах,Шаман;
//Гномы=>Ремесленник,Собиратель

nations = ['Люди','Светлые Эльфы','Темные Эльфы','Камаэль','Орки','Гномы'];
classes = [
        ['Люди','Воитель'],
        ['Люди','Рыцарь'],
        ['Люди','Разбойник'],
        ['Светлые Эльфы', 'Светлый Рыцарь'],
        ['Светлые Эльфы', 'Разведчик'],
        ['Светлые Эльфы', 'Светлый Маг'],
        ['Светлые Эльфы', 'Оракул Евы'],
        ['Темные Эльфы', 'Темный Рыцарь'],
        ['Темные Эльфы', 'Ассасин'],
        ['Темные Эльфы', 'Темный маг'],
        ['Темные Эльфы', 'Оракул Шилен'],
        ['Камаэль', 'Солдат'],
        ['Камаэль', 'Надзиратель'],
        ['Орки','Налетчик'],
        ['Орки','Монах'],
        ['Орки','Шаман'],
        ['Гномы','Ремесленник'],
        ['Гномы','Собиратель']

];
$(function(){
    $('.userbar_nation11').live('change', function(){
        nation = $(this).val();
        news_classes = [];
        for(var i=0; i<classes.length; i++) {
            if (nation == classes[i][0]){
                news_classes.push(classes[i][1]);
            }
        }
        html = '';
        for(var i=0; i<news_classes.length; i++) {
            html = html + '<option>'+ news_classes[i] +'</option>';
        }

        $('.userbar_class11').html(html);
    });
});

$(function(){
	$('.userbar_design div').live('click', function(){
		$('.userbar_design div').not(this).removeClass('current_userbar');
		$(this).addClass('current_userbar');
		$('.current_userbar input').attr('checked', 'checked');
	});
    
});

$(function(){
    $('.minus_inactive, .plus_inactive').click(function(){
        
        $(this).parent().append('<span class="rate_popup">Для изменения рейтинга авторизуйтесь</span>');
        $(this).parent().find('.rate_popup').hide().fadeIn(300).delay(2000).fadeOut(500, function(){
            $(this).remove();
        });


    });
});

/*modal_window*/
$(function(){
    $('.profile_edit_link').click(function(){
        $('.modal_window').show();
    });
    $('.modal_close').click(function(){
        $(this).parent().hide();
    });
    $('.modal_close').live('click', function(){
        $(this).parent().hide();
    });

    var months = ['Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь'];
    $("#profile_form_birthdate").datepicker({
			defaultDate: "+1w",
			changeMonth: true,
            changeYear: true,
            yearRange: '1970:2010',
			numberOfMonths: 1,
            dateFormat: 'dd.mm.yy',
            dayNames: ['Воскресенье', 'Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота'],
            dayNamesMin: ['Вс', 'Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб'],
            firstDay: 1,
            monthNames: months,
            monthNamesShort: months

		});

    $(".profile_edit_form").ajaxForm(function(data){
        $('.modal_window').hide();
        var sex_val = $(".profile_edit_form input[name=sex]:checked").val();
        var birth_val = $(".profile_edit_form #profile_form_birthdate").val();
        var about_val = $(".profile_edit_form #profile_form_about").val();
        if (sex_val == '1'){
            $('.profile_param_value_sex').text('мужской');
        }
        else {
            $('.profile_param_value_sex').text('женский');
        }

        $('.profile_param_value_date_of_birth').text(birth_val);
        $('.profile_param_value_about').text(about_val);
        if (data=='new_avatar'){
            window.location.reload();
        }


    });

    $(".auth_from_in_base").ajaxForm(function(data){
        if (data=='login_failed'){
            $('.modal_window').hide();
            $('#modal_window').show();
        }
        else{
            if (!isNaN(data)){
                var html = '<div class="modal_close">×</div>';
                html += '<div class="modal_header">Ваш аккаунт не активирован</div>';
                html += '<div class="modal_content"><p>При регистрации на ваш e-mail было выслано письмо со ссылкой для активации аккаунта. Если вы не получали письма, то пройдите по <a href="/reactivate/'+data+'/">ссылке</a> и на ваш e-mail придёт письмо со ссылкой для активации</p></div>';
                $('#modal_window').html(html);
                $('#modal_window').show();

            }
            else {
                window.location.href = data;
            }

        }


    });


    $('#registration_link').click(function(){
        $('.modal_window').hide();
        $('#modal_window_register').show();
    });

    $('#auth_link').click(function(){
        $('.modal_window').hide();
        $('#modal_window_auth').show();
    });


});

