// JavaScript Document
$.noConflict();
(function($) {
    $(document).ready(function(){
        /*** IE6 png fix ***/
        if ($.browser.msie && $.browser.version.substr(0,1)<7){
            var pngSelectors = [
            ".pngFix",
            ".block-fimage img"
            ];
            setTimeout(function(){
                DD_belatedPNG.fix(pngSelectors.join(', '));
            }, 300);
        }

        /*** END ***/

        /*** watermark ***/
        var inputSelectors = [
        ".block-search .form-item input",
        ".block-for-input-custom input"
        ];

        setTimeout(function(){
            $(inputSelectors.join(', ')).watermark({})
        }, 300);
        /*** END ***/

        /*** IE8 button fix ***/
        if ($.browser.msie && $.browser.version.substr(0,1)==8){
            $(".form-submit").mousedown(function(){
                $(this).removeClass("form-submit-unclick").addClass("form-submit-click");
                $(this).mouseout(function(){
                    $(this).removeClass("form-submit-click").addClass("form-submit-unclick");
                });
            }).mouseup(function(){
                $(this).removeClass("form-submit-click").addClass("form-submit-unclick");
            });
        }
        /*** END ***/

        /*** zoomer ***/

        /*var textUp = $("a.text-up");textUp.attr("href", "javascript:void(0)");
    var textDown = $("a.text-down");textDown.attr("href", "javascript:void(0)");
    var maxFontSize = 16;
    var minFontSize = 12;

    var fontSizeSelectors = [
      "#content"
    ];

    textUp.click(function(){
      curenFontSize = parseFloat($(fontSizeSelectors.join(', ')).css("fontSize"));
      fsi = curenFontSize;fsi++;
      if(curenFontSize < maxFontSize){$(fontSizeSelectors.join(', ')).css("fontSize", fsi + "px");}
    });
    textDown.click(function(){
      curenFontSize = parseFloat($(fontSizeSelectors.join(', ')).css("fontSize"));
      fsi = curenFontSize;fsi--;
      if(curenFontSize > minFontSize){$(fontSizeSelectors.join(', ')).css("fontSize", fsi + "px");}
    });*/

        /*** END ***/

        /*** first-last elements ***/

        $("ul").each(function(){
            $("li:first" ,this).addClass("first");
            $("li:last" ,this).addClass("last");
        });

        /*** END ***/

        /*** comboBoxes ***/

        $(".block-custom-text ol li, .block-somegallery-text ol li").each(function(){
            $(this).html("<span class='li'>" + $(this).html() + "</span>");            
        });
	
	$('li.active_link a').addClass('active');
	
        /*** END ***/
        
        /*** change color ol li number of item  ***/

        setTimeout(function(){
            comboBoxes()
        }, 100);

        /*** END ***/
    
        setTimeout(function(){
            init_pager_infodoc()
        }, 100);
        
        setTimeout(function(){
            $('div.block-for-select').each(function(){
                var $this = $(this),
                $select = $this.find('select'),
                $abuts = $this.parents("div.block-pad").find("div.block-buttuns a"),
                $ateasers = $this.parents("div.block-handle").find("div.block-buttuns a");
                
                if ($this.hasClass('block-for-select-small')) {
                    var valueContainer = $this.find("div.comboboxValueContent");
                    var labelValue = valueContainer.text();
                    valueContainer.text(labelValue.substr(0,10) + '...');                    
                    $abuts.attr('href', $select.val());                    
                }
                $ateasers.attr('target', '_self');
                $abuts.attr('target', '_self');                
            });     
        }, 500);
	
        
    setTimeout(function(){
      $("div.add-paragraphs-image .block-custom-text-image .large-image").each(function(index){
          if (typeof arrimgap !== 'undefined' && typeof arrimgap[index] !== 'undefined') {
              $(this).find('a.minus').before(arrimgap[index]);
          }
      });
    }, 3000);
    
    
        $("div.add-paragraphs-image a.plus").each(function(index){
            $(this).bind("click", function(){
                var $contimg = $(this).parents("div.block-custom-text").find("div.add-paragraphs-image .block-custom-text-image");
                $(".image", $contimg).hide();
                $(".large-image", $contimg).show();
                $contimg.removeClass("block-custom-text-image").addClass("block-custom-text-image-wide");
                return false;
            });
        });

        $("div.add-paragraphs-image a.minus").each(function(index){
            $(this).bind("click", function(){
                var $contimglg = $(this).parents("div.block-custom-text").find("div.add-paragraphs-image .block-custom-text-image-wide");
                $(".large-image", $contimglg).hide();
                $(".image", $contimglg).show();
                $contimglg.removeClass("block-custom-text-image-wide").addClass("block-custom-text-image");
                return false;
            });
        });

        
        // main paragraph gallery
        $('div.block-gallery').each(function(){
            var $this = $(this);
            $this.find('div.block-item-img a.plus').click(function(event){
                
                var $gallery = $this;//$(this).parents("div.block-gallery");
                //var $pargel = $(this).parents(".block-gallery-content");
                $("ul li", $gallery).each(function(){
                    $("div.block-item-img", this).hide();
                    $("div.block-item-large", this).show();
                });
                var index = $("div.block-item-img a.plus", $gallery).index(this);
                var $images = $("div.block-item-large", $gallery);
                
                if ($gallery.parent().hasClass('add-pars-gallery')) {
                    var idxOfParagraphs = $("div.add-pars-gallery .block-gallery").index($gallery);
                    var imagesArr = arrlargeimgap[idxOfParagraphs];
                } else {
                    imagesArr = arrlargeimg;
                }
    
                var countImgs = $images.size();
                if (imagesArr[index] != '') {
                    $images.eq(index).find('a.minus').before(imagesArr[index]);
                    imagesArr[index] = '';
                }
                $gallery.parents(".block-post .block-custom-text").removeClass("block-custom-text").addClass("block-somegallery-text");
                
                var links = $("div.block-pager-carousel .block-ui ul li a", $gallery);
                if (links.size()) {
                    var btnind = Math.ceil((index + 1) / 6);
                    links.eq(btnind - 1).click();    
                    var beginbtndel = (Math.ceil(countImgs / 6) == 1 ? 0 : Math.ceil(countImgs / 6));
                    links.slice(beginbtndel).each(function(){$(this).hide();});
                    $('div.block-pager-carousel a.prev, div.block-pager-carousel a.next', $gallery).hide();
                } else {
                    preload(null);
                }                
                event.stopPropagation();
            });
            
            
            $this.find('div.block-item-large a.minus').click(function(event){
                
                var $gallery = $this;//$(this).parents("div.block-gallery");
                //var $pargel = $(this).parents("div.block-gallery-content");  
                $gallery.find("ul li").each(function(){
                    $("div.block-item-large", this).hide();
                    $("div.block-item-img", this).show();
                });
                
                var index = $("div.block-item-large a.minus", $gallery).index(this);
                var $images = $("div.block-item-img", $gallery);
                
                if ($gallery.parent().hasClass('add-pars-gallery')) {
                    var idxOfParagraphs = $("div.add-pars-gallery .block-gallery").index($gallery);
                    var imagesArr = arrgalap[idxOfParagraphs];
                } else {
                    imagesArr = arrimg;
                }
                
                var countImgs = $images.size();
                if (imagesArr[index] != '') {
                    $images.eq(index).find('a.plus').before(imagesArr[index]);
                    imagesArr[index] = '';
                }
                $gallery.parents(".block-post .block-somegallery-text").removeClass("block-somegallery-text").addClass("block-custom-text");
                
                var countbtns = (Math.ceil(countImgs/3)==1 ? 0 : Math.ceil(countImgs/3));
                if (countbtns > 0) {
                var links = $("div.block-pager-carousel .block-ui ul li a", $gallery);
                links.each(function(idx){$(this).show();});
                var curindbtn = Math.ceil((index+1)/3);
                links.eq(curindbtn-1).click();
                } else {
                    preload(null);
                }                
                event.stopPropagation();
            });
        });
        
        
        // news single image plus-minus
	$("div.block-custom-text-image").each(function(){
   	 var $this = $(this);
   	 $this.find('div.image a.news-plus').click(function(){
       	     $(this).parents('div.image').hide();
       	     $this.find('div.large-image').show();
       	     $this.removeClass('block-custom-text-image').addClass('block-custom-text-image-wide');
   	 });
   	 $this.find('div.large-image a.news-minus').click(function(){
       	     $(this).parents('div.large-image').hide();
       	     $this.find('div.image').show();
       	     $this.removeClass('block-custom-text-image-wide').addClass('block-custom-text-image');
    	 });
	});
        
        $('selec[name=]').change();
        
        /*** jQuery carousel ***/

        function mycarousel_initCallback(carousel) {
            var $pager = carousel.clip.parents('div.block-three-items').find('div.block-pager');
            if ($pager.length == 0) {
                $pager = carousel.clip.parents('div.block-carpag-wrapper').find('div.block-pager');
            }
            $(".block-ui ul li a", $pager).bind("click", function() {
                carousel.scroll(jQuery.jcarousel.intval((($(this).text())*3) - 2));
                $(this).parents('ul').find('a').removeClass("active");
                $(this).addClass("active");
                return false;
            });
            $("a.next", $pager).bind("click", function() {
                carousel.next();
                index = Math.floor((carousel.first - 1)/carousel.options.scroll) + ((carousel.first - 1) % carousel.options.scroll > 0 ? 1 : 0);
                $(this).parents('div.block-ui').find('ul a').removeClass("active").eq(index).addClass('active');
                return false;
            });

            $("a.prev", $pager).bind("click", function() {
                carousel.prev();
                index = Math.floor((carousel.first - 1)/carousel.options.scroll) + ((carousel.first - 1) % carousel.options.scroll > 0 ? 1 : 0);
                $(this).parents('div.block-ui').find('ul a').removeClass("active").eq(index).addClass('active');
                return false;
            });
        }

        function mycarousel_threeItemsBlockPager_initCallback(carousel){
            var $pager = carousel.clip.parents('div.block-pager');
            var $items = $(".block-ui ul li a", $pager);
            var items_size =  $items.size();
            $items.bind("click", function() {

                var index = $(this).text();
                carousel.scroll(jQuery.jcarousel.intval(index));


                $(this).parents('ul').find('a').removeClass("active");
                $(this).addClass("active");
                return false;
            });

            $('a.prev', $pager).bind("click", function() {
                //var i = parseInt($items.filter('.active').text());
                //if ((i > 1) && (i < 6)) return false;
                carousel.prev();
                return false;
            });
            $('a.next', $pager).bind("click", function() {
                var i = parseInt($items.filter('.active').text());
                if ((i > items_size - 5) && (i < items_size)) return false;
                carousel.next();
                return false;
            });
        }
        $('div.block-three-items').find('div.block-pager ul').jcarousel({
            scroll: 1,
            visible: 5,
            buttonNextHTML: null,
            buttonPrevHTML: null,
            wrap: "both",
            initCallback: mycarousel_threeItemsBlockPager_initCallback
        });
    
        $('div.block-two-items').find('div.block-pager ul').jcarousel({
            scroll: 1,
            visible: 5,
            buttonNextHTML: null,
            buttonPrevHTML: null,
            wrap: "both",
            initCallback: mycarousel_threeItemsBlockPager_initCallback
        });


        function mycarousel_galleryBlockPager_initCallback(carousel){
            var $pager = carousel.clip.parents('div.block-pager');

            $(".block-ui ul li a", $pager).bind("click", function() {
                var index = parseInt($(this).text() - 1);

                carousel.scroll(jQuery.jcarousel.intval($(this).text()));
                           
                $(this).parents('ul').find('a').removeClass("active");
                $(this).addClass("active");
                return false;
            });

            $('a.prev', $pager).bind("click", function() {
                carousel.prev();          
                return false;
            });
            $('a.next', $pager).bind("click", function() {
                carousel.next();
                return false;
            });
        }
        $('div.block-gallery').find('div.block-pager ul').jcarousel({
            scroll: 1,
            visible: 5,
            buttonNextHTML: null,
            buttonPrevHTML: null,
            wrap: "both",
            initCallback: mycarousel_galleryBlockPager_initCallback
        });
    

        function mycarousel_simple_initCallback(carousel) {
            var $pager = carousel.clip.parents('div.block-carpag-wrapper').find('div.block-pager');

            $(".block-ui ul li a", $pager).bind("click", function() {
                carousel.scroll(jQuery.jcarousel.intval($(this).text()));
                $(this).parents('ul').find('a').removeClass("active");
                $(this).addClass("active");
                return false;
            });
            $("a.next", $pager).bind("click", function() {
                carousel.next();
                var index = Math.floor((carousel.first - 1)/carousel.options.scroll) + ((carousel.first - 1) % carousel.options.scroll > 0 ? 1 : 0);
                $(this).parents('div.block-ui').find('ul a').removeClass("active").eq(index).addClass('active');
                return false;
            });

            $("a.prev", $pager).bind("click", function() {
                carousel.prev();
                var index = Math.floor((carousel.first - 1)/carousel.options.scroll) + ((carousel.first - 1) % carousel.options.scroll > 0 ? 1 : 0);
                $(this).parents('div.block-ui').find('ul a').removeClass("active").eq(index).addClass('active');
                return false;
            });
        }

        function mycarouselgallery_initCallback(carousel) {
            var $gallery = carousel.clip.parents('div.block-gallery');
            var $pager   = $gallery.find('div.block-pager');
            var $tsblock = $('div.block-gallery-same', $gallery);
            $(".block-ui ul li a", $pager).bind("click", function() {
                var scrollItem = (jQuery.jcarousel.intval($(this).text())-1)*carousel.options.scroll+1;
                carousel.scroll(scrollItem);
                $(this).parents('div.block-ui').find('ul a').removeClass("active");
                $(this).addClass("active");

                return false;
            });

            var imageItem = $(".block-gallery-content .block-item-img", $tsblock);
            var imageItemLarge = $(".block-gallery-content .block-item-large", $tsblock);
            if (imageItem){
                imageItem.click(function(){
                    var index = imageItem.index(this); 
                    
                    //alert(index);
                    var nextItem = (index + 1 < imageItem.size() ? index + 1 : 0);
                    var numImg = 6;
                    //alert(nextItem);
                    
                    //var imageLiblock = imageItem.parents("li");
                    var imageLiblock = $('div.block-gallery-content li', $tsblock);
                    //console.log(imageLiblock);
                    var $current = imageLiblock.eq(nextItem).animate({
                        opacity: 1
                    }, 1000).addClass("active");
                    imageLiblock.not($current).stop().css("opacity", 0).removeClass("active");

                    var $pargal = $(this).parents("div.block-gallery");
            
                    var imgInt = parseInt(index);
            
            
                    if ($gallery.parent().hasClass('add-pars-gallery')) {
                        var idxOfParagraphs = jQuery("div.add-pars-gallery .block-gallery").index($gallery);
        
                        if ($gallery.parents("div.block-somegallery-text").width()) {            
                            var imagesArr = arrlargeimgap[idxOfParagraphs];
                        } else {
                            numImg = 3;
                            imagesArr = arrgalap[idxOfParagraphs];
                        }
        
                    } else {
                        if ($gallery.parents("div.block-somegallery-text").width()) {            
                            imagesArr = arrlargeimg;
                        } else {
                            numImg = 3;
                            imagesArr = arrimg;
                        }
                    }
    
//                    if ($pargal.parents("div.block-somegallery-text").width()) {
//                        var numImg = 6;
//                        var imagesArr = arrlargeimg;
//                    } else {
//                        numImg = 3;
//                        imagesArr = arrimg;
//                    }

                    $("div.block-gallery-content > ul > li", $pargal).slice(imgInt*numImg, imgInt*numImg+numImg).each(function(index){
                        var ind = imgInt * numImg + index;
                        if (imagesArr[ind] != ''){
                            if ($pargal.parents("div.block-somegallery-text").width()) {
                                $(this).children("div.block-item-large").find('a.minus').before(imagesArr[ind]);
                            } else {
                                $(this).children("div.block-item-img").find('a.plus').before(imagesArr[ind]);
                            }
                            imagesArr[ind] = '';
                        }
                    });
                });
            }
            if (imageItemLarge){
                imageItemLarge.click(function(){
                    var index = imageItemLarge.index(this);
                    var nextItem = (index + 1 < imageItemLarge.size() ? index + 1 : 0);  
                    var numImg = 6;
                    //var imageLiblock = imageItemLarge.parents("li");
                    var imageLiblock = $('div.block-gallery-content li', $tsblock);
                    var $current = imageLiblock.eq(nextItem).animate({
                        opacity: 1
                    }, 1000).addClass("active");
                    imageLiblock.not($current).stop().css("opacity", 0).removeClass("active");
            
                    var $pargal = $(this).parents("div.block-gallery");
            
                    var imgInt = parseInt(index);
                    if ($gallery.parent().hasClass('add-pars-gallery')) {
                        var idxOfParagraphs = jQuery("div.add-pars-gallery .block-gallery").index($gallery);
        
                        if ($gallery.parents("div.block-somegallery-text").width()) {            
                            var imagesArr = arrlargeimgap[idxOfParagraphs];
                        } else {
                            numImg = 3;
                            imagesArr = arrgalap[idxOfParagraphs];
                        }
        
                    } else {
                        if ($gallery.parents("div.block-somegallery-text").width()) {            
                            imagesArr = arrlargeimg;
                        } else {
                            numImg = 3;
                            imagesArr = arrimg;
                        }
                    }
            
//                    if ($pargal.parents("div.block-somegallery-text").width()) {
//                        var numImg = 6;
//                        var imagesArr = arrlargeimg;
//                    } else {
//                        numImg = 3;
//                        imagesArr = arrimg;
//                    }
                    $("div.block-gallery-content > ul > li", $pargal).slice((imgInt * numImg), (imgInt * numImg + numImg)).each(function(index){
                        var ind = imgInt * numImg + index;
                        if (imagesArr[ind] != '') {
                            if ($pargal.parents("div.block-somegallery-text").width()) {
                                $(this).children("div.block-item-large").find('a.minus').before(imagesArr[ind]);
                            } else {
                                $(this).children("div.block-item-img").find('a.plus').before(imagesArr[ind]);
                            }
                            imagesArr[ind] = '';
                        }
                    });
                });
            }
        }

        $(".jQuery-carousel ul")
        .not('.block-viewer .jQuery-carousel ul')
        .not('.block-carpag-wrapper .jQuery-carousel ul')
        .each(function(){
            $(this).jcarousel({
                scroll: 3,
                visible: 5,
                wrap: "both",
                buttonNextHTML: null,
                buttonPrevHTML: null,
                initCallback: mycarousel_initCallback
            });
        });

        $(".block-carpag-wrapper .jQuery-carousel ul").each(function(){
            $(this).jcarousel({
                scroll: 1,
                visible: 1,
                wrap: "both",
                buttonNextHTML: null,
                buttonPrevHTML: null,
                initCallback: mycarousel_simple_initCallback
            });
        });

        //$(".block-viewer .jQuery-carousel ul").each(function(){
        //  $(this).jcarousel({
        //    scroll: 3,
        //    visible: 3,
        //    buttonNextHTML: null,
        //    buttonPrevHTML: null,
        //    initCallback: mycarouselgallery_initCallback
        //  });
        //});
    
        $(".block-somegallery-text .block-gallery .block-viewer .jQuery-carousel ul").each(function(){
            $(this).jcarousel({
                scroll: 6,
                visible: 3,
                buttonNextHTML: null,
                buttonPrevHTML: null,
                initCallback: mycarouselgallery_initCallback
            });
        });

        $(".block-custom-text .block-gallery .block-viewer .jQuery-carousel ul").each(function(){
            $(this).jcarousel({
                scroll: 3,
                visible: 3,
                buttonNextHTML: null,
                buttonPrevHTML: null,
                initCallback: mycarouselgallery_initCallback
            });
        });
    
        //    $(".block-pager-carousel ul").each(function(){
        //      $(this).jcarousel({
        //        scroll: 1,
        //        visible: 5
        //      });
        //    });

        $(".block-gallery-same").each(function(){
            var imageItem = $(".block-gallery-content li", this);
            var imageView = $(".block-viewer li", this);
            imageItem.css("opacity", 0);
            $(".block-gallery-content li:first", this).addClass("active").css("opacity", 1);
            if(imageView){
                imageView.click(function(){
                    index = $(imageView).index(this);
                    $current = $(imageItem).eq(index).animate({
                        opacity: 1
                    }, 1000).addClass("active");
                    $(imageItem).not($current).stop().css("opacity", 0).removeClass("active");
                });
            }
        });

        function init_pager_infodoc() {
            $(".block-infodoc").each(function(){
                var docsItem = $(".block-infodoc-content", this);
                var butPager = $(".block-pager .block-ui li a", this);
                $("div.block-infodoc-content", this).removeClass("active");
                $("div.block-infodoc-content:first", this).addClass("active");
                $(".block-pager .block-ui li:first a", this).addClass("active");
                if(butPager){
                    butPager.click(function(){
                        index = $(butPager).index(this);
                        $current = $(docsItem).eq(index).addClass("active"); 
                        $(docsItem).not($current).stop().removeClass("active"); 
                        $(this).parents('div.block-ui').find('ul a').removeClass("active");
                        $(this).addClass("active");      
                        $('div.block-infodoc-2col').each(function(){
                            $(this).find('div.item-text-inner').equalize({
                                step:2
                            });
                        });          
                    });
                } 
            });
        }

        function mycarouselvert_initCallback(carousel) {
            $(".block-calendar a.next").bind("click", function() {
                carousel.next();
                return false;
            });

            $(".block-calendar a.prev").bind("click", function() {
                carousel.prev();
                return false;
            });
        }

        $(".block-calendar ul").each(function(){
            $(this).jcarousel({
                vertical: true,
                scroll: 3,
                visible: 3,
                wrap: "both",
                animation: 500,
                buttonNextHTML: null,
                buttonPrevHTML: null,
                initCallback: mycarouselvert_initCallback
            });
        });

        function mycarousel_faq_initCallback(carousel) {
            var $pager = carousel.clip.parents('div.block-carfaq').find('div.block-actions');
            $("a.next", $pager).bind("click", function() {
                carousel.next();
                return false;
            });

            $("a.prev", $pager).bind("click", function() {
                carousel.prev();
                return false;
            });
        }

        $(".block-carfaq .block-carfaq-items ul").each(function(){
            $(this).jcarousel({
                vertical: true,
                scroll: 1,
                visible: 3,
                wrap: "both",
                animation: 500,
                buttonNextHTML: null,
                buttonPrevHTML: null,
                initCallback: mycarousel_faq_initCallback
            });
        });

        setTimeout(function(){
            ///
            $('.block-pager').each(function() {
                var $this = $(this);
		if ($this.parents('div.block-gallery').length) {
		    return false;
		}
                var itemWidth = 31;
                if ($this.hasClass('pager-2col')) {
                    itemWidth = 32;
                }
                var $items = $this.find('.block-ui ul li');
		$this.find('div.block-ui ul').css({'width': itemWidth * $items.size() + 'px'});
                if ($items.size() < 5) {
	            var widthBlockClip = $items.size() * itemWidth + 3;
                    $this.find('div.jcarousel-clip-horizontal').css({'width': widthBlockClip + 'px'});
                    var widthUl = parseInt($this.find('div.block-ui ul').width()) + 32;
                    $this.find('div.block-ui').css({'width': widthUl + 'px'});
                }
            });
        }, 100);

        /*** END ***/

        $(".block-tophead-menu a.active").each(function(){
            $(this).parent().prev("li").addClass("no-bg");
        });
        $(".block-tophead-menu a").each(function(){
            $(this).hover(
                function(){
                    $(this).parent().prev("li").addClass("no-bg-2");
                },
                function(){
                    $(this).parent().prev("li").removeClass("no-bg-2");
                }
                );
        });
        //$(".block-tophead-menu li.first").next("li").addClass("seccond");
        $("div.block-tophead-menu li.second").toggle(
            function(){
                var $this = $(this);
                $this.find('a').addClass('active');
                $this.prev().addClass("no-bg-3");
                $this.addClass('opened').removeClass('closed');
                $('div.block-tophead-submenu').slideDown();
            },
            function(){
                var $this = $(this);
                $this.addClass('closed').removeClass('opened');
                $('div.block-tophead-submenu').slideUp('normal', function(){
                    if ($this.parent().find('a.active').length > 1) {
                        $this.find('a').removeClass('active');
                        $this.prev().removeClass("no-bg-3");
                    }
                });
            }
            );

        $(".block-video").each(function(){
            var thisI = $(this).height();
            var innerItem = $(".block-titles", this).height();
            var someWidth = thisI - innerItem;
            if(someWidth > 0){
                $(".block-titles", this).css("paddingTop", someWidth + "px")
            }
        });

        /*** dropdown menu ***/
        var dd_timeout_value = 300;
        var dd_mainitem_out_timeout = null;
        var dd_mainitem_out_item = null;
        function dd_mainitem_out() {
            var $this = dd_mainitem_out_item;
            if ($this === null) {
                return;
            }
            var index = $this.parent().children('li').index($this);
            var ddi = $dropdowns_items.get(index);

            $this.removeClass('item-hover');
            $this.removeClass("item-hover-first");
            $this.next().removeClass("item-hover-next");
            if (typeof(ddi) != 'undefined') {
                var $ddi = $(ddi);
                $ddi.css({
                    top :-9999,
                    left:-9999
                });
            }
        }
        var $dropdowns = $('<div id="dropdown-menu-wrapper"></div>');
        $('body').append($dropdowns);
        $("div.block-bothead-menu > ul > li > h2 > a").each(function(index){
            var $a = $(this);
            $ul = $a.parent().next('ul');
            if ($ul.length > 0) {
                if ($ul.hasClass('dd-menu-region')) {
                    var $wrap = $('<div id="dropdown-menu-wrapper-'+ index +'" class="dropdown-menu-item dd-menu-region-item"></div>');
                }
                else {
                    var $wrap = $('<div id="dropdown-menu-wrapper-'+ index +'" class="dropdown-menu-item"></div>');
                }
                $wrap.append('<div class="block-dropdown"></div>');
                $wrap.append($ul);
                $dropdowns.append($wrap);
            }
        });
        var $dropdowns_items = $dropdowns.children('div');
        $dropdowns_items.each(function(){
            var $this = $(this);
            var $ul = $this.children('ul');
            var $le = $this.children('div.block-dropdown');
            $le.width(
                $ul.width()
                );
        });

        $('li', $dropdowns).each(function(){
            var $this = $(this);
            var $a = $this.children('a');
            $a.width(
                parseInt($this.width())
                - parseInt($a.css('paddingLeft'))
                - parseInt($a.css('paddingRight'))
                );
        });

        $dropdowns_items.hover(
            function() {
                clearTimeout(dd_mainitem_out_timeout);
            },
            function(){
                dd_mainitem_out_timeout = setTimeout(function(){
                    dd_mainitem_out();
                }, dd_timeout_value);
            }
            );

        $('li', $dropdowns).hover(
            function(e){
                var $this = $(this);
                $this.addClass("item-hover");
                if ($this.hasClass('first')) {
                    $this.addClass('item-hover-first');
                }
                $(this).find('ul').css({
                    visibility: 'visible'
                });

                var $child_ul = $this.children('ul');
                if ($child_ul.length > 0) {
                    var $main = $('div.block-bothead-menu');

                    var main_width = parseInt($main.width());
                    var main_left  = parseInt($main.offset().left);
                    var this_left  = parseInt($this.offset().left);
                    var this_width = parseInt($this.width());
                    var chul_width = parseInt($child_ul.width());

                    if (main_left + main_width <= this_left + this_width + chul_width) {
                        var $parent_ul = $this.parents('ul:last');
                        $parent_ul.addClass('dropdown-ul-fright');
                        $child_ul.css('left', -1 * $child_ul.width());
                    }
                }
                clearTimeout(dd_mainitem_out_timeout);
            },
            function(e){
                var $this = $(this);
                $this.removeClass("item-hover");
                if ($this.hasClass('first')) {
                    $this.removeClass('item-hover-first');
                }
                $this.find('ul').css({
                    visibility: 'hidden'
                });
            }
            );

        $("div.block-bothead-menu ul li").hover(
            function(){
                var $this = $(this);
                if ($this != dd_mainitem_out_item) {
                    dd_mainitem_out();
                    dd_mainitem_out_item = null;
                }
                $this.addClass('item-hover');
                if ($this.hasClass('first')) {
                    $this.addClass("item-hover-first");
                }
                $this.next().addClass("item-hover-next");
                var index = $this.parent().children('li').index($this);
                var ddi = $dropdowns_items.get(index);

                var _height = parseInt($this.height());
                var _left = parseInt($this.offset().left);
                var _top  = parseInt($this.offset().top);

                var $wrapper = $(this).parent();
                var _wleft = _left - parseInt($wrapper.offset().left);
                var _width = $wrapper.width();

                if (typeof(ddi) != 'undefined') {
                    var $ddi = $(ddi);
                    var width_ddi = $ddi.width();
                    var uleft = _left;
                    if (_wleft + width_ddi >= _width) {
                        uleft = _left - (_wleft + width_ddi - _width);
                        $ddi.children('ul').addClass('dropdown-ul-fright');
                    }
                    $ddi.css({
                        top : _top + _height,
                        left: uleft + 1
                    });
                }
            },
            function(){
                var $this = $(this);
                dd_mainitem_out_item = $this;
                dd_mainitem_out_timeout = setTimeout(function(){
                    dd_mainitem_out();
                }, dd_timeout_value);
            }
            );

        /*** END ***/
        $('.block-pager .block-ui a:not(.block-pager .block-ui ul a)').each(function(){
            $this = $(this);
            if(!($this.hasClass("prev") || $this.hasClass("next"))){
                $this.remove();
            }
        });

        /*content-block-help*/
        function mycarousel_contentBlockHelp_initCallback(carousel){
            var $pager = carousel.clip.parents('div.content-block-help').find('div.content-block-help-pager');
            $('a.prev', $pager).click(function() {
                carousel.prev();
                return false;
            });
            $('a.next', $pager).click(function() {
                carousel.next();
                return false;
            });
            $('ul a', $pager).each(function(i){
                $(this).click(function(){
                    carousel.scroll(i + 1);
                    return false;
                });
            });
        }
        $('div.content-block-help ul.item-list').jcarousel({
            scroll: 1,
            visible: 1,
            buttonNextHTML: null,
            buttonPrevHTML: null,
            initCallback: mycarousel_contentBlockHelp_initCallback,
            itemVisibleInCallback: function(carousel, item, index){
                var $pager = carousel.clip.parents('div.content-block-help').find('div.content-block-help-pager');
                if ($pager.length == 0) {
                    $pager = carousel.clip.parents('div.content-block-carmed').find('div.content-block-help-pager');
                }
                $('ul a', $pager).removeClass('active').eq(index - 1).addClass('active');

                var size = carousel.options.size;
                if (index == size) {
                    $('a.next', $pager).css('opacity', 0.5);
                } else if (index == 1) {
                    $('a.prev', $pager).css('opacity', 0.5);
                } else{
                    $('a.prev, a.next', $pager).css('opacity', 1);
                }
            }
        });
        function mycarousel_contentBlockPager_initCallback(carousel) {
            var $pager = carousel.clip.parents('div.content-block-help').find('div.content-block-help-pager');
            $('a.prev', $pager).click(function() {
                if (($('ul a', $pager).index($('ul a', $pager).filter('.active'))+1) % 3 == 1) {
                    carousel.prev();
                    return false;
                }
            });
            $('a.next', $pager).click(function() {
                if (($('ul a', $pager).index($('ul a', $pager).filter('.active'))+1) % 3 == 0) {
                    carousel.next();
                    return false;
                }
            });
        }
        $('div.content-block-help-pager ul').jcarousel({
            scroll: 3,
            visible: 3,
            buttonNextHTML: null,
            buttonPrevHTML: null,
            initCallback: mycarousel_contentBlockPager_initCallback
        });

        /* set checkboxes for pawermail */
        $("#check_uid81_0").bind("click",function() {
            if ($(this).is(':checked')) {
                $("#uid75").val("_c");
            } else {
                $("#uid75").val("");
            }
        });
    
        function pw_checkbox_value() {
            //if (jQuery("#check-box-pw1").is(":checked")) {
            if (jQuery('#check_uid81_0').is(":checked")) {
                jQuery("#uid75").val("_c");
            } else {
                jQuery("#uid75").val("");
            }
        }
        
        //check_uid81_0
        setTimeout(function(){
            pw_checkbox_value()
        }, 500);

        function pw_contactform_setid(){
            var contactId = jQuery("#contactForm").attr("href");
            if (contactId) {
                var cid = parseInt(contactId.substr(contactId.indexOf("cid=")+4));
                if (cid) {
                    jQuery("#uid82").val(cid);
                }
            }
        }
        setTimeout(function(){
            pw_contactform_setid()
        }, 500);
    
        /*content-block-carmed*/
        function mycarousel_contentBlockCarMed_initCallback(carousel) {
            var $pager = carousel.clip.parents('div.content-block-carmed').find('div.content-block-carmed-pager');
            $('a.prev', $pager).click(function() {
                carousel.prev();
                return false;
            });
            $('a.next', $pager).click(function() {
                carousel.next();
                return false;
            });
            $('ul a', $pager).each(function(i){
                $(this).click(function(){
                    carousel.scroll(i + 1);
                    return false;
                });
            });
        }
        $('div.content-block-carmed ul.item-list').jcarousel({
            scroll: 1,
            visible: 1,
            buttonNextHTML: null,
            buttonPrevHTML: null,
            initCallback: mycarousel_contentBlockCarMed_initCallback,
            itemVisibleInCallback: function(carousel, item, index){
                var $pager = carousel.clip.parents('div.content-block-carmed').find('div.content-block-carmed-pager');
                $('ul a', $pager).removeClass('active').eq(index - 1).addClass('active');

                var size = carousel.options.size;
                if (index == size) {
                    $('a.next', $pager).css('opacity', 0.5);
                } else if (index == 1) {
                    $('a.prev', $pager).css('opacity', 0.5);
                } else{
                    $('a.prev, a.next', $pager).css('opacity', 1);
                }
            }
        });

        /*block-tophead-submenu*/
        var $submenu = $('div.block-tophead-submenu');
        $('ul.level1 > li > a', $submenu).click(function(event){
            var $this = $(this);
            var $li = $this.parent();
            if (!$li.hasClass('active')) {
                $li.parent().find('li.active').removeClass('active');
                $li.addClass('active');
            }
        });
        var ul1li_left = 0;
        $('ul.level1 > li', $submenu).each(function(){
            var $this = $(this);
            var left = parseInt($this.offset().left, 10);
            if (left < ul1li_left) {
                $this.prev().addClass('last-p');
            }
            ul1li_left = left;
        });

        $('ul.level2').each(function(){
            var ul2li_left = 0;
            $(this).find('li').each(function(){
                var $this = $(this);
                var left = parseInt($this.offset().left, 10);
                if (left < ul2li_left) {
                    $this.prev().addClass('last-p');
                }
                ul2li_left = left;
            });
        });

        var ul1_height = $('ul.level1 > li:last').offset().top - $('ul.level1 > li:first').offset().top
        + $('ul.level1 > li:first').height();
        var ul2_height = $('ul.level2:first > li:last').offset().top - $('ul.level2:first > li:first').offset().top
        + $('ul.level2:first > li:first').height();
        var wDelimiterTop = parseInt(
            ul1_height + parseInt($('ul.level1').css('paddingTop'), 10) + 17
            ,10);

        $('div.block-tophead-submenu-dl', $submenu).css('top', wDelimiterTop);

        $('ul.level2', $submenu).css('top', wDelimiterTop + 10);

        var subMenuHeight = parseInt(
            wDelimiterTop + ul2_height
            + parseInt($('ul.level1').css('paddingTop'), 10)
            , 10);

        $submenu.height(subMenuHeight);
        $submenu.css({
            position: 'relative',
            top: 0,
            display: 'none'
        });

        /*align right block image*/
        setTimeout(function(){
            var $header = $('#header');
            var header_image_height = parseInt($('div.block-head-image', $header).height(), 10);
            var header_right_height = parseInt($('div.block-right', $header).height(), 10);

            var header_right_top = 10;
            if (header_image_height > 0 && header_right_height > 0) {
                header_right_top = parseInt((header_image_height - header_right_height) / 2, 10)-3; //
            }
            $('div.block-right').css('top', header_right_top);
            if ($('div.block-right').find('div.local').length) $('div.block-right').css('top', '50px');
        }, 10);

        //block media justifying

        jQuery('div.block-media-items div.block-media-item:not(:nth-child(3n))').addClass('block-media-item-nl');

        var stimeout = 1;
        if (jQuery.browser.safari) {
            stimeout = 1000;
        }

        setTimeout(function(){
		
            //infodoc block text vertical equalizing
            jQuery('div.block-infodoc-2col').each(function(){
                jQuery(this).find('div.item-text-inner').equalize({
                    step:2
                });
            });
        }, stimeout);

        /**
     * expandable ul handlers
     */
        //prepare contents
        setTimeout(function(){
            $('ul.expandable-list div.expandable-list-inner:visible').each(function(){
                var _height = $(this).height();
                $(this).css({
                    height: _height
                });
            });
        }, stimeout);

        $('ul.expandable-list div.expandable-list-inner:not(:visible)').each(function(){
            var $this = $(this);
            $this.css({
                position:'absolute',
                visibility: 'hidden'
            });
            $this.slideDown(1, function(){
                var _height = $(this).height();
                $(this).css({
                    position:'static',
                    visibility:'visible',
                    height:_height,
                    display:'none'
                });
            });
        });
        //click handler
        $('ul.expandable-list a.expandable-list-link').click(function(){
            var $this = $(this);
            var $pli = $this.parents('li.expandable-list-item');
            var $cli = $pli.find('div.expandable-list-inner');
            if ($pli.hasClass('expandable-list-opened')) {
                //close action
                $cli.slideUp('slow', function(){
                    $pli.removeClass('expandable-list-opened');
                });
            }
            else {
                //open action
                $pli.parent()
                .children('li.expandable-list-opened')
                .removeClass('expandable-list-opened')
                .find('div.expandable-list-inner').slideUp('slow');

                $pli.addClass('expandable-list-opened');
                $cli.slideDown('slow');
            }
            return false;
        });
        //stepped donate form slider
        if ($("#input-form-donate-value-slider").length > 0) {
            $("#input-form-donate-value-slider").slider({
                value:25,
                min: 5,
                max: 100,
                step: 5,
                slide: function(event, ui) {
                    $("#input-form-donate-value").val(ui.value + "");
                }
            });
            $("#input-form-donate-value").val($("#input-form-donate-value-slider").slider("value"));
        }

        /*
     * global
     * add specific class to each last li in the line
     * so we will get something like:
     * ul
     *  li | li | li
     *  li
     *  li | li | li | li
     *
     * with this it is possible to hide background right border for each last li in line
     */

        $('ul.custom-list-lines').each(function(){
            var cuslils = 0;
            $('li', this).each(function() {
                var $this = $(this);
                var left = parseInt($this.offset().left, 10);
                if (left < cuslils) {
                    $this.prev().addClass('last-p');
                }
                cuslils = left;
            });
            $('li:last', this).addClass('last-p');
        });


        $('div.block-two-items').each(function(){
            $(this).find('div.block-items').equalize({
                step:2
            });
        });

        $('div.block-custom').each(function(){
            $(this).find('div.eq').equalize({
                step:2
            });
        });




        $("#schellsuchen").click(function(){
            $("#schellsuchen-form").submit();
        });

        $("#suche").click(function(){
            $("#suche-form").submit();
        });

        $("input[name='nach']").each(function(){
            $(this).change(function(){
                var uri = $("input[name='hidden_uri']").val();
                window.location.href=uri+'&tx_asbsuchergebnisse[sort]='+$(this).val();
            });
        });

        setTimeout(function(){
            if (jQuery('#contactbox').width()){
                jQuery('#documents').hide();
            }
        }, 100);


        $('#a-cont').bind("click", function () {
            $('#documents').toggle();
            $('#contactbox').toggle();
            $('#a-cont').addClass("active");
            $('#a-docs').removeClass("active");
        });
        $('#a-docs').bind("click", function () {
            $('#contactbox').toggle();
            $('#documents').toggle();
            $('#a-cont').removeClass("active");
            $('#a-docs').addClass("active");
            init_pager_infodoc();
        //      jQuery('div.block-infodoc-2col').each(function(){
        //			jQuery(this).find('div.item-text-inner').equalize({
        //				step:2
        //			});
        //     });
        });
	
        setTimeout(function(){
            var $footerItems = $('div#footer .block-items .block-item');
            if($footerItems.size()==4) {
                $footerItems.css("width", "210px");
            } else if ($footerItems.size()==3) {
                $footerItems.css("width", "294px");
            }
        }, 100);

        /* FANCY BOX LINKS */
        var initOptionsfb = {
            'transitionIn'	: 'elastic',
            'transitionOut'	: 'elastic',
            'autoScale'	: false,
            'type'		: 'iframe',
            'width'           : 425,
            'height'          : 660
        };

        $('#contactForm').fancybox({
            'transitionIn'	: 'elastic',
            'transitionOut'	: 'elastic',
            'autoScale'			: false,
            'type'				: 'iframe',
            'width'       : 425,
            'height'      : 735
        });

        $('.newsletterForm').fancybox({
            'transitionIn'	: 'elastic',
            'transitionOut'	: 'elastic',
            'autoScale'			: false,
            'type'				: 'iframe',
            'width'       : 425,
            'height'      : 660
        });

        $('.empfehlenForm').fancybox({
            'transitionIn'	: 'elastic',
            'transitionOut'	: 'elastic',
            'autoScale'			: false,
            'type'				: 'iframe',
            'width'       : 425,
            'height'      : 690
        });

        $('#facebookWindow').fancybox({
            'transitionIn'	: 'elastic',
            'transitionOut'	: 'elastic',
            'autoScale'			: false,
            'type'				: 'inline',
            'width'       : 450,
            'height'      : 150
        });

        $('#twitterWindow').fancybox({
            'transitionIn'	: 'elastic',
            'transitionOut'	: 'elastic',
            'autoScale'			: false,
            'type'				: 'inline',
            'width'       : 450,
            'height'      : 150
        });
	
        $('.contactForm').fancybox(initOptionsfb);
    
        $('a.bestellenForm').fancybox({
            'transitionIn'	: 'elastic',
            'transitionOut'	: 'elastic',
            'autoScale'	: false,
            'type'		: 'iframe',
            'width'           : 425,
            'height'          : 720
        });
    

        /* END FANCY BOX LINKS */
  
        $(window).load(function () {
            getSubCategories();
        });

 
        //var rs_timer = null;
        //$("input[name=regionalsuche]").live("keyup", function(e){
	//    var $this = $(this);
        //    if($this.val().length > 3) {
	//	if (rs_timer) {
	//	    clearTimeout(rs_timer);
	//	}        
        //        rs_timer = setTimeout(function(){
        //            $.ajax({
        //                type: "GET",
        //                url: "index.php?id=53&tx_asbschnellsuche[action]=getCompany",
        //                data: "tx_asbschnellsuche[search]=" + $this.val(),
        //                dataType:"html",
        //                success: function(msg){
        //                    $("li.company").remove();
        //                    $("p.find-nothing-yellow").remove();
        //                    $("li.fixed-top").append(msg);
        //                },
        //                complete: function(){
	//
        //                }
        //            });
        //            
        //        }, 300);
        //   }
        //});


	var rs_timer = null;
        $("input[name=regionalsuche]").live("keyup", function(e){
            var $this = $(this); 
            if ($this.val().length > 3) {
                clearTimeout(rs_timer);
                rs_timer = setTimeout(function(){
                    $.ajax({
                        type: "POST",
                        url: 'index.php',
                        data: {                            
                            eID: 'regSearch',
                            tx_regsearch_pi1: ({
                                'inparam': $this.val()
                            })
                        },
                        dataType:"html",
                        success: function(data){
                            $("li.company").remove();
                            $("p.find-nothing-yellow").remove();
                            $("li.fixed-top").append(data);                            
                        }
                    });                    
                }, 200);
            }
        });


        // Print page
        $(".print-page").bind("click", function(){
            window.print();
            return false;
        }); 
    //  });
    }); // document.ready END

    $(function (){
        var mediaSize = $('div.block-media-item .image img').size();
        $('div.block-media-item .image img').load(function(){
         
            $(this).parents('div.image').addClass('loaded');
            var imgLoaded = $(this).parents('div.block-media-items-inner').find('div.loaded').size();
            if(imgLoaded == mediaSize){
                $('div.block-media-item').equalize({
                    step:3
                });
            }
        });
        
        var emphahlenLink = $('#footer .block-bottom-actions a.empfehlenForm').attr('href');
        $('div.content-flinks a.empfehlenForm').attr('href', emphahlenLink);
        
    });
   
    // BOOKMARK for 'merken'
    if($.browser.opera) {
        var aTag = $("a.jqbookmark");
        if (aTag.attr("rel") == ""){ // don't overwrite the rel attrib if already set
            aTag.attr("rel","sidebar");
        }
    } else {
        $("a.jqbookmark").click(function(event){

            event.preventDefault(); // prevent the anchor tag from sending the user off to the link
            var title = location.href,
            url = document.title;
            //alert(url);
            //alert(title);
            if ($.browser.mozilla) { // Mozilla Firefox Bookmark
                alert('mozilla');
                window.sidebar.addPanel(title, url);
            } else if(jQuery.browser.msie) { // IE Favorite
                window.external.AddFavorite( url, title);
            } else if(jQuery.browser.opera) { // Opera 7+
                return false; // do nothing - the rel="sidebar" should do the trick
            } else { // for Safari, Konq etc - browsers who do not support bookmarking scripts (that i could find anyway)
                alert('Unfortunately, this browser does not support the requested action,'
                    + ' please bookmark this page manually.');
            }
            return false;
        });
    }
// END BOOKMARK for 'merken'
})(jQuery);


