//
// Some twicks for Domberi, (c) 2010 www.novelsite.ru, NK
//

window.onresize = resize;
function resize() {
    var hh = parseInt($("html").attr("clientHeight")) - 820;
    if (hh > 52) {
        $("#container").css({'margin-top': hh+'px'});
    }
}

   $(document).ready(function(){ 
        $("ul.sf-menu").supersubs({ 
                minWidth:    10,
                maxWidth:    22,
                extraWidth:  1
            }).superfish({ 
                animation: {opacity:'show',height:'show'},
                dropShadows:   false,
                speed: 'fast',
                delay: 500
        });
        
        resize();
        
    });
    
    $(function() {
        var galleries = $('.ad-gallery').adGallery({
        loader_image: '/js/jquery.a_d-gallery/loader.gif',
        width: 594, // Width of the image, set to false and it will read the CSS width
        height: 484, // Height of the image, set to false and it will read the CSS height
        thumb_opacity: 1, // Opacity that the thumbs fades to/from, (1 removes fade effect)
                      // Note that this effect combined with other effects might be resource intensive
                      // and make animations lag
        start_at_index: 0, // Which image should be displayed at first? 0 is the first image
    //    description_wrapper: $('#descriptions'), // Either false or a jQuery object, if you want the image descriptions
                                           // to be placed somewhere else than on top of the image
        animate_first_image: false, // Should first image just be displayed, or animated in?
        animation_speed: 400, // Which ever effect is used to switch images, how long should it take?
        display_next_and_prev: false, // Can you navigate by clicking on the left/right on the image?
        display_back_and_forward: false, // Are you allowed to scroll the thumb list?
        scroll_jump: 0, // If 0, it jumps the width of the container
        slideshow: {
           enable: true,
           autostart: true,
           speed: 9000,
           start_label: 'Слайдшоу',
           stop_label: 'Стоп',
           stop_on_scroll: true,
           countdown_prefix: '(',
           countdown_sufix: ')',
           onStart: false,
           onStop: false
        },
        effect: 'fade',
        enable_keyboard_move: true,
        cycle: true,
        callbacks: {
            init: false,
            afterImageVisible: function() {
                var i = this.current_index + 1;
                $("body").css({'background' : 'url(/gallery/firstpage/bg1_' + i + '.jpg) top'});
                $(".ad-image-description").css({'background' : 'url(/pic/b88.png) top'});
                //DD_belatedPNG.fix('.ad-image-description');
                //this.preloadImage(this.current_index + 1);
            },
            beforeImageVisible: false
        }
        });
        
        // this get number of image and then get url for deep to project
        $(".ad-image-wrapper").click(function(event) {
            var ss = $(this).find('img').attr('src');
            ss = parseInt(ss.substring(ss.length-5, ss.length-4));
            if (ss == 0) {
                ss = 1;
            }

            event.preventDefault();
            linkLocation = $("#firstpage"+ss).attr('rel');
            jQuery("body").fadeOut(1000, function redirectPage() {window.location = linkLocation;});
    	 
            return false;
        });
        
    });
