
function balonme()
{
    $('span.baloonme').hover(function(){

        $(this).find("em").animate({
            opacity: "show",
            top: "-75"
        }, "slow");
        var imagepath = $(this).find("em").attr("title");
        var ourimage = new Image();
        ourimage.src=imagepath;
        if (ourimage.height == 0 || ourimage.width == 0)
        {
            var div_marginleft = 100 - $(this).width()/2;
            var div_margintop = 100 - $(this).height()/2;
        }
        else
        {
            var hc = ourimage.height/300;
            var wc = ourimage.width/300;
            if (hc > 1 || wc > 1)
            {
                if (hc >= wc)
                {
                    ourimage.width = 300/ourimage.height * ourimage.width;
                    ourimage.height = 300;
                }
                if (hc < wc)
                {
                    ourimage.height = 300/ourimage.width * ourimage.height;
                    ourimage.width = 300;
                }
            }
            var div_marginleft = ourimage.width/2 - $(this).width()/2;
            var div_margintop = ourimage.height/2 - $(this).height()/2;
        }

        $(this).find("em").show("slow");
        $(this).find("em").addClass("baloonclass");
        $(this).find("em").css("margin-left","-"+div_marginleft+"px");
        $(this).find("em").css("margin-top","-"+div_margintop+"px");
        var hoverText = $(this).attr("title");
        $(this).find("em").append("<img src=\""+imagepath+"\" alt=\""+hoverText+"\" />");
        if (ourimage.height == 0 || ourimage.width == 0)
        {
            $(this).find("em").find("img").css("width","300");
            $(this).find("em").find("img").css("height","300");
        }
        else
        {
            $(this).find("em").find("img").css("width",ourimage.width);
            $(this).find("em").find("img").css("height",ourimage.height);
        }
    }, function() {
        $(this).find("em").hide("fast");
        $(this).find("em").empty();
    }
    );
}

function filtermenu2 (){
    $('#shopfilter').hover(function() {
        $(this).children("ul").slideDown("slow");
        $("#shopfilter ul li:has(ul)").hover(function()
        {
            $(this).children("ul").css("display", "none");
            $(this).children("ul").slideDown("slow");
        },
        function()
        {
            $(this).children("ul").slideUp("fast");
        });
    },
    function() {
        $(this).children("ul").slideUp("fast");
    }
    );
}
function filtermenu (){

    $('#shopfilter').click(function() {
        $(this).attr("name", "clickon");
        $(this).children("ul").css("left", "-180");
        $(this).children("ul").slideDown("slow");
        $("#shopfilter ul li:has(ul)").click(function()
        {
            $(this).parent().find("ul").css("display", "none");
            $(this).children("ul").css("left", "-170");
            $(this).children("ul").slideDown("slow");

            $(this).children("ul li a").click(function(){
                $('#shopfilter').find("ul").hide();
            });
        });
    }
    );
}

function bottom2brouserBottom ()
{
    var toHeight = $().height();
    toHeight -= 241 + 80; //247

    if($('#uploadmyart input:hidden[name=operation]').val() == "add")
    {
        toHeight -= $('#myart_add_form').height()
    }
    if ($.browser.msie)
    {
        toHeight -= 6;
    }
    if ($.browser.opera)
    {
        toHeight += 20;
    }

    if ($("#leftmenu").height() <= toHeight)
    {
        $("#leftmenu").height(toHeight);
    }

    if ($('#leftmenu').height() >= $('#content').height())
    {
        $('#content').height($('#leftmenu').height());
    }
}

function input_blur_focus_text(id)
{
    var text = $(id).parent().prev().text();
    $(id).attr('value',text);
    $(id).blur(function(){
        if ($(this).attr('value') == '')
        {
            $(this).attr('value',text);
        }
    });
    $(id).focus(function(){
        if ($(this).attr('value') == text)
        {
            $(this).attr('value','');
        }
    });
}

function lvivart_vendor_desc()
{
    var h1 = $('#vendoritem h1');
    var hi_title = h1.html();
    
    var mybioalttext = (langid == "01") ? "біографія" : "biography";

    h1.prepend('<span id="vdesc" title="' + mybioalttext + '"></span>');
    $('h1').click(function(){
        h1.append('<div id="eelbox"></div>');
        $('#eelbox').html('<div id="eelboxb"></div>');
        var eel_left = $('#eelbox').width() /2 - 210;
        var eel_top = 200;
        $('#eelboxb').each (function(){
            $(this).html(hi_title+$('#eevendordescription').html());
            $(this).animate({
                "left": eel_left,
                "top": eel_top,
                "width": 400,
                "height": 300
            }, "slow");
        });
        $('#eelbox').click(function(){
            h1.empty().html(hi_title).prepend('<span id="vdesc"></span>');
            return false;
        });

    });
}

function lvivart_count_mybio()
{
    var maxChars = 1000;
    $('#mybiocounter').html(maxChars - $('#mybio').val().length);
    $('#mybio').bind('keydown keypress keyup',function(e) {
        // если строка больше maxChars урезаем её
        if($(this).val().length > maxChars)
        {
            $(this).val($(this).val().substr(0,maxChars));
        }
        // определяем колличество оставшихся для ввода сиволов
        var l = maxChars - $(this).val().length;
        // отображаем значение в информере
        $('#mybiocounter').html(l);
    });
}

