/* jQuery.ScrollTo: 		*/	;(function($){var m=$.scrollTo=function(b,h,f){$(window).scrollTo(b,h,f)};m.defaults={axis:'xy',duration:parseFloat($.fn.jquery)>=1.3?0:1};m.window=function(b){return $(window).scrollable()};$.fn.scrollable=function(){return this.map(function(){var b=this,h=!b.nodeName||$.inArray(b.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!h)return b;var f=(b.contentWindow||b).document||b.ownerDocument||b;return $.browser.safari||f.compatMode=='BackCompat'?f.body:f.documentElement})};$.fn.scrollTo=function(l,j,a){if(typeof j=='object'){a=j;j=0}if(typeof a=='function')a={onAfter:a};if(l=='max')l=9e9;a=$.extend({},m.defaults,a);j=j||a.speed||a.duration;a.queue=a.queue&&a.axis.length>1;if(a.queue)j/=2;a.offset=n(a.offset);a.over=n(a.over);return this.scrollable().each(function(){var k=this,o=$(k),d=l,p,g={},q=o.is('html,body');switch(typeof d){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px)?$/.test(d)){d=n(d);break}d=$(d,this);case'object':if(d.is||d.style)p=(d=$(d)).offset()}$.each(a.axis.split(''),function(b,h){var f=h=='x'?'Left':'Top',i=f.toLowerCase(),c='scroll'+f,r=k[c],s=h=='x'?'Width':'Height';if(p){g[c]=p[i]+(q?0:r-o.offset()[i]);if(a.margin){g[c]-=parseInt(d.css('margin'+f))||0;g[c]-=parseInt(d.css('border'+f+'Width'))||0}g[c]+=a.offset[i]||0;if(a.over[i])g[c]+=d[s.toLowerCase()]()*a.over[i]}else g[c]=d[i];if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],u(s));if(!b&&a.queue){if(r!=g[c])t(a.onAfterFirst);delete g[c]}});t(a.onAfter);function t(b){o.animate(g,j,a.easing,b&&function(){b.call(this,l,a)})};function u(b){var h='scroll'+b;if(!q)return k[h];var f='client'+b,i=k.ownerDocument.documentElement,c=k.ownerDocument.body;return Math.max(i[h],c[h])-Math.min(i[f],c[f])}}).end()};function n(b){return typeof b=='object'?b:{top:b,left:b}}})(jQuery);
/* jQuery.easing.outtake: 	*/	jQuery.extend( jQuery.easing,{	easeOutQuad: function (x, t, b, c, d) {		return -c *(t/=d)*(t-2) + b;	},	easeOutBack: function (x, t, b, c, d, s) {		if (s == undefined) s = 1.70158;		return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;	}	});

$(document).ready(function(){

	jQuery('p').linkify();
	foldTOCItems();
	scrollToTOCItems();

});

function foldTOCItems() {
	$('ul.toc li ul li ul').slideUp(0);
	$('ul.toc > li > ul > li').each(function(){
	
		$(this).find('a').prepend('<small class="collapser">[+]</small> ');
		$(this).parent().find('li ul li a small.collapser').remove();
		
		$(this).find('a').click(function(){

			$(this).parent().find('ul').toggle(250,'easeOutBack');

			if ($(this).parent().find('small.collapser').html() == '[+]') {
				$(this).parent().find('small.collapser').html('[–]');
			}
			else {
				$(this).parent().find('small.collapser').html('[+]');			
			}
			
		});
	});
	$('ul.toc')
		.before('<h3 style="color:black;margin:0;padding:.5em 0 0 0">Table Of Contents</h3>')
		.before('<a class="TOCToggleButtons" id="expandAll" href="#">[+] Expand All</a>')
		.before('<a class="TOCToggleButtons" id="collapseAll" href="#">[–] Collapse All</a>');

	$('.TOCToggleButtons').css(
		{
			display:	'block',
			float:		'left',
			fontSize:	'.75em',
			marginTop:	'1em'
		}
	);
	$('.TOCToggleButtons:eq(1)').after('<div class="clearfloat" />');
	$('.TOCToggleButtons#expandAll').click(
		function(){
			$('ul.toc li ul li ul').slideDown(250,'easeOutQuad');
		}
	);
	$('.TOCToggleButtons#collapseAll').click(
		function(){
			$('ul.toc li ul li ul').slideUp(250,'easeOutQuad');
		}
	);
	
}

function scrollToTOCItems() {
	$('.toc a').click(function(){
		$.scrollTo( this.hash, 250, { easing:'easeOutQuad' });
		$(this.hash).find('span.message').text( this.title );
		return false;
	});	
}

(function($){
  var url1 = /(^|&lt;|\s)(www\..+?\..+?)(\s|&gt;|$)/g,
      url2 = /(^|&lt;|\s)(((https?|ftp):\/\/|mailto:).+?)(\s|&gt;|$)/g,

      linkifyThis = function () {
        var childNodes = this.childNodes,
            i = childNodes.length;
        while(i--)
        {
          var n = childNodes[i];
          if (n.nodeType == 3) {
            var html = $.trim(n.nodeValue);
            if (html)
            {
              html = html.replace(/&/g, '&amp;')
                         .replace(/</g, '&lt;')
                         .replace(/>/g, '&gt;')
                         .replace(url1, '$1<a class="autolinker" href="http://$2">$2</a>$3')
                         .replace(url2, '$1<a class="autolinker" href="$2">$2</a>$5');
              $(n).after(html).remove();
            }
          }
          else if (n.nodeType == 1  &&  !/^(a|button|textarea)$/i.test(n.tagName)) {
            linkifyThis.call(n);
          }
        }
      };

  $.fn.linkify = function () {
    return this.each(linkifyThis);
  };
})(jQuery);