﻿/// <reference path="jquery-1.4.1-vsdoc.js" />
jQuery.noConflict();

jQuery.cookie = function (key, value, options) {

    if (arguments.length > 1 && (value === null || typeof value !== "object")) {
        options = jQuery.extend({}, options);

        if (value === null) {
            options.expires = -1;
        }

        if (typeof options.expires === 'number') {
            var days = options.expires, t = options.expires = new Date();
            t.setDate(t.getDate() + days);
        }

        return (document.cookie = [
            encodeURIComponent(key), '=',
            options.raw ? String(value) : encodeURIComponent(String(value)),
            options.expires ? '; expires=' + options.expires.toUTCString() : '',
            options.path ? '; path=' + options.path : '',
            options.domain ? '; domain=' + options.domain : '',
            options.secure ? '; secure' : ''
        ].join(''));
    }

    options = value || {};
    var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
    return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};

(function($){
$.fn.collapsible = function () {
    return $(this).each(function () {

        //define
        var collapsibleHeading = $(this);
        var collapsibleContent = collapsibleHeading.next();

        //modify markup & attributes
        collapsibleHeading.addClass('collapsible-heading')
			.prepend('<span class="collapsible-heading-status"></span>')
			.wrapInner('<a href="#" class="collapsible-heading-toggle"></a>');

        collapsibleContent.addClass('collapsible-content');

        //events
        collapsibleHeading
			.bind('collapse', function () {
			    $(this)
					.addClass('collapsible-heading-collapsed')
					.find('.collapsible-heading-status').text('Vis ');

			    collapsibleContent.slideUp(function () {
			        $(this).addClass('collapsible-content-collapsed').removeAttr('style').attr('aria-hidden', true);
			    });
			})
			.bind('expand', function () {
			    $(this)
					.removeClass('collapsible-heading-collapsed')
					.find('.collapsible-heading-status').text('Skjul ');

			    collapsibleContent
					.slideDown(function () {
					    $(this).removeClass('collapsible-content-collapsed').removeAttr('style').attr('aria-hidden', false);
					});
			})
			.click(function () {
			    if ($(this).is('.collapsible-heading-collapsed')) {
			        $(this).trigger('expand');
			    }
			    else {
			        $(this).trigger('collapse');
			    }
			    return false;
			})
			.trigger('collapse');
    });
};	
})(jQuery);

