﻿/*
* UWV Script
* 
* 2010 Lucien Immink, Maurits Koekoek, the people's valley
*/

$(document).ready(function () {
    $("body").addClass("DOMReady");

    // add pretty closers to contentblocks except intro
    $(".home .block[id!=intro], .home #contactDropdown, body.particulierenHome #contactDropdown").append("<div class='closer'></div>");

    // replace h2 by link for contact overlay
    $("#contactDropdown .link").replaceWith("<a href='#' class='link'>" + $("#contactDropdown .link").text() + "</a>");

    // open/close Contact-overlay
    $("#contactDropdown .link").click(function () {
        $("#contactDropdown #contactContent, #contactDropdown .closer").toggle();
        $(this).toggleClass("active");

        $("body").bind("click keyup", function (e) { //clicking outside of contactDropdown hides it
            if (e.keyCode == '27' || e.type == 'click') {
                $("#contactDropdown #contactContent, #contactDropdown .closer").toggle();
                $("#contactDropdown .link").toggleClass("active");
                $("body").unbind();
            }
        });
        return false;
    });

    $("#contactContent").click(function (event) { // contactContent is regarded as "body" in above listener; this makes the links still work properly
        event.stopPropagation();
    });

    if ($("body.particulierenHome #secties .block").length > 0) {			// tidy up sectionblocks in particulieren home
        synchIntroHeights();
    }

    if ($("body.particulierenHome").length > 0) {
        initCarrousel();
    }

    if ($("body.particulieren .orientatie".length > 0)) {
        $(".buttons").each(function () {
            var middleOffset = ($(this).parents(".row").height() - $(this).height()) / 2 + 10;
            $(this).css({
                "margin-top": middleOffset + "px"
            });
        });
        $(".antwoord, .subantwoord, .subvraag").each(function () {
            $(this).css("height", $(this).parent(".row").height());
        });
        $(".orientatie a").css({
            "border-radius": "5px",
            "-pie-background": "linear-gradient(top,#32acfe, #027cce)"
        });

        $(".orientatie .row").hover(function () {
            $(".orientatie .row").removeClass("hover");
            $(this).addClass("hover");

            $(".orientatie").addClass("disabled");
            $(this).parent(".orientatie").removeClass("disabled");

            $(".ja").hide();
            $(".ja", this).show();

        }, function () {
            $(this).removeClass("hover");
            $(".orientatie").removeClass("disabled");
            $(".ja").hide();
            $(".orientatie").each(function () {
                $(".row:first .ja", this).show();
            });
        });

        $(".nee:last").remove();

        /*
        // portalChoser (tabbing through a site only works on a tags, so the trigger must be on the a, not the div)
        $("#login .digidLogin>a").bind("click mouseenter", function (e) {
        $("#login .digidLogin, #login #digid").addClass("open");
        });
        // with tabbing the popup remains visible, but we don't lose functionality
        $("#login .digidLogin").bind("mouseleave", function (e) {
        $("#login .digidLogin, #login #digid").removeClass("open");
        });
        */

        $(".kantoren li .stad").click(function () {
            $(this).parents(".block").each(function () {
                $(this).find("ul.kantoren>li").removeClass("open");
            });
            $(this).parents("li").toggleClass("open");
        });
    }
    // pngfix on selected elements - do this AFTER DOMmanipulation
    if ($.browser.msie && $.browser.version < 7) {
        try {
            $("#top").pngFix();
        } catch (e) { }
    }

    $(".questions ul.directNaar li:last").css("border", "none");

    var focussedID;

    var elements = $("div[id='taf']");
    if (elements.length > 1) {
        // Laatste laten staan, die staat rechts
        for (var i = 0; i < elements.length - 1; i++) {
            $($("div[id='taf']")[i]).remove();
        }
    }

    var style = $.cookie("style");
    if (style == "average") {
        $("body").removeClass("big");
        $("body").addClass("average");
        $("#averageFont").addClass("active");
        $("#smallFont").removeClass("active");
        $("#bigFont").removeClass("active");
        synchIntroHeights();
        recalculteTooltips($(document));
    }
    else {
        if (style == "big") {
            $("body").removeClass("average");
            $("body").addClass("big");
            $("#bigFont").addClass("active");
            $("#smallFont").removeClass("active");
            $("#averageFont").removeClass("active");
            synchIntroHeights();
            recalculteTooltips($(document));
        }
        else {
            $("body").removeClass("average");
            $("body").removeClass("big");
            $("#smallFont").addClass("active");
            $("#averageFont").removeClass("active");
            $("#bigFont").removeClass("active");
            synchIntroHeights();
            recalculteTooltips($(document));
        }
    }
    // Add label over effects
    $('label.over').labelOver('label-over');
    // rounded borders effects
    if ($.browser.msie && $.browser.version == 7) {
        $("form:first").append($("#taf").wrap("<div class='block'></div>").parent().css({ "z-index": 10000, "position": "fixed" }));
    } else if ($.browser.msie && $.browser.version == 6) {
        $("form:first").append($("#taf").wrap("<div class='block'></div>").parent().css({ "z-index": 10000, "position": "fixed" }));
    }
    if ($.browser.msie && $.browser.version < 7) {

    } else {
        $("#container .searchInput, #container .freeoptioninput, input[type=text], input[type=password], body.particulieren .tableview .files .date").css({
            "-moz-border-radius": "5px",
            "-webkit-border-radius": "5px",
            "border-radius": "5px",
            "behavior": "url(../systeem/diversen/PIE.htc)",
            "position": "relative"
        });
        $("#digid").css({
            "behavior": "url(../systeem/diversen/PIE.htc)"
        });
        if (!$.browser.msie) {
            $(" #container .block fieldset .text, .disclaimer textarea").css({
                "-moz-border-radius": "5px",
                "-webkit-border-radius": "5px",
                "border-radius": "5px"
            });
        }
        $(".disclaimer textarea").css({
            "-moz-border-radius": "5px",
            "-webkit-border-radius": "5px",
            "border-radius": "5px",
            "behavior": "url(../systeem/diversen/PIE.htc)"
        });
        $("#container .list:not(.noborder):not(.files):(.verticalform), .events .tabs li").css({
            "-moz-border-radius-topleft": "5px",
            "-moz-border-radius-topright": "5px",
            "-webkit-border-top-left-radius": "5px",
            "-webkit-border-top-right-radius": "5px",
            "border-top-left-radius": "5px",
            "border-top-right-radius": "5px",
            "behavior": "url(../systeem/diversen/PIE.htc)"
        });

        $("#right .loggedin").css({
            "-moz-box-shadow": "0 0 5px rgba(0,0,0,0.5)",
            "-webkit-box-shadow": "0 0 5px rgba(0,0,0,0.5)",
            "box-shadow": "0 0 5px #999999"
        });
        if ($.browser.msie && $.browser.version > 7) {
            $("#right .loggedin").css({
                "box-shadow": "0 0 5px #666666",
                "border-radius": "5px",
                "behavior": "url(../systeem/diversen/PIE.htc)"
            });
            $("#container .list:not(.noborder):not(.files):(.verticalform)").css({
                "border-radius": "5px",
                "behavior": "url(../systeem/diversen/PIE.htc)"
            });
        }
        $("#personal").css({
            "box-shadow": "0 0 8px #666666",
            "border-radius": "5px",
            "position": "relative",
            "behavior": "url(../systeem/diversen/PIE.htc)"
        });
        $("#personal .widget").css({
            "box-shadow": "0 0 10px #E5BB82",
            "position": "relative",
            "behavior": "url(../systeem/diversen/PIE.htc)"
        });
        $(".werkgeversportaal #right .loggedin, .tableview").css({
            "border-radius": "5px",
            "position": "relative"
        });
        $(".werkgeversportaal #right .loggedin .widget").css({
            "box-shadow": "0 0 5px #CFDCDF",
            "position": "relative"
        });
        if ($.browser.msie && $.browser.version > 7) {
            $(".werkgeversportaal #right .loggedin, .werkgeversportaal #right .loggedin .widget, .tableview").css({
                "behavior": "url(../systeem/diversen/PIE.htc)"
            });
        }
        $(".mijnuwv .verticalform .notice, .mijnuwv .inverse .notice, .werkgeversportaal .inverse .notice.info").css({
            "box-shadow": "2px 2px 5px #aaaaaa",
            "position": "relative",
            "behavior": "url(../systeem/diversen/PIE.htc)"
        });
    }
    if ($.browser.mozilla && Number($.browser.version.substring(0, 1)) >= 2) $("html").addClass("fx4");
    if ($.browser.mozilla) $("html").addClass("mozilla");
    if ($.browser.webkit) $("html").addClass("webkit");
    if (/iPhone|iPod/i.test(navigator.userAgent)) { $("html").addClass("iphone"); }
    // mouseover on li's
    $("a").bind("focus mouseenter blur mouseleave", function (e) {
        if ($(this).parent()[0].nodeName.toUpperCase() == "LI") {
            if (e.type == "focus" || e.type == "mouseenter") {
                $(this).parent().addClass("hover");
            } else {
                $(this).parent().removeClass("hover");
            }
        } else if ($(this).parents("li").length != 0) {
            if (e.type == "focus" || e.type == "mouseenter") {
                $(this).parents("li").addClass("hover");
            } else {
                $(this).parents("li").removeClass("hover");
            }
        }
        if ($(this).parent().hasClass("file")) {
            if (e.type == "focus" || e.type == "mouseenter") {
                $(this).parent().addClass("hover");
            } else {
                $(this).parent().removeClass("hover");
            }
        }
    });
    // portalChoser (tabbing through a site only works on a tags, so the trigger must be on the a, not the div)
    $("#portalChoser>div").append("<div id='portalChoserBottom'>&nbsp;</div>");
    $("#portalChoser>a").bind("click mouseenter", function (e) {
        $(this).parent().find("div").addClass("open");
        $(this).parent().addClass("open");
    });
    // with tabbing the popup remains visible, but we don't lose functionality
    $("#portalChoser").bind("mouseleave", function (e) {
        $(this).parent().find("div").removeClass("open");
        $(this).parent().removeClass("open");
    });
    // portalPulldown (tabbing through a site only works on a tags, so the trigger must be on the a, not the div)
    // without javascript this is not a link (duh); with we need a link so tabbing works; add the link
    $("#portalpulldownlink").wrapInner("<a id='portalpulldownlink' href='#' />").removeAttr("id");
    $(".portalpulldownlink").wrapInner("<a class='portalpulldownlink' href='#' />").removeAttr("class");
    $(".portalpulldownlink").before("<span class='portalpulldownSeperator' />");
    var timeout = 0;
    $("#portalpulldownlink").unwrap().bind("click mouseenter mouseleave", function (e) {
        if (e.type == "mouseleave") {
            $("#portalpulldown").removeClass("open");
            $("#portalpulldownlink").removeClass("open");
            clearTimeout(timeout);
        } else if (e.type == "mouseenter") {
            timeout = setTimeout(function () {
                $("#portalpulldown").addClass("open");
                $("#portalpulldownlink").addClass("open");
            }, 500);
        } else if (e.type == "click") {
            if ($("#portalpulldownlink").hasClass("open")) {
                $("#portalpulldown").removeClass("open");
                $("#portalpulldownlink").removeClass("open");
                clearTimeout(timeout);
            } else {
                $("#portalpulldown").addClass("open");
                $("#portalpulldownlink").addClass("open");
                clearTimeout(timeout);
            }
        }
    });


    $(".portalpulldownlink").unwrap().bind("click mouseenter mouseleave", function (e) {
        if (e.type == "mouseleave") {
            $(".portalpulldown").removeClass("open");
            $(".portalpulldownlink").removeClass("open");
            clearTimeout(timeout);
        } else if (e.type == "mouseenter") {
            var position = $(this).position();
            $("+ .portalpulldown", this).css("left", position.left);
            timeout = setTimeout(function () {
                $(".portalpulldown").addClass("open");
                $(".portalpulldownlink").addClass("open");
            }, 500);
        } else if (e.type == "click") {
            if ($(".portalpulldownlink").hasClass("open")) {
                $(".portalpulldown").removeClass("open");
                $(".portalpulldownlink").removeClass("open");
                clearTimeout(timeout);
            } else {
                $(".portalpulldown").addClass("open");
                $(".portalpulldownlink").addClass("open");
                clearTimeout(timeout);
            }
        }

    });

    // with tabbing the popup remains visible, but we don't lose functionality
    $("#portalpulldown").bind("mouseleave mouseenter", function (e) {
        if (e.type == "mouseleave") {
            $("#portalpulldown").removeClass("open");
            $("#portalpulldownlink").removeClass("open");
        } else if (e.type == "mouseenter") {
            $("#portalpulldown").addClass("open");
            $("#portalpulldownlink").addClass("open");
        }
    });

    $(".portalpulldown").bind("mouseleave mouseenter", function (e) {
        if (e.type == "mouseleave") {
            $(this).removeClass("open");
            $("+ .portalpulldownlink", this).removeClass("open");
        } else if (e.type == "mouseenter") {
            $(this).addClass("open");
            $("+ .portalpulldownlink", this).addClass("open");
        }
    });
    // alting for content tables
    $(".block table:not(.plain)").each(function () {
        $(this).find(">tbody>tr").each(function (i) {
            if (i % 2 == 1) {
                $(this).addClass("alt");
            }
        });
    });
    // alting for double tables (1,2 = normal, 3,4 = alt)
    $(".block table.double:not(.plain)").each(function () {
        $(this).find(">tbody>tr").each(function (i) {
            $(this).removeClass("alt");
            if (i % 4 > 1) {
                $(this).addClass("alt");
            }
        });
    });
    // alting for triple tables (1,2,3 = normal, 4,5,6 = alt)
    $(".block table.triple:not(.plain)").each(function () {
        $(this).find(">tbody>tr").each(function (i) {
            $(this).removeClass("alt");
            if (i % 6 > 2) {
                $(this).addClass("alt");
            }
        });
    });
    // add zoom icon to overlayable images
    if ($.browser.msie && $.browser.version < 8) {
        $("img.overlay").each(function () {
            $(this).parent().css({
                "cursor": "pointer"
            });
            var ie6style;
            if ($(this).attr("class").indexOf("right") != -1) {
                ie6style = "rightzoom";
            } else {
                ie6style = "leftzoom";
            }
            $(this).parent().append("<img src='/images/zoom.png' class='" + ie6style + "'/>");
        });
    } else {
        $("img.overlay").each(function () {
            $(this).parent().append("<img src='/images/zoom.png' class='zoom'/>");
            $(this).parent().wrapInner("<span class='" + $(this).attr("class") + "' />");
        });
    }
    $("a.overlay").bind("focus mouseenter blur mouseleave", function (e) {
        if (e.type == "focus" || e.type == "mouseenter") {
            $(this).find(".zoom").attr("src", "/images/zoom_hover.png");
        } else {
            $(this).find(".zoom").attr("src", "/images/zoom.png");
        }
    });
    // item to store gallery objects in;
    var gallery = {};
    // overlay effects (ALL images with the overlay class are triggered); be sure to add
    $("a.overlay").click(function () {
        var tarimg = $(this).find("img.overlay");

        var loadNewItem = function (src) {
            var img = new Image();
            img.onload = function () {
                img.width = this.width;
                img.height = this.height;
                calcNavHeight(img);
                $("#overlay #overlaytitle").text($(gallery.items[gallery.index]).find("img").attr("alt"));
                $("#overlay").css({
                    "width": img.width
                });
                $("#popincontent").html(img);
                var api = $("#overlay").data("overlay");
                api.load();
            };
            img.onerror = function (e) {
                $("#overlay #overlaytitle").text("");
                $("#overlay").css({
                    "width": 560
                });
                $("#popincontent").load(img.src, function () {
                    calcNavHeight();
                });
                var api = $("#overlay").data("overlay");
                api.load();
            };
            img.src = src;
        }
        var calcNavHeight = function (img) {
            var imgHeight;
            try {
                imgHeight = Math.max($("#overlay img").height(), Math.max(img.height, 420));
            } catch (e) {
                imgHeight = Math.max($("#overlay img").height(), 420);
            }
            $("#overlay #prev, #overlay #next").css("height", imgHeight);
        };
        var toggleNav = function () {
            if (gallery.items != undefined) {
                if (gallery.index <= 0) {
                    $("#overlay #prev").hide();
                } else {
                    $("#overlay #prev").show();
                }
                if (gallery.index == (gallery.items.length - 1)) {
                    $("#overlay #next").hide();
                } else {
                    $("#overlay #next").show();
                }
            }
        };
        var gotoItem = function (i) {
            // load the next item from the cached predefined gallery array; this can either be a positive (+1) or a negative(-1)
            gallery.index += i;

            // roundabout
            toggleNav();

            // get the new item to load from the cache
            var newItem = $(gallery.items[gallery.index]);
            // replace the content with the new data (which is exactly the same as opening a 2nd+ item with closing the gallery in between
            loadNewItem(newItem.attr("href"));
        };
        var storeGallery = function () {
            gallery.items = tarimg.parents(".photos").find(">li>a.overlay");
            gallery.index = tarimg.parents(".photos").find(">li").index(tarimg.parents("li"));
        }
        var addNavigation = function () {
            if (tarimg.parents(".photos").find(">li").length > 1) {
                // add navigation items and add the events to them
                if ($("#overlay #prev").length == 0) {
                    $("#overlay").prepend("<a href='#' id='prev'></a>");
                    $("#overlay").append("<a href='#' id='next'></a>");
                    $("#overlay #prev").click(function () {
                        gotoItem(-1);
                        return false;
                    });
                    $("#overlay #next").click(function () {
                        gotoItem(1);
                        return false;
                    });
                }
                toggleNav();
            }
        };
        if ($("#overlay").length == 0) {
            var img = new Image();
            img.onload = function (e) {
                // target is an image
                img.width = this.width;
                img.height = this.height;
                var div = document.createElement("div");
                div.id = "overlay";
                var title = document.createElement("div");
                title.id = "overlaytitle";
                title.innerHTML = tarimg.attr("alt");
                if (title.innerHTML == "undefined") title.innerHTML = "";
                div.appendChild(title);
                title = $(title);
                title.css({
                    "color": "#0668C3",
                    "margin": "0 0 10px"
                });
                var content = document.createElement("div");
                content.id = "popincontent";
                content.appendChild(img);
                calcNavHeight(img);
                div.appendChild(content);
                $("body").append(div);
                // fancy styling
                var div = $(div);
                div.css({
                    "-moz-box-shadow": "0 0 3em #000",
                    "-webkit-box-shadow": "0 0 3em #000",
                    "box-shadow": "0 0 3em #000",
                    "width": this.width
                });
                $("#overlay").overlay({
                    load: true,
                    closeOnClick: true,
                    mask: {
                        color: "#fff",
                        opacity: 0.8
                    }
                });
                $("#overlay .close").text("sluiten");
                addNavigation(); // add navigation if needed (function will add buttons if needed)
            };
            img.onerror = function (e) {
                // target is not an image; so ajaxload the content
                var div = document.createElement("div");
                div.id = "overlay";
                var title = document.createElement("div");
                title.id = "overlaytitle";
                div.appendChild(title);
                var content = document.createElement("div");
                content.id = "popincontent";
                $(content).load(img.src, function () {
                    calcNavHeight();
                });
                div.appendChild(content);
                $("body").append(div);
                // fancy styling
                var div = $(div);
                div.css({
                    "-moz-box-shadow": "0 0 3em #000",
                    "-webkit-box-shadow": "0 0 3em #000",
                    "box-shadow": "0 0 3em #000",
                    "width": 560
                });
                $("#overlay").overlay({
                    load: true,
                    closeOnClick: true,
                    mask: {
                        color: "#fff",
                        opacity: 0.8
                    }
                });
                $("#overlay .close").text("sluiten");
                addNavigation(); // add navigation if needed (function will add buttons if needed)
            };
            // update the gallerycache
            storeGallery();
            img.src = $(this).attr("href");
        } else {
            // always update the overlay with the new info (we only use one overlay for all images)

            // update the gallerycache; we might be jumping to a new one
            storeGallery();
            // check if navigation is already enabled!
            addNavigation();
            toggleNav();
            loadNewItem(tarimg.parents("a").attr("href"));
        }
        window.scrollTo(0, 0);
        return false;
    });
    if ($.browser.msie && $.browser.version < 8) {
        var allPhotos = $(".photos>li");

        allPhotos.each(function (i) {
            $(this).css("z-index", allPhotos.length - i);
        });
    }
    //social share
    $(".share>a.sharelink").bind("click", function (e) {
        $(this).parent().toggleClass("openshare");
        if ($.browser.msie && $.browser.version < 8) {
            $(this).parent().css({ "zoom": 1 });
        }
        return false;
    });
    $(".share>div").prepend("<a href='#' class='closeShare'>Sluiten</a>");
    $(".share .closeShare").bind("click", function (e) {
        $(this).parents(".share").removeClass("openshare");
        return false;
    });

    // readspeak toggle
    $(".reader").click(function () {
        if ($("body").hasClass("bg_small") || $("body").hasClass("small_readspeak")) {
            $("body").toggleClass("small_readspeak").toggleClass("bg_small");
            if ($("body").hasClass("home")) {
                $("body").toggleClass("home-ie6_readspeak");
            }
            return false;
        } else {
            $("body").toggleClass("big_readspeak").toggleClass("bg_big");
            return false;
        }
    });
    $("#readspeak").append("<a href='#' class='closeSpeaker'>Sluiten</a>");
    $("#readspeak .closeSpeaker").bind("click", function (e) {
        if ($("body").hasClass("bg_small") || $("body").hasClass("small_readspeak")) {
            $("body").toggleClass("small_readspeak").toggleClass("bg_small");
            return false;
        } else {
            $("body").toggleClass("big_readspeak").toggleClass("bg_big");
            return false;
        }
    });


    // print (only for javascript enabled browsers (others just just ctrl-p :)
    if (!$("body").hasClass("inlogpagina") && !$("body").hasClass("home")) {
        if ($("body").hasClass("mijnuwv") || $("body").hasClass("werkgeversportaal")) {
            $("#metanav li.last").before("<li class='print'><a href='#'>Print</a></li>");
        } else {
            $("#metanav").prepend("<li class='first print'><a href='#'>Print</a></li>");
        }
        $("li.print").click(function () {
            window.print();
        });
    }
    // small average big (only for javascript enabled browsers )
    $(document).bind("FontsizeChange", function () {
        onFontsizeChange();
        recalculteTooltips($(document));
    });
    $("#smallFont").click(function () {
        $("body").removeClass("average");
        $("body").removeClass("big");
        $("#smallFont").addClass("active");
        $("#averageFont").removeClass("active");
        $("#bigFont").removeClass("active");
        $.cookie("style", "small", { expires: 365, path: '/' });
        $(document).trigger("FontsizeChange");
    });
    $("#averageFont").click(function () {
        $("body").removeClass("big");
        $("body").addClass("average");
        $("#averageFont").addClass("active");
        $("#smallFont").removeClass("active");
        $("#bigFont").removeClass("active");
        $.cookie("style", "average", { expires: 365, path: '/' });
        $(document).trigger("FontsizeChange");
    });
    $("#bigFont").click(function () {
        $("body").removeClass("average");
        $("body").addClass("big");
        $("#bigFont").addClass("active");
        $("#smallFont").removeClass("active");
        $("#averageFont").removeClass("active");
        $.cookie("style", "big", { expires: 365, path: '/' });
        $(document).trigger("FontsizeChange");
    });
    //ie6 :hover fix
    if ($.browser.msie && $.browser.version < 7) {
        $("input:submit").bind("mouseenter mouseleave focus blur", function (e) {
            if (e.type == "focus" || e.type == "mouseenter") {
                $(this).removeClass("button").attr("class", $(this).attr("class") + "_hover").addClass("button");
                $(this).addClass("button");
            } else {
                var className = $(this).removeClass("button").attr("class");
                if (className.indexOf("_hover") > -1) {
                    className = className.substr(0, className.indexOf("_hover"));
                }
                $(this).attr("class", className);
                $(this).addClass("button");
            }
        });
    }
    // mac background fix
    pl = navigator.platform;
    if (pl.indexOf("Mac") != -1) {
        $("body").addClass("mac");
    }
    // open taf box
    $("a[rel]").overlay({
        closeOnClick: false,
        mask: {
            color: '#fff',
            opacity: 0.8
        }
    });
    var div = $("#taf");
    div.css({
        "-moz-box-shadow": "0 0 3em #000",
        "-webkit-box-shadow": "0 0 3em #000",
        "box-shadow": "0 0 3em #000"
    });

    $(".news").bind("mouseenter mouseleave", function (e) {
        if (e.type == "mouseenter") {
            $(this).addClass("newshover");
        } else {
            $(this).removeClass("newshover");
        }
    });
    $(".news").bind("click", function () {
        window.location.href = $(this).find("a").attr("href");
    });
    // moreInfo overlay
    $("a.extraInfoLink").bind("mouseenter mouseleave click", function () {
        var target = $(this).attr("href");
        $(target).css({
            "left": $(this).position().left + (($.browser.msie && $.browser.version > 7) ? 40 : 20)
        });
        $(target).toggle();
        return false;
    });
    if (!$.browser.safari) {
        $(".block").each(function () {
            var fieldsets = $(this).find("fieldset");
            var amount = fieldsets.length;
            if (amount > 1) {
                fieldsets.each(function (i) {
                    $(this).css({
                        "z-index": amount - i
                    });
                });
            }
        });
    }
    if ($.browser.safari) {
        $("fieldset legend").addClass("safariLegend");
        $(".form fieldset").addClass("safariFieldset");
    }
    $(".share").wrap("<div class='clearboth' />");
    $("input[type=text]").focus(function () {
        focussedID = $(this).attr('id');
    });
    $("input[type=text][id*='Search']").each(function (i, e) {
        $(this).bind("keydown", function (e) {
            if (e.keyCode == '13') {
                var button = '#' + focussedID.replace('_txt', '_btn');
                $(button).focus();
                $(button).click();
            }
        });
    });

    $("input[type=submit][id*='Search']").each(function (i, e) {
        $(this).bind("submit click", function (e) {
            var re = new RegExp('(&#)|(<(?=(!|\\w|\\%|/)))', 'g');
            var text = '#' + $(this).attr("id").replace('_btn', '_txt');
            $(text).val($(text).val().replace(re, ''));
            $(text).val($(text).val().replace('<', ''));
            $(text).val($(text).val().replace('>', ''));
            $(text).val($(text).val().replace(':', ''));
            $(text).val($(text).val().replace('?', ''));
        });
    });

    // Webforms vergroten van Textarea	
    $("textarea.InputType2").each(function () {
        $(this).height($(this).attr("rows") * 20 - 20);
    });

    // Webforms vergroten van linker helft tov rechterhelft (!IE)
    $("div>div.RadioButtonListLeft").each(function () {
        $(this).height($(this).next().height());
    });
    if ($(".carrousel").length > 0) {
        extendTabbedContent();
    }
    if ($(".tabbedcontent").length > 0) {
        setTabbedContent();
    }
    if ($("input.date").length > 0) {
        addDatePicker();
    }
    if ($(".sortable").length > 0) {
        addSort();
    }
    if ($(".tableview .withdetails .link a").length > 0) {
        addTableToggle();
    }
    if ($(".verticalform").length > 0) {
        addSimpleFormValidation();
    }
    if ($(".notice").length > 0) {
        addCloseToNoticeBlock();
    }
    if ($("#faqLink, .directFAQ").length > 0) doFaqPopin();
    
    $(".inverse li:has(a)").bind("mouseover mouseout", function (e) {
        if (e.type == "mouseover") {
            $(this).addClass("hover");
            $(this).css("cursor", "pointer");
        } else {
            $(this).removeClass("hover");
        }
    });
    
    $(".inverse:has(a):not(.relatedResults) li, .loggedin li").click(function () {
        document.location.href = $(this).find("a").attr("href");
    });
    $(".colourfull li").bind("mouseover mouseout", function (e) {
        if (e.type == "mouseover") {
            $(this).addClass("hover");
        } else {
            $(this).removeClass("hover");
        }
    });
    $(".colourfull li").click(function () {
        if ($(this).find("a").attr("href") !== undefined) {
            document.location.href = $(this).find("a").attr("href");
        }
    });
    // aansluitnummerzoeker toggle
    $("a[href=#aansluitnummerzoeker]").click(function () {
        $($(this).attr("href")).toggle();
        return false;
    });

    $(".printGuide").html("<a href='#'>Print stappenplan</a>");
    $(".printGuide a").click(function () {
        window.print();
        return false;
    });

    if ($(".guideTable").length > 0) {
        addGuide();
    }
    //Highlight search terms when entering website from Google
    googlehighlight();

    //Apply all acronyms published from Tridion
    applyAcronyms();

    if ($(".mijnuwv").length > 0) doMijnUwv();

    if ($(".werkgeversportaal").length > 0) doWerkgeversPortaal();

    if ($.browser.msie && $.browser.version == 6) {
        if (!$("#right").next().hasClass("clear")) $("#right").after("<div class='clear'>&nbsp;</div>")
    }
    $(".searchResults .result").each(function () {
        $(this).bind("mouseenter mouseleave", function (e) {
            (e.type == "mouseenter") ? $(this).addClass("hover") : $(this).removeClass("hover");
        });
        $(this).click(function () {
            document.location.href = $(this).find(">h2>a").attr("href");
        });
    });

    $(".withTitle").each(function () {
        var $origin = $(this);
        $origin.after("<div class='tooltip abbr'><span class='pointer'></span><p>" + $(this).attr("title") + "</p></div>");
        $origin.next().css({
            "left": $origin.width() + 10
        });
        $origin.attr("title", "");
        $origin.bind("mouseenter mouseleave", function (e) {
            if (e.type == "mouseenter") {
                $(this).next().show();

            } else {

                $(this).next().hide();

            }
        });
    });

    $("#left .selectType .searchPerson").click(function () {
        $(this).parent().hide();
        $($(this).attr("href")).fadeIn("fast");
        return false;
    });
    $("#findEmployee .cancel").click(function () {
        var $block = $(this).parents("#findEmployee");
        $block.fadeOut("fast");
        $block.prev().show();
        return false;
    });

    $(".toggleTable h2").click(function () {
        $(this).toggleClass("open").next().toggle();
    });

    // add pointer to tooltips
    $(".tooltip").each(function () {
        if ($(".pointer", $(this)).length == 0) {
            $(this).prepend("<span class='pointer'>&nbsp;</span>");
        }
    });
    
});
function go_acronyms(keyvalues) {
	 if (keyvalues != '') {
		keyvalues = keyvalues.replace(/\"/g, "");
		var keyvaluepair = keyvalues.split('$');
		for (var i = 0; i < keyvaluepair.length; i++) {
		  var keyvalue = keyvaluepair[i].split('#');
		  var key = keyvalue[0];
		  var value = keyvalue[1];
		  addAcronyms(key, document.getElementById("left"), value);
		}
	 }
}
function addAcronyms(term, container, explanation, found) {
	 var term_low = term.toLowerCase();
	 for (var i = 0; i < container.childNodes.length; i++) {
		var node = container.childNodes[i];

		if (node.nodeType == 3 && !found) {
		  var data = node.data;
		  var data_low = data.toLowerCase();
		  if (data_low.indexOf(term_low) != -1) {
			 //term found!
			 found = true;
			 var new_node = document.createElement('span');
			 node.parentNode.replaceChild(new_node, node);
			 var result;
			 while ((result = data_low.indexOf(term_low)) != -1) {
				new_node.appendChild(document.createTextNode(data.substr(0, result)));
				new_node.appendChild(create_acronym_node(document.createTextNode(data.substr(result, term.length)), explanation));
				data = data.substr(result + term.length);
				data_low = data_low.substr(result + term.length);
			 }
			 new_node.appendChild(document.createTextNode(data));
		  }
		} else {
		  //recurse
		  if (!found)
			 found = addAcronyms(term, node, explanation, found);
		}
		if (found) {
		  return true;
		}
	 }
}
function create_acronym_node(child, explanation) {
	 var node = document.createElement('acronym');
	 node.title = explanation;
	 node.appendChild(child);
	 return node;
}
var recalculteTooltips = function (container) {
    $(".tooltip", container).each(function () {

        $(this).css("left", $(this).prev().width() + 10);

    });
};
var setTabbedContent = function () {
	 var excecute = function () {
		var activeTab = $(".tabbedcontent .tabs li.active a").attr("href");
		$(".tabbedcontent .content").hide();
		$(activeTab).show();
	 };
	 $(".tabbedcontent .tabs a").click(function () {
		$(this).parents("ol").find("li").removeClass("active");
		$(this).parent().addClass("active");
		excecute();
		return false;
	 });
	 excecute();
}
var extendTabbedContent = function () {
	 var excecute = function () {
		var activeTab = $(".tabbedcontent .tabs li.active a").attr("href");
		$(".tabbedcontent .content").hide();
		$(activeTab).show();
	 };
	 $(".carrousel .tabs li:first").addClass("active");
	 $(".carrousel .tabs a").bind("mouseenter", function () {
		$(this).parents("ol").find("li").removeClass("active");
		$(this).parent().addClass("active");
		excecute();
	 });
	 var height = 0;
	 $(".carrousel .content").each(function () {
		height = Math.max(height, $(this).height());
	 });
	 $(".carrousel .content").each(function () {
		$(this).height(height);
	 });
}
var addDatePicker = function () {
    $.dpText = {
        TEXT_CLOSE: 'Kies een datum <span>X</span>',
        TEXT_CHOOSE_DATE: 'Kies een datum'
    };
    Date.firstDayOfWeek = 1;
    Date.format = 'dd-mm-yyyy';
    $("input.date").each(function () {
		if($(this).val() != "")
		{
			$(this).datePicker({
				startDate: '01/01/1970',
				endDate: new Date(),
				displayClose: true
			}).dpSetOffset(-117, 20);
		}
		else
		{
			var datum = new Date();
			datum.setFullYear(datum.getFullYear() - 1);
			$(this).datePicker({
				startDate: '01/01/1970',
				endDate: new Date(),
				displayClose: true,
				year: (($(this).parent(".daterow").length > 0) ? datum.getFullYear() : new Date().getFullYear())
			}).dpSetOffset(-117, 20);
		}
    });
    $("input.date").click(function () {
        $(this).next().click();
    });
    $("input.date").bind("focus blur", function (e) {
        if (e.type == "focus") {
            $(this).parent().find(".dateExample").css("display", "inline-block");
        } else {
            $(this).parent().find(".dateExample").hide();
        }
    });
};
var addTableToggle = function () {
    $(".tableview .withdetails .link a").live("click", function () {
        var target = $(this).attr("href");
        if ($("body").hasClass("werkgeversportaal")) {
            if (!$(this).hasClass("cancel")) {
                $(target).find("td").fadeIn();
                $(this).parent().find(".edit, .remove, .request, .check").hide();
                $(this).parent().find(".cancel").show();
            } else {
                $(this).closest("tr").siblings().find(">td").hide();
                $(this).parent().find(".edit, .remove, .request, .check").show();
                $(this).parent().find(".cancel").hide();
            }
        } else {
            if (!$(this).hasClass("open")) {
                $(this).addClass("open");
                if ($("body").hasClass("particulieren")) {
                    $(this).text("Meer informatie verbergen");
                } else {
                    $(this).text("Sluit gegevens");
                }
                $(target).find("td").fadeIn();
            } else {
                $(this).removeClass("open");
                if ($("body").hasClass("particulieren")) {
                    $(this).text("Meer informatie");
                } else {
                    $(this).text("Toon gegevens");
                }
                $(target).find("td").fadeOut();
            }
        }
        return false;
    });
    $(".tableview .withdetails .details a.cancel").live("click", function () {
        var firstTr = $(this).closest("table").find("tr:first");
        firstTr.siblings().find(">td").hide();
        firstTr.find(".edit, .remove, .request").show();
        firstTr.find(".cancel").hide();
        return false;
    });


    // align tableview table in werkgeversportaal
    $("thead", ".werkgeversportaal .tableview").each(function () {
        var table = $(this).parent();
        $("th", $(this)).each(function (i) {
            $(this).width($(this).width());
            if ($(this).hasClass("link") && $(this).width() > 130) {
                // reset th widths
                $(this).parent().find(">th").css("width", "auto");
                $(this).width(130);
            }
        });
    });
    $("tbody", ".werkgeversportaal .tableview .withdetails").each(function (i) {
        var table = $(this).parents(".tableview>table");
        $("tr:first td", $(this)).each(function (i) {
            $(this).width($("thead th:nth-child(" + (i + 1) + ")", table).width());
            if ($(this).hasClass("link")) {
                if ($(this).width() !== $("thead th:nth-child(" + (i + 1) + ")", table).width()) {
                    $(this).width($("thead th:nth-child(" + (i + 1) + ")", table).width());
                }
            }
        });
    });
    $("tbody", ".werkgeversportaal .tableview td:not(.withdetails)").each(function (i) {
        var table = $(this).parents(".tableview>table");
        $("tr:first td", $(this)).each(function (i) {
            $(this).width($("thead th:nth-child(" + (i + 1) + ")", table).width());
            if ($(this).hasClass("link")) {
                if ($(this).width() !== $("thead th:nth-child(" + (i + 1) + ")", table).width()) {
                    $(this).width($("thead th:nth-child(" + (i + 1) + ")", table).width());
                }
            }
        });
    });
};
var addSimpleFormValidation = function () {
    var EMAILFIELD = "Dit veld is geen correct e-mail adres.";
    var TEXTFIELD = "Dit veld is verplicht en mag geen leestekens bevatten.";
    var TEXTNUMBERFIELD = "Dit veld is verplicht en mag geen leestekens bevatten.";
    var NUMBERFIELD = "Dit veld mag alleen getallen bevatten.";
    var CONTACTFIELD = "Dit veld bevat geen geldig aansluitnummer.";
    var PHONEFIELD = "Dit veld bevat geen geldig telefoonnummer.";
    var BANKFIELD = "Dit veld bevat geen geldig bankrekeningnummer.";
    var PARTNERFIELD = "De twee velden komen niet overeen.";
    var POSTALCODEFIELD = "Dit veld bevat geen geldige postcode";
    var PASSWORDFIELD = "Dit wachtwoord is niet sterk genoeg";
    var RANGEFIELD = "Dit is geen geldige periode";

    var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
    var telephonePatern = /^0[1-9][0-9]{8}$/;
    var postalcodePatern = /^[0-9]{4} ?[a-zA-Z]{2}$/;
    var textPattern = /^.[a-zA-Z.-]*$/;
    var textNumberPattern = /^.[a-zA-Z0-9]*$/;

    var checkMandatory = function (testString) {
        return testString.length !== 0;
    };
    var checkText = function (test) {
        var isNotEmpty = textPattern.test(test.val());
        var isMandatory = (test.hasClass("mandatory")) ? true : false;
        if (isMandatory) {
            return isNotEmpty;
        } else {
            return true;
        }
    };

    var checkNumberText = function (test) {
        var isMandatory = test.hasClass("mandatory");
        if (isMandatory && test.val().length > 0) {
            return textNumberPattern.test(test.val());
        } else if (test.val().length == 0 && !isMandatory) {
            return true;
        } else {
            return false;
        }
    };

    var checkEmail = function (testString) {
        return emailPattern.test(testString);
    };
    var checkNumber = function (testString) {
        return !isNaN(testString) && checkMandatory(testString); // true = a number
    };
    var checkContactNumber = function (testString) {
        return checkNumber(testString) && testString.length == 15;
    };
    var checkPhoneNumber = function (test) {
        var testString = test.val();
        testString = testString.replace(/ /g, ""); //remove spaces
        testString = testString.replace(/-/g, ""); // remove -
        testString = testString.replace(/\+/g, ""); // remove +
        testString = testString.replace(/\(/g, ""); // remove (
        testString = testString.replace(/\)/g, ""); // remove )
        var isMandatory = (test.hasClass("mandatory")) ? true : false;
        if (isMandatory) {
            return telephonePatern.test(testString); ;
        } else if (testString.length == 0) {
            return true;
        } else {
            return false;
        }
    };
    var checkBankAccount = function (test) {
        var testString = test.val();
        testString = testString.replace(/ /g, ""); //remove spaces
        testString = testString.replace(/-/g, ""); // remove -
        testString = testString.replace(/\+/g, ""); // remove +
        testString = testString.replace(/\(/g, ""); // remove (
        testString = testString.replace(/\)/g, ""); // remove )
        var isMandatory = (test.hasClass("mandatory")) ? true : false;
        if (isMandatory) {
            if (isNaN(testString)) {

                return false;
            } else if (testString.length == 1 || testString.length == 2 || testString.length == 8 || testString.length > 10) {
                return false;
            } else {
                return true;
            }
            //return ()
        } else if (testString.length == 0) {
            return true;
        } else if (testString.length == 1 || testString.length == 2 || testString.length == 8 || testString.length > 10) {
            return false;
        } else {
            return true;
        }
    };
    var checkPartner = function (testString, testString2) {
        return testString == testString2 && checkMandatory(testString);
    };
    var checkPostalCode = function (testString) {
        return postalcodePatern.test(testString);
    };
    var checkPassword = function (testString) {
        var checked = 0;
        var upper = /[A-Z]+/;
        var lower = /[a-z]+/;
        var number = /[0-9]+/;
        var special = /[\W]+/;

        if (upper.test(testString)) {
            checked++;
        }
        if (lower.test(testString)) {
            checked++;
        }
        if (number.test(testString)) {
            checked++;
        }
        if (special.test(testString)) {
            checked++;
        }
        if (checked > 2) {
            return true;
        } else {
            return false;
        }
    };

    var checkRange = function (date0, date1) {
        var ar0 = date0.val().split("-");
        var ar1 = date1.val().split("-");

        var d0 = new Date(ar0[2], (ar0[1] - 1), ar0[0]);
        var d1 = new Date(ar1[2], (ar1[1] - 1), ar1[0]);

        if (date0.hasClass("low")) {
            return d1 >= d0;
        } else {
            return d0 >= d1;
        }
    };

    $(".verticalform .text, .verticalform .password").blur(function () {
        var $form = $(this).parents(".verticalform");
        if ($(this).hasClass("password") && $(this).parent().parent().find(".failtext").length == 0) {
            $(this).parent().parent().prepend("<div class='failtext'>&nbsp;</div>");
        } else if (!$(this).hasClass("password") && $(this).parent().hasClass("cell") && $(this).parent().parent().find(".failtext").length == 0) {
            $(this).parent().parent().prepend("<div class='failtext'>&nbsp;</div>");

        } else if (!$(this).hasClass("password") && !$(this).parent().hasClass("cell") && $(this).parent().find(".failtext").length == 0) {
            $(this).parent().prepend("<div class='failtext'>&nbsp;</div>");
        }
        // hide serverside checks
        $(this).parent().addClass("clientCheck");

        // check textfield
        if ($(this).hasClass("text")) {
            if (checkText($(this))) {
                $(this).parents(".row").removeClass("fail");
                $(this).parents(".row").find(".failtext").hide();
            } else {
                $(this).parents(".row").removeClass("check").addClass("fail");
                $(this).parents(".row").find(".failtext").text(TEXTFIELD).show();
            }
        }

        //check partner
        if ($(this).hasClass("partner")) {
            var classes = $(this).attr("class");
            var partnerof = classes.substring(classes.indexOf("partnerof-") + 10);
            if (partnerof.indexOf(" ") > -1) {
                partnerof = partnerof.substring(0, partnerof.indexOf(" "));
            }
            if ($("#" + partnerof).hasClass("password") && !checkPassword($("#" + partnerof).val())) {
                $(this).parents(".row").removeClass("check").addClass("fail");
                $(this).parents(".row").find(".failtext").text(PASSWORDFIELD).show();
                $("#" + partnerof).parents(".row").removeClass("check").addClass("fail");
                $("#" + partnerof).parents(".row").find(".failtext").text(PASSWORDFIELD).show();
            } else
                if ($("#" + partnerof).val() == "" || checkPartner($(this).val(), $("#" + partnerof).val())) {
                    $(this).parents(".row").removeClass("fail");
                    $("#" + partnerof).parents(".row").removeClass("fail");
                    $(this).parents(".row").find(".failtext").hide();
                    $("#" + partnerof).parents(".row").find(".failtext").hide();
                } else {
                    $(this).parents(".row").removeClass("check").addClass("fail");
                    $("#" + partnerof).parents(".row").removeClass("check").addClass("fail");
                    $(this).parents(".row").find(".failtext").text(PARTNERFIELD).show();
                }
        }

        // check if partnerfield is correct
        var $partnerfield = $(".partnerof-" + $(this).attr("id"));
        if ($partnerfield.length > 0) {
            if (checkPartner($(this).val(), $partnerfield.val())) {
                $(this).parents(".row").removeClass("fail");
                $partnerfield.parents(".row").removeClass("fail");
                $(this).parents(".row").find(".failtext").hide();
                $partnerfield.parents(".row").find(".failtext").hide();
            } else {
                $(this).parents(".row").removeClass("check").addClass("fail");
                $partnerfield.parents(".row").removeClass("check").addClass("fail");
                $(this).parents(".row").find(".failtext").text(PARTNERFIELD).show();
            }
        }

        // check email field
        if ($(this).hasClass("email")) {
            if (checkEmail($(this).val())) {
                $(this).parent().removeClass("fail");
                $(this).parent().find(".failtext").hide();
            } else {
                $(this).parent().removeClass("check").addClass("fail");
                $(this).parent().find(".failtext").text(EMAILFIELD).show();
            }
        }

        //check number field
        if ($(this).hasClass("number")) {
            if (checkNumber($(this).val())) {
                $(this).parent().removeClass("fail");
                $(this).parents(".row").find(".failtext").hide();
            } else {
                $(this).parent().removeClass("check").addClass("fail");
                $(this).parents(".row").find(".failtext").text(NUMBERFIELD).show();
            }
        }

        //check text-number field
        if ($(this).hasClass("textNumber")) {
            if (checkNumberText($(this))) {
                $(this).parent().removeClass("fail");
                $(this).parent().find(".failtext").hide();
            } else {
                $(this).parent().removeClass("check").addClass("fail");
                $(this).parent().find(".failtext").text(TEXTNUMBERFIELD).show();
            }
        }

        //check contactfield
        if ($(this).hasClass("contactnumber")) {
            if (checkContactNumber($(this).val())) {
                $(this).parent().removeClass("fail");
                $(this).parent().find(".failtext").hide();
            } else {
                $(this).parent().removeClass("check").addClass("fail");
                $(this).parent().find(".failtext").text(CONTACTFIELD).show();
            }
        }

        //check phonenumber
        if ($(this).hasClass("telephone")) {
            if (checkPhoneNumber($(this))) {
                $(this).parent().removeClass("fail");
                $(this).parent().find(".failtext").hide();
            } else {
                $(this).parent().removeClass("check").addClass("fail");
                $(this).parent().find(".failtext").text(PHONEFIELD).show();
            }
        }

        //check phonenumber
        if ($(this).hasClass("bankaccount")) {
            if (checkBankAccount($(this))) {
                $(this).parent().removeClass("fail");
                $(this).parent().find(".failtext").hide();
            } else {
                $(this).parent().removeClass("check").addClass("fail");
                $(this).parent().find(".failtext").text(BANKFIELD).show();
            }
        }

        //check dateRange
        if ($(this).hasClass("dateRange")) {
            var classes = $(this).attr("class");
            var partnerof = classes.substring(classes.indexOf("dateRangeOf-") + 12);
            partnerof = partnerof.substring(0, partnerof.indexOf(" "));
            if ($("#" + partnerof).val() == "" || checkRange($(this), $("#" + partnerof))) {
                $(this).parents(".row").removeClass("fail");
                $("#" + partnerof).parents(".row").removeClass("fail");
                $(this).parents(".row").find(".failtext").hide();
                $("#" + partnerof).parents(".row").find(".failtext").hide();
            } else {
                $(this).parents(".row").removeClass("check").addClass("fail");
                $("#" + partnerof).parents(".row").removeClass("check").addClass("fail");
                $(this).parents(".row").find(".failtext").text(RANGEFIELD).show();
            }
        }

        // check postalcode
        if ($(this).hasClass("postalcode")) {
            if (checkPostalCode($(this).val())) {
                $(this).parent().removeClass("fail");
                $(this).parent().find(".failtext").hide();
            } else {
                $(this).parent().removeClass("check").addClass("fail");
                $(this).parent().find(".failtext").text(POSTALCODEFIELD).show();
            }
        }

    });
    $(".verticalform input[type!=submit], .verticalform textarea").focus(function () {
        $(this).parent().find(".tooltip").show();
    });
    $(".verticalform input, .verticalform textarea").blur(function () {
        $(this).parent().find(".tooltip").hide();
    });

    var setCurrentPasswordStrength = function (c) {
        var regLower = /^[a-z]/;
        var regUpper = /^[A-Z]/;
        var regNumber = /^[0-9]/;
        var regexp = /^[\W]/;

        if (regLower.test(c)) currentPassword.hasLower = true;
        if (regUpper.test(c)) currentPassword.hasUpper = true;
        if (regNumber.test(c)) currentPassword.hasNumber = true;
        if (regexp.test(c)) currentPassword.hasSpecial = true;
    };

    $(".verticalform .password").keyup(function (e) {
        currentPassword = window.currentPassword || new Object();

        var str = $(this).val();
        if (e.keyCode == 8) {
            // backspace removes the last Char so check which chars are currently used in the password thusfar
            // firstly reset the passwordStrengthObject
            currentPassword.hasNumber = false;
            currentPassword.hasLower = false;
            currentPassword.hasUpper = false;
            currentPassword.hasSpecial = false;
            for (var i = 0; i < str.length; i++) {
                setCurrentPasswordStrength(str.substring(i, i + 1));
            }
        } else {
            setCurrentPasswordStrength(str.substring(str.length - 1));
        }
        var tooltip = $(this).parent().find(".tooltip");
        if ($(this).val().length == 0) {
            tooltip.removeClass("small").removeClass("missing").removeClass("strong").addClass("none").html("<p>Tips om uw wachtwoord sterk genoeg te maken: gebruik minimaal 3 van de 4 volgende verschillende tekens: Een of meerdere hoofdletter(s), kleine letter(s), cijfer(s) en een symbool.</p>");
        } else if ($(this).val().length < 7) {
            tooltip.removeClass("none").removeClass("missing").removeClass("strong").addClass("small").html("<p>Om uw wachtwoord sterk genoeg te maken gebruikt u nog een of meerdere hoofdletter(s), kleine letter(s), cijfer(s) en een symbool.</p>");
        } else {
            if (!currentPassword.hasNumber || !currentPassword.hasLower || !currentPassword.hasUpper || !currentPassword.hasSpecial) {
                var missing = "";
                var missingI = 0;
                if (!currentPassword.hasNumber) {
                    missing += "nummer ";
                    missingI++;
                }
                if (!currentPassword.hasLower) {
                    missing += "kleine letter ";
                    missingI++;
                }
                if (!currentPassword.hasUpper) {
                    missing += "hoofdletter ";
                    missingI++;
                }
                if (!currentPassword.hasSpecial) {
                    missing += "speciaal karakter ";
                    missingI++;
                }
                if (missingI == 1) {
                    tooltip.removeClass("none").removeClass("missing").removeClass("small").addClass("strong").html("<p>Uw wachtwoord is sterk genoeg.</p>");
                } else {
                    tooltip.removeClass("none").removeClass("small").removeClass("strong").addClass("missing").html("<p>Om uw wachtwoord sterk genoeg te maken moet u nog een " + missing + " gebruiken.</p>");
                }
            } else {
                tooltip.removeClass("none").removeClass("missing").removeClass("small").addClass("strong").html("<p>Uw wachtwoord is sterk genoeg.</p>");
            }
        }
    });
    $(".verticalform .password").bind("focus blur", function (e) {
        $(this).parent().toggleClass("activePasswordRow");
    });
};
var addCloseToNoticeBlock = function () {
	 $(".notice, .errorblock").each(function () {
		$(this).prepend("<a class='close' href='#'>sluiten</a>");
		$(this).find(".close").click(function () {
		  $(this).parent().fadeOut("slow");
		  return false;
		});
	 });
}

var onFontsizeChange = function () {
	 if ($(".carrousel").length > 0) {
		$(".carrousel .content").height("auto");
		var height = 0;
		$(".carrousel .content").each(function () {
		  height = Math.max(height, $(this).height());
		});
		$(".carrousel .content").each(function () {
		  $(this).height(height);
		});
	 }
	 synchIntroHeights();
}

function initCarrousel() {

	 var items = $("#carrousel li").length;
	 var additionalSettings = {
		timerContainer: "#controls",
		delay: 12000
	 };
	 $("#carrouselNav").empty();
	 var navigItems = new Array();

	 $("#carrousel li").each(function (i) {
		i++;
		$(this).addClass("item-" + i);
	 });

	 // build the navigation according to the amount of items found
	 for (var i = 0; i < items; i++) {
		var counter = (i + 1);
		$("#carrouselNav").append("<li class='li-item-" + counter + "'><a href=''></a></li>");
		navigItems[i] = "#carrouselNav li[class=li-item-" + counter + "]"; // we need this for jCarouselLite's btnGo var
	 }
	 
	 // animated timer
	 $(additionalSettings.timerContainer).append("<div id='timer'></div>");
	 var timerWidth = $("#carrouselNav").width();
	 startTimer = function() {
		$("#timer").stop().animate({
		  width: timerWidth
		}, additionalSettings.delay);
	 };	 
	
	 // let jCarouselLite do its thing
	 $("#carrousel").jCarouselLite({
		auto: additionalSettings.delay,
		speed: 1000,
		hoverPause: true,
		pauseButton: '.pause',
		btnNext: '.next',
		btnPrev: '.prev',
		btnGo: navigItems,
		circular: true,
		visible: 1,
		beforeStart: function (el) {
		  $("#carrouselNav li").removeClass("on");
		  $("#timer").stop().css("width", "0");
		},
		afterEnd: function (el) {
		  var elementID = $(el[0]).attr("class");
		  $("#carrouselNav li[class=li-" + elementID + "]").addClass("on");
		  if (!$(".pause").hasClass("on")) {
			 startTimer();
		  };
		}

	 });
	 startTimer();

	 // some graphical changes
	 $("#carrouselNav li:first").addClass("on");


 /*
	 var carrouselitems = new Object();
	 $("#carrousel li").each(function () {
		carrouselitems[$(this).attr("class")] = $(this);
	 });
	 for (itm in carrouselitems) {
		carrouselitems[itm].addClass("print");
	 }
	
	 $("#carrousel").append("<ul class='print' />");
	 for (item in carrouselitems) {
	 $("#carrousel ul.print").append(carrouselitems[item]);
	 }
	 */
}
function synchIntroHeights() {
	 $("body.particulierenHome #secties .block").css("height", "auto");
	 $("body.particulierenHome #secties .block:last").addClass("last");
	 var highestElement = 0;
	 $("body.particulierenHome #secties .block").each(function () {
		if ($(this).height() > highestElement) {
		  highestElement = $(this).height();
		}
	 });
	 $("body.particulierenHome #secties .block").css("height", highestElement);

}
var addGuide = function () {

	var fillGuide = function (obj) {
	        var startArray = obj.val().split("-");
	        var startdatum = new Date(startArray[2], startArray[1] - 1, startArray[0], 0, 0, 0, 0);
	        if (startArray[0] != startdatum.getDate() || startArray[1] != startdatum.getMonth() + 1 || startArray[2] != startdatum.getFullYear()) {
	            // input date != calculated date so it's wrong
	            obj.parent().addClass("error");
	        } else {
	            obj.parent().removeClass("error");
		        $(".guideTable .datum").each(function (i) {
		            var timespan = $("#hfactie" + i).val();
			    var datum = new Date(startArray[2], startArray[1] - 1, startArray[0], 0, 0, 0, 0);
		
		            switch (timespan.substring(timespan.length - 1)) {
		                case "d":
		                    datum.setDate(startdatum.getDate() + Number(timespan.substring(0, timespan.length - 1)));
		                    break;
		                case "m":
		                    datum.setMonth(startdatum.getMonth() + Number(timespan.substring(0, timespan.length - 1)));
		                    break;
		                case "y":
		                    datum.setFullYear(startdatum.getFullYear() + Number(timespan.substring(0, timespan.length - 1)));
		                    break;
		                default:
		                    break;
		            }
		            $(this).text(datum.getDate() + "-" + Number(datum.getMonth() + 1) + "-" + datum.getFullYear());
		            $(this).css("display", "block");
		        });
		}
	}

	 $(".guideTable").closest(".block").find("input[class*='date']").bind("change", function () {
		fillGuide($(this));
	 });
	 if ($(".guideTable").closest(".block").find("input[class*='date']").val() != "") {
		fillGuide($(".guideTable").closest(".block").find("input[class*='date']"));
	 }
};
var showAboutToTimeOut = function () {
	 $("#aboutToTimeOut").css({
		"-moz-box-shadow": "0 0 3em #000",
		"-webkit-box-shadow": "0 0 3em #000",
		"box-shadow": "0 0 3em #000"
	 });

	 var api = $("#aboutToTimeOut").data("overlay");
	 if (api != null) {
		api.load();
	 } else {

		$("#aboutToTimeOut").overlay({
		  load: true,
		  closeOnClick: false,
		  mask: {
			 color: "#fff",
			 opacity: 0.8
		  }
		});
	 }	
	 var timeToGo = 60; // in seconds
	 $("#aboutToTimeOut .timer").text(timeToGo + " seconden");
	 var timer = setInterval(function () {
		timeToGo -= 1;
		if (timeToGo < 1) {
		  showTimedOut();
		  clearTimeout(sessionTimeoutThread);
		  clearTimeout(timer);
		} else {
		  $("#aboutToTimeOut .timer").text((timeToGo == 1) ? timeToGo + " seconde" : timeToGo + " seconden");
		}
	 }, 1000);
	 $("#extendSession").click(function () {
		// get a file to extend the session
		$.get("widgets/ziek.html", function () {
		  clearTimeout(sessionTimeoutThread);
		  clearTimeout(timer);
		  // reset the timeout
		  sessionTimeoutThread = setTimeout(function () {
			 showAboutToTimeOut();
		  }, sessionTimeout - 60);
		  // remove the popin
		  var api = $("#aboutToTimeOut").data("overlay");
		  api.close();
		});
	 });
	 $("#endSession").click(function () {
		// get a file to end the session
		$.get("widgets/ziek.html", function () {
		  clearTimeout(sessionTimeoutThread);
		  clearTimeout(timer);
		  // redirect to the pre-loggedin page (should this be the content of the logout service?)
		  document.location.href = $(this).attr("href");
		});
	 });
};
var showTimedOut = function () {
	 $("#TimeOut").css({
		"-moz-box-shadow": "0 0 3em #000",
		"-webkit-box-shadow": "0 0 3em #000",
		"box-shadow": "0 0 3em #000"
	 });

	 var api = $("#aboutToTimeOut").data("overlay");
	 if (api != null) {
		api.close();
	 }

	 $("#TimeOut").overlay({
		load: true,
		closeOnClick: false,
		mask: {
		  color: "#fff",
		  opacity: 0.8
		}
	 });
	 setTimeout(function () {
		$("#TimeOut").css("z-index", 10000);
		$("#exposeMask").show();
	 }, 500);

	 $("#renewSession").click(function () {
		// redirect to the pre-loggedin page
		document.location.href = $(this).attr("href");
	 });
	 $("#endSession2").click(function () {
		// redirect to the pre-loggedin page (should this be the content of the logout service?)
		document.location.href = $(this).attr("href");
	 });
};

var sessionTimeout = 30 * 60 * 1000; // in minutes

var sessionTimeoutThread = setTimeout(function () {
	 // session is about to timeout
		showAboutToTimeOut();
	 }, sessionTimeout - 60);

var doFaqPopin = function () {
	 $("#faqPopin").css({
		"-moz-box-shadow": "0 0 3em #000",
		"-webkit-box-shadow": "0 0 3em #000",
		"box-shadow": "0 0 3em #000",
		"behavior": "none"
	 });
	 $("#faqLink").click(function () {

		var api = $("#faqPopin").data("overlay");
		if (api != null) {
		  api.load();
		} else {

		  $("#faqPopin").overlay({
			 load: true,
			 closeOnClick: true,
			 top: 100,
			 mask: {
				color: "#fff",
				opacity: 0.8
			 }
		  });
		  $("#faqPopin .close").text("sluiten");
		}
		setTimeout(function () {
		  $("body").append($("#faqPopin"));
		});
		return false;
	 });
	 $(".directFAQ a").click(function () {
		var api = $("#faqPopin").data("overlay");
		if (api != null) {
		  api.load();
		} else {

		  $("#faqPopin").overlay({
			 load: true,
			 closeOnClick: true,
			 top: 100,
			 mask: {
				color: "#fff",
				opacity: 0.8
			 }
		  });
		  $("#faqPopin .close").text("sluiten");
		}
		setTimeout(function () {
		  $("body").append($("#faqPopin"));
		});
		$("#faqPopin li>a[href=" + $(this).attr("href") + "]").click();
		return false;
	 });
	 $("#faqPopin li>a").click(function () {
		if ($($(this).attr("href")).css("display") !== "block") {
		  $("#faqPopin .answer").slideUp("fast");
		  $("#faqPopin>ul>li").removeClass("open");
		  $($(this).attr("href")).slideDown("fast");
		  $(this).parent().addClass("open");
		}
		return false;
	 });
};

var doMijnUwv = function () {
    var zebra = function (obj) {
        obj.each(function () {
            $(this).find(">tbody>tr").each(function (i) {
                if (i % 2 == 1) {
                    $(this).addClass("alt");
                }
            });
        });
    };

    var zebra3 = function (obj) {
        obj.each(function () {
            $(this).find(">tbody>tr").each(function (i) {
                if (i % 6 > 2) {
                    $(this).addClass("alt");
                }
            });
        });
    };

    var dropshadow = function (obj) {
        $(obj).css({
            "box-shadow": "2px 2px 5px #aaaaaa",
            "position": "relative",
            "behavior": "url(../systeem/diversen/PIE.htc)"
        });
    };

    var hover = function (obj) {
        obj.bind("mouseenter mouseleave", function (e) {
            if (e.type == "mouseenter") {
                $(this).addClass("hover");
            } else {
                $(this).removeClass("hover");
            }
        });
    };

    var doWorkedWeek = function () {
        $(".workedWeek").each(function () {
            // add rounded corners to the inputs
            $("input[type=text], select", $(this)).css({
                "border-radius": "5px",
                "behavior": "url(../systeem/diversen/PIE.htc)"
            });
            
            // check if week needs to be shown
            $("#workedWeeks input:checked").each(function () {
                $("." + $(this).attr("id")).show();
            });
            if ($(this).hasClass("show")) $(this).show();
            // show / hide workedWeeks
            $("#workedWeeks input").click(function () {
                if ($(this).attr("checked")) {
                    $("." + $(this).attr("id")).fadeIn("fast");
                } else {
                    $("." + $(this).attr("id")).fadeOut("fast");
                }
            });
            $(".workedWeek input[type=text]").bind("focus blur", function (e) {

                if (e.type == "blur") {
                    if ($(this).index() == "0" && $(this).hasClass("worked")) {
                        if ($(this).val() > 24) {
                            $(this).addClass("error");
                            if ($(this).parents("table").prev().hasClass("error")) {
                                $(this).parents("table").prev().show();
                            } else {
                                $(this).parents("table").before("<p class='error'>Vul een juiste tijd in</p>");
                            }
                        } else {
                            $(this).removeClass("error");
                            if ($(this).parents("table").prev().hasClass("error")) {
                                $(this).parents("table").prev().hide();
                            }
                        }
                    }
                    if ($(this).index() == "1" && $(this).hasClass("worked")) {
                        if ($(this).val() > 59) {
                            $(this).addClass("error");
                            if ($(this).parents("table").prev().hasClass("error")) {
                                $(this).parents("table").prev().show();
                            } else {
                                $(this).parents("table").before("<p class='error'>Vul een juiste tijd in</p>");
                            }
                        } else {
                            $(this).removeClass("error");
                            if ($(this).parents("table").prev().hasClass("error")) {
                                $(this).parents("table").prev().hide();
                            }
                        }
                    }
                }
            });
        });
    };

    $(".ajaxHolder").each(function () {
        var holder = $(this);
        if (holder.find("a.noJS").attr("href") != undefined) {
            $.ajax({
                url: holder.find("a.noJS").attr("href"),
                success: function (data) {
                    holder.slideUp("fast");
                    holder.html(data);
                    zebra($("table:not(.plain):not(.triple)", holder));
                    zebra3($("table.triple", holder));
                    if (holder.parents("#personal").length == 0) dropshadow($(".info", holder));
                    hover($("li"), $(this));
                    holder.slideDown("fast");
                },
                error: function () {
                    holder.slideUp("fast");
                    holder.html("<div class='notice'><p>Deze gegevens zijn tijdelijk niet beschikbaar</p></div>");
                    holder.slideDown("fast");
                }
            });
        }
    });

    var doAddPrint = function () {
        if ($(".print h1 .excel").length > 0) {
            $(".print h1 .excel").after("<a href='#' class='print'>Printen</a>");
        } else {
            $(".print h1").prepend("<a href='#' class='print'>Printen</a>");
        }
        $(".print h1 .print").click(function () {
            window.print();
            return false;
        });
    };

    if ($("#right #actions li").length == 0) $("#right #actions").hide();

    if ($(".workedWeek").length > 0) doWorkedWeek();

    if ($(".print").length > 0) doAddPrint();

    $(".mijnuwv .inverse tbody tr:first-child th, .mijnuwv .inverse tbody tr:first-child td").css({
        "border-top": "1px solid #C4E4FB"
    });

    $(".mijnuwv .inverse tbody tr:last-child th, .mijnuwv .inverse tbody tr:last-child td").css({
        "border-bottom": "1px solid #C4E4FB"
    });

    $(".mijnuwv .inverse .workedWeek tbody tr:last-child th, .mijnuwv .inverse .workedWeek tbody tr:last-child td").css({
        "border-bottom": "0"
    });

    $(".mijnuwv .inverse .workedWeek tbody tr:first-child th, .mijnuwv .inverse .workedWeek tbody tr:first-child td").css({
        "border-top": "0"
    });

    $("#left .login").css({
        "box-shadow": "0px 0px 8px #aaaaaa",
        "position": "relative",
        "border-radius": "5px",
        "behavior": "url(../systeem/diversen/PIE.htc)"
    });

    $(".workedWeek .seventh input").blur(function () {
        if ($(this).index() == 1) {
            // hours
            if (isNaN($(this).val()) || Number($(this).val()) > 23 || Number($(this).val()) < 0) {
                $(this).addClass("error");
                if ($(this).parent().parent().find("p.error").length == 0) {
                    $(this).parent().parent().prepend("<p class='error'>Vul een juiste tijd in</p>");
                }
            } else {
                $(this).removeClass("error");
                if ($(this).parent().parent().find("input.error").length == 0) {
                    $(this).parent().parent().find("p.error").remove();
                }
            }
        } else {
            if (isNaN($(this).val()) || Number($(this).val()) > 59 || Number($(this).val()) < 0) {
                $(this).addClass("error");
                if ($(this).parent().parent().find("p.error").length == 0) {
                    $(this).parent().parent().prepend("<p class='error'>Vul een juiste tijd in</p>");
                }
            } else if (($(this).prev().val() == "00" || $(this).prev().val() == "0") && Number($(this).val()) != 0) {
                $(this).addClass("warning");
                if ($(this).parent().parent().find("p.error").length == 0) {
                    $(this).parent().parent().prepend("<p class='error'>Heeft u minder dan een uur gewerkt?</p>");
                }
            } else {
                $(this).removeClass("error").removeClass("warning");
                if ($(this).parent().parent().find("input.error").length == 0) {
                    $(this).parent().parent().find("p.error").remove();
                }
            }
        }
        // calculate total

        var totalWorked = {
            hours: 0,
            minutes: 0
        };

        $(".workedWeek .seventh").each(function () {
            totalWorked.hours += Number($("input:first", $(this)).val());
            totalWorked.minutes += Number($("input:last", $(this)).val());
        });
        if (totalWorked.minutes > 59) {
            var minutes = totalWorked.minutes % 60;
            var addedHours = Math.floor(totalWorked.minutes / 60);
            totalWorked.minutes = (minutes < 10) ? "0" + minutes : minutes;
            totalWorked.hours = totalWorked.hours + addedHours;
        }
        $(".workedWeek.total input:first").val(totalWorked.hours);
        $(".workedWeek.total input:last").val(totalWorked.minutes);
    });

    $(".multiToggle").click(function () {
        var value = $(this).val().split("-");

        for (var i = 0; i < value.length; i++) {
            (i == 0) ? $(value[i]).show() : $(value[i]).hide();
            recalculteTooltips($(value[i]));
        }
    });
};

	 var doWerkgeversPortaal = function () {
	     $("#left .login").css({
	         "box-shadow": "0px 0px 8px #aaaaaa",
	         "position": "relative",
	         "border-radius": "5px",
	         "behavior": "url(../systeem/diversen/PIE.htc)"
	     });
	     $(".toggleOn").each(function () {
	         $(this).click(function () {
	             $(this).parent().siblings(".togglable").show().find("input").attr("disabled", false);
	         });
	     });
	     $(".toggleOff").each(function () {
	         $(this).click(function () {
	             $(this).parent().siblings(".togglable").hide().find("input").attr("disabled", true);
	         });
	     });
	     
	     $(".ziekteperioden .add").click(function (e) {
	         e.preventDefault();
	         var clone = $(this).prev().clone(true);
	         // update all ids in the clone
	         clone.find("[id]").each(function () {
	             $(this).attr("id", $(this).attr("id") + "_c");
	         });
	         // reapply the datepicker to all found date inputs
	         clone.find("input.date").each(function () {
	             var isRanged = $(this).hasClass("ranged");
	             $(this).dpRemove();
	             $(this).datePicker({
	                 startDate: '01/01/1970',
	                 displayClose: true,
	                 ranged: isRanged
	             }).dpSetOffset(-117, 20);
	         });
	         $(this).before(clone);
	     });
	     $("table[class^=toggle-]").each(function () {
	         var max = $(this).attr("class");
	         max = Number(max.substr(max.indexOf("-") + 1));
	         if ($(">tbody>tr", $(this)).length > max) {
	             $(">tbody>tr:gt(" + (max - 1) + ")", $(this)).hide();
	             $(">tbody", $(this)).append("<tr class='toggle'><td colspan='6'><a href='#'>Toon alle " + Number(($("tbody>tr", $(this)).length)) + "</a></td></tr>");
	             $(".toggle", $(this)).click(function () {
	                 $(this).hide();
	                 $(this).parent().find("tr[class != toggle]").show();
	                 return false;
	             });
	         }
	     });
	     $(".checkall a").click(function () {
	         var hasChecked = false;
	         if ($(this).parent().find("input:checked").length > 0) hasChecked = true;
	         $(this).parent().find("input[type=checkbox]").each(function () {
	             (hasChecked) ? $(this).removeAttr("checked") : $(this).attr("checked", true);
	         });
	         return false;
	     });
	     $(".werkgeversportaal #right .loggedin .highlightWidget").each(function () {
	         var animated = $(this);
	         var config = {
	             startColor: "rgb(245, 249, 251)",
	             stopColor: "rgb(254, 244, 192)",
	             startColorRGB: "rgb(245,249,251)",
	             stopColorRGB: "rgb(254,244,192)",
	             startColorRGBs: "rgb(245, 249, 251)",
	             stopColorRGBs: "rgb(254, 244, 192)",
	             startColorHex: "#f5f9fb",
	             stopColorHex: "#fef4c0",
	             speed: 500,
	             loopCount: 6,
	             targetColor: function () {
	                 var newColor = "";
	                 if (animated.css("backgroundColor").indexOf("#") != -1) {
	                     // we need to use the hexCode (ie < 9 && firstRun ie9)
	                     config.startColor = config.startColorHex;
	                     config.stopColor = config.stopColorHex;
	                 } else if (animated.css("backgroundColor").indexOf(" ") > -1) {
	                     // we need to use the RGBcode with spaces (chrome, firefox)
	                     config.startColor = config.startColorRGBs;
	                     config.stopColor = config.stopColorRGBs;
	                 } else {
	                     // we need to use the RGBcode (ie9+ 2nd and later runs)
	                     config.startColor = config.startColorRGB;
	                     config.stopColor = config.stopColorRGB;
	                 }
	                 (animated.css("backgroundColor") == config.startColor) ? newColor = config.stopColor : newColor = config.startColor;
	                 // console.log(newColor + ", " + animated.css("backgroundColor"));
	                 return newColor;
	             }
	         };
	         var animate = function (config) {
	             animated.animate({
	                 backgroundColor: config.targetColor()
	             }, config.speed, function () {
	                 if (config.loopCount > 0) {
	                     config.loopCount = config.loopCount - 1;
	                     animate(config);
	                 }
	             });

	         };
	         animate(config);

	     });

	 };

	 var addSort = function () {
	     $(".sortable").each(function () {

	         var cache = []; // our cache object for this sortable
	         var $table = $(this);
	         var $th;
	         var dir = "";

	         // fill the cache object
	         (function () {
	             $(">tbody tr", $table).each(function () {
	                 var row = [];
	                 $("tr:first>td", $(this)).each(function () {
	                     if (!$(this).hasClass("date")) {
	                         row.push($(this));
	                     } else {
	                         var arr = $(this).text().split("-");
	                         var date = new Date(arr[2], Number(arr[1]) - 1, arr[0]);
	                         row.push(date);
	                     }
	                 });
	                 cache.push(row);
	             });
	         })();

	         var sortTable = function (a, b) {
	             var aa, bb;
	             a = a[$th.index()];
	             b = b[$th.index()];
	             if (a instanceof Date) {
	                 aa = a;
	                 bb = b;
	             } else {
	                 aa = a.text();
	                 bb = b.text();
	             }
	             if (dir == "down") {
	                 if (aa < bb) return 1;
	                 if (aa > bb) return -1;
	                 return 0;
	             } else {
	                 if (bb < aa) return 1;
	                 if (bb > aa) return -1;
	                 return 0;
	             }
	         };

	         $("th:not(.link)", $(this)).each(function () {
	             $(this).append(" <span></span>");
	             $(this).click(function () {
	                 var thisDir = ($(this).hasClass("asc")) ? "asc" : "desc";
	                 $(this).parent().find(">th").removeClass("asc").removeClass("desc");
	                 if (thisDir == "asc") {
	                     $(this).removeClass("asc").addClass("desc");
	                     dir = "down";
	                 } else {
	                     $(this).removeClass("desc").addClass("asc");
	                     dir = "up";
	                 }
	                 $th = $(this);
	                 // sort the table
	                 cache.sort(sortTable);
	                 // redraw the table body
	                 for (var i = 0; i < cache.length; i++) {
	                     var row = $(cache[i][0]).parents(".withdetails");
	                     // place the items of this row in the row of the actual table
	                     var actualRow = $(">tbody tr:nth-child(" + (Number(i) + 1) + ")", $table);
	                     actualRow.empty().append(row);
	                 }
	             });
	         });

	         $(".withdetails>table>tbody>tr:first-child", $(this)).each(function () {
	             $(">td:not(:last-child)", $(this)).bind("mouseenter mouseleave click", function (e) {
	                 var link = $(this).find("a");
	                 if (link.length == 1) {
	                     if (e.type == "click") document.location.href = link.attr("href");
	                     if (e.type == "mouseenter") $(this).css("cursor", "pointer");
	                     if (e.type == "mouseleave") $(this).css("cursor", "default");
	                 }
	             });
	         });
	     });
	 };

	 (function (d) { d.each(["backgroundColor", "borderBottomColor", "borderLeftColor", "borderRightColor", "borderTopColor", "color", "outlineColor"], function (f, e) { d.fx.step[e] = function (g) { if (!g.colorInit) { g.start = c(g.elem, e); g.end = b(g.end); g.colorInit = true } g.elem.style[e] = "rgb(" + [Math.max(Math.min(parseInt((g.pos * (g.end[0] - g.start[0])) + g.start[0]), 255), 0), Math.max(Math.min(parseInt((g.pos * (g.end[1] - g.start[1])) + g.start[1]), 255), 0), Math.max(Math.min(parseInt((g.pos * (g.end[2] - g.start[2])) + g.start[2]), 255), 0)].join(",") + ")" } }); function b(f) { var e; if (f && f.constructor == Array && f.length == 3) { return f } if (e = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(f)) { return [parseInt(e[1]), parseInt(e[2]), parseInt(e[3])] } if (e = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(f)) { return [parseFloat(e[1]) * 2.55, parseFloat(e[2]) * 2.55, parseFloat(e[3]) * 2.55] } if (e = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(f)) { return [parseInt(e[1], 16), parseInt(e[2], 16), parseInt(e[3], 16)] } if (e = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(f)) { return [parseInt(e[1] + e[1], 16), parseInt(e[2] + e[2], 16), parseInt(e[3] + e[3], 16)] } if (e = /rgba\(0, 0, 0, 0\)/.exec(f)) { return a.transparent } return a[d.trim(f).toLowerCase()] } function c(g, e) { var f; do { f = d.curCSS(g, e); if (f != "" && f != "transparent" || d.nodeName(g, "body")) { break } e = "backgroundColor" } while (g = g.parentNode); return b(f) } var a = { aqua: [0, 255, 255], azure: [240, 255, 255], beige: [245, 245, 220], black: [0, 0, 0], blue: [0, 0, 255], brown: [165, 42, 42], cyan: [0, 255, 255], darkblue: [0, 0, 139], darkcyan: [0, 139, 139], darkgrey: [169, 169, 169], darkgreen: [0, 100, 0], darkkhaki: [189, 183, 107], darkmagenta: [139, 0, 139], darkolivegreen: [85, 107, 47], darkorange: [255, 140, 0], darkorchid: [153, 50, 204], darkred: [139, 0, 0], darksalmon: [233, 150, 122], darkviolet: [148, 0, 211], fuchsia: [255, 0, 255], gold: [255, 215, 0], green: [0, 128, 0], indigo: [75, 0, 130], khaki: [240, 230, 140], lightblue: [173, 216, 230], lightcyan: [224, 255, 255], lightgreen: [144, 238, 144], lightgrey: [211, 211, 211], lightpink: [255, 182, 193], lightyellow: [255, 255, 224], lime: [0, 255, 0], magenta: [255, 0, 255], maroon: [128, 0, 0], navy: [0, 0, 128], olive: [128, 128, 0], orange: [255, 165, 0], pink: [255, 192, 203], purple: [128, 0, 128], violet: [128, 0, 128], red: [255, 0, 0], silver: [192, 192, 192], white: [255, 255, 255], yellow: [255, 255, 0], transparent: [255, 255, 255]} })(jQuery);

