/****************************************************************************************
*			  Attach Icons and pop-up and blank window behaviour to elements			*
****************************************************************************************/

function externalAndPopUpLinks()
{
	var defW = 640;
	var defH = 480;
	/* todo - check for missing or invalid width and height settings and set a default value for the popup*/
	var popupTitle = 'popup';
	var scrW = screen.availWidth;
    var scrH = screen.availHeight;
    var anchors = document.getElementsByTagName("a"); 
    var theAnchor, i, target, relIndex, relSplit, linkDest; 
    for (i=0;i<anchors.length;i++)
	{
		theAnchor = anchors[i];
		/* does this anchor have a rel attribute set? */
		if( theAnchor.getAttribute("href") && theAnchor.getAttribute("rel") != null)
		{
			linkDest = theAnchor.getAttribute("href"); 
			relIndex = theAnchor.getAttribute("rel"); 
			relSplit = relIndex.split(" ");
			switch(relSplit[0]) 
			{
				case 'external' :
					// Set to open the page in a new window
					applyBlankTarget(theAnchor);
				break;
				case 'popup' :
					/* if popup parameters missing fill in with defaults */
					if(relSplit[1]==null){relSplit[1]='popup';}
					if(relSplit[2]==null){relSplit[2]=defW;}
					if(relSplit[3]==null){relSplit[3]=defH;}
					theAnchor.setAttribute("rel" , relSplit[0] + ' ' + relSplit[1] + ' ' + relSplit[2] + ' ' + relSplit[3]);
					theAnchor.title+=relSplit[1];
					theAnchor.title+=' (popup that opens in new window)';
					popupW=relSplit[2];
					popupH=relSplit[3];
					theAnchor.title+=' ' + popupW + 'x' + popupH;
					theAnchor.onclick=function() {newWin=window.open(this.href,this.rel.split(" ")[1],'location=no,menubar=no,status=no,resizable=yes,toolbar=no,scrollbars=yes,width=' + this.rel.split(" ")[2] + ',height=' + this.rel.split(" ")[3]);if(window.focus){newWin.focus()} return false;}
				break;
			}
		}
	}
}

function applyBlankTarget(elementRef)
{
	// Put a span after the a and put the external bg image in it
	var externalSpan = document.createElement('span');
	var spanTextNode = document.createTextNode(' ');
	externalSpan.appendChild(spanTextNode);
	externalSpan.className = 'blank';
	elementRef.parentNode.insertBefore(externalSpan, elementRef.nextSibling);
	
	// Set to open the page in a new window
	elementRef.title +=' (Opens in a new window)';
	elementRef.target = '_blank';
}


function fileLinks() 
{
	var a = document.getElementsByTagName('a');
	var aLen = a.length;
	for (var i=0; i<aLen; i++) {
		var ext = a[i].href.slice(-3);
		switch(ext) {
			case 'rtf' :
				a[i].className += ' '+ext;
				break;
			case 'doc' :
				a[i].className += ' '+ext;
				break;
			case 'xls' :
				a[i].className += ' '+ext;
				break;
			case 'ppt' :
				a[i].className += ' '+ext;
				break;
			case 'vsd' :
				a[i].className += ' '+ext;
				break;
			case 'mpp' :
				a[i].className += ' '+ext;
				break;
			case 'xml' :
				a[i].className += ' '+ext;
				break;
			case 'pdf' :
				a[i].className += ' '+ext;
				break;
			case 'mp3' :
				a[i].className += ' audio';
				break;
			case 'wav' :
				a[i].className += ' audio';
				break;
			case 'wma' :
				a[i].className += ' audio';
				break;
			case 'mpg' :
				a[i].className += ' video';
				break;
			case 'mov' :
				a[i].className += ' video';
				break;
			case 'wmv' :
				a[i].className += ' video';
				break;
			case 'zip' :
				a[i].className += ' '+ext;
				break;
			case 'mdb' :
				a[i].className += ' '+ext;
				break;
			case 'txt' :
				a[i].className += ' '+ext;
				break;
		}
	}
}
// --> 