function getOnChangeSubCat(){
    getSubCategories();
}

function equalizeASB(){
    jQuery('div.block-media-items div.block-media-item:not(:nth-child(3n))').addClass('block-media-item-nl');

    var stimeout = 1;
    if (jQuery.browser.safari) {
        stimeout = 1000;
    }

    setTimeout(function(){
        jQuery('div.block-media-items-inner').each(function(){
            jQuery(this).children('div.block-media-item').equalize({
                step:3
            });
        });

        //infodoc block text vertical equalizing
        jQuery('div.block-infodoc-2col').each(function(){
            jQuery(this).find('div.item-text-inner').equalize({
                step:2
            });
        });


    }, stimeout);
}

function getSubCategories(){
    var id = jQuery('select#category option:selected').val();
    var catid = jQuery('input#hidden-cat').val();
    var servtitle = jQuery('input#service-preset').val();
    jQuery.ajax({
        type: "POST",
        url: "index.php?tx_asbschnellsuche[action]=fillSubCategory",
        data: "tx_asbschnellsuche[uid]="+id+"&tx_asbschnellsuche[preset]="+catid+"&tx_asbschnellsuche[service_title]="+servtitle,
        dataType:"html",
        success: function(msg){
            jQuery("#subcategory-inner").html('');
            jQuery("#subcategory-inner").html(msg);
        },
        complete: function(){
            comboBoxes('#subcategory-inner select');
        }
    });
}

