function slideshow(count, index, time, animatetime) {
    $('#slideshow').animate({ opacity: 1}, time,function(){
        if(index>=count){
            index=0;
            preindex=count-1;
            $('#slideshow img').eq(index).fadeIn(0, function(){
                $('#slideshow img').eq(preindex).fadeOut(animatetime);
            });
            slideshow(count, index+1, time);
            return ;
        }
        if(index==0)
            preindex=count-1;
        else
            preindex = index-1;
        $('#slideshow img').eq(index).fadeIn(animatetime, function(){
            $('#slideshow img').eq(preindex).hide();
        });
        
        slideshow(count, index+1, time);
        return ;
    })
}

function closebutton() {
    $('#bigimage').remove();

}

$(document).ready(function(){
    /*слайды*/
    var count=$('#slideshow img').size();
    var obj=$('#slideshow img');

    obj.hide();
    obj.eq(0).show();

    slideshow(count, 1, 4000, 1300);
    /*слайды*/

    
    

    $('.showimage').click(function(){
        var href = $(this).attr('href');
        var str = '<table id="bigimage" class="fixed_in_ie" onclick="closebutton();"><tr><td><a class="fixed_in_ie" onclick="closebutton();" id="closebutton" href="#close">Закрыть</a><img onclick="closebutton();" class="imageb" src="'+href+'" alt=""></td></tr></table>';
        $("body").append(str);
        var $img = $('#bigimage .imageb');
	    $img.load(function(){

            // удаляем атрибуты width и height
            $(this).removeAttr("width")
            .removeAttr("height")
            .css({ width: "", height: "" });
            // получаем заветные цифры
            var imgW  = $(this).width();
            var imgH = $(this).height();

            if(imgH>imgW && imgH>700) {
                imgW = Math.round(imgW/(imgH/700));
                imgH = 620;
            }else if(imgW>imgH && imgW>1000) {
                imgH = Math.round(imgH/(imgW/1000));
                imgW = 800;
            }
            $('#bigimage .imageb').css("width",imgW+'px');
            $('#bigimage .imageb').css("height",imgH+'px');
        });
        return false;
    });

    
    /*меню*/

     $('#sidebar ul li').hover(
        function() {
            $(this).find('ul:first').stop(true, true);
            $(this).find('ul:first').slideDown();
        },
        function() {
            $(this).find('ul:first').slideUp('fast');
        }
    );

    

    /*
    $('#sidebar ul li').mouseover(function(){
        $(this).children('ul').show('slow');
    })

    $('#sidebar ul li').mouseleave(function(){
        $(this).children('ul').hide(100);
    })*/
    
    $('#sidebar>ul>li>a').attr('title','');
    $('#sidebar li:has(ul)').find('a:first').append('&nbsp;&raquo;');
    /*меню*/

    /*высота колонок*/
    $('#content').css('min-height',($('#rightcolumn').height()-176)+'px');
	//$('#main').height($('#body').height());
	$('#main').css('min-height','3000px');
    /*if($('#left').height()>$('#right').height())
        $('#right').css('min-height', $('#left').height()+'px');*/
    /*else
        $('#left').css('min-height', $('#right').height()+'px');*/
    /*высота колонок*/
    
})
