$(document).ready(function(){
    if($('#customer-main-menu').length) {  
        $('#customer-main-menu li:last').css('background-image','none');
    }
    if($('ul.customer-secondary-menu').length) {  
        $('ul.customer-secondary-menu li:last').css('background-image','none');
    }
    if($('#news-summary').length) {  
        $('#news-summary li:last').css('background-image','none');
    }
    if($('#events-summary').length) {  
        $('#events-summary li:last').css('background-image','none');
    }
    if($('#downloads').length) {  
        $('#downloads li:last').css('background-image','none');
    }
    if($('#more-information-links').length) {  
        $('#more-information-links li:last').css('background-image','none');
    }
    
    /* Landing page customer type buttons hover */
    if($('.customer-quick-links').length) {
        $('.customer-quick-links img').hover(function() {
            $(this).stop().fadeTo('fast','0.5');
        }, function() {
            $(this).stop().fadeTo('fast','1');
        });
    };
    
    /* FAQ ACCORDION start */
    if($('.faq-accordion').length) {
        // hide FAQ item content
        $('.accordion-item-content').css('height','0');
        $('.faq-accordion h4 a').click(function() {
            if($(this).parent().parent().hasClass('active')) {
                $(this).parent().parent().removeClass('active');
                $(this).parent().next('div').css('height','0');
            } else {
                $(this).parent().parent().addClass('active');
                $(this).parent().next('div').css('height','auto');
            }
            return false;
        });
    }
    /* LIGHTBOX FOR GALLERY*/
    if($('.gallery-list').length) {
        $('a.fancy').fancybox({
            overlayShow: true,
            overlayOpacity: 0.8
        });
    }
    
    // Clear Search text on focus
    $('.search-field').focus(function () {
        if($(this).val() == "Search") {
            $(this).val("");
        }
    });
    // Place 'Search' text in search bar if empty
    $('.search-field').blur(function () { 
        if($(this).val() == "") {
            $(this).val("Search");
        } 
    });

        /* Pagination for news and event items */
        var max_items_per_page = 10;
        function pageselectCallback(page_index, jq){            
                //hide results once called by initPagination 
                $('#hiddenresult').hide();
                //show pagination containers
                $('#Searchresult').show();
                $('#Pagination').show();
                // Get number of elements per pagionation page from form            
                var num_entries = $('#hiddenresult div.summary-item').length;
                var items_per_page = max_items_per_page;
                var max_elem = Math.min((page_index+1) * items_per_page, num_entries);
                var newcontent = '';                                   
                $('#Searchresult').empty()
                // Iterate through a selection of the content and build an HTML string
                for(var i=page_index*items_per_page;i<max_elem;i++)
                {
                        $('#Searchresult').append($('#hiddenresult div.summary-item:eq('+i+')').clone());
                }    
                // Prevent click eventpropagation
                return false;
        }
      
        function initPagination() {
                var num_entries = $('#hiddenresult div.summary-item').length;
                // Create pagination element
                $("#Pagination").pagination(num_entries, {
                        items_per_page:max_items_per_page,
                        callback:pageselectCallback                    
                });
        }
                            
        $(document).ready(function(){      
                if ($('#hiddenresult div.summary-item').length > (max_items_per_page - 1)) {                    
                        initPagination();
                }
        });

});