// Browser specific layout functions 
jQuery.fn.layOut = function() {

	if (browser.safari) { 
	    jQuery('input[type=file]').css({ backgroundColor: "transparent", border: "none"}); 
	};

	if (browser.winIE6Down) {
	    try { DD_belatedPNG.fix('.png'); document.execCommand('BackgroundImageCache', false, true); } catch (e) { };
	};
		
    if (browser.winIE) {
        jQuery('input:checkbox, input:radio, input:hidden').css({ border: "none", background: "none" });
        jQuery('#container.wide .right-pane:first').insertBefore("#container.wide .content-pane");

    }
}

jQuery.fn.fontSize = function() {
    // Set events
    jQuery.each(['txt-size-01', 'txt-size-02', 'txt-size-03'], function(i, v) {
        jQuery("." + v).click(function(event) {
            event.preventDefault();
            jQuery("body").removeClass();
            jQuery.cookie("fontSize", v, { path: '/', expires: -1 });
            if (v != 'txt-size-01') {
                jQuery("body").addClass(v);
            }
            return false;
        });
    });
    // Read cookie
    var val = jQuery.cookie("fontSize");
    if (val && (val != '') && (val != 'txt-size-01')) {
        jQuery("body").addClass(val);
    }
}


// Toggle input value
jQuery.fn.toggleVal = function() {
    return this.focus(function() {
        if (this.value == this.defaultValue) {
            this.value = "";
        }
    }).blur(function() {
        if (!this.value.length) {
            this.value = this.defaultValue;
        }
    });
};

// Toggle div sequence
jQuery.fn.toggleSeq = function(id, class1, class2) {
//    jQuery('#' + id + ' li a:first').addClass(class2);
//    jQuery('#' + id + ' li div:first').show();
    jQuery('#' + id + ' li a').click(function() {
        var checkElement = jQuery(this).next();
        if (checkElement.is('div.drempel')) {
            if (!checkElement.is(':visible')) {
                jQuery('#' + id + ' li a').removeClass(class2);
                jQuery(this).addClass(class2);
                jQuery('#' + id + ' div.drempel:visible').toggle({ height: 'toggle' }, { queue: true, duration: 600 }); //, opacity: 'toggle' breaks cleartype IE7	
                checkElement.animate({ height: 'toggle' }, { queue: true, duration: 600 }); //, opacity: 'toggle' breaks cleartype IE7
            }
            else {
                jQuery('#' + id + ' div.drempel:visible').toggle({ height: 'toggle' }, { queue: true, duration: 600 }); //, opacity: 'toggle' breaks cleartype IE7	
                checkElement.animate({ height: 'toggle' }, { queue: true, duration: 600 }); //, opacity: 'toggle' breaks cleartype IE7
                jQuery('#' + id + ' li a').removeClass(class2);
            }
            return false;
        }
    });
};

// Toggle div
jQuery.fn.toggleDiv = function(text1, text2, class1, class2) {
    return this.toggle(function() {
        var el = jQuery('#' + this.href.split('#')[1]);
        jQuery(this).text(text2);
        jQuery(this).removeClass(class1);
        jQuery(this).addClass(class2);
        el.animate({ height: 'toggle' }, { queue: false, duration: 600 }); //, opacity: 'toggle' breaks cleartype IE7
    }, function() {
        var el = jQuery('#' + this.href.split('#')[1]);
        jQuery(this).text(text1);
        jQuery(this).removeClass(class2);
        jQuery(this).addClass(class1);
        el.animate({ height: 'toggle' }, { queue: false, duration: 400 }); //, opacity: 'toggle' breaks cleartype IE7
    });
};


// Tooltips
jQuery.fn.tooltip = function() {
    xOffset = -20;
    yOffset = 0;
    $("a.tooltip").hover(function(e) {
        this.t = this.title;
        this.title = "";
        $("body").append("<p id='tooltip'>" + this.t + "</p>");
        $("#tooltip")
			.css("top", (e.pageY - xOffset) + "px")
			.css("left", (e.pageX + yOffset) + "px")
			.fadeIn("fast");
    },
	function() {
	    this.title = this.t;
	    $("#tooltip").remove();
	});
    $("a.tooltip").mousemove(function(e) {
        $("#tooltip")
		.css("top", (e.pageY - xOffset) + "px")
		.css("left", (e.pageX + yOffset) + "px");
    });		
};

