// PLEASE NOTE. JAVASCRIPT APPENDED TO THIS FILE DOES NOT RUN. PLACE AT START.

// Enable development mode for the disqus plugin on all non-production sites.
if (document.domain != 'adnams.co.uk') {
    var disqus_developer = 1; // developer mode is on
}

      //installed this because somethign was conflicting with the jquery '$' symbole
      jQuery.noConflict();

      jQuery(document).ready(function() {

        //create slideshow instance
        jQuery('#banner-slideshow').cycle({
          fx:     'fade',
          speed: 1000,
          timeout: 7000,
          cssFirst: null,
          pagerAnchorBuilder: function(idx, slide) {return '';} //wipe out default pager code
        });

        //clear form fields on focus
        jQuery.fn.clearFields = function() {
          return this.focus(function() {
        		if( this.value == this.defaultValue ) {
        			this.value = "";
        		}
        	}).blur(function() {
        		if( !this.value.length ) {
        			this.value = this.defaultValue;
        		}
        	});
        };
        jQuery("input[type=text]").clearFields();
        jQuery(".wpcf7-form textarea").clearFields();


        //compress the sidebar archives list
        jQuery.fn.hideextra = function (options) {

            var defaults = {
                extraElement: 'li',
                extraClass: 'extra',
                buttonClass: 'showMore',
                maxItems: 5,
                moreText: "previous...",
                lessText: "show less..."
            };

            var options = jQuery.extend(defaults, options);

            this.each(function (listIndex, listInstance) {

                var listItems = jQuery(listInstance).children(options.extraElement);

                for (i = 0; i < listItems.length; i++) {

                    if (i > (options.maxItems)) {
                        jQuery(listItems[i]).hide();
                        jQuery(listItems[i]).addClass(options.extraClass);
                    }
                }

                var hiddenLis = jQuery(options.extraElement + '.' + options.extraClass, jQuery(listInstance));

                // Add More/Less Link
                if (listItems.length > options.maxItems) {
                    jQuery(listInstance).append('<li><a href="#_" class="' + options.buttonClass + '">' + hiddenLis.length + ' ' + options.moreText + '</a></li>');
                }

                // Add the click events
                var moreLink = jQuery('.' + options.buttonClass, jQuery(listInstance));

                moreLink.click(function () {

                    if (moreLink.text().indexOf(options.moreText) > 0) {
                        hiddenLis.show();
                       moreLink.text(options.lessText);
                    }
                    else {
                        hiddenLis.hide();
                        moreLink.text(hiddenLis.length + ' ' + options.moreText);
                    }
                });

            });

        };
        jQuery("#archives-3 ul").hideextra();

		//Selector to check whether item has a child UL - if so we can change its background position.
		jQuery("ul#subnav li ul li.current_page_item:has(ul)").addClass("hasChild");


      });
