
  var show_me_more_current_page = 1;
  var show_me_more_lock = '';

  // show me more function
  function show_me_more(section, move, total_pages) {
    if (show_me_more_lock != '' && show_me_more_lock == move) {
      return false;
    }
    
    // lock the function
    show_me_more_lock = move;
    
    // determine next page
    if (move == 'prev') {
      var move_to = parseInt(show_me_more_current_page) - 1;
    }
    else {
      var move_to = parseInt(show_me_more_current_page) + 1;
    }
    
    if (move == 'next' && show_me_more_current_page == total_pages) {
      move_to = 1;
    }
    
    if (move == 'prev' && show_me_more_current_page == 1) {
      move_to = total_pages;
    }

    // build query string
    var base_url = $('#base_url').val();
    var query_string = base_url + '/show-more-ajax/' + section + '/' + move_to;

    // request page
    $.getJSON(query_string,
        function(data){
          $('#show_more_' + section).html(data.html);
          
          show_me_more_current_page = move_to;
          show_me_more_lock = '';
        }
    );
    
  }

  // reviews filter javascript - updates the running counter of how many content items availble, based on selection.
  function refresh_filter_count() {
    var base_url = $('#base_url').val();
    var query_string = base_url + '/list-reviews-ajax?filter0=' + $('#reviews-filter-form #edit-filter0').val() + '&filter1=' + $('#reviews-filter-form #edit-filter1').val() + '&filter2=' + $('#reviews-filter-form #edit-filter2').val() + '&filter3=' + $('#reviews-filter-form #edit-filter3').val();
    
    $.getJSON(query_string,
        function(data){
          $('#find_via_filters_num_results').text(data.count);
        }
    );
  }
  
  
  // show hide for large amount of category terms
  function categories_show_hide (target) {    
    $('#' + target).hide();
    $('#' + target).addClass('more-terms-is-hidden');
    $('#' + target).after('<ul><li><strong><span id="' + target + '-show-hide">Show more...</span></strong></li></ul>');
    
    $('#' + target + '-show-hide').css('cursor', 'pointer').click(function() {
      if ($(this).text() == 'Show more...') {
        // show
        $('#' + target).slideDown();
        $(this).text('Show less...');
      }
      else {
        // hide
        $('#' + target).slideUp();
        $(this).text('Show more...');
      }
    });
  }

  // jQuery DOM Load
  $().ready(function() {
    
    // results per page drop down
    if ($('select#edit-view-results-per-page').length > 0 || $('select#edit-results-per-page').length > 0) { 
      
      /**
       * The following code is for the results per page tags drop down
       */
      $('select#edit-results-per-page').change(function() {
      var currentURL = String(window.location).replace(/results_per_page=\d*/g, '');
      currentURL = currentURL+'&results_per_page='+$(this).val();
      currentURL = String(currentURL).replace(/\&{2,}/g, '&');
        window.location = currentURL;     
      });
  
      $('select#edit-view-results-per-page').change(function() {
        var currentURL = String(window.location).replace(/results=\d*/g, '');
        var query_prepend = '';
        if (currentURL.indexOf('?') == -1) {
          query_prepend = '?'; 
        }
        else {
          var current_length = currentURL.length - 1;
          if (currentURL.charAt(current_length) != '?' && currentURL.charAt(current_length) != '&') {
            query_prepend = '&';
          }
        }
        currentURL = currentURL + query_prepend + 'results=' + $(this).val();
        currentURL = String(currentURL).replace(/\&{2,}/g, '&');
        window.location = currentURL;     
      });
    
    }
    // end results per page drop down
    
    
    // Reviews article page, add carousel to the image thumbnails
    if ($('#reviews-caro').length > 0) {
      $('#reviews-caro').tabs({fx: {opacity: 'toggle'}});
      
      $('#reviews-caro .listing-mini li').each(function(i) {
        $(this).bind ("mouseenter", function() {
          $('#reviews-caro').tabs('select',i);
        });
      });
    }

    // Reviews article page, technical spec details slide down area    
    if ($('#tech-spec-link').length > 0) {
      $('#tech-spec-link').click(function() {
        $("div#tech-spec").slideToggle('slow'); // show/hide the extra info
      });
    }

     // Same as reviews carousel, but used in buying guides, techniques and news indepth
     // inline at bottom of first page body content. 
     if ($('.inline-caro').length > 0) {
      $('.inline-caro').tabs({fx: {opacity: 'toggle'}});
      $('.inline-caro .listing-mini li').each(function(i) {
      $(this).bind ("mouseenter", function() {
        $('.inline-caro').tabs('select',i);
        });
      });
    } 
    
    // show hidden quicktabs
    $('.quicktabs div').show(); 
    
    // unhide any carousel elements
    if ($('#reviews-caro').length > 0 || $('.inline-caro').length > 0) {
      $('#caro1 img, #caro2 img, #caro3 img').show(); // show hidden carousel items
    }
    
    
    // Homepage 'Whats new' landing block carousel
    if ($('#whats-new-landing-block').length > 0) {
      
      function whats_new_prep_and_slide(idx) {
        prev_index = idx - 1;
        if (prev_index < 0) {
          prev_index = 4;
        }
        $('#whats-new-landing-block .left ul li:eq(' + prev_index + ') .info').css('bottom', '-60px');
        $('#whats-new-landing-block .left ul li:eq(' + idx + ') .info').animate({opacity: 1.0}, 2000).animate({bottom: 0});
      }
      
      // redefine Cycle's updateActivePagerLink function 
      $.fn.cycle.updateActivePagerLink = function(pager, currSlideIndex) {
        prev_index = currSlideIndex - 1;
        if (prev_index < 0) {
          prev_index = 4;
        }
        $('#whats-new-landing-block .left ul li:eq('+prev_index+') .info').css('bottom', '-60px');
        $(pager).find('li').removeClass('active_slide').filter('li:eq('+currSlideIndex+')').addClass('active_slide');
        $('#whats-new-landing-block .left ul li:eq('+currSlideIndex+') .info').animate({opacity: 1.0}, 2000).animate({bottom: 0}); // wait 2 seconds.
      };
      
      wn_total_items = $('#whats-new-landing-block .right ul li').length - 1;
      
      $('#whats-new-landing-block .left ul').cycle({ 
        fx: 'fade',
        speed: 300,
        timeout: 6000,
        pause: 1,
        pager: '#whats-new-landing-block .right ul',
        pagerAnchorBuilder: function (idx, slide) {
          var li_html = $('#whats-new-landing-block .right ul li:eq(' + idx + ')').html(); // get current li's contents
          
          if (idx == wn_total_items) { // remove the old li's
            $('#whats-new-landing-block .right ul li:lt(' + (wn_total_items + 1) + ')').remove();
          }
          
          $('#whats-new-tab-' + idx).mouseover(function() {whats_new_prep_and_slide(idx);});
          
          return '<li id="whats-new-tab-' + idx + '">' + li_html + '</li>';
        },
        pagerEvent: 'mouseover',
        pauseOnPagerHover: true
      });
      
      $('#whats-new-landing-block .left ul li .content').removeClass('hidden'); // remove the hide class as cycle will have kicked in
    }
    
    // unhide the other tabs on explore user photos
    if ($('#block-quicktabs-4').length > 0) {
      $('#block-quicktabs-4 .block-views').show(); // show hidden carousel items
    }
    
    
    // reviews filter
    if ($('#reviews-filter-form').length > 0) {
      refresh_filter_count();
      $('#reviews-filter-form #edit-filter0').change(refresh_filter_count);
      $('#reviews-filter-form #edit-filter1').change(refresh_filter_count);
      $('#reviews-filter-form #edit-filter2').change(refresh_filter_count);
      $('#reviews-filter-form #edit-filter3').change(refresh_filter_count);
      
      $('#find_via_filters_num_results').css('cursor', 'pointer');
      $('#find_via_filters_num_results').click(function(){
        $('#reviews-filter-form').submit();
      });
    }
    
    // search box
    $('#search-block #edit-keys').focus(function(){
      if ($(this).val() == 'Search for...') {
        $(this).val('');
      }
    }).blur(function(){
      if ($(this).val() == '') {
        $(this).val('Search for...');
      }
    });
    
    // upload form
    $('#edit-taxonomy-albums-create-wrapper #edit-taxonomy-albums-create').focus(function(){
      if ($(this).val() == 'Type album name here...') {
        $(this).val('');
      }
    }).blur(function(){
      if ($(this).val() == '') {
        $(this).val('Type album name here...');
      }
    });    

  });