jQuery(function ($) {
    Engine = {
        fixes: {
            browsers: function () {
                if (jQuery.browser.webkit) {
                    jQuery("html").addClass("webkit");
                }
                if (jQuery.browser.mozilla) {
                    jQuery("html").addClass("mozilla");
                }
                if (jQuery.browser.opera) {
                    jQuery("html").addClass("opera");
                }
            },
            zebraTable: function () {
                $("tr:nth-child(odd)").addClass("odd");
            },
            cssContent: function () {
                $("blockquote").each(function () {
                    $(this)
                        .prepend("<b class='before'>\"</b>")
                        .append("<b class='after'> </b>");
                })
            },
            zIndexWorkaround: function () {
                $(".dropdown ul").parents().each(function () {
                    var p = $(this);
                    var pos = p.css("position");

                    if (pos == "relative" || pos == "absolute" || pos == "fixed") {
                        p.hover(
                            function () {
                                $(this).addClass("on-top");
                            },
                            function () {
                                $(this).removeClass("on-top");
                            }
                        );
                    }
                });
            }
        },
        form: {
            inputTypes: function () {
                /*
                $("input.tel").each(function () { this.type = "tel"; });
                $("input.url").each(function () { this.type = "url"; });
                $("input.email").each(function () { this.type = "email"; });
                $("input.datetime").each(function () { this.type = "datetime"; });
                $("input.date").each(function () { this.type = "date"; });
                $("input.month").each(function () { this.type = "month"; });
                $("input.week").each(function () { this.type = "week"; });
                $("input.time").each(function () { this.type = "time"; });
                $("input.datetime-local").each(function () { this.type = "datetime-local"; });
                $("input.number").each(function () { this.type = "number"; });
                $("input.range").each(function () { this.type = "range"; });
                */
                /*
                $.tools.dateinput.localize("da", {
                months: 'januar,februar,marts,april,maj,juni,juli,august,september,oktober,november,december',
                shortMonths: 'jan,feb,mar,apr,maj,jun,jul,aug,sep,okt,nov,dec',
                days: 'søndag,mandag,tirsdag,onsdag,torsdag,fredag,lørdag',
                shortDays: 'sø,ma,ti,on,to,fre,lø'
                });
                $("input.date").dateinput({
                lang: 'da',
                format: 'dd-mm-yyyy',
                firstDay: 1
                });
                */
                $("input.date").datepicker({
                    dateFormat: "dd-mm-yy",
                    firstDay: 1,
                    nextText: 'Næste',
                    prevText: 'Forrige',
                    dayNamesMin: ['Sø', 'Ma', 'Ti', 'On', 'To', 'Fr', 'Lø'],
                    dayNamesShort: ['Søn', 'Man', 'Tir', 'Ons', 'Tor', 'Fre', 'Lør'],
                    monthNamesShort: ['Jan', 'Feb', 'Mar', 'Apr', 'Maj', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dec'],
                    monthNames: ['Januar', 'Februar', 'Marts', 'April', 'Maj', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'December']
                });
                
            }
        },
        ui: {

            search: function () {

                var testInput = document.createElement("input");
                if (!(!!(testInput.placeholder === "") && !!(testInput.placeholder !== "undefined"))) {

                    var $search = $("#search input.text");
                    if ($search.length) {
                        var _default = $search.attr("placeholder");
                        $search
						    .attr("value", _default)
						    .focus(function () {
						        if (this.value == _default) {
						            this.value = "";
						        }
						    })
						    .blur(function () {
						        if (this.value == "") {
						            this.value = _default;
						        }
						    });
                    }

                }
            },

            collapsible: function () {
                $(".collapsible h3").collapsible();
                $(".collapsible .js-hide").removeClass("js-hide");
            },

            dropdown: function () {
                $(".dropdown").bind("mouseenter", function () {
                    $(this).addClass("show");
                });
                $(".dropdown").bind("mouseleave", function () {
                    $(this).removeClass("show");
                });
                $(".dropdown").bind("click", function () {
                    $(this).toggleClass("show");
                });

            },

            tabs: function () {
                var $themebox = $("#themebox");
                if ($themebox) {
                    var headings = $('h2', $themebox);
                    $themebox.append('<ul class="tabs"><\/ul>');
                    //For every heading create an item (<li>)
                    headings.each(function () {
                        var text = $(this).text();
                        $(".tabs", $themebox).append('<li><a href="#">' + text + '</a></li>');
                    });

                    // setup ul.tabs to work as tabs for each div directly under div.panes
                    $(".tabs", $themebox).tabs(".panes > div");
                }
            },
            jobslider: function () {

                var $jobslider = $("#jobslider");

                if ($jobslider) {

                    var $navi = $('.navi', $jobslider);
                    $navi.append('<a class="prev"><b></b></a>');

                    $navi.append('<ul class="tabs"><\/ul>');
                    var $tabs = $('.tabs', $jobslider);

                    var headings = $('.nameTitle', $jobslider);
                    headings.each(function () {
                        var text = $(this).html();
                        $tabs.append('<li><a href="#">' + text + '</a></li>');
                    });
                    $("li:first-child a", $tabs).addClass("current");
                    $navi.append('<a class="next"><b></b></a>');

                    $jobslider
                        .scrollable()
                        .navigator({
                            navi: "#flowtabs",
                            naviItem: "li > a",
                            activeClass: "current",
                            history: true
                        });
                }

            },

            contact: function () {
                var $contact = $(".contact");
                if ($contact.length) {
                    var $select = $contact.find("select");
                    if ($select.length) {
                        $select
                            .change(
                                function () {
                                    $("#" + this.value).show().siblings().hide();
                                    $.cookie("contact", this.value)
                                }
                            )
                            .val($.cookie("contact"));

                        if ($select.val()) {
                            $("#" + $select.val()).show().siblings().hide()
                        } else {
                            $contact.find(".item:gt(0)").hide();
                        }
                    }
                }
            },

            printSend: function () {
                var $tools = $("#tools");
                if ($tools.length) {
                    $tools.find(".print a").click(function () {
                        window.print();
                        return false;
                    });

                    /*.html("<div><a href='#' title='Print (CTRL + P)'>Print</a><a href='#' title='Send link (ALT + F + S + H)'>Send</a></div>")
                    .find("a:first-child")
                    .click(function () { window.print(); return false; })
                    .end()
                    .find("a:last-child")
                    .click(function () { alert("Således sender du et link til denne side via dit email-program.\n\n - Klik på 'Filer' i menubjælken (ALT + F)\n - Vælg 'Send...' (S)\n - Vælg 'Hyperlink med e-mail...' (H)"); return false; });
                    */
                }
            }

        }
    }
});


/*	On DOM loaded */
jQuery(document).ready(function ($) {
    Engine.fixes.browsers();
    if (jQuery.browser.msie) {
        if (jQuery.browser.version <= 7) {
            Engine.fixes.cssContent();
            Engine.fixes.zIndexWorkaround();
        }
        if (jQuery.browser.version <= 8) {
            Engine.fixes.zebraTable();
        }
    }
    Engine.ui.tabs();
    Engine.ui.jobslider();
    Engine.ui.search();
    Engine.ui.contact();
    Engine.ui.printSend();
    Engine.ui.collapsible();
    Engine.ui.dropdown();
    Engine.form.inputTypes();
});

/*	On WINDOW loaded */
jQuery(window).load(function ($) {
});