/**********************************************************************
/**********************************************************************
/ LOCATIONPATH.JS
/**********************************************************************
/**********************************************************************/

// Striketrough breadcrumb
function strikeTrough(linkID) {
    $(linkID).toggleClass('strikeTrough');
}

// Clears form and changes text color
// Usage: <input id="search" name="search" type="text" value="Type uw zoekterm" 
// onfocus="checkEntry(this,'Type uw zoekterm');"/>
function checkEntry(o, dTxt) {
    if (!o.defTxt) {
        o.defTxt = dTxt;
        o.onblur = function() {
            trimField(this);
            with (this) {
                if (value == '' || value == defTxt) {
                    value = defTxt;
                    o.style.color = '#a5acb2';
                }
            }
        }
    }
    if (o.value == o.defTxt) {
        o.value = '';
        o.style.color = '#000000';
    }
}
function trimField(o) {
    var v = o.value.replace(/^ +| +$/g, '');
    o.value = v;
}

// Mouse-over images
// Usage: <body id="bodyHome" onload="createMouseOvers();"> 
// name images "name_over" and "name_out"
function createMouseOvers() {
    var p = 0, d = document.images;
    prelImgs = new Array();
    for (var i = 0; i < d.length; i++) {
        var o = d[i];
        if (o.src.indexOf('_out') != -1) {
            var s = o.src, l = s.length, e = s.substring(l - 4, l);
            o.outSrc = s;
            o.overSrc = s.substring(0, l - 8) + '_over' + e;
            o.onmouseover = function() { this.src = this.overSrc; }
            o.onmouseout = function() { this.src = this.outSrc; }
            prelImgs[p] = new Image();
            prelImgs[p].src = o.overSrc;
            p++;
        }
    }
}

/**********************************************************************
/**********************************************************************
/ EXTERNAL.JS
/**********************************************************************
/**********************************************************************/

//open external links in new window
jQuery.fn.externalLinks = function() {
    var localDomain = (location.href.split('/')[2]);
    var base = jQuery('base');
    if (base.length > 0) {
        localDomain = base[0].href.replace('http://', '').replace('/', '');
    }	
    var localExtensionsInNewWindow = Array('doc', 'xls', 'pdf');
    var list = document.getElementsByTagName('A');
    for (var i = 0; i < list.length; i++) {
        var aEl = list[i];
        // Bij links naar PDF wordt wel eens #page=X gebruikt onderstaande split fixed dit.
        var aElHref = aEl.href.split("#", 1)[0];
        // check for extensions
        var extension = (aElHref.substring(aElHref.length - 4, aElHref.length)).toLowerCase();
        var foundExtension = false;
        for (var j = 0; j < localExtensionsInNewWindow.length; j++) {
            if (extension == '.' + localExtensionsInNewWindow[j]) {
                foundExtension = true;
                break;
            }
        };
        

        // open in new window if conditions are right
        if ((aElHref.split('/')[2] != localDomain && aElHref.indexOf('mailto:') == -1 && aElHref.indexOf('javascript:') == -1) || foundExtension) {
            $(aEl).addClass('external'); //.attr('title', 'external link'); (Issue FB-1917)
            aEl.onclick = function() {
                window.open(this.href);
                return false;
            }
        }
    }
};

/**********************************************************************
/**********************************************************************
/ TABLES.JS
/**********************************************************************
/**********************************************************************/

