
/* ++++++++++++++++++++++++++++++++
 ++	jQuery Palette v0.1.10		++
 ++	jquery.pallette-0.1.10.js	++
 ++	updated	2008-11-04			++
 ++										++
 ++	Dependencies:					++
 ++	- jQuery 1.2.6 or higher	++
 ++++++++++++++++++++++++++++++++ */
(function($) {
    $.fn.extend({
        /* ================================
        ==  Extending jQuery methods  ==
        ================================ */
        palette: "0.1.10",

        contentObj: window.contentObj ||
        {},

        hashRef: function() { // v0.1.5
            //	Finds corresponding element(s), based on href= attribute (hash) of first matched element. Works both ways.
            return this.is("[href*='#']") ? ($(this[0].href.substring(this[0].href.lastIndexOf("#")))) : $("[href$='#" + this[0].id + "']");
        },

        forRef: function() { // v0.1.5
            //	Finds corresponding label(s), input, select or textarea, based on for= attribute of first matched element. Works both ways.
            return this.is("label[for]") ? $("#" + this[0].htmlFor) : $("label[for='" + this[0].id + "']");
        },

        overLabel: function() { // v0.1.7
            //	Makes 'overLabel' behavior possible. Works both on labels and form fields.
            //	Concept based on http://www.alistapart.com/articles/makingcompactformsmoreaccessible/
            //	CSS:		.jsOverLabel (on label)
            //				.jsOverLabelBlur (on parent of form field: blur)
            //	Deps.:	forRef() method (v0.1+)
            return this.each(function() {
                var jThis = $(this);
                var jRef = jThis.forRef();
                if (jThis.is("label[for]")) {
                    var jFormControl = jRef;
                    var jLabels = jThis;
                }
                else {
                    var jFormControl = jThis;
                    var jLabels = jRef;
                }
                if (!(jFormControl.length > 0 && jLabels.length > 0))
                    return true; // continue
                jLabels.each(function() {
                    $(this).addClass("jsOverLabel");
                    if (jFormControl.val() === "")
                        jFormControl.parent().addClass("jsOverLabelBlur");
                    jFormControl.focus(function() {
                        $(this).parent().removeClass("jsOverLabelBlur");
                    }).blur(function() {
                        var jFormControl = $(this);
                        if (jFormControl.val() === "")
                            jFormControl.parent().addClass("jsOverLabelBlur");
                    }).click(function() { // needed for Webkit to pass focus to input
                        $(this).forRef().each(function() { // .focus() does not seem to work on every matched element, therefore .each() 
                            this.focus();
                        });
                    });
                });
            });
        },

        clickable: function(cpTtl) { // v0.1.8
            //	Makes elements clickable, linking to location specified by href= attribute of first descending link (where href is not "#" and does not start with "javascript:").
            // Args.:	cpTtl:	[Boolean | optional]	Specifies whether or not to copy the title= attribute from the link to clickable element (default: true)
            //	CSS:		.jsClickable (on this)
            //				.jsClickableHover (on this:hover)
            //				.jsGuide (on guiding link)
            return this.each(function() {
                var jClickElem = $(this);
                var jGuideLink = $("a[href]:not([href='#']):not([href^='javascript:'])", jClickElem).eq(0);
                var href = jGuideLink.attr("href");
                if (!href)
                    return true; // continue
                $(this).data("href", href);
                if ((cpTtl || cpTtl == null) && !this.title && jGuideLink[0].title)
                    this.title = jGuideLink[0].title;
                jClickElem.click(function() {
                    window.location.href = $(this).data("href");
                }).hover(function() {
                    $(this).addClass("jsClickableHover");
                }, function() {
                    $(this).removeClass("jsClickableHover");
                }).addClass("jsClickable");
                jGuideLink.addClass("jsGuide");
            });
        },

        selectNav: function() { // v0.1.7
            //	Adds auto submit behavior to select boxes, for navigational use. Works with keyboard too (in IE, FX and Op)
            //	CSS:		.jsSelectNav (on parent of select box)
            return this.filter("select").each(function() {
                $(this).focus(function() {
                    $(this).data("origValue", this.value);
                }).change(function() {
                    if ($(this).data("newValue"))
                        $(this).data("origValue", $(this).data("newValue"));
                    $(this).data("newValue", this.value);
                }).blur(navigate).click(navigate).parent().addClass("jsSelectNav");

                function navigate() {
                    var newValue = $(this).data("newValue");
                    if (newValue && newValue != $(this).data("origValue"))
                        this.form.submit();
                };
            });
        },

        popLink: function(props) { // v0.1.8
            // Opens matching links in popup. Default properties can be overridden with props argument
            // Args.:	props:	[Object]		Key/value pairs of properties that differ from default
            //	CSS:		.jsPopup (on link, default class name can be overridden)

            // Default properties may be changed and can be overridden on function call:
            var defProps = {
                target: "_blank", // [String]		Target name of popup
                blank: false, // [Boolean]	Blank window: true > no properties are applied / false > properties are applied 
                width: 500, // [Integer]	Width popup window
                height: 550, // [Integer]	Height popup window
                absH: false, // [Boolean]	Horizontal positioning: true > absolute / false > center
                absV: false, // [Boolean]	Vertical positioning: true > absolute / false > center
                popH: 640, // [Integer]	Horizontal position. If absHor is false, this value will be used as minimal screen width in case the available screen width is unknown
                popV: 480, // [Integer]	vertical position. If absVert is false, this value will be used as minimal screen height in case the available screen height is unknown
                print: false, // [Boolean]	Print version. If true, the toolbar will be shown in case the browser does not support window.print
                props: ["resizable"], // [Array]		Array with, comma seperated, window propertie names [String] which must be 'on'. E.g. ['location','scrollbars']
                keepRef: false, // [Boolean]	Keep reference to popup window. If true a reference will be kept in $.data("ref") stored on the link
                className: "jsPopup", // [String]		Class name set on popup link
                replaceLoc: false // [Boolean]	Replace popup location in browser's history or not
            };

            // Do not change code below:
            if (!props)
                props = {};
            for (var p in defProps)
                if (!props[p])
                props[p] = defProps[p];

            var propString = "";
            if (!props.blank) {
                if (props.print && !window.print && $.inArray("toolbar", props.props) == -1)
                    props.props.push("toolbar");

                function calcPos(prop, dim) {
                    if (window.screen && window.screen.availWidth)
                        prop = window.screen["avail" + dim];
                    return Math.round((prop - props[dim.toLowerCase()]) / 2);
                };
                if (!props.absH)
                    props.popH = calcPos(props.popH, "Width");
                if (!props.absV)
                    props.popV = calcPos(props.popV, "Height");

                propString = "width=" + props.width + ",height=" + props.height + ",left=" + props.popH + ",top=" + props.popV;
                if (props.props.length > 0)
                    propString = propString + "," + props.props.join(",");
            };

            return this.filter("a[href], area[href]").each(function() {
                $(this).data("popup", {
                    target: props.target,
                    props: propString,
                    repl: props.replaceLoc,
                    keepRef: props.keepRef
                }).click(function(e) {
                    var popProps = $(this).data("popup");
                    var popup = window.open(this.href, popProps.target, popProps.props, popProps.repl);
                    if (popProps.keepRef)
                        $(this).data("ref", popup);
                    e.preventDefault();
                    ;
                }).addClass(props.className);
            });
        },

        IEinlineIcons: function() { // v0.1
            // Appends a span with a non-breaking space to the matched elements (in IE) as a placeholder for an icon
            // CSS:		.jsIEfix (on matched elements)
            //				.jsInlineIcon (on appended span)
            return !$.browser.msie ? this : this.append('<span class="jsInlineIcon">&nbsp;</span>').addClass("jsIEfix");
        },

        TreeView: function(options) {

            settings = $.extend({
                opencss: 'collapsable',
                closecss: 'expandable',
                hitareacode: '<div class="hitarea"></div>'
            }, options);
            return this.each(function() {
                $(this).addClass('TreeView').find("li>ul").hide().parent().addClass(settings.closecss + ' folder').prepend(settings.hitareacode);
                $('.hitarea').click(function() {
                    var hit = $(this);
                    if (hit.parent().hasClass(settings.closecss)) {
                        hit.parent().removeClass(settings.closecss).addClass(settings.opencss).find('ul:first').show();
                        if (hit.parent().find('ul:first>li>div.hitarea').length == 0) {
                            hit.parent().find('li:first').prepend(settings.hitareacode + '<br />');
                        }
                    }
                    else {
                        hit.parent().removeClass(settings.opencss).addClass(settings.closecss).find('ul').hide().end().find('li.' + settings.opencss).removeClass(settings.opencss).addClass(settings.closecss);
                    }
                });
            });
        },

        Sitemap: function() {
            return this.each(function() {
                var item = $(this);
                if (item.find('ul').length > 0) {
                    item.html('+ ' + item.html());
                    item.find('li').Sitemap();
                }
                else {
                    item.html('- ' + item.html());
                }
            });
        },

        KeywordPopup: function() {
            return this.each(function() {
                var link = $(this);
                var key = link.attr('rel').split('_')[1];
                link.click(function() {
                    $.HideKeywordPopup();
                    $('#keyword_' + key).addClass('jskeywordpopup');
                    //Comment the next lines until return false to disable ajax
                    if ($('#keyword_' + key).length == 0) {
                        $.get(link.attr('href'), function(data) {
                            $('body').append('<div class="keywordpopup" id="keyword_' + key + '">' + data + '</div>');
                            $('#keyword_' + key).AddCloseButton();
                            $('#keyword_' + key).addClass('jskeywordpopup');
                        });
                    }
                    else {
                        $('#keyword_' + key).addClass('jskeywordpopup');
                    }
                    return false;
                });
            });
        },

        AddCloseButton: function() {
            return this.each(function() {
                var div = $(this);
                div.prepend('<a href="#" class="closebutton">X</a>')
                div.find('a').click(function() {
                    $.HideKeywordPopup();
                    return false;
                });
            });
        }

    });

    $.extend({        /* ========================
         ==  Custom functions  ==
         ======================== */
        // custom project function here, triggered with: $.functionName();
        HideKeywordPopup: function() {
            $('.keywordpopup').removeClass('jskeywordpopup');
        }

    });
})(jQuery);

