/*
 * jQuery Expander plugin
 * Version 0.4  (12/09/2008)
 * @requires jQuery v1.1.1+
 *
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */


(function($) {

  $.fn.expander = function(options) {

    var opts = $.extend({}, $.fn.expander.defaults, options);
    var delayedCollapse;
    return this.each(function() {
      var $this = $(this);
      var o = $.meta ? $.extend({}, opts, $this.data()) : opts;
     	var cleanedTag, startTags, endTags;	
     	var allText = $this.html();
     	var startText = allText.slice(0, o.slicePoint).replace(/\w+$/,'');
     	startTags = startText.match(/<\w[^>]*>/g);
   	  if (startTags) {startText = allText.slice(0,o.slicePoint + startTags.join('').length).replace(/\w+$/,'');}
   	  
     	if (startText.lastIndexOf('<') > startText.lastIndexOf('>') ) {
     	  startText = startText.slice(0,startText.lastIndexOf('<'));
     	}
     	var endText = allText.slice(startText.length);    	  
     	// create necessary expand/collapse elements if they don't already exist
   	  if (!$('span.details', this).length) {
        // end script if text length isn't long enough.
       	if ( endText.replace(/\s+$/,'').split(' ').length < o.widow ) { return; }
       	// otherwise, continue...    
       	if (endText.indexOf('</') > -1) {
         	endTags = endText.match(/<(\/)?[^>]*>/g);
          for (var i=0; i < endTags.length; i++) {

            if (endTags[i].indexOf('</') > -1) {
              var startTag, startTagExists = false;
              for (var j=0; j < i; j++) {
                startTag = endTags[j].slice(0, endTags[j].indexOf(' ')).replace(/(\w)$/,'$1>');
                if (startTag == rSlash(endTags[i])) {
                  startTagExists = true;
                }
              }              
              if (!startTagExists) {
                startText = startText + endTags[i];
                var matched = false;
                for (var s=startTags.length - 1; s >= 0; s--) {
                  if (startTags[s].slice(0, startTags[s].indexOf(' ')).replace(/(\w)$/,'$1>') == rSlash(endTags[i]) 
                  && matched == false) {
                    cleanedTag = cleanedTag ? startTags[s] + cleanedTag : startTags[s];
                    matched = true;
                  }
                };
              }
            }
          }

          endText = cleanedTag && cleanedTag + endText || endText;
        }
     	  $this.html([
     		startText,
     		'<span class="read-more">',
     		o.expandPrefix,
       		'<a href="#">',
       		  o.expandText,
       		'</a>',
        '</span>',
     		'<span class="details">',
     		  endText,
     		'</span>'
     		].join('')
     	  );
      }
      var $thisDetails = $('span.details', this),
        $readMore = $('span.read-more', this);
   	  $thisDetails.hide();
 	    $readMore.find('a').click(function() {
 	      $readMore.hide();

 	      if (o.expandEffect === 'show' && !o.expandSpeed) {
          o.beforeExpand($this);
 	        $thisDetails.show();
          o.afterExpand($this);
          delayCollapse(o, $thisDetails);
 	      } else {
          o.beforeExpand($this);
 	        $thisDetails[o.expandEffect](o.expandSpeed, function() {
            $thisDetails.css({zoom: ''});
            o.afterExpand($this);
            delayCollapse(o, $thisDetails);
 	        });
 	      }
        return false;
 	    });
      if (o.userCollapse) {
        $this
        .find('span.details').append('<span class="re-collapse">' + o.userCollapsePrefix + '<a href="#">' + o.userCollapseText + '</a></span>');
        $this.find('span.re-collapse a').click(function() {

          clearTimeout(delayedCollapse);
          var $detailsCollapsed = $(this).parents('span.details');
          reCollapse($detailsCollapsed);
          o.onCollapse($this, true);
          return false;
        });
      }
    });
    function reCollapse(el) {
       el.hide()
        .prev('span.read-more').show();
    }
    function delayCollapse(option, $collapseEl) {
      if (option.collapseTimer) {
        delayedCollapse = setTimeout(function() {  
          reCollapse($collapseEl);
          option.onCollapse($collapseEl.parent(), false);
          },
          option.collapseTimer
        );
      }
    }
    function rSlash(rString) {
      return rString.replace(/\//,'');
    }    
  };
    // plugin defaults
  $.fn.expander.defaults = {
    slicePoint:       100,  // the number of characters at which the contents will be sliced into two parts. 
                            // Note: any tag names in the HTML that appear inside the sliced element before 
                            // the slicePoint will be counted along with the text characters.
    widow:            4,  // a threshold of sorts for whether to initially hide/collapse part of the element's contents. 
                          // If after slicing the contents in two there are fewer words in the second part than 
                          // the value set by widow, we won't bother hiding/collapsing anything.
    expandText:       'read more', // text displayed in a link instead of the hidden part of the element. 
                                      // clicking this will expand/show the hidden/collapsed text
    expandPrefix:     '&hellip; ',
    collapseTimer:    0, // number of milliseconds after text has been expanded at which to collapse the text again
    expandEffect:     'fadeIn',
    expandSpeed:      '',   // speed in milliseconds of the animation effect for expanding the text
    userCollapse:     true, // allow the user to re-collapse the expanded text.
    userCollapseText: '[collapse expanded text]',  // text to use for the link to re-collapse the text
    userCollapsePrefix: ' ',
    beforeExpand: function($thisEl) {},
    afterExpand: function($thisEl) {},
    onCollapse: function($thisEl, byUser) {}
  };
})(jQuery);
;
/*
 * Basic jQuery Slider plug-in v.1.1
 * 
 * http://www.basic-slider.com
 *
 * Authored by John Cobb
 * Visit my blog at http://www.johncobb.name
 * Or say helo on twitter: @john0514
 *
 * Copyright 2011, John Cobb
 * Free for all to use, abuse and improve under the MIT license.
 * http://www.opensource.org/licenses/mit-license.php
 * 
 * August 2011
 */

(function($){
	$.fn.bjqs = function(options) {
		
	var settings = {};	
		
	var defaults = {
		width: 700,					// Width + Height used to ensure consistency
		height: 300,				// Width + Height used to ensure consistency
		animation: 'fade',			// The type of animation (slide or fade)
		animationDuration: 450, 	// The duration in ms of the transition between slides
		automatic: true,			// Automatically rotate through the slides
		rotationSpeed: 4000,		// Delay in ms between auto rotation of the slides
		hoverPause: true,			// Pause the slider when any elements receive a hover event
		showControls: true,			// Show the manual slider controls
		centerControls: true,		// Center the controls vertically
		nextText: 'Next',			// Text to display in 'next' controller
		prevText: 'Prev',			// Text to display in 'previous' controller
		showMarkers: true,			// Show positional markers
		centerMarkers: true,		// Center the positional indicators
		keyboardNav: true,			// Allow navigation with arrow keys
		useCaptions: true			// Use image title text as caption
	}
	
	// Overwrite the defaults with the provided options (if any)
	settings = $.extend({}, defaults, options);
	
	// Variables
	var	$container = this;
		$slider = $('ul.bjqs'),
		slides = $slider.children('li'),
		slideCount = slides.length,
		animating = false,
		paused = false,
		current = 0,
		slidePosition = 1,
		next = 0,
		$active = slides.eq(current),
		forward = 'forward',
		back = 'backward'
	
	// Make everything consistent in size
	// TODO: move away from px and make slider responsive
	slides.css({'height':settings.height,'width':settings.width});
	$slider.css({'height':settings.height,'width':settings.width});
	$container.css({'height':settings.height,'width':settings.width});

	// Add unique class to slide list elements to differentiate from slide content list elements
	slides.addClass('bjqs-slide');
	
	// Phat Controller(s)
	if(settings.showControls && slideCount > 1){
		
		// Create the elements for the controls
		$controlContainer = $('<ul class="bjqs-controls"></ul>');
		$next = $('<li><a href="#" class="bjqs-next" class="controls">'+settings.nextText+'</a></li>');
		$previous = $('<li><a href="#" class="bjqs-prev" class="controls">'+settings.prevText+'</a></li>');
		
		// Bind click events to the controllers
		$next.click(function(e){
			e.preventDefault();
			if(!animating)
				bjqsGo(forward,false);
		});
		
		$previous.click(function(e){
			e.preventDefault();
			if(!animating)
				bjqsGo(back, false);
		});
		
		// Put 'em all together and what do you get? Ding dong. Hotdog
		$next.appendTo($controlContainer);
		$previous.appendTo($controlContainer);
		$controlContainer.appendTo($container);
		
		// Vertically center the controllers
		if(settings.centerControls){
			$control = $next.children('a');
			offset = ($container.height() -$control.height()) / 2;
			$next.children('a').css('top', offset).show();
			$previous.children('a').css('top', offset).show();
		}
		
	}
	
	// Let's put in some markers
	if(settings.showMarkers && slideCount > 1){
		
		$markerContainer = $('<ol class="bjqs-markers"></ul>');
		
		//Create a marker for each banner and add append it to the wrapper
		$.each(slides,function(key,value){
			if(settings.animType == 'slide'){
				if(key != 0 && key != slideCount-1)
					$marker = $('<li><a href="#">'+key+'</a></li>');
			}
			else{
				key++
				$marker = $('<li><a href="#">'+key+'</a></li>');
			}
			
			$marker.click(function(e){
				e.preventDefault();
				if(!$(this).hasClass('active-marker') && !animating)
					bjqsGo(false,key);
			});
			
			$marker.appendTo($markerContainer);
			
		});
		
		markers = $markerContainer.children('li');
		markers.eq(current).addClass('active-marker');
		$markerContainer.appendTo($container);
		
		if(settings.centerMarkers){
			offset = (settings.width - $markerContainer.width() )/ 2;
			$markerContainer.css('left', offset);
		}
		
	}
	
	// Enable keyboard navigation
	if(settings.keyboardNav && slideCount > 1){
		
		$(document).keyup(function(event) {
			
			if(!paused){
				clearInterval(bjqsInterval);
				paused=true;
			}
			
			if (!animating) {
				if(event.keyCode == 39){
					event.preventDefault();
					bjqsGo(forward, false);
				}
				else if(event.keyCode == 37){
					event.preventDefault();
					bjqsGo(back,false);
				}
			}
			
			if(paused & settings.automatic){
				bjqsInterval = setInterval(function(){ bjqsGo(forward) }, settings.rotationSpeed);
				paused=false;
			}
			
		});
	}
	
	// Show captions
	if(settings.useCaptions){
		
		$.each(slides, function(key, value){
			
			var $slide = $(value);
			var $slideChild = $slide.children('img:first-child');
			var title = $slideChild.attr('title');
			
			if(title){
				var $caption = $('<p class="bjqs-caption">'+title+'</p>');
				$caption.appendTo($slide);
			}

		});
		
	}
	
	// Run a bubble-bath and float in that m'fkr like a hovercraft. (enable hover pause)
	if(settings.hoverPause && settings.automatic){
			
		$container.hover(function(){
			if(!paused){
				clearInterval(bjqsInterval);
				paused=true;
			}
		},function(){
			if(paused){
				bjqsInterval = setInterval(function(){ bjqsGo(forward) }, settings.rotationSpeed);
				paused=false;
			}
		});
		
	}
	
	
	// We have to make a few tweaks if we're sliding instead of fading
	if(settings.animation == 'slide' && slideCount > 1){
		
		$first = slides.eq(0);
		$last = slides.eq(slideCount-1);
		
		$first.clone().addClass('clone').removeClass('slide').appendTo($slider);
		$last.clone().addClass('clone').removeClass('slide').prependTo($slider);
		
		slides = $slider.children('li');
		slideCount = slides.length;
		
		$wrapper = $('<div class="bjqs-wrapper"></div>').css({
			'width' : settings.width,
			'height' : settings.height,
			'overflow' : 'hidden',
			'position' : 'relative'
		});
		
		$slider.css({
			'width' : settings.width*slideCount,
			'left' : -settings.width
		});
		
		slides.css({
			'float': 'left',
			'position': 'relative',
			'display' : 'list-item'
		});
		
		$wrapper.prependTo($container);
		$slider.appendTo($wrapper);
		
	}
	
	// Check position to see if we're at the first or last slide and update 'next' accordingly
	var checkPosition = function(direction){
		
		if(settings.animation == 'fade'){
			
			if(direction == forward){
				!$active.next().length ? next = 0 : next++
			}
			else if(direction == back){
				!$active.prev().length ? next = slideCount-1 : next--
			}
			
		}
		
		if(settings.animation == 'slide'){
			
			if(direction == forward){
				next = slidePosition + 1;
			}
			
			if(direction == back){
				next = slidePosition - 1;
			}
		}
		
		return next;
	}
	
	// Kick off the rotation if we're on auto pilot, but only if we have more than 1 slide (thanks Efrain!)
	if(settings.automatic && slideCount > 1){
		var bjqsInterval = setInterval(function(){ bjqsGo(forward,false) }, settings.rotationSpeed);
	}
	
	// Show the first slide	
	slides.eq(current).show();
	$slider.show();
	
	// What comes next? Hey, Bust a move!
	var bjqsGo =  function(direction,position){
		
		if(!animating){
			
			if(direction){
				next = checkPosition(direction);
			}
			else if(position && settings.animation == 'fade'){
				next = position-1;
			}else{
				next = position;
			}
			
			animating = true;
			
			if(settings.animation == 'fade'){
				
				if(settings.showMarkers){
					markers.eq(current).removeClass('active-marker');
					markers.eq(next).addClass('active-marker');
				}
				
				$next = slides.eq(next);
				
				$active.fadeOut(settings.animationDuration);
				$next.fadeIn(settings.animationDuration, function() {
					$active.hide();
					current = next;
					$active = $next;
					animating = false;
				});
			}
			else if(settings.animation == 'slide'){
				
				if(settings.showMarkers){
					
					markers.eq(slidePosition-1).removeClass('active-marker');
					
					if(next==slideCount-1){
						markers.eq(0).addClass('active-marker');
					}else if(next==0){
						markers.eq(slideCount-3).addClass('active-marker');
					}else{
						markers.eq(next-1).addClass('active-marker');
					}
					
				}
				
				$slider.animate({'left': -next*settings.width}, settings.animationDuration, function(){
					
					if(next==0){
						slidePosition=slideCount-2;
						$slider.css({'left' : -slidePosition*settings.width});
					}else if(next==slideCount-1){
						slidePosition=1;
						$slider.css({'left' : -settings.width});
					}else{
						slidePosition=next;
					}
					
					animating=false;
					
				});
				
			}
			
		}
		
	}
		
	return this; // KTHXBYE
	
	}
})(jQuery);;
jQuery(document).ready(function(){  // do not alter this line
  (function($) { // $ function fix do not alter this line

    // remove comment icon from lists if comments are disabled for node.
		$('span.Closed').hide();
		
		// add the 'first' class to the top h2 on the issues page
		$('.view-id-issues h2:first').addClass('first');
		
		/**
		 * jQuery Slider in right rail
		 */
		// wrap blocks to include in slider
		$('#block-block-36').wrapAll('<li id="slide-first">/');
		$('#block-block-24').wrapAll('<li id="slide-second">/');
		$('#slide-first, #slide-second').wrapAll('<div id="sidebar-slide"><ul class="bjqs">/');
			
		// initiate slider
		$('#sidebar-slide').bjqs({
			'rotationSpeed' : 6000,
      'width' : 300,
      'height' : 250,
		  'animationDuration': 250,
				
      'showMarkers' : true,
      'showControls' : true,
      'centerMarkers' : false
		});
		
		/**
     * add classes
		 */
	  $(".block-pbs-drilldown ul.menu li:last").addClass('last');
		
		/**
		 * equip zone block expander
		 */
		$('div.expander').expander({
      slicePoint:       100,  // default is 100
			expandPrefix:     '',			
      expandText:         '<span class="expand-toggle">+ more</span>', // default is 'read more...'
      collapseTimer:    0, // re-collapses after x seconds; default is 0, so no re-collapsing
      userCollapseText:   '<span class="expand-toggle">- less</span>'  // default is '[collapse expanded text]'
    });
					
		/**
     * moving the ads from the bottom to their respective locations
		 *
		 * looking for the ad code?  look in the bottom ad blocks, this is where they load and hide before moving.
		 * ads need to load at the bottom of the page so that they can grab elements in the DOM... 
		 * loading at top is before said element is loaded
		 */
		$('#leaderboard-1 a').appendTo('#leaderboard-top');
		$('#medallion-1 a').appendTo('#medallion-top');
		$('#boombox-1 a').appendTo('#boombox-top');
		$('#boombox-2 a').appendTo('#boombox-bottom');
		$('#leaderboard-2 a').appendTo('#leaderboard-bottom');
		$('#medallion-2 a').appendTo('#medallion-bottom');
    
		
	})(jQuery); // end of $ function fix - do not alter
}); // end of document ready - do not alter;

