
    var loc = location.href;
    var topNews;
    var topNewsIndex = 1;
    var photoIndex = 1;



    $(document).ready(function(){ 
         $('.galleryScroll').jcarousel({
            scroll: 4,
            initCallback: mycarousel_initCallback,
            itemFirstInCallback:  mycarousel_itemFirstInCallback,
            buttonNextHTML: null,
            buttonPrevHTML: null
        });
        
        $('#multimedia_gallery').jcarousel({
            initCallback: multimedia_initCallback,
            itemLoadCallback: multimedia_itemLoadCallback,
            size:2,
            buttonNextHTML: null,
            buttonPrevHTML: null,      
            scroll:2
        });
        
        $('#interest_gallery').jcarousel({
            initCallback: interest_initCallback,
            itemLoadCallback: interest_itemLoadCallback,
            size:6,
            buttonNextHTML: null,
            buttonPrevHTML: null,      
            scroll:6
        });
        
        $('#indextop_gallery').jcarousel({
            scroll: 4,
            initCallback: indextop_initCallback,
            itemFirstInCallback:  indextop_itemFirstInCallback,
            buttonNextHTML: null,
            buttonPrevHTML: null,
            scroll:4
        });
        
    });
    //=========================  indextop_gallery ==================================
    //================================================================================ 
    function  indextop_initCallback(carousel){

        var lastID = carousel.size();
        lastID = lastID+1;
        scrollTopSmallGallery(lastID);        
        
        $('#indextop_gallery a').mouseenter(function(){
            var currentId = $(this).attr('id');
            currentId = currentId.substr(1);
            if (currentId != topNewsIndex){                
                topNewsIndex = parseInt(currentId);
                showTopNews(currentId);
                clearInterval(topNews);
            }
            return false;
        }).mouseleave(function(){
            clearInterval(topNews);
            scrollTopSmallGallery(lastID);
        });
        
        function showTopNews(id){
            $('#indextop_gallery a').removeClass('stat_box_current');
            $('#a'+id).addClass('stat_box_current');
            $('.top_image_big').hide().css('opacity', 0);
            $('#li'+id).show().animate({opacity:1});
        }
        
        
        function scrollTopSmallGallery(lastID){
            topNews = setInterval(function(){

                topNewsIndex++;
                if(topNewsIndex == lastID){
                    topNewsIndex = 1;
                    carousel.scroll(1);
                }
                topNewsIndexM = topNewsIndex - 1;
                if (topNewsIndexM % 4 == 0){
                    carousel.next();
                }
                showTopNews(topNewsIndex);
            }, 10000);
        } 
       
        //  Buttons to left and right on min photo
        $('#indextop-next').bind('click', function() {
            carousel.next();            
            activeItem();            
            return false;
        });

        $('#indextop-prev').bind('click', function() {
            carousel.prev();
            activeItem();
            return false;
        });
        
        function activeItem(){
            currentId = carousel.first;
            if (currentId != topNewsIndex){
                topNewsIndex = currentId;
                showTopNews(currentId);
            }
        }
        
    }
    
    function   indextop_itemFirstInCallback(carousel, item, idx, state){
              
    }
    
    //================================================================================ 
    //================================================================================ 
    
    //=========================  interest_gallery ==================================
    //================================================================================
    function  interest_initCallback(carousel){
        //  Buttons to left and right on min photo
        $('#interest-next').bind('click', function() {
            carousel.next();
            return false;
        });

        $('#interest-prev').bind('click', function() {
            carousel.prev();
            return false;
        });
    }
    
    function interest_itemLoadCallback(carousel, state)
    {         
        // Check if the requested items already exist
        if (carousel.has(carousel.first, carousel.last)) {
            jQuery('#interest-next').show(); 
            jQuery('#interest-prev').show();
            return;
        }

        jQuery.get(
        '/?module=publications&action=GetInterest&start_elements=6',
        {
            first: carousel.first,
            last: carousel.last
        },
        function(xml) {
            interest_itemAddCallback(carousel, carousel.first, carousel.last, xml);
        },
        'xml'
        );
    };
    
    function interest_itemAddCallback(carousel, first, last, xml)
    {
        // Set the size of the carousel
        carousel.size(parseInt(jQuery('total', xml).text()));
        //alert(parseInt(jQuery('total', xml).text()));
        jQuery('news', xml).each(function(i) {
            firstcall = first;
            carousel.add(firstcall + i, interest_getItemHTML(jQuery('image', this).text(), jQuery('url', this).text(), jQuery('title', this).text()));
        });
        jQuery('#multimedia-next').show();
    };
    
    function interest_getItemHTML(imageurl, url, title, id)
    {      
        return_value2='<a href="'+ url +'" title="'+ title +'" class="">'
        +'<i>&nbsp;</i><img src="' + imageurl + '" width="128" height="86" alt="" title="" /><br />'
        +title
        +'</a>';
        return return_value2;
    };
    //================================================================================
    //================================================================================
    
      
    
    //=========================  multimedia_gallery ==================================
    //================================================================================
    function  multimedia_initCallback(carousel){
        //  Buttons to left and right on min photo
        $('#multimedia-next').bind('click', function() {
            carousel.next();
            return false;
        });

        $('#multimedia-prev').bind('click', function() {
            carousel.prev();
            return false;
        });
    }
    
    function multimedia_itemLoadCallback(carousel, state)
    {         
        // Check if the requested items already exist
        if (carousel.has(carousel.first, carousel.last)) {
            jQuery('#multimedia-next').show(); 
            jQuery('#multimedia-prev').show();
            return;
        }

        jQuery.get(
        '/?module=publications&action=GetMultimedia&start_elements=2',
        {
            first: carousel.first,
            last: carousel.last
        },
        function(xml) {
            multimedia_itemAddCallback(carousel, carousel.first, carousel.last, xml);
        },
        'xml'
        );
    };
    
    function multimedia_itemAddCallback(carousel, first, last, xml)
    {
        // Set the size of the carousel
        carousel.size(parseInt(jQuery('total', xml).text()));
        //alert(parseInt(jQuery('total', xml).text()));
        jQuery('news', xml).each(function(i) {
            firstcall = first;
            carousel.add(firstcall + i, mycarousel_getItemHTML(jQuery('image', this).text(), jQuery('url', this).text(), jQuery('title', this).text(), jQuery('id', this).text(), jQuery('stclass', this).text()));
        });
        jQuery('#multimedia-next').show();
    };
    
    function mycarousel_getItemHTML(imageurl, url, title, id, stclass)
    {      
        return_value2='<a href="'+ url +'" title="'+ title +'" class="'+ stclass +'">'
        +'<i>&nbsp;</i><img src="' + imageurl + '" width="128" height="86" alt="" title="" /><br />'
        +title
        +'</a>';
        return return_value2;
    };
    //================================================================================
    //================================================================================
    
    

    function mycarousel_initCallback(carousel) {             
        
        //  Buttons to left and right on min photo
        $('#mycarousel-next').bind('click', function() {
            carousel.next();
            return false;
        });

        $('#mycarousel-prev').bind('click', function() {
            carousel.prev();
            return false;
        });
        
        //  Click current image
        $('.cur_image').bind('click', function() {
            $('.big_image').hide();
            $('.imgdsc').hide();
            var minid = $(this).attr('id').split('-');
            $('#big_image-'+minid[1]).show();
            $('#dsc-'+minid[1]).show();
            $('.cur_image').removeClass('stat_box_current');
            $(this).addClass('stat_box_current');
            return false;
        });
        
        //  Buttons to left and right on big photo
        
        $('.previmg').click( function () {
            return clickPrev();
        } );
        
        $('.nextimg').click( function () {
            return clickNext();
        } );
        
        
        function clickNext(){
            album_id=$(carousel.container).attr("id");
            photoIndex= $(carousel.container).find('.stat_box_current').attr('id').split('-');
            photoIndex = photoIndex[1];
            if(photoIndex < carousel.size()) {
                var t = parseInt(photoIndex)+1;
                carousel.scroll(t);
                $('#min_image-'+t).click();
            }else{
                carousel.scroll(1);
                $('#min_image-1').click();    
            }
            return false;
        }
        
        function clickPrev(){
            album_id=$(carousel.container).attr("id");
            photoIndex= $(carousel.container).find('.stat_box_current').attr('id').split('-');
            photoIndex = photoIndex[1];
            if(photoIndex > 1) {
                var t = parseInt(photoIndex)-1;
                carousel.scroll(t);
                $('#min_image-'+t).click();
            }else{
                carousel.scroll(carousel.size());
                $('#min_image-'+carousel.size()).click();    
            }
            return false;
        }
        
        
    };
    
    function mycarousel_itemFirstInCallback(carousel, item, idx, state) {
  
    };