/* ======================
 ==  Function calls  ==
 ====================== */
jQuery(function($) {
    $(document.body).css('font-size', $.cookie('font-size'));
    $('#footer ul').attr('id', 'foot').append('<li><a href="javascript:window.print();">' + Print + '</a>').children('li:last').addClass('last');
    $('#mainMenu>ul>li:last').addClass('last');
    $('#breadcrumb>ul>li:first').addClass('first');
    $("div#zoeker").after('<div id="fontsize"><a id="small" href="#">A</a>&nbsp;<a id="medium" href="#">A</a>&nbsp;<a id="large" href="#">A</a></div>');
    $("a#small").click(function() {
        $(document.body).css('font-size', '0.7em');
        $.cookie('font-size', '0.7em', { expires: 365, path: '/' });
    });
    $("a#medium").click(function() {
        $(document.body).css('font-size', '0.8em');
        $.cookie('font-size', '0.8em', { expires: 365, path: '/' });
    });
    $("a#large").click(function() {
        $(document.body).css('font-size', '0.9em');
        $.cookie('font-size', '0.9em', { expires: 365, path: '/' });
    });

    var h = $('#content').height();
    if ($('#main').length > 0) {
        h = $('#main').height();
    }

    if ($('.terms').length == 0) {
        if (h > $(window).height()) {
            $('#content').prepend('<a name="top"></a>');
            if (AddLinkToTop) {
                var linkcount = $(".jsbacktotop").length;
                if (linkcount > 0) {
                    $('#backlink').prepend('<br /><a class="jsbacktotop" href="#top">' + ToTopLink + '</a><br /><br /><br />');
                } else {
                    $('#content').append('<br /><a class="jsbacktotop" href="#top">' + ToTopLink + '</a><br />');
                }
            }
        }
    }

    $('.alphabet li:first').addClass('first');
    $('.alphabet li:last').addClass('last');
    $('.sitemap .links li').Sitemap();
    //$('.keywordpopup').AddCloseButton(); //uncomment when ajax is disabled
    $('.keywordlink').KeywordPopup();
    $('.radioList input').click(function() {
        var radio = $(this);

        $('.radioList input').each(function() {
            $(this).removeAttr('checked');
        });
        radio.attr('checked', 'checked');        
    });
});
