// Filetype icons and external links
$(document).ready(function() {	

	// Add email icons to email links
	$("a[href^='mailto:']").addClass("email");

	//Add external link icon to external links - 
	$('a').filter(function() {
		//Compare the anchor tag's host name with location's host name
	    return this.hostname && this.hostname !== location.hostname;
	  }).addClass("external").attr("target", "_blank");	
	 
});

// Pull Quotes
$(document).ready(
   function()
   {
	$('span.pullquote').each(function() {
	text = $(this).text();
	text=text.replace( /\((.*)\)/gi, " " );
	if ($(this).is(".right")) 
		$(this).parent().before('<blockquote class="pullquote right"><p>&quot;'+ text +'&quot;</p></blockquote>');
			else
		$(this).parent().before('<blockquote class="pullquote"><p>&quot;'+ text +'&quot;</p></blockquote>');
	});                
   }
);


/* Image Caption */

//Get Element by Class Name from: http://www.robertnyman.com/2005/11/07/the-ultimate-getelementsbyclassname/

function getElementsByClassName(oElm, strTagName, strClassName){
    var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for(var i=0; i<arrElements.length; i++){
        oElement = arrElements[i];      
        if(oRegExp.test(oElement.className)){
            arrReturnElements.push(oElement);
        }   
    }
    return (arrReturnElements)
}


//Function for converting title tags on images into caption

function addCaption(xClass) {
	var allImages = getElementsByClassName(document, "img", xClass);
	for ( var i=0; i < allImages.length; i++) {
		var imageCaption = document.createTextNode(allImages[i].title);
		var imageContainer = document.createElement("div");
		var imagePara = document.createElement("p");
		var imageWidth = allImages[i].getAttribute("width");
		var spareSpan = document.createElement("span"); //This adds an extra span. Useful for curved corners
		imagePara.appendChild(imageCaption);
		allImages[i].parentNode.insertBefore(imageContainer, allImages[i]);
		imageContainer.appendChild(allImages[i]);
		if ( allImages[i].title != "" ) {
		imageContainer.appendChild(imagePara); 
		}
		imageContainer.appendChild(spareSpan);		
		imageContainer.className = xClass
		spareSpan.className = "spareSpan"
		allImages[i].className = "imgCaption"
		imageContainer.style.width = imageWidth + "px";
		
    }
}

// Runs all the listed functions on the loading of the window

window.onload=function(){
addCaption("imgLeft");
addCaption("imgRight");
}

/* FAQs */
$.fn.orphans = function(){
  var ret = [];
  this.each(function(){$.each(this.childNodes, function() {
    if (this.nodeType == 3 && $.trim(this.nodeValue)) ret.push(this)
    })}); 
   return $(ret);
}
//http://www.learningjquery.com/2008/02/simple-effects-plugins
jQuery.fn.blindToggle = function(speed, easing, callback) {
  var h = this.height() + parseInt(this.css('paddingTop')) + parseInt(this.css('paddingBottom'));
  return this.animate({marginTop: parseInt(this.css('marginTop')) < 0 ? 0 : -h}, speed, easing, callback); 
};
jQuery.fn.fadeToggle = function(speed, easing, callback) {
  return this.animate({opacity: 'toggle', height: 'toggle'}, speed, easing, callback);
};
$(document).ready(function() {
//s/jq/a
    $('.expand').css('cursor','pointer').orphans().wrap('<a href="#expand/collapse" title="expand/collapse"></a>');
    $('.collapse').hide(); 
    
    $('#show .expand').click(function() {
        $(this).toggleClass("arrow-up");
        $(this).next('.normal').toggle();
        $(this).next('.slow').toggle('slow');
    });
    
    $('#slide .expand').click(function() {
        $(this).toggleClass("arrow-up");
        $(this).next('.normal').slideToggle();
        $(this).next('.slow').slideToggle('slow');
    });
    
    $('#tabbed .expand').click(function() {
        $(this).toggleClass("arrow-up");
        $(this).next('.normal').fadeToggle();
        $(this).next('.slow').fadeToggle('slow');
    });
});

/* New Window */
$(function(){
$('a.external').click(function(){
window.open(this.href);
return false;
});
});



    $(document).ready(function(){ 
        $(document).pngFix(); 
    }); 