function comboBoxes(selector){
    var selects;
    if (!selector) {
        selects = jQuery(".block-for-select select");
    } else {
        selects = jQuery(selector);
    }
    selects.each(function(){
        var combobox = jQuery(this).combobox(
        {
            comboboxContainerClass: "comboboxContainer",
            comboboxValueContentContainerClass: "comboboxValueContainer",
            comboboxValueContentClass: "comboboxValueContent",
            comboboxDropDownClass: "comboboxDropDownContainer",
            comboboxDropDownButtonClass: "comboboxDropDownButton",
            comboboxDropDownItemClass: "comboboxItem",
            comboboxDropDownItemHoverClass: "comboboxItemHover",
            comboboxDropDownGroupItemHeaderClass: "comboboxGroupItemHeader",
            comboboxDropDownGroupItemContainerClass: "comboboxGroupItemContainer"
        },
        {
            animationType: "fade",
            width: "230px",
            height:"25px"
        });
        //change button link after select 'change'
        combobox.combobox.onChange = function(select) {
            var $parblock = select.parents('div.block-for-select');
            if ($parblock.size() && $parblock.hasClass('block-for-select-small')) {
                var comboboxValueContent = select.closest("div.comboboxContainer").find("div.comboboxValueContent");
                var labelValue = comboboxValueContent.text();
                comboboxValueContent.text(labelValue.substr(0,10) + '...');
            }            
            
            if (select.hasClass("subitems-search")) {
                comboboxValueContent = select.closest("div.comboboxContainer").find("div.comboboxValueContent");
                labelValue = comboboxValueContent.text();
                comboboxValueContent.text(labelValue.substr(0,22) + '...');
            }
            select.parents("div.block-custom .block-handle").find("div.block-buttuns a").attr('href', select.val());
            
            if (select.hasClass('news-pid')) {                
                if (select.val() != 'all') {
                    window.location = select.val();
                }
            }
        };
        
    });
}

