var basics = function(){
    $(function(){if (jQuery.browser.msie){try{document.execCommand("BackgroundImageCache",false,true);} catch(err){}}});
    $("a").focus(aBlur);
    $("h1").addClass("asLink").click(goHome);
    if ($.browser.msie) {
    homeLogo = $('#home h1');
    if (homeLogo) {
        $.getScript("/l/js/jquery.flash.minified.js", function(){
            
            homeLogo
                .css("cursor", "default")
                .css("text-indent", "0")
                .css("line-height", "1000px")
                .css("padding", "5px 0 0 46px")
                .flash({
                    src: '/logo.swf',
                    width: 153,
                    height: 282
                });
        });
    }
    }
};
var done = function(){
    $('#waiting').html("<span></span>");
    $('#parents').animate({bottom:80}, "slow");
};
var aBlur = function(){
    this.blur();
};
var aFocus = function(){
    $("a").focus(aBlur);
};
var waiting = function(){
    $("#waiting").html("<span>?</span>");
}
var goHome = function(){
    location.href = "/";
};

var slideup;

var hideSlide = function(){
    slideup.hide('fast', done);
}
var showSlide = function(){
    waiting();
    slideup = $("#slideup");
    if (slideup) {
        slideup.show('fast');
        slideup.load(this.href+'?request=1', doneSlide);
    } else {
        done();
    }
    return false;
};
var loadSlide = function(){
    waiting();
    if (slideup) {
        slideup.show();
        slideup.load(this.href+'?request=1', doneSlide);
    } else {
        done();
    }
    return false;
};
var doneSlide = function(){
    $("#slideup a").click(loadSlide);
    $("#slideup img").css({ cursor: "pointer"}).click(hideSlide);
    done();
}


var loadFullInfo = function(){
    waiting();
    fullInfo = $("../../div.full_info", this);
    if (fullInfo) {
        fullInfo.show();
        fullInfo.load(this.href+'?request=1', done);
    } else {
        done();
    }
    return false;
};
var showAnsver = function(){
    waiting();
    ansver = $("../../div.ansver",this);
    if (ansver) {
        ansver.show();
        ansver.load(this.href+'?request=1', done);
    } else {
        done();
    }
    return false;
};
var sautb = function(){
    waiting();
    $("div.ab", this).toggle();
    done;
};
var showAutor = function(){
    waiting();
    autorPiece = $("../../div.ap",this);
    autorInfo = $("../../div.ab",this);
    if (autorInfo) {
        autorInfo.show();
        autorInfo.load(this.href+'?request=1', function(){
            autorPiece.hide();
            done();
            });
    } else {
        done();
    }
    return false;
};
var showAutorsList = function(){
    waiting();
    $("#showlist").load(this.href+'?request=1', function(){
        done();
        $("a").focus(aBlur);
        $("div.at/a").click(showAutor);
        });
    return false;
};

function esc(s){
    return escape(s).replace(new RegExp('\\+','g'), '%2B');
}
var t = null;
var by = '';
var at = '';
var y = '';
var showBy = function(){
    waiting();
    $("#showlist").load('/autors/by'+by+'?y='+y+'&at='+esc(at), function(){
        done();
        $("a").focus(aBlur);
        $("div.at/a").click(showAutor);
        });
};
var showByFamily = function(){
    if (this.value !== '') {
        if (t) {
            clearTimeout(t);
        }
        by = 'family';
        at = this.value;
        y = this.id;
        t = setTimeout(showBy, 1000);
    }
};
var showByTitle = function(){
    if (this.value !== '') {
        if (t) {
            clearTimeout(t);
        }
        by = 'title';
        at = this.value;
        y = this.id;
        t = setTimeout(showBy, 1000);
    }
};

var logOut = function(){
    q = window.confirm($("#mess_log_3").text());
    if (q) {
        location.href = "/login.php?logout="+location.href;
    }
    return false;
};

var loginVal = 'guest';
var passwVal = 'guest';

var clearLogMessTO = 0;

var clearLogMess = function(){
    clearLogMessTO = setTimeout('$("#log_mess").empty()', 10000);
};
var clearTO = function(){
    clearTimeout(clearLogMessTO);
};
var clearLogin = function(){
    if (this.value = loginVal) 
    this.value = '';
    $("#log_mess").html($("#mess_log_1").html());
    clearTO();
};
var clearPassw = function(){
    if (this.value = passwVal) 
    this.value = '';
    $("#log_mess").html($("#mess_log_2").html());
    clearTO();
};
var setLogin = function(){
    if (this.value == '') {
        this.value = loginVal;
        clearLogMess();
    }
};
var setPassw = function(){
    if (this.value == '') {
        this.value = passwVal;
        clearLogMess();
    }
};
var checkLogin = function(){
    $("#log_mess").empty();
    if (($("#inp_login").val() == '')||($("#inp_login").val() == loginVal)) {
        $("#log_mess").html($("#mess_log_1").html());
        this.blur();
        return false;
    }
    if (($("#inp_passw").val() == '')||($("#inp_passw").val() == passwVal)) {
        $("#log_mess").html($("#mess_log_2").html());
        this.blur();
        return false;
    }
    this.blur();
    document.getElementById("login").submit();
};

var customStart = function(){ 
}

$(document).ready(function(){
    basics();
    $("#logout").click(logOut);
    $("#inp_login").focus(clearLogin);
    $("#inp_passw").focus(clearPassw);
    $("#inp_login").blur(setLogin);
    $("#inp_passw").blur(setPassw);
    $("#inp_ok").click(checkLogin);
    customStart();
    done();
}); 
