$(function() {

    $('div.itemport').hover(function() {
        //$(this+' div.divscr').removeClass('divscrnotvisible');


        var divsk = this.id;
        var hei = $('#svn' + divsk).height();

        $('#s' + divsk).stop().animate({ height: hei + "px" });

        //$('#s'+divsk).stop().slideDown(700);

    }, function() {
        //$('div.itemport').addClass('divscrnotvisible');
        var divsk = this.id;
        //$('.divscr').stop().slideUp(700);
        //$('#s'+divsk).slideUp(700);
        $('#s' + divsk).stop().animate({ height: "0px" });


    });

    $('div.nashavitka').click(function() {

        $('#viz').stop().animate({ top: "-25px" });


    });
    $('div.vizclose').click(function() {

        $('#viz').stop().animate({ top: "-1000px" });


    });

    $('div.nashavitka').click(function() {

        $('#formobr').stop().animate({ top: "70px" });
        $('#alldark').show();

    });
    $('div.closeform').click(function() {

        $('#formobr').stop().animate({ top: "-1000px" });
        $('#alldark').hide();

    });

    /*$.ajax({
        type: "POST",
        url: "/tw.php",
        data: "",
        success: function(msg) {
            $('.natwitter').html(msg);
        }
    });*/
});

function countLines(strtocount, cols) {
    var hard_lines = 1;
    var last = 0;
    while (true) {
        last = strtocount.indexOf("\n", last + 1);
        hard_lines++;
        /* if ( hard_lines == 35) break; */
        if (last == -1) break;
    }
    var soft_lines = Math.ceil(strtocount.length / (cols - 1));
    var hard = eval("hard_lines " + unescape("%3e") + "soft_lines;");
    if (hard) soft_lines = hard_lines;
    return soft_lines;
}

// функция вызывается при каждом нажатии клавиши в области ввода текста
function ResizeTextArea(the_form, min_rows) {
    the_form.rows = Math.max(min_rows, countLines(the_form.value, the_form.cols));
}

function isValidEmail(email, strict) {
    if (!strict) email = email.replace(/^\s+|\s+$/g, '');
    return (/^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/i).test(email);
}

function gen() {
    var rd = Math.floor(Math.random() * (100000 - 1 + 1)) + 1;
    var email = document.getElementById('thisname').value;
    var message = document.getElementById('txt').value;
    var thiscat = document.getElementById('thissub').value;

    if (thiscat > 0 && email != '' && message != '' && isValidEmail(email, false)) {
        $.ajax({
            type: "POST",
            url: "/aj.php",
            data: "message=" + message + '&email=' + email + '&thiscat=' + thiscat + '&rd=' + rd + '&key=45674465421465465',
            success: function(html) {
                if (html == "not") {
                    document.getElementById('error').innerHTML = 'Вы можете отправлять сообщения не чаще <br />чем раз в 30 секунд.';
                    document.getElementById('error').style.display = 'block';
                    document.getElementById('zapok').style.display = 'none';
                } else {
                    document.getElementById('error').innerText = ' ';
                    document.getElementById('zapok').style.display = 'block';
                    document.getElementById('error').style.display = 'none';
                    document.getElementById('formot').style.display = 'none';
                }
            }
        });
    } else {
        if (email == '' || message == '') {
            document.getElementById('error').innerHTML = 'Вы заполнили не все поля.';
            document.getElementById('error').style.display = 'block';
            document.getElementById('zapok').style.display = 'none';
        }
        if (!isValidEmail(email, false)) {
            document.getElementById('error').innerHTML = 'Неправильный E-mail адрес.';
            document.getElementById('error').style.display = 'block';
            document.getElementById('zapok').style.display = 'none';
        }

    }
}

function InstallFancybox() {
    //alert($.browser.version);
    if ('fancybox' in jQuery.fn) {
        if (!$.browser.opera || $.browser.version >= 9.5) {
            $("#kino div.images-column a.poster,\
				#actions .poster a,\
				#basic-pages div.gallery-thumbs a,\
				#basic-pages div.djpark-events .poster a,\
				div.frame-4 a,\
				div.photo-part-photo .item,\
				a.fancybox").fancybox({
				    'zoomSpeedIn': 300,
				    'zoomSpeedOut': 300,
				    'overlayOpacity': 0.6
				});
        }
    }
}



$(function() {

    InstallFancybox();


});

function getImageSize($img) {

}
function vzkom(id) {
    if ($('#' + id).is(":hidden")) {
        $('#' + id).show(400);

    } else {
        $('#' + id).hide(400);
    }
}
function sbform() {
    var par1 = $('#plll1').val();
    var par2 = $('#plll2').val();
    var par3 = $('#plll3').val();
    var par4 = $('#plll4').val();

    if (par1 && par2 && par3 && par4 && par1 != 'г. Екатеринбург, бассейн Ариант, 3 дорожка' && par2 != '12.12.2012' && par3 != 'Владимир Владимирович' && par4 != '233-68-03') {
        $.ajax({
            type: "POST",
            url: "/ajform.php",
            data: "mesto=" + par1 + '&dat=' + par2 + '&name=' + par3 + '&phone=' + par4 + '&key=45674465421465465',
            success: function(html) {
                $('#errpole').hide();
                $('#okform').show();
                setTimeout(function() {
                    $('#formobr').stop().animate({ top: "-1000px" });
                    $('#alldark').hide();
                    $('#okform').hide();
                    $('#errpole').hide();
                }, 3000);
            }
        });
    } else {
        $('#errpole').show();
    }
}
function closeff() {
    $('#formobr').stop().animate({ top: "-1000px" });
    $('#alldark').hide();
}