function preload(butPgr) {
    var $gallery = jQuery(butPgr).parents("div.block-gallery");
    var numImg = 6;
    if ($gallery.parent().hasClass('add-pars-gallery')) {
        var idxOfParagraphs = jQuery("div.add-pars-gallery .block-gallery").index($gallery);
        
        if ($gallery.parents("div.block-somegallery-text").width()) {            
            var imagesArr = arrlargeimgap[idxOfParagraphs];
        } else {
            numImg = 3;
            imagesArr = arrgalap[idxOfParagraphs];
        }
        
    } else {
        if ($gallery.parents("div.block-somegallery-text").width()) {            
            imagesArr = arrlargeimg;
        } else {
            numImg = 3;
            imagesArr = arrimg;
        }
    }
    
    var imgInt = 0;
    if (butPgr != null) {
        var contid = jQuery(".block-pager-carousel .block-ui ul li a", $gallery).index(butPgr);
        imgInt = parseInt(contid);
    }

    jQuery("div.block-gallery-content > ul > li", $gallery).slice((imgInt * numImg), (imgInt * numImg + numImg)).each(function(index){
        var ind = imgInt * numImg + index;
        if (imagesArr[ind] != ''){
            if (jQuery($gallery).parents("div.block-somegallery-text").width()) {
                jQuery(this).children("div.block-item-large").find('a.minus').before(imagesArr[ind]);
            } else {
                jQuery(this).children("div.block-item-img").find('a.plus').before(imagesArr[ind]);
            }
            imagesArr[ind] = '';
        }
    });
}

