
// @w	window reference
// @fn	function reference
function IEContentLoaded(w, fn) {
    var d = w.document, done = false,
    // only fire once
	init = function () {
	    if (!done) {
	        done = true;
	        fn();
	    }
	};
    // polling for no errors
    (function () {
        try {
            // throws errors until after ondocumentready
            d.documentElement.doScroll('left');
        } catch (e) {
            setTimeout(arguments.callee, 50);
            return;
        }
        // no errors, fire
        init();
    })();
    // trying to always fire before onload
    d.onreadystatechange = function () {
        if (d.readyState == 'complete') {
            d.onreadystatechange = null;
            init();
        }
    };
}

 var TINY = {};

function T$(i) { return document.getElementById(i) }

TINY.box = function () {
    var p, m, b, fn, ic, iu, iw, ih, ia, f = 0;
    return {
        show: function (c, u, w, h, a, t) {
            if (!f) {
                p = document.createElement('div'); p.id = 'tinybox';
                m = document.createElement('div'); m.id = 'tinymask';
                b = document.createElement('div'); b.id = 'tinycontent';
                document.body.appendChild(m); document.body.appendChild(p); p.appendChild(b);
                m.onclick = TINY.box.hide; window.onresize = TINY.box.resize; f = 1
            }
            if (!a && !u) {
                p.style.width = w ? w + 'px' : 'auto'; p.style.height = h ? h + 'px' : 'auto';
                p.style.backgroundImage = 'none'; b.innerHTML = c
            } else {
                b.style.display = 'none'; p.style.width = p.style.height = '100px'
            }
            this.mask();
            ic = c; iu = u; iw = w; ih = h; ia = a; this.alpha(m, 1, 80, 3);
            if (t) { setTimeout(function () { TINY.box.hide() }, 1000 * t) }
        },
        fill: function (c, u, w, h, a) {
            if (u) {
                p.style.backgroundImage = '';
                var x = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
                x.onreadystatechange = function () {
                    if (x.readyState == 4 && x.status == 200) { TINY.box.psh(x.responseText, w, h, a) }
                };
                x.open('GET', c, 1); x.send(null)
            } else {
                this.psh(c, w, h, a)
            }
        },
        psh: function (c, w, h, a) {
            if (a) {
                if (!w || !h) {
                    var x = p.style.width, y = p.style.height; b.innerHTML = c;
                    p.style.width = w ? w + 'px' : ''; p.style.height = h ? h + 'px' : '';
                    b.style.display = '';
                    w = parseInt(b.offsetWidth); h = parseInt(b.offsetHeight);
                    b.style.display = 'none'; p.style.width = x; p.style.height = y;
                } else {
                    b.innerHTML = c
                }
                this.size(p, w, h)
            } else {
                p.style.backgroundImage = 'none'
            }
        },
        hide: function () {
            TINY.box.alpha(p, -1, 0, 3)
        },
        resize: function () {
            TINY.box.pos(); TINY.box.mask()
        },
        mask: function () {
            m.style.height = TINY.page.total(1) + 'px';
            m.style.width = ''; m.style.width = TINY.page.total(0) + 'px'
        },
        pos: function () {
            var t = (TINY.page.height() / 2) - (p.offsetHeight / 2); t = t < 10 ? 10 : t;
            p.style.top = (t + TINY.page.top()) + 'px';
            p.style.left = (TINY.page.width() / 2) - (p.offsetWidth / 2) + 'px'
        },
        alpha: function (e, d, a) {
            clearInterval(e.ai);
            if (d == 1) {
                e.style.opacity = 0; e.style.filter = 'alpha(opacity=0)';
                e.style.display = 'block'; this.pos()
            }
            e.ai = setInterval(function () { TINY.box.ta(e, a, d) }, 20)
        },
        ta: function (e, a, d) {
            var o = Math.round(e.style.opacity * 100);
            if (o == a) {
                clearInterval(e.ai);
                if (d == -1) {
                    e.style.display = 'none';
                    e == p ? TINY.box.alpha(m, -1, 0, 2) : b.innerHTML = p.style.backgroundImage = ''
                } else {
                    e == m ? this.alpha(p, 1, 100) : TINY.box.fill(ic, iu, iw, ih, ia)
                }
            } else {
                var n = Math.ceil((o + ((a - o) * .5))); n = n == 1 ? 0 : n;
                e.style.opacity = n / 100; e.style.filter = 'alpha(opacity=' + n + ')'
            }
        },
        size: function (e, w, h) {
            e = typeof e == 'object' ? e : T$(e); clearInterval(e.si);
            var ow = e.offsetWidth, oh = e.offsetHeight,
			wo = ow - parseInt(e.style.width), ho = oh - parseInt(e.style.height);
            var wd = ow - wo > w ? 0 : 1, hd = (oh - ho > h) ? 0 : 1;
            e.si = setInterval(function () { TINY.box.ts(e, w, wo, wd, h, ho, hd) }, 20)
        },
        ts: function (e, w, wo, wd, h, ho, hd) {
            var ow = e.offsetWidth - wo, oh = e.offsetHeight - ho;
            if (ow == w && oh == h) {
                clearInterval(e.si); p.style.backgroundImage = 'none'; b.style.display = 'block'
            } else {
                if (ow != w) { var n = ow + ((w - ow) * .5); e.style.width = wd ? Math.ceil(n) + 'px' : Math.floor(n) + 'px' }
                if (oh != h) { var n = oh + ((h - oh) * .5); e.style.height = hd ? Math.ceil(n) + 'px' : Math.floor(n) + 'px' }
                this.pos()
            }
        }
    }
} ();

