// Avoid conflicts, use local object for all properties
var homepage = new Object();


// Classes to apply enlarged "hit area"
homepage.targetedClasses = ['learn-more-button', 'headings'];

// Without firstLoad, returning to the page would result in repeated and unecessary multiple cornering
//var firstLoad = false;

// Add the rounded corners to all classes specified in targetedClasses
function setHitArea() {

    // Inspect every DIV element in the DOM
    for (var i=0;i<document.getElementsByTagName("div").length; i++) {
        
        // Get its class (if present)
        var className = document.getElementsByTagName("div").item(i).className;
        
        // flag to check if we have a match
        var found = false;
        
        // Check all classes we are interested in
        for (var c in homepage.targetedClasses) {
            // Does the className have multiple classes ??
            var tokens = className.split(" ");
            
            // Loop through tokenised class value (if any)
            for (var t=0; t<tokens.length; t++) {
                if (homepage.targetedClasses[c] == tokens[t]) {
                    found = true;
                    break;
                }
            }
        }
        
        if (found) {
            // Fetch the dev element we found
            var div = document.getElementsByTagName("div").item(i);

            var links = div.getElementsByTagName("a");
            if(links.length > 0) {
            
                // Add a class to the div so we can identifiy it (and change the cursor)
                div.className = div.className + " linkified";
            
                var onclickStr = "window.location='" + links[0] + "'; window.status=' + links[0] + ';";
                              
                addEvent('onclick', div, followLink );
                addEvent('onmouseover', div, showLinkText);
                addEvent('onmouseout', div, hideLinkText);
                
            }
        }
    }
 }


// Add function to onload handler
addEvent('onload', window, setHitArea);


// Display the link in the window status bar
function hoverLink(div, action) {

    var links = div.getElementsByTagName("a");

    if(links.length > 0) {
        
        if(action == 'show') {
            window.status = links[0];
        } else {
            window.status = '';
        }
    }
}


function showLinkText() {
    hoverLink(this, 'show');
}

function hideLinkText() {
    hoverLink(this, 'hide');
}



// Redirect the browser to the nested link location
function followLink() {

    var div = this;
        
    var links = div.getElementsByTagName("a");
    
    if(links.length > 0) {
        window.location=links[0];
    }
    
}