function slide2(operation){
    var last = ee_slide2_array.length - 1;
    var prev_element = ee_slide2_element;
    if (operation == "prev"){
        ee_slide2_element = ee_slide2_element - 1;
    }
    if (operation == "next"){
        ee_slide2_element = ee_slide2_element + 1;
    }

    if (ee_slide2_element < 0){
        ee_slide2_element = last;
    }

    if (ee_slide2_element > last){
        ee_slide2_element = 0;
    }

    allwidth = 0;
    for(i=0; i<=jk; i++) {
        if (i == ee_slide2_element) {
            allwidth += $('img#'+ee_slide2image_array[i]).width()*5/3;
        }else {
            if (i == prev_element) {
                allwidth += $('img#'+ee_slide2image_array[i]).width()*3/5;
            }else {
                allwidth += $('img#'+ee_slide2image_array[i]).width();
            }
        }
    }
    $('#shopslide2 #smallnavagator').animate({
        'padding-left':(Math.round((600-allwidth)/2)-15)
        },500);

    $("#"+ee_slide2_array[prev_element]).fadeOut(600);
    $("#"+ee_slide2_array[ee_slide2_element]).fadeIn(600);
    $("#"+ee_slide2image_array[prev_element]).animate({
        'opacity':'0.5',
        'height':'30'
    }, 500);
    $("#"+ee_slide2image_array[ee_slide2_element]).animate({
        'opacity':'1',
        'height':'50'
    }, 500);
    slidestop();
}

function slide2set(j) {}

function slide2timeout() {
    setTimeout("slide2timeout()",100)
}

function slide2start() {
    t = setInterval("slide2('next')", 4500);
    $('#shopslide2').css('background-image','none');
}

function slide2stop() {
    clearInterval(t);
}

function slide2control() {
    if (ss_operation == 'stop') {
        slide2stop();
    }
    else {
        slide2start();
    }
}

function slide2smallnavagator_width() {
    allwidth = 0;
    for(i=0; i<=jk; i++) {
        allwidth += $('img#'+ee_slide2image_array[i]).width() + 4 ;
    }
    $('#shopslide2 #smallnavagator').animate({
        'padding-left':Math.round(((704-allwidth)/2))
        },100);
}

function ua_romashka () {
}

function ee_preload_all_images(path) {
    res = false;
//    alert($(path).length);
//    images[i] = new Image();
//    images[i].src = "images/" + file.name;
//    images[i].name = file.size;
    var images = new Array($(path).length);
    for(i=0; i<$(path).length; i++) {
    images[i] = new Image();
    images[i].src = $(path+':eq('+i+')').attr('src');
    images[i].name = 'filesize'+i;
    alert(i+' = '+images[i].complete+' = '+$(path+':eq('+i+')').attr('src'));
    if (images[i].readyState == "complete") {

    }
//    alert(i+' = '+images[i].readyState+' = '+$(path+':eq('+i+')').attr('src'));
//    if (images[i].readyState != "complete") {images[i].onload = function() {
//        setLoadedStatus(this.src, this.name);
//    };
//    }
//    else setLoadedStatus(images[i].src, images[i].name);

    }
   
    
}

$(document).ready(function(){
    //leftmenu.height = content.height

    filtermenu();
    //показати ФЕ біографію
    if($('#eevendordescription').length)
    {
        lvivart_vendor_desc();
    }
    //кількість символів в біографії
    if($('#mybio').length)
    {
        lvivart_count_mybio();
    }
    //форма додавання нових
    if($('#uploadmyart input:hidden[name=operation]').val() == "add")
    {
        $('#myart_add_form').hide('slow');

    }
    $('#myart_add_link').click(function(){
        $('#myart_add_form').slideToggle();
    });
    //список елементів в майаарті
    $('div.myart_dl_list:odd').after('<div class="separator"></div>');

    //comments
    $('#comments_count').html('<span class="openhide">'+$('#comments_count').text()+'</span>');
    $('#fe_comment_form_addblock').html('<span class="openhide">'+$('#fe_comment_form_addblock').text()+'</span>');
    $('#comments_list > dl').hide();
    if ($('#fe_errorflag').text() != '1') {
        $('#fe_comment_form').hide();
    }

    $('#comments_count').click(function(){
        $('#comments_list > dl').toggle('fast');
    });

    $('#fe_comment_form_addblock').click(function(){
        $('#fe_comment_form').toggle('fast');
    });

    $('#comments_list a').click(function(){
        var retr_id = $(this).attr('rel');
        $('#ee_comments_parent_id').val(retr_id);
        $('#comments_list > dl').hide();
        $('#fe_comment_form').show();
        return false;
    });

    $('.remark').css('opacity','0.5');
    
    bottom2brouserBottom ();

    $('#leftmenu > ul > li > a').click(function(){
        if($(this).next('ul').length) {
            $(this).next('ul').slideToggle();
            return false;
        } else {
            return true;
        }
    });
    $('#leftmenu > ul > li').each(function(){
        if ($(this).find('ul').length) {
            $(this).next().css('margin-top','22px');
        }
    });
});