/*
 * Add Link Titles and Icons
 *
 * This function will loop through all the elements in a page and add
 * a title attribute to all anchor tags.  For anchor tags with a className
 * of "external" the title will be "New Window:" followed by the link text.
 * For all anchor tags just the link text will be used for the title.  
 *
 * To override this functionality, just specify a title in the anchor tag.  
 * Anchors with defined titles will be ignored.
 * 
 * The function will also add icons for three classes of links:
 * internal, pdf, and doc.  Icons are added by writing the image tags
 * when the page loads. 
 * 
 * 
 */
addTitlesIcons = function(sContextPath) {
	var allLinks = document.getElementsByTagName("a");
	for (i=0; i<allLinks.length; i++) {
		var linkClass=allLinks.item(i).className		
		
		if (allLinks.item(i).title.length == 0) { 
			switch(linkClass){
				case "external":
					var hrefIndex = allLinks.item(i).href.indexOf("destination=");
					if(hrefIndex != -1) {
						allLinks.item(i).title = "New Window: " + unescape(allLinks.item(i).href.substring(hrefIndex + 12, allLinks.item(i).href.length));
					} else {
						allLinks.item(i).title = "New Window: " + allLinks.item(i).innerHTML;
					}
					break;
				case "popup-normal external":
					allLinks.item(i).title = "New Window: " + allLinks.item(i).innerHTML;
					break;						
				default:
					allLinks.item(i).title = allLinks.item(i).innerHTML;
					break;
			}		
		}
		
		switch(linkClass){
			case "internal":
				allLinks.item(i).innerHTML = allLinks.item(i).innerHTML + "<img src='" + sContextPath + "/assets/images/icons/internal.gif' alt='' width='11' height='11' border='0' />"
				break
			case "pdf popup-pdf":
				allLinks.item(i).innerHTML = "<img src='" + sContextPath + "/assets/images/icons/pdf.gif' class='icon-pdf' alt='' width='14' height='14' border='0' />" + allLinks.item(i).innerHTML
				break
			case "doc popup-doc":
				allLinks.item(i).innerHTML = "<img src='" + sContextPath + "/assets/images/icons/doc.gif' class='icon-doc' alt='' width='14' height='14' border='0' />" + allLinks.item(i).innerHTML
				break				
		}
	}
}
