
(function() {

    var ua = navigator.userAgent,
        isIE6 = (/MSIE\s6/).test(ua),
        isIE7 = (/MSIE\s7/).test(ua),
        isIE8 = (/MSIE\s8/).test(ua);

    String.prototype.caps = function() {
        return this.substring(0, 1).toUpperCase() + this.substring(1, this.length);
    };

    String.prototype.stripHTML = function() {
        return this.replace(/(\<[a-z]+(\s([a-z]+\=["'][\w\-]+['"]))?(\/)?\>|\<\/[a-z]+\>)/gi, " ").replace(/\s{2,}/g, " ");
    };

    String.prototype.longestWord = function() {
        var that = this.stripHTML(), words = that.split(" "), i, longestWord = "";
        for (i = 0; i < words.length; i += 1) {
            if (words[i].replace(/[^\w]$/, "").length > longestWord.length) {
                longestWord = words[i].replace(/[^\w]$/, "");
            }
        }
        return longestWord;
    };

    $.log = function(message) {
        if (window.console && window.console.debug) {
            console.debug(arguments);
        } else if (window.console && window.console.log) {
            console.log(arguments);
        } else {
            alert(message);
        }
    };

    $.fn.extend({
        normalize: function() { // removes all non-tags from an HTMLElement
            $(this).each(function() {
                var that = this,
                cn = that.childNodes,
                i;

                for (i = cn.length - 1; i > -1; i -= 1) {
                    if (!cn[i].tagName) {
                        that.removeChild(cn[i]);
                    }
                }
            });
            return this;
        },
        replaceTag: function(newTag) {
            var that = this,
                nt = null,
                i;

            if (typeof newTag === "string") {
                for (i = 0; i < that.length; i += 1) {
                    nt = document.createElement($.trim(newTag));
                    nt.innerHTML = that[i].innerHTML;

                    that[i].parentNode.replaceChild(nt, that[i]);
                }
            }

            return that;
        }
    });

    $.uniqueId = function(id) {
        var count = 0,
			result;

        if (document.getElementById(id + count)) {
            while (document.getElementById(id + count)) {
                count += 1;
            }
        }

        result = id + count;

        return result;
    };

    $.create = function(newElementObject) {
        // custom create HTML
        var neo = newElementObject,
        tagName = (neo && neo.tagName) ? neo.tagName : "div",
        newElement = document.createElement(tagName),
        ne = newElement,
        p, // properties
        i,
		clone,
		clones = neo.repeat,
		j,
		df,
		dynProp = null; //dynamic property

        if (neo.type) {
            ne.setAttribute("type", neo.type);
        }

        if (neo) {
            for (p in neo) {
                if (typeof neo[p] === "function") {
                    dynProp = neo[p]();
                    if (typeof ne.style[p] === "string") {
                        ne.style[p] = dynProp;
                    } else {
                        ne[p] = dynProp;
                    }
                } else if (!(/(tagName|appendChildren|type|repeat)/).test(p)) {
                    if (typeof ne.style[p] === "string") {
                        ne.style[p] = neo[p];
                    } else {
                        ne[p] = neo[p];
                    }
                } else if (p === "appendChildren") {
                    if (typeof neo[p] === "object" && neo[p].length) {
                        for (i = 0; i < neo[p].length; i += 1) {
                            ne.appendChild($.create(neo[p][i]));
                        }
                    } else if (typeof neo[p] === "object") {
                        ne.appendChild($.create(neo[p]));
                    }
                }
            }
        }

        if (clones) {
            df = document.createDocumentFragment();

            for (i = 0; i < clones; i += 1) {
                clone = newElement.cloneNode(true);
                df.appendChild(clone);
            }

            newElement = df;
        }

        return newElement;
    };

    var omoClick = function() {
        $(".searchResult tr > :not(.checkBox), .startList tr > :not(:last-child)").live("mouseover", function() {
            $(this.parentNode).addClass("hover");
        });
        $(".searchResult tr > :not(.checkBox), .startList tr > :not(:last-child)").live("mouseout", function() {
            $(this.parentNode).removeClass("hover");
        });

        /*$(".searchResult tr > *:not(.checkBox)").live("mousedown", function (e) {
        $(this.parentNode).find("input[type=checkbox]").trigger("click");
        });*/

        $("a.puffLink").each(function() {
            var that = this, url = that.href;

            that.parentNode.style.cursor = "pointer";

            $(this).click(function(e) {
                e.preventDefault();
            });

            $(that.parentNode).click(function() {
                if (that.target && that.target === "_blank") {
                    window.open(url, "", "");
                } else {
                    document.location = url;
                }
            });
        });
    },
    tableStripes = function() {
        var tableRow = "even";
        $(".programComparisonMatrix tbody.group.active").show();
        $(".programComparisonMatrix tbody.group.active").prev("tbody").find(".moreStat").addClass("showing");
        $(".programComparisonMatrix tbody").each(function() {
            if (tableRow == "odd") {
                $(this).addClass("odd");
            } else {
                $(this).addClass("even");
            }
            // alert($(this).next().hasClass("group"))
            if (!$(this).next("tbody").hasClass("group")) {
                if (tableRow == "odd") {
                    tableRow = "even";
                } else {
                    tableRow = "odd";
                }
            }

        });
    },
    extWindows = function() {
        $("a[rel=external]").attr("target", "_blank");
        $("a[rel^=popup]").click(function() {
            theHref = $(this).attr("href");
            var popupWidth, popupHeight
            var relSplit = $(this).attr("rel").split("|");
            if (relSplit[1]) {
                popupWidth = relSplit[1];
                popupHeight = relSplit[2];
            } else {
                popupWidth = 435;
                popupHeight = 350;
            }
            popMeUp(theHref, popupWidth, popupHeight)
            return false;
        });
    },
    popMeUp = function(strURL, strWidth, strHeight) {
        theWin = window.open(strURL, "popupWin", "scrollbars,resizable,height=" + strHeight + ",width=" + strWidth);
        theWin.focus();
    },
    tipAFriend = function(e) {
        var that = this;
        $(".popupTip").each(function() {
            this.style.position = "absolute";
            this.style.top = parseInt(that.offsetTop + that.offsetHeight, 10) + "px";

            if ($(this).hasClass("hiddenJS")) {
                $(this).removeClass("hiddenJS");
            } else {
                $(this).addClass("hiddenJS");
            }
        });
        e.preventDefault();
    },
    checkSelect = function() {
        if ($(".search select").val() !== "") {
            $(".search input").attr("disabled", "");
            $(".search input.field").removeClass("disabled");
        } else {
            $(".search input").attr("disabled", "disabled");
            $(".search input").val("");
            $(".search input.field").addClass("disabled");
        }
    },
    doSearch = function(e, button) {
        if (window.event && window.event.keyCode === 13 || e && e.keyCode == 13) {
            document.getElementById(button).click();
            return false;
        }

        return true;
    },
    truncateThis = function() {
        var len = 100;
        $(".truncateMe").each(function() {
            var origText = $(this).html();
            if (origText.length > len) {
                $(this).next(".removeTruncate").show();

                /* Truncate the content of the P, then go back to the end of the
                previous word to ensure that we don't truncate in the middle of
                a word */
                trunc = origText.substring(0, len);
                trunc = trunc.replace(/[\wåäöÅÄÖ]+$/, '');

                /* Add an ellipses to the end and make it a link that expands
                the paragraph back to its original size */
                $(this).html(trunc + '...')
                $(this).parents("tr").find(".removeTruncate").click(function(e) {
                    e.preventDefault();
                    $(this).parents("tr").find(".truncateMe").html(origText);
                    $(this).hide();
                });
            }
        });

    },
    truncateThat = function() {
        var len = 50;
        $("div.programComparisonMatrix th ").each(function() {
            if ($(this).text().match(/Kommentar/gi)) {
                $(this).append('<a href="#" class="unTruncate">Läs hela kommentarerna</a>')
                $(this).parents("tr").find("td").each(function() {
                    var orgText = $(this).html();
                    var theTd = $(this);
                    if (orgText.length > len) {
                        theTd.css("textAlign", "left");
                        $(this).parents("tr").find("th").find("a").css({
                            display: 'block',
                            clear : 'left'
                        });

                        trunc = orgText.substring(0, len);
                        trunc = trunc.replace(/[\wÅÄÖåäö]+$/, '');


                        $(this).html(trunc + '...')
                        $(this).parents("tr").find("th").find("a").click(function(e) {
                            e.preventDefault();
                            theTd.html(orgText);
                            $(this).hide();
                        });
                    }

                });




            }


            /*
            */
        });

    },

    getStyle = function(el, styleProp) {
        // taken from http://www.quirksmode.org/dom/getstyles.html and modifyed by Petter Ahlberg Feb 13 2009
        var x = (el.tagName) ? el : document.getElementById(el),
            y,
            uc = styleProp.match(/(\-)([a-z])/) ? styleProp.match(/(\-)([a-z])/)[0].toString().replace(/\-/, "").toUpperCase() : null;

        if (x.currentStyle) {
            if (uc) {
                styleProp = styleProp.replace(/\-[a-z]/, uc);
            }
            y = x.currentStyle[styleProp];
        } else if (window.getComputedStyle) {
            y = document.defaultView.getComputedStyle(x, null).getPropertyValue(styleProp);
        }
        return y;
    },
    goodBrowser = (/(gecko|webkit)/i).test(ua),
    equalHeight = function(collection) {
        var h = 0,
            i = 0,
            c = (typeof collection === "object" && collection.length) ? collection : (jQuery ? jQuery(collection) : null),
            ci = null,
            pt = 0,
            pb = 0;

        if (c) {
            for (i = 0; i < c.length; i += 1) {

                if (c[i].offsetHeight > h) {

                    ci = $(c[i]);
                    pt = parseInt(ci.css("padding-top"), 10);
                    pb = parseInt(ci.css("padding-bottom"), 10);

                    h = parseInt((c[i].offsetHeight - parseInt(pt + pb, 10)), 10);
                }
            }

            for (i = 0; i < c.length; i += 1) {
                c[i].style.height = h + "px";
            }
        }

    };

    $(document).ready(function() {
        var count = 0;
        //show and hide tr
        $("div.info").hide();

        //show and hide list	
        $(".sf-menu .current ul").hide();
        $(".sf-menu .current").click(function() {
            $(".sf-menu .current ul").show();
            return false;
        });

        // disable input if nothing is chosen from select   
        checkSelect();
        $(".search select").change(checkSelect);

        $("tbody tr:last-child, tbody tr td:last-child").addClass("last-child");

        $(".programList tr > *").each(function() {

            if (!this.innerHTML.trim()) {
                this.innerHTML = "<br />";
            }

            this.innerHTML = this.innerHTML.replace(/\&nbsp\;/g, " ");

            if ((/^(\-|ja|nej|\d+(\s\%)?)$/i).test(this.innerHTML.trim()) || (/^\-(\s+)?[\(](\d+(\s)?)+(\s+)?(\%)?[\)]$/).test(this.innerHTML.trim())) {
                this.style.textAlign = "center";
                this.style.verticalAlign = "middle";
                //this.innerHTML = this.innerHTML.caps();
            }
        });


        if ((/MSIE\s[5-6]/).test(navigator.userAgent)) {
            $(".programList .active.first-child").each(function() {
                $(this).addClass("active-first-child");
            });

            $(".programList .active.nth-child(2)").each(function() {
                $(this).addClass("active-nth-child2");
            });
        }
        $("#tipAFriendLink").click(tipAFriend);
        $(".popupTip a.close").click(function() {
            $(".popupTip").addClass("hiddenJS");
        });
/*
        if ($(".programList").length) {
            if ($(".popupTip").length) {

                //$("div.aside.col").prepend("<ul class=\"tools\"><li class=\"printLi\"><a href=\"javascript:window.print();\">Skriv ut</a></li><li><a id=\"tipAFriendLink\" class=\"noShow\" href=\"/\">Tipsa en v&auml;n</a></li></ul><div class=\"row\"></div>");

                $("div.aside.col").prepend($.create({
                    className: "util",
                    appendChildren: [{
                        tagName: "a",
                        className: "spriteA print",
                        href: "javascript:window.print();",
                        innerHTML: "Skriv ut"
                    }, {
                        tagName: "a",
                        id: "tipAFriendLink",
                        href: "/",
                        className: "spriteA print",
                        innerHTML: "Tipsa"
}]
                    }));

                    $("#tipAFriendLink").click(tipAFriend);
                    $(".popupTip a.close").click(function() {
                        $(".popupTip").addClass("hiddenJS");
                    });
                } else {
                    $("div.aside.col").prepend("<ul class=\"tools\"><li class=\"printLi\"><a href=\"javascript:window.print();\">Skriv ut</a></li></ul><div class=\"row\"></div>");
                }

            }
*/
            $(".normal .compareButton.disabled").live("click", function(e) {
                e.preventDefault();
            });


            $(".normal .compareButton.enabled").live("click", function(e) {
                document.location = this;
            });

            omoClick();
            extWindows();
            tableStripes();
            truncateThis();
            truncateThat();
        });

        var hsk = {
            re: {
                ssl: function(str, rstr, type, gim) { // Space Separated List
                    // str = String to test
                    // rstr = a str or regExp to test
                    // type = test|match
                    // gim = g|i|m or any combo of the letters "g", "i", "m"
                    var reStr = "(^|\\s)" + rstr + "(\\s|$)", re = gim ? new RegExp(reStr, gim) : new RegExp(reStr), result;

                    if (type && type === "match") {
                        result = str.match(re);
                    } else {
                        result = (re).test(str);
                    }
                    return result;
                }
            },
            ie6: {
                init: function() {
                    var keys;
                    for (keys in this) {
                        if (typeof this[keys] === "function" && keys !== "init") {
                            this[keys]();
                        }
                    }
                },
                hoverElements: [".compareButton", "#header #mainSearch input", "#linkBox li"],
                addHover: function() {
                    var i, that = this, el = that.hoverElements;
                    for (i = 0; i < el.length; i += 1) {
                        $(el[i]).bind("mouseover", function() {
                            $(this).addClass("hover");
                        });
                        $(el[i]).bind("mouseout", function() {
                            $(this).removeClass("hover");
                        });
                    }
                },
                pngBgToGif: function() {
                    var tg = $(".toGif").find("*:not(.noGif)"), i, orgBg;
                    for (i = 0; i < tg.length; i += 1) {
                        if ((/\.png['"]\)$/i).test(tg[i].currentStyle.backgroundImage)) {
                            tg[i].style.backgroundImage = tg[i].currentStyle.backgroundImage.replace(/\.png/i, ".gif");
                        }
                    }
                }
            },
            ie7: {
                startSearch: function() {
                    $("div#start div.startSearch").find("div.rcTop, div.rcBottom").each(function() {
                        var that = this;

                        that.style.width = that.parentNode.offsetWidth + "px";
                    });
                },
                init: function() {
                    var mids = $(".normal .puff .corners .mid"), i;
                    for (i = 0; i < mids.length; i += 1) {
                        mids[i].style.width = (mids[i].parentNode.parentNode.offsetWidth - 12) + "px";
                    }

                    hsk.ie7.startSearch();
                }
            },
            starNumbers: function() {
                $(".stars td").each(function() {
                    var nbrs = this.innerHTML.match(/\d/g), i, str;
                    if (nbrs) {
                        this.innerHTML = this.innerHTML.replace(/\s/g, "");
                        for (i = 0; i < nbrs.length; i += 1) {
                            $(this).append("<img alt=\"" + nbrs[i] + "\" class=\"png\" src=\"/UI/images/hogskole/numbers/" + nbrs[i] + ".png\" />");
                        }
                        while (!this.firstChild.tagName) {
                            this.removeChild(this.firstChild);
                        }
                    }
                });
            },
            /*topFiller : function () {
            var tf = document.getElementById("topFiller"), ns;
            
            ns = tf.nextSibling;
            while (!ns.tagName) {
            ns = ns.nextSibling;
            }
            
            tf.style.width = parseInt((tf.parentNode.offsetWidth - ns.offsetWidth) + 1, 10) + "px";
            tf.style.height = ns.offsetHeight + "px";
            },*/
            setOpacity: function() {
                var o = $(".opacity"),
                i,
                opElem,
                bgColor,
                ops,
                hh,
                left = "5px", //isIE6 ? 0 : "5px",
                offsWidth = null,
                pl = null;

                opElem = function(el, bgc, op) {
                    var opFix = "";

                    if (!op) {
                        op = 5;
                    }

                    //offsWidth = el.offsetWidth;

                    if ((/MSIE\s\d/).test(navigator.userAgent)) {
                        opFix = "filter:alpha(opacity=" + op + "0)";
                    } else {
                        opFix = "opacity: 0." + op + ";";
                    }

                    $(el.parentNode).prepend("<div style=\"position:absolute; left: " + left + "; background-color:" + bgc + ";width:" + offsWidth + "px;height:" + el.offsetHeight + "px;" + opFix + "\"><!-- 4 ie6 --></div>");
                };

                /*for (i = 0; i < o.length; i += 1) {
                offsWidth = o[i].offsetWidth;
                pl = parseInt($(o[i]).css("padding-left"), 10);

                    o[i].style.width = parseInt(offsWidth - pl, 10) + "px";

                    bgColor = getStyle(o[i], "background-color");

                    if (o[i].className.match(/op\d+/)) {
                ops = o[i].className.match(/op\d+/).toString().replace(/[^\d]/g, "");
                }

                    opElem(o[i], bgColor, ops);
                o[i].style.backgroundColor = "transparent";
                o[i].style.position = "absolute";

                    o[i].style.left = left;
                }*/

                $("div.puff:not(.box) .wrapper p").each(function() {
                    //alert(this.parentNode.innerHTML);
                    hh = $(this.parentNode).find("h3")[0];
                    if (hh) {
                        this.style.paddingTop = parseInt(hh.offsetHeight + 5, 10) + "px";
                    }
                });

                equalHeight("#start div.puff div.wrapper");
            },
            /*menuHover : function () {
            $("#header li").bind("mouseover", function () {
            if ((/MSIE\s\d/).test(navigator.userAgent)) {
            this.style.filter = "alpha(opacity=50)";
            } else {
            this.style.opacity = ".5";
            }
            });
            $("#header li").bind("mouseout", function () {
            if ((/MSIE\s\d/).test(navigator.userAgent)) {
            this.style.filter = "";
            } else {
            this.style.opacity = "";
            }
            });
            },*/
            setChecked: function() {
                var cbs = document.location.search.toString().match(/selection\=(\d+(\,)?)+/) ? document.location.search.toString().match(/selection\=(\d+(\,)?)+/g) : false, i;

                if (cbs) {

                    cbs = cbs.toString().replace(/selection\=/, "").split(",");

                    for (i = 0; i < cbs.length; i += 1) {
                        $("input[type=checkbox][value=" + cbs[i] + "]").each(function() {
                            this.checked = true;
                        });
                    }
                    hsk.setUrl();
                }
            },
            setUrl: function() {
                var that = this, cbs = $(".start div.compareList input[type=checkbox]"), sl = $(".startList a"), dls = document.location.search, type,
            sel = dls.match(/[\?\&]selection\=(\d+(\,)?)+/g) ? dls.match(/[\?\&]selection\=(\d+(\,)?)+/g).toString() : null, oq, q, re, four;

                if (!that.tagName) {
                    if (sel) {
                        sl.each(function() {
                            this.href += sel;
                            q = this.href;
                        });
                    }
                } else {
                    if (that.checked) {
                        if (!sel) {
                            oq = "&selection=" + that.value;

                            sl.each(function() {
                                if (!(/selection\=/).test(this.href)) {
                                    this.href += oq;
                                } else {
                                    this.href += "," + that.value;
                                }
                                q = this.href;
                            });
                        } else {
                            sl.each(function() {
                                this.href += "," + that.value;
                                q = this.href;
                            });
                        }
                    } else {
                        sl.each(function() {
                            re = new RegExp("(\\=|\\,)(" + that.value + ")(\\,|\\&|$)");
                            if ((/selection\=/).test(this.href)) {
                                this.href = this.href.replace(re, "$1$3");

                                if ((/\,$/).test(this.href)) {
                                    this.href = this.href.replace(/\,$/, ""); ;
                                }

                                if ((/([\?\&]selection\=)(\,)(\d)/).test(this.href)) {
                                    re = new RegExp("([\\?\\&]selection\\=)(\\,)(\\d)");
                                    this.href = this.href.replace(re, "$1$3");
                                }

                                this.href = this.href.replace(/\,{2,}/g, ",");

                                if ((/[\?\&]selection\=/).test(this.href) && !(/[\?\&]selection\=\d+/).test(this.href)) {
                                    this.href = this.href.replace(/[\?\&]selection\=/, "");
                                }
                                q = this.href;
                            }
                        });
                    }
                }

                sl.each(function() {
                    if (!(/\?/).test(this.href) && (/\&/).test(this.href)) {
                        this.href = this.href.replace(/\&/, "?");
                    }
                });

                type = dls.match(/type\=\d/) ? dls.match(/type\=\d/) : "type=1";

                q = q.replace(/(http:\/{2}[a-z]+(\.[a-z]{2, 4})?(\/(list|compare))?)/, "");
                four = q.match(/selection\=(\d+(\,)?)+/) ? q.match(/selection\=(\d+(\,)?)+/g).toString().replace(/[^\d\,]+/, "").replace(/\,$/, "").split(",") : null;

                if (four && four.length) {
                    $(".compareButton").unbind("click", hsk.compCheck).addClass("enabled");
                } else {
                    $(".compareButton").bind("click", hsk.compCheck).removeClass("enabled");
                }

                if (four && four.length > 3) {
                    cbs.each(function() {
                        if (!this.checked) {
                            this.disabled = true;
                        }
                    });
                } else {
                    cbs.each(function() {
                        if (!this.checked) {
                            this.disabled = false;
                        }
                    });
                }
            },
            compCheck: function(e) {
                e.preventDefault();
            },
            wideTable: function() {
                $("td").each(function() {
                    if ((/development\.DataAccess\.Statistic/).test(this.innerHTML)) {
                        this.innerHTML = this.innerHTML.replace(/development\.DataAccess\.Statistic/, "Development. DataAccess. Statistic");
                    }
                });

                $("table").each(function() {
                    if (this.offsetWidth > 650) {
                        $(this).find("th, td").each(function() {
                            if ((/kommunikationsvetenskap/).test(this.innerHTML.trim())) {
                                this.innerHTML = this.innerHTML.replace(/kommunikationsvetenskap/, "kommunikations- vetenskap");
                            }
                            if ((/informationsvetenskap/).test(this.innerHTML.trim())) {
                                this.innerHTML = this.innerHTML.replace(/informationsvetenskap/, "informations- vetenskap");
                            }
                            if ((/fadderf\u00F6retags(verksamheten)/).test(this.innerHTML.trim())) {
                                this.innerHTML = this.innerHTML.replace(/fadderf\u00F6retagsverksamheten/, "fadderf\u00F6retags- verksamheten");
                            }
                        });
                    }
                });

            },
            addVideoArrow: function() {
                var vl = $("img.video"), i, nd, w, h, va;
                for (i = 0; i < vl.length; i += 1) {
                    w = vl[i].offsetWidth;
                    h = vl[i].offsetHeight;
                    $(vl[i].parentNode).append("<div class=\"videoArrow\"></div>");

                    va = $(vl[i].parentNode).find(".videoArrow")[i];

                    va.style.top = parseInt((h / 2) - (va.offsetHeight / 2), 10) + "px";
                    va.style.left = parseInt((w / 2) - (va.offsetWidth / 2), 10) + "px";
                }
            },
            toggleTbody: function(e) {
                var that = this, pn = that.parentNode;

                while (!(/tbody/i).test(pn.tagName)) {
                    pn = pn.parentNode;
                }

                if (!this.isVisib) {
                    $(this.info[0]).show();
                    $(pn).addClass("showing");
                    this.isVisib = true;
                } else {
                    $(this.info[0]).hide();
                    $(pn).removeClass("showing");
                    this.isVisib = false;
                }
                e.preventDefault();
            },
            ieButton: function() {
                $("body.ie7, body.ie8").find("div.ieButton").each(function() {
                    var that = this,
                    w = that.offsetWidth,
                    h = that.offsetHeight,
                    topBottom = [{
                        className: "sRight"
                    }, {
                        className: "sLeft"
                    }, {
                        className: "sMid"
}],
                    mh7 = 24,
                    mh8 = 20;

                        that.parentNode.style.position = "relative";

                        $(that).before($.create({
                            className: "css2Shadow",
                            top: function() {
                                return isIE7 ? parseInt(that.offsetTop - 1, 10) + "px" : parseInt(that.offsetTop - 4, 10) + "px";
                            },
                            left: function() {
                                return parseInt(that.offsetLeft - 4, 10) + "px";
                            },
                            width: function() {
                                return parseInt(that.offsetWidth + 10, 10) + "px";
                            },
                            appendChildren: [{
                                className: "sTop",
                                appendChildren: topBottom
                            }, {
                                className: "sMiddle",
                                height: function() {
                                    return isIE7 ? parseInt(that.offsetHeight - mh7, 10) + "px" : parseInt(that.offsetHeight - mh8, 10) + "px";
                                },
                                appendChildren: [{
                                    className: "smRight",
                                    height: function() {
                                        return isIE7 ? parseInt(that.offsetHeight - mh7, 10) + "px" : parseInt(that.offsetHeight - mh8, 10) + "px";
                                    }
                                }, {
                                    className: "smLeft",
                                    height: function() {
                                        return isIE7 ? parseInt(that.offsetHeight - mh7, 10) + "px" : parseInt(that.offsetHeight - mh8, 10) + "px";
                                    }

}]
                                }, {
                                    className: "sBottom",
                                    appendChildren: topBottom
}]
                                }));
                            });
                        },
                        init: function() {

                            var i, n = 10;
                            if (isIE6) {
                                hsk.ie6.init();
                            }
                            if (isIE7) {
                                hsk.ie7.init();
                            }

                            if (isIE6 || isIE7) {
                                $("div#start div.puff div.corners div.mid").each(function() {
                                    var that = this;

                                    that.style.width = parseInt(that.parentNode.offsetWidth - 12, 10) + "px";
                                });
                            }

                            if ((/MSIE\s[678]/).test(navigator.userAgent)) {
                                $("div.moreCoop div.box:last-child").addClass("last-child");
                            }

                            if (!document.getElementsByClassName) {
                                document.getElementsByClassName = function(cn) {
                                    var result = {},
                    resultIndex = 0,
                    all = document.getElementsByTagName("*"),
                    i,
                    re = new RegExp("(^|\\s)" + cn.trim() + "(\\s|$)");

                                    for (i = 0; i < all.length; i += 1) {

                                        if (all[i].className && (re).test(all[i].className)) {
                                            result[resultIndex] = all[i];
                                            resultIndex += 1;
                                        }
                                    }
                                    result.length = resultIndex;

                                    return result;
                                };
                            }

                            for (i = 0; i < n; i += 1) {
                                $(document.body).append("<img class=\"preLoad\" src=\"/UI/images/hogskole/numbers/" + i + ".png\" />");
                            }

                            hsk.setOpacity();
                            //hsk.menuHover();
                            //hsk.topFiller();

                            hsk.starNumbers();

                            $(".compareButton").bind("click", hsk.compCheck);

                            if ($(".start div.compareList").length) {
                                hsk.setChecked();
                                $(".start div.compareList input[type=checkbox]").click(hsk.setUrl);
                            }

                            $(".programList th.header").each(function() {
                                var re = "groupHeader\\_[\\w\\-]+", cn;

                                if (hsk.re.ssl(this.className, re, "test")) {
                                    cn = hsk.re.ssl(this.className, re, "match")[0].replace(/Header/, "").toString();

                                    this.innerHTML = "<a href=\"/#\">" + this.innerHTML + "</a>";

                                    $(this).find("a").click(function(e) {
                                        this.info = document.getElementsByClassName(cn);
                                        e.preventDefault();
                                    })

                                    $(this).find("a").click(hsk.toggleTbody);
                                }
                            });

                            $("div.box.click h3 a").each(function() {
                                var that = this,
                t = $(that),
                url = that.href,
                box = $(that).closest("div.box.click");

                                t.click(function(e) {
                                    e.preventDefault();
                                });

                                box.css({
                                    cursor: "pointer"
                                }).click(function(e) {
                                    document.location = url;
                                });

                            });

                            //hsk.wideTable();

                            if ((/WebKit/).test(navigator.userAgent)) {
                                setTimeout(hsk.addVideoArrow, 10);
                            } else {
                                hsk.addVideoArrow()
                            }

                            $(".preLoad").each(function() {
                                this.parentNode.removeChild(this);
                            });

                            $(".pageList h3 .arrow").each(function() {
                                $(this.parentNode).find("a").append(this);
                                if ((/MSIE\s7/).test(navigator.userAgent)) {
                                    this.style.position = "relative";
                                    this.style.top = "-4px";
                                }
                            });


                            /*$("fieldset").each(function () {
                            var that = this,
                            t = $(that),
                            cs = that.currentStyle,
                            k,
                            newId = $.uniqueId("test_"),
                            str = "<ul style=\"min-width: 300px;\"><li>" + that.tagName + "</li><li>offsetWith = " + that.offsetWidth + "</li>";
                    
                    for (k in cs) {
                            if (cs[k] && !(/(border|padding|font|margin)/gi).test(k) && !(/^(none|null|normal|auto|#[\d\w]+)$/gi).test(cs[k])) {
                            //if (cs[k] && (/^\d+(px)?$/gi).test(cs[k])) {
                            str += "<li>" + k + " = " + cs[k] + "</li>";
                            }
                            }
                    
                    str += "</ul>"
                
                $("body").append($.create({
                            position : "absolute",
                            display : "none",
                            border : "1px solid #000",
                            id : newId,
                            padding : "10px",
                            top : parseInt(t.offset().top + that.offsetHeight) + "px",
                            left : parseInt(t.offset().left - that.offsetHeight) + "px",
                            backgroundColor : "#fff",
                            zIndex : "5000",
                            textAlign : "left",
                            innerHTML : str
                            }));
                
                t.bind("mouseover mouseout", function (e) {
                    
                    e.stopPropagation();
                    
                    if (e.type === "mouseover") {
                            $("#" + newId).show();
                            } else {
                            $("#" + newId).hide();
                            }
                            });
                
            });*/

                            var ieStuff = null;

                            if (isIE6 || isIE7 || isIE8) {
                                ieStuff = function() {
                                    $(".nbrHits p a:last-child").addClass("last-child");

                                    $("div.compareList tr:nth-child(odd)").addClass("odd").find("td:first-child").addClass("first-child");
                                    $("div.compareList tr:nth-child(even)").addClass("even");

                                    $("div.programComparisonMatrix tbody:nth-child(4n), div.programComparisonMatrix tbody:nth-child(4n-3)").addClass("odd");
                                    //$("div.programComparisonMatrix tbody:nth-child(even)").addClass("even");

                                    $("div.otherInformation tbody tr:nth-child(odd)").addClass("odd");
                                    $("div.otherInformation tbody tr:nth-child(even)").addClass("even");
                                }
                                ieStuff();
                            }

                            $("body.ie7 div.moreCoop").css({
                                width: function() {
                                    return (this.parentNode.offsetWidth - 60) + "px";
                                }
                            });

                            equalHeight("#content div.compare > div.col");
                            equalHeight("div.backLink p, div.backLink a");
                            equalHeight("div.startSearch fieldset > div.col");

                            $("div.moreCoop div.box:nth-child(4)").addClass("nth-child4");

                            $("div.programComparisonMatrix tbody th a span.moreStat").parent().normalize().find("span.moreStat").each(function() {
                                var that = this,
                ih = that.offsetHeight,
                ns = that.nextSibling,
                txth = that.nextSibling.offsetHeight,
                np = parseInt(((ih - txth) / 2), 10);

                                if (np >= 0) {
                                    ns.style.padding = parseInt(((ih - txth) / 2) + 1, 10) + "px 0";
                                } else {
                                    that.style.marginTop = parseInt(np + 1, 10).toString().replace(/^-/, "") + "px";
                                }

                                $(that).closest("a").css({
                                    width: function() {
                                        return (this.offsetWidth - 14) + "px";
                                    }
                                });
                            });

                            $("div.programComparisonMatrix tr.ranking > td").each(function() {
                                var that = this,
                    t = $(that),
                    rank = parseInt(that.innerHTML, 10),
                    splitRank = null;

                                that.innerHTML = "";

                                t.append($.create({
                                    tagName: "span",
                                    className: "rank spriteA",
                                    repeat: 4
                                }));

                                splitRank = function() {
                                    var ret = "";

                                    if (rank >= 0 && rank <= 105) {
                                        ret = "4";
                                    } else if (rank >= 106 && rank <= 210) {
                                        ret = "3";
                                    } else if (rank >= 211 && rank <= 315) {
                                        ret = "2";
                                    } else if (rank >= 316 && rank <= 420) {
                                        ret = "1";
                                    }

                                    return ret;
                                } ();

                                t.find("span:nth-child(-n+" + splitRank + ")").addClass("ranked");

                            });

                            $("div.programComparisonMatrix tbody a span.moreStat").parent().click(function(e) {
                                e.preventDefault();

                                var tb = $(this).closest("tbody");

                                tb.find(".moreStat").toggleClass("showing");
                                tb.next("tbody").toggle();
                            });


                            var prm = Sys.WebForms.PageRequestManager.getInstance(),
                pageUpdate = function() {
                    $("div.filterByComparison input[type=radio]:checked").closest("li").addClass("checked").find("label").wrapInner("<span class=\"spriteA\"></span>");

                    if (ieStuff) {
                        ieStuff();
                    }

                    hsk.ieButton();
                };

                            prm.add_pageLoaded(function(data) {
                                pageUpdate();
                            });

                            $("div.programComparisonMatrix tbody a[rel~='inlinePopUp']").click(function(e) {
                                e.preventDefault();

                                var that = this,
                    url = that.href
                                newId = $.uniqueId("ajaxPopUp_"),
                    ofs = $(that).offset();

                                if (!that.store) {
                                    that.store = {};
                                }

                                if (that.store.popUpId) {
                                    $("#" + that.store.popUpId).remove();
                                    delete that.store.popUpId;
                                } else {
                                    that.store.popUpId = newId;

                                    $("body").append($.create({
                                        className: "ajaxPopUp2",
                                        id: newId,
                                        left: function() {
                                            return parseInt(ofs.left + that.offsetWidth, 10) + "px";
                                        }
                                    }));

                                    $("#" + newId).load(url + " div.popUpContent", function() {
                                        $("#" + newId).css({
                                            top: function() {
                                                return (ofs.top - (this.offsetHeight / 2)) + "px";
                                            }
                                        }).find("div.popUpContent").append($("<a />", {
                                            href: "/",
                                            innerHTML: "St&auml;ng",
                                            className: "close spriteA",
                                            click: function(e) {
                                                e.preventDefault();

                                                $("#" + newId).remove();
                                                delete that.store.popUpId;
                                            }
                                        })).find("h1").replaceTag("h3");
                                    });
                                }

                            });

                            $("a[href$=\.pdf], a[href$=\.doc], a[href$=\.docx], a[href$=\.xls], a[href$=\.xlsx]").each(function() {
                                var t = $(this),
                    href = this.href,
                    docType = href.toString().match(/[a-zA-Z]+$/ig).toString().toLowerCase();

                                t.addClass("docIcon " + docType + "Icon");
                            });

                            $(".mainSearch .button input, #start .startSearch fieldset button, #start .startSearch fieldset .button input, .compare .button button, .compare .button input").live("mouseover mouseout", function() {
                                $(this).toggleClass("omo");
                            });

                            document.body.style.visibility = "visible";
                        }
                    };
                    $(document).ready(hsk.init);
                } ());