/*
 * Adapt the site's content to use 3rd party branding
 * Created: 2009-08-13, A.Lewis
 * 
 */

// flag the content's links' hrefs to use the CTN site's skin
var ctn_links_container;
function ctn_linkAdapter(e){
    // parse event object
    if (!e) var e = window.event;
    var el = e.target ? e.target : e.srcElement;  // W3C:IE
    if (el.nodeType == 3) el = el.parentNode; // defeat Safari bug
    // handle event
    var els = [], l = [], s = "";
    if(!ctn_links_container) ctn_links_container = $("content");
    els = $$("#" + ctn_links_container.id + " a");
    // get content links
    for(var i = 0; i < els.length; i++)
    {
        if(els[i].nodeType == 1 && els[i].tagName.toLowerCase() == "a" && els[i].href)
        l.push(els[i]);
    }
    // edit content links
    for(var j = 0; j < l.length; j++)
    {
        if(l[j].href.indexOf("/ctn/") == -1 && l[j].href.indexOf("ctn=1") == -1)
        {
            l[j].href += (l[j].href.indexOf("?") == -1) ? "?ctn=1" : "&ctn=1";
        }
    }
    if(e.stopPropagation)
        e.stopPropagation(); // W3C
    else
        e.cancelBubble();    // IE
};