function showHide(e) {

    // element vinden dat de click veroorzaakt
    var targetClick;
    if (window.event) {
        // IE
        targetClick = e.srcElement;
    } else {
        // Alle andere browsers
        targetClick = e.target;
    }

    // id van targetClick opvragen en daar de laatste 2 cijfers van pakken
    var targetId = targetClick.id;
    targetId = targetId.substr(11, 12);
    // id opbouwen van te tonen comment block
    targetId = "comment" + targetId;

    //Alle openstaande comments sluiten
    hideAllTableCommants();
    
    // Kijken of de table row nu al getoond wordt
    if (document.getElementById(targetId).style.visibility == "hidden" || document.getElementById(targetId).style.visibility == "") {
        document.getElementById(targetId).style.visibility = "visible";
        document.getElementById(targetId).style.position = "relative";
    } else {
        document.getElementById(targetId).style.visibility = "hidden";
        document.getElementById(targetId).style.position = "absolute";
    }
}

function hideAllTableCommants(e) {
    // commentaar blocken ophalen
    for (var i = 0; i < 200; i++) {
        var cName = String(i);
        if (i < 10) {
            cName = '0' + cName;
        }
        var tableComment = document.getElementById('comment' + cName);
        if (tableComment) {
            tableComment.style.visibility = "hidden";
            tableComment.style.position = "absolute";
        }
    }
}

function addListeners(e) {
    /* table comments */
    for (var i = 0; i < 200; i++) {
        var cName = String(i);
        if (i < 10) {
            cName = '0' + cName;
        }
        var linkShowCommant = document.getElementById('showCommant' + cName);
        if (linkShowCommant) {
            jQuery(linkShowCommant).click(showHide);
        }
        var linkHideCommant = document.getElementById('closeAllCom' + cName);
        if (linkHideCommant) {
            jQuery(linkHideCommant).click(hideAllTableCommants);
        }
    }
}

/**********************************************************************
/**********************************************************************
/ MYREPORT.JS
/**********************************************************************
/**********************************************************************/

function fnMy_CheckboxSelected() {
    var oneOrMoreChecked = false;
    var checkBoxTable = document.getElementById('checkboxTable');

    var inputs = checkBoxTable.getElementsByTagName('input');
    for (var i = 0; i < inputs.length; i++) {
        if (inputs.item(i).checked) {
            oneOrMoreChecked = true;
        }
    }
    
    if (!oneOrMoreChecked) { 
        alert('Selecteer een of meer artikel(en) voor download.') 
    };
    return oneOrMoreChecked;
}
 
/**********************************************************************
/**********************************************************************
/ Jargon
/**********************************************************************
/**********************************************************************/

function fnSwitchJargon() {
    jQuery('span.insight, span.insight-none').toggleClass('insight').toggleClass('insight-none')
}

/**********************************************************************
/**********************************************************************
/ Send to friend
/**********************************************************************
/**********************************************************************/

function fnOpenSendToFriend(strUrl) {
    var strPopinUrl = jQuery('base')[0].href + 'ContentControls/Forms/SendToFriend.aspx?strUrl=' + escape(strUrl)
    pageTracker._trackPageview('CT send to friend');
    return Aspacts.Idios3.I_CAP.Scripting.InlineWin.OpenPopinUrlStyle(strPopinUrl, 475, 330, true, 'sendafriend-')
}


/**********************************************************************
/**********************************************************************
/ STARTUP CODE
/**********************************************************************
/**********************************************************************/

if (browser.winIE6Down) {
    var jsPath = "Scripts/";  
    document.write('<scr' + 'ipt type="text/javascript" src="' + jsPath + 'fixpng.js"><\/scr' + 'ipt>');
}


jQuery(function() {

    // Noscript and drempelvrij 
    jQuery('.drempel').css({ 'display': 'none' });
    jQuery('.noscript').css({ 'display': 'block !important' });

    // Suckerfish
    jQuery("ul.nav li").hover(
        function() { $(this).addClass("active"); },
        function() { $(this).removeClass("active"); }
    );

    // Table events
    addListeners();
    createMouseOvers();

    // Activate layout miniplugins
    jQuery('html').externalLinks();
    jQuery('html').layOut();
    jQuery('html').fontSize();
    jQuery('html').tooltip();
    jQuery('.togval').toggleVal();

    jQuery('html').toggleSeq('video', 'vid-plus', 'vid-min');
});

