$(document).ready(function(){
    
    $('#lightbox a').lightBox({
        imageLoading:'/i/jquery/lightbox-images/lightbox-ico-loading.gif',
        imageBtnClose:'/i/jquery/lightbox-images/lightbox-btn-close2.gif',
        imageBtnPrev:'/i/jquery/lightbox-images/lightbox-btn-prev2.gif',
        imageBtnNext:'/i/jquery/lightbox-images/lightbox-btn-next2.gif',
        imageBlank:'/i/jquery/lightbox-images/lightbox-blank.gif',
        txtImage:'Изображение',
        txtOf:'из'
    });
    
    if (document.documentElement.clientHeight>$('#all').height()) {
        if ($('#mainfiller').length) {
            $('#mainfiller').attr('height', document.documentElement.clientHeight-$('#all').height()+$('#mainfiller').height());
        }
        else {
            $('#filler').attr('height', document.documentElement.clientHeight-$('#all').height());
        }
        
    }
    
    $(".jMyCarousel").jMyCarousel({
        visible:jMyCarousel_calc_width(),
        eltByElt:true
    });
    
    $('.captcha').click(function(){
        $(this).attr('src', '/captcha/rand-'+parseInt(Math.random()*999999999)+'/');
    });
    
    $('.validate').validate();
    
});

var jMyCarousel_width = 0;
function jMyCarousel_calc_width() {
    
    $(".jMyCarousel img").each(function(){
        jMyCarousel_width += this.width;
    });
    
    return jMyCarousel_width>$("#td_jMyCarousel").width() ? ($("#td_jMyCarousel").width()-10)+'px' : jMyCarousel_width+'px';
    
}

function query(url, div, data) {
    
    $.ajax({
        cache:false,
        type:'POST',
        dataType:'json',
        url:url,
        data:data,
        success:function(response){
            $('#'+div).html(response.html);
        }
    });
    
}

function checknum(e) {
    
    return (e.keyCode >= 48 && e.keyCode <= 57)
    
}

function fixPNG(element) {
    
    if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent)) {
        var src;
        if (element.tagName=='IMG') {
            if (/\.png$/.test(element.src)) {
                src = element.src;
                element.src = "/i/spacer.gif";
            }
        }
        else {
            src = element.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i)
            if (src) {
                src = src[1];
                element.runtimeStyle.backgroundImage="none";
            }
        }
        if (src) {
            element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
        }
    }
    
}