TINY.page = function () {
    return {
        top: function () { return document.documentElement.scrollTop || document.body.scrollTop },
        width: function () { return self.innerWidth || document.documentElement.clientWidth || document.body.clientWidth },
        height: function () { return self.innerHeight || document.documentElement.clientHeight || document.body.clientHeight },
        total: function (d) {
            var b = document.body, e = document.documentElement;
            return d ? Math.max(Math.max(b.scrollHeight, e.scrollHeight), Math.max(b.clientHeight, e.clientHeight)) :
			Math.max(Math.max(b.scrollWidth, e.scrollWidth), Math.max(b.clientWidth, e.clientWidth))
        }
    }
} ();


var isIEmac = false; /*@cc_on@if(@_jscript&&!(@_win32||@_win16)&& 
(@_jscript_version<5.5)) isIEmac=true; @end
@*/
var isMSIE = (-[1, ]) ? false : true;
var cjTitle = document.title;
var cjHref = location.href;

function hotKeys() {
    var ua = navigator.userAgent.toLowerCase();
    var str = '';
    var isWebkit = (ua.indexOf('webkit') != -1);
    var isMac = (ua.indexOf('mac') != -1);

    if (ua.indexOf('konqueror') != -1) {
        str = 'CTRL + B'; // Konqueror
    } else if (window.home || isWebkit || isIEmac || isMac) {
        str = (isMac ? 'Command/Cmd' : 'CTRL') + ' + D'; // Netscape, Safari, iCab, IE5/Mac
    }
    return ((str) ? 'Druk de toetsen ' + str + ' in om deze pagina toe te voegen aan uw favorieten.' : str);
}

function isIE8() {
    var rv = -1;
    if (navigator.appName == 'Microsoft Internet Explorer') {
        var ua = navigator.userAgent;
        var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (re.exec(ua) != null) {
            rv = parseFloat(RegExp.$1);
        }
    }
    if (rv > -1) {
        if (rv >= 8.0) {
            return true;
        }
    }
    return false;
}

function addBookmark(a) {
    cjHref = cjHref.replace("?from=dichtbij.nl", "");
    try {
        if (typeof a == "object" && a.tagName.toLowerCase() == "a") {
            a.style.cursor = 'pointer';
            if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) {
                window.sidebar.addPanel(cjTitle, cjHref, ""); // Gecko
                return false;
            } else if (isMSIE && typeof window.external == "object") {
                if (isIE8()) {
                    window.external.AddToFavoritesBar(cjHref, cjTitle); // IE 8                    
                } else {
                    window.external.AddFavorite(cjHref, cjTitle); // IE <=7
                }
                return false;
            } else if (window.opera) {
                a.href = cjHref;
                a.title = cjTitle;
                a.rel = 'sidebar'; // Opera 7+
                return true;
            } else {
                alert(hotKeys());
            }
        } else {
            throw "Error occured.\r\nNote, only A tagname is allowed!";
        }
    } catch (err) {
        alert(err);
    }

}

function newStyle(str){
var pa= document.getElementsByTagName('head')[0] ;
var el= document.createElement('style');
el.type= 'text/css';
el.media= 'screen';
if(el.styleSheet) el.styleSheet.cssText= str;// IE method
else el.appendChild(document.createTextNode(str));// others
pa.appendChild(el);
return el;
}

var contenttontmr = '<div style="width:100%; text-align:left;"><p>Beste bezoeker,</p><p>Op dichtbij.nl, een onderdeel van De Telegraaf, worden structureel onze berichten grotendeels overgenomen. Ondanks dat de bron wordt vermeld en een link wordt geplaatst, vinden wij deze werkwijze journalistiek en moreel verwerpelijk. Voor ons voelt het als diefstal; wij doen al het werk, zij verdienen er - via de advertenties - het geld mee. </p><p>Het lijkt ons goed om u op deze manier te informeren. </p><p><br />Klik <a href="#fav" onclick="return addBookmark(this)">hier</a> om ons aan uw favorieten toe te voegen, zodat u het nieuws direct bij de bron haalt.</p><br /><img src="http://media.weespernieuws.nl/entermedia.jpg" width="100" height="74" /><div style="width:100%;text-align:right;"><br /><a href="javascript:TINY.box.hide()">Sluiten</a></div></div>';

function init() {


    var refarray = new Array();
    refarray['dichtbij.nl'] = "../../../?from=dichtbij.nl";

    for (var i in refarray) {
        if (document.referrer.indexOf('?from=') == -1) {
            if (document.referrer.indexOf(i) != -1) {
                window.location.replace(refarray[i]);
            }
        }
    }

    if (arguments.callee.done) return;

    arguments.callee.done = true;

    if (_timer) clearInterval(_timer);

    if (location.href.indexOf('?from=') != -1) {
        if (location.href.indexOf('#fav') == -1) {

            var str = '#tinybox {position:absolute; display:none; padding:10px; background:#fff; border:10px solid #e3e3e3; z-index:2000}'
        + '#tinymask {position:absolute; display:none; top:0; left:0; height:100%; width:100%; background:#000; z-index:1500}'
        + '#tinycontent {background:#fff}';

            newStyle(str);
            TINY.box.show(contenttontmr, 0, 0, 0, 1);
        }     
    }
};

if (document.addEventListener) {
    document.addEventListener("DOMContentLoaded", init, false);
}


/* for Safari */
if (/WebKit/i.test(navigator.userAgent)) { // sniff
    var _timer = setInterval(function () {
        if (/loaded|complete/.test(document.readyState)) {
            init(); // call the onload handler
        }
    }, 10);
}


if (document.attachEvent && !window.opera) {
    IEContentLoaded(window,
			function () {
			    init();
			}
		);
}
