// JavaScript Document

var areanames = new Array('content','rightcol');

function showIcons() {
	for(i in areanames) {
		scanforlinks(areanames[i]);
	}
}

function getContentArea(areaname) {
	node =  document.getElementById(areaname);
		
	return node;
}

function scanforlinks(areaname) {
    // securing against really old DOMs
	
    if (! document.getElementsByTagName){return false};
    if (! document.getElementById){return false};
    // Quick utility function by Geir Bækholt
    // Scan all links in the document and set classes on them dependant on
    // whether they point to the current site or are external links

    contentarea = getContentArea(areaname)
    if (!contentarea){return false}

    links = contentarea.getElementsByTagName('a');
    for (i=0; i < links.length; i++) {
		
        if ((links[i].getAttribute('href'))&&(links[i].className.indexOf('link-plain')==-1 )) {
            var linkval = links[i].getAttribute('href')
            // check if the link href is a relative link, or an absolute link to the current host.

            if (linkval.toLowerCase().substring((linkval.length-4), linkval.length).indexOf('.pdf') == 0) {
                    //pdf file, add the pdf class
					
                    wrapNode(links[i], 'span', 'link-pdf')
                
            } else if (linkval.indexOf('http:') != 0) {
                // not a http-link. Possibly an internal relative link, but also possibly a mailto ot other snacks
                // add tests for all relevant protocols as you like.

                protocols = ['mailto', 'ftp', 'news', 'irc', 'h323', 'sip', 'callto', 'https']
                // h323, sip and callto are internet telephony VoIP protocols

                for (p=0; p < protocols.length; p++) {
                    if (linkval.indexOf(protocols[p]+':') == 0) {
                        // this link matches the protocol . add a classname protocol+link
                        //links[i].className = 'link-'+protocols[p]
                        wrapNode(links[i], 'span', 'link-'+protocols[p])
                        break;
                     }
                }
            } else {
                // we are in here if the link points to somewhere else than our site.
                if ( links[i].getElementsByTagName('img').length == 0 ) {
                    // vps - in my case all my PDF files were internal to my site only.
                    // If you want to add an icon for external links also, add code similar to above here also
                    // we do not want to mess with those links that already have images in them
                    //links[i].className = 'link-external'
                    wrapNode(links[i], 'span', 'link-external')
                    //links[i].setAttribute('target','_blank')
                }
            }
        }
    }
}

function wrapNode(node, wrappertype, wrapperclass){ 
	// utility function to wrap a node "node" in an arbitrary element of type "wrappertype" , with a class of "wrapperclass" 
	var wrapper = document.createElement(wrappertype) 
	wrapper.className = wrapperclass; 
	innerNode = node.parentNode.replaceChild(wrapper,node); 
	wrapper.appendChild(innerNode) 
} 


function addEvent(obj, evType, fn){
	if (obj.addEventListener){
		obj.addEventListener(evType, fn, true);
		return true;
	} else if (obj.attachEvent){
		var r = obj.attachEvent("on"+evType, fn);
		return r;
	} else {
		return false;
	}
}

addEvent(window, 'load', showIcons);


// JavaScript Document
function displayRandom() {
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="138" height="400">')
	document.write('<param name="movie" value="/quotes/randomquotes.swf" />')
	document.write('<param name="quality" value="high" />')
	document.write('<embed src="/quotes/randomquotes.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="138" height="400"></embed>')
	document.write('</object>')
}

function checkForFlash(requiredMajorVersion, requiredMinorVersion, requiredRevision,alternateContent,funcPointer) {
	// Version check based upon the values entered above in "Globals"
	var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
	
	// Check to see if the version meets the requirements for playback
	if (hasReqestedVersion) {
		funcPointer();
		
	} else {  // flash is too old or we can't detect the plugin
		document.write(alternateContent);  // insert non-flash content
	}
}
