function add_load_event(func){
    var oOldOnLoad = window.onload;
    if(typeof window.onload != 'function'){
        window.onload=func;
    }
        
    else {
        window.onload=function(){
        oOldOnLoad();
        func();
        }
    }
}

function setLinks(){
    if(!document.getElementsByTagName){         
        return false;     
    }
    var iAlertCount = 0;
    var aAnchors = document.getElementsByTagName("a");
    for(var i=0; i<aAnchors.length; i++){
        var oLink = aAnchors[i];
        if(oLink.getAttribute("href") && oLink.getAttribute('rel')==("contentwarning")){
            oLink.onclick=function(){
                if(iAlertCount<1){
                    if(!confirm("CONTENT WARNING:\nSome of the photos on the page you requested may be slightly naughty and are intended for mature adults. \n\nClick 'Ok' if your mother would consider you a mature adult, otherwise click 'Cancel' and fuhgedaboudit")){
                    return false;
                    }
                    else{
                        if(iAlertCount < 1){
                            alert("Ok, I warned you: naughty photos ahead.\n\nEnjoy, Perv!");
                        }
                        if(iAlertCount < 5){
                            iAlertCount += 1;
                        }
                    }
                }
                else if(iAlertCount == 1){
                   if(!confirm("CONTENT WARNING:\nSome of the photos on the page you requested may be slightly naughty and are...\n\nYou again? \n\nSo, you like the naughty pics, huh?")){
                    return false;
                    } 
                    if(iAlertCount < 5){
                            iAlertCount += 1;
                    }
                }
                else if(iAlertCount == 2){
                    if(!confirm("CONTENT WARNING:\nSome of the photos on the page you requested may be slightly naughty and are...\n\nDoes you're mama know you're looking at all these naughty pics?.\n\nThis is the LAST time I'm gonna warn ya.")){
                        return false;
                     }
                     if(iAlertCount < 5){
                            iAlertCount += 1;
                    }
                }
                
            }
        }
        if(oLink.getAttribute("href") && (oLink.getAttribute("href").indexOf("flickr")) || (oLink.getAttribute('rel')==("external") || oLink.getAttribute('rel')==("contentwarning"))){
            oLink.target="_blank";
        }
    }
}
function flickrPreview(){
    var oFlickrList = document.getElementById("flickrlist");
    var aListItems = oFlickrList.getElementsByTagName("li");
    for (var i=0;i<aListItems.length; i++){
        var aLinks = aListItems[i].getElementsByTagName("a");
        var aFlickrSamples = aListItems[i].getElementsByTagName("div");
        aLinks[0].onmouseover = function(){
            aFlickrSamples[0].setAttribute('style','display:block');
        }
        aLinks[0].onmouseout = function(){
            aFlickrSamples[0].setAttribute('style','display:none');
        }
            
    }
}

add_load_event(setLinks);
add_load_event(flickrPreview);