// You may adapt elements of this JS in your own projects, but the unique combination of images, colors, sizes, typography, and positioning ("the design") is copyright 2008 Greg Robleto and may not be reproduced. This stylesheet is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 2.5 License. <http://creativecommons.org/licenses/by-nc-nd/2.5/>  

//============================================================================

// JQUERY CUSTOM LIBRARIES

//============================================================================

// - Anchor Links
// - Pull Quotes
// - Img Align
// - Img Caption
// - Footnotes
// - DropDown Menus
// -Rounded Corners

 
   // ANCHOR LINKS -- Create a UL of anchors from the H3 tags in the content  
    function anchorLinks() {
		$('<ul id="anchorlist"></ul>').insertAfter('div#sidebar');
		$('<h2 id="anchorlinks">On this Page</h2>').insertBefore('ul#anchorlist');
		$('h3:not(.noanchor)').each(function(index) {
			$(this).before('<a name="anchor-' + (index+1) + '" id="anchor-' + (index+1) + '" class="anchor nofollow"></a>');
			$('ul#anchorlist').append('<li><a href="#anchor-' + (index+1) + '" class="nofollow">' + $(this).text() + '</a></li>');
			
			});
	}   
	
	// PULL QUOTES -- Create a pull quote DIV from selected SPAN text
	function pullQuotes() {
		$('span.pull-quote').each(function(index) {
			var $parentPara = $(this).parent('p');
			$parentPara.css('position','relative');
			var $clonedCopy = $(this).clone();
			$clonedCopy
				.removeClass('pull-quote')
				.addClass('pulled')
				.find('span.drop')
					.html('&hellip;')
				.end()
				.prependTo($parentPara)
				.wrap('<div class="pulled-wrapper"></div>');
			var $clonedText = $clonedCopy.text();
			$clonedCopy.html($clonedText);	
		});		
	}
	
   	
	// IMG ALIGN -- Overwrites the image alignment with a CSS-based alignment
	function imgAlign() {
		$('img').each(function(index) {
			if ($(this).hasClass("alignright")) { var $alignment = "alignright" };
			if ($(this).hasClass("alignleft")) { var $alignment = "alignleft" };
			if ($(this).hasClass("aligncenter")) { var $alignment = "aligncenter" };
			var $width = $(this).attr("width");
			$(this)
				.wrap('<div class="img-wrapper"></div>')
				.removeAttr("align")
				.addClass("img")
				.removeClass($alignment)
				.parent().addClass($alignment)
			$('.img-wrapper').css("width", $width);
		});
		$('div.img-wrapper').each(function(index) {
			$(this)
				.removeClass('img')
				.removeClass('size-medium')
		});
	}
	
	// IMG CAPTION -- Create a caption from an IMG title
	function imgCaption() {
		$('#content_main img[@title]:not(.nocaption)').each(function(index) {
			$(this).after('<caption id="caption-' + (index+1) + '" class="caption">' +  $(this).attr("title") + '</caption>')				
		}); 
	}
	
	
   // FOOTNOTES -- Create a UL of footnotes from the A:href tags in the content  
   function footnotes(){ 
	$('<ul id="footnotelist"></ul>').insertAfter('div#site-info');
		$('<h3 id="footnotelinks">Links on this Page</h2>').insertBefore('ul#footnotelist');
		$('a:not(.nofollow)').each(function(index) {
			$(this).before('<a name="footnote-' + (index+1) + '" id="footnote-' + (index+1) + '" class="footnote"></a>');
			$('ul#footnotelist').append('<li><a href="#footnote-' + (index+1) + '"><strong>' + $(this).text() + '</strong> -- ' + $(this).attr("href") + '</a></li>');
			});
	}

	            
   // DROPDOWNENU -- Create a drop dowm menu using the main #nav  
   function dropDownMenu(){
	$(" #nav ul ").css({display: "none"}); // Opera Fix
	$(" #nav li").hover(function(){
			$(this).find('ul:first').css({visibility: "visible",display: "none"}).slideDown(400);
			},function(){
			$(this).find('ul:first').css({visibility: "hidden"});
			});
	}
	
   // ROUNDED CORNERS -- Use four SPANs to create rounded corners on a DIV
   function roundedCorners(){
   		$('div.rounded').each(function(index) {
			$('<span class="corner ne"></span><span class="corner nw"></span>').prependTo($(this));
			$('<span class="corner se"></span><span class="corner sw"></span>').appendTo($(this));
		}); 
	}
	
   // PURGE FACEBOOK CSS -- Get rid of the forced upon Facebook Connect CSS
   function purgeFB_ConnectCSS(){
   		$('head link').each(function(index) {
   			$(this).remove()
		});
	}
	
	
	
	
	 $(document).ready(function(){
		//anchorLinks();
		//footnotes();
		//imgAlign();
		//imgCaption();
		//purgeFB_ConnectCSS()
		});

 