﻿$(function () {
   
  //initCustomForms();
});

function initCustomForms() {
    $('select:not([multiple])').customSelect({
        onCreate: function (select, replaced, optHolder) {
            optHolder.show();
            var replacedWidth = replaced.width() + 1;
            var scrollable = optHolder.find('.inside');
            var sizer = optHolder.find('.m');
            var diffInner = 11;
            var diffWidth = 34;
            optHolder.css({ width: replacedWidth });
            sizer.css({ width: replacedWidth - diffInner });
            scrollable.children().css({ width: replacedWidth - diffWidth });
            scrollable.jScrollPane({
                showArrows: false,
                scrollbarWidth: 12,
                scrollbarMargin: 3
            });
        },
        onHide: function (replaced) {
            $('select').prev().each(function () {
                $(this).hide();
            });
            replaced.show();
        },
        onShow: function (replaced) {
            $('select').prev().each(function () {
                $(this).show();
            });
        }
    });
}

// custom selects module
$.fn.customSelect = function (_options) {
    var _options = $.extend({
        selectStructure: '<div class="select_wrap"><div class="select"></div><a class="link_select" href="#"></a><div class="disabled"></div></div>',
        optStructure: '<div class="drop"><div class="content_drop"><div class="wrap"><div class="l"></div><div class="m"><div class="inside"><ul></ul></div></div><div class="r"></div></div></div></div>',
        hideOnMouseOut: false,
        copyClass: true,
        onCreate: false,
        onHide: true,
        onShow: true,
        activeClass: 'active',
        focusClass: 'focus',
        selectText: '.select',
        selectBtn: '.link_select',
        selectDisabled: '.disabled',
        optList: 'ul'
    }, _options);
    return this.each(function () {
        var select = $(this);
        if (!select.hasClass('outtaHere')) {
            if (select.is(':visible')) {//
                var activeClass = _options.activeClass;
                var focusClass = _options.focusClass;
                var hideOnMouseOut = _options.hideOnMouseOut;
                var copyClass = _options.copyClass;
                var onCreate = _options.onCreate;
                var onHide = _options.onHide;
                var onShow = _options.onShow;
                var replaced = $(_options.selectStructure);
                var selectText = replaced.find(_options.selectText);
                var selectBtn = replaced.find(_options.selectBtn);
                var selectDisabled = replaced.find(_options.selectDisabled).hide();
                var optHolder = $(_options.optStructure);
                var optList = optHolder.find(_options.optList);
                if (copyClass) optHolder.addClass('drop-' + select.attr('class'));

                if (select.attr('disabled')) selectDisabled.show();

                select.find('option').each(function () {
                    var selOpt = $(this);
                    var _opt = $('<li><a href="#"><span>' + selOpt.html() + '</span></a></li>');
                    if (selOpt.attr('selected')) {
                        selectText.html(selOpt.html());
                        _opt.addClass('selected');
                    }
                    _opt.children('a').click(function () {
                        optList.find('li').removeClass('selected');
                        select.find('option').removeAttr('selected');
                        $(this).parent().addClass('selected');
                        selOpt.attr('selected', 'selected');
                        selectText.html(selOpt.html());
                        select.change();
                        optHolder.hide();
                        replaced.removeClass(activeClass);
                        return false;
                    });
                    optList.append(_opt);
                });
                replaced.width(select.outerWidth());
                replaced.insertBefore(select);
                optHolder.css({
                    width: select.outerWidth(),
                    display: 'none',
                    position: 'absolute'
                });

                replaced.append(optHolder);
                if (typeof onCreate === 'function') onCreate(select, replaced, optHolder);
                optHolder.hide();

                var optTimer;
                replaced.hover(function () {
                    if (optTimer) clearTimeout(optTimer);
                }, function () {
                    if (hideOnMouseOut) {
                        optTimer = setTimeout(function () {
                            optHolder.hide();
                            replaced.removeClass(activeClass);
                        }, 200);
                    }
                });
                optHolder.hover(function () {
                    if (optTimer) clearTimeout(optTimer);
                }, function () {
                    if (hideOnMouseOut) {
                        optTimer = setTimeout(function () {
                            optHolder.hide();
                            replaced.removeClass(activeClass);
                        }, 200);
                    }
                });
                selectText.click(function () {
                    if (optHolder.is(':visible')) {
                        optHolder.hide();
                        replaced.removeClass(activeClass);
                        replaced.parent().addClass(focusClass);
                    }
                    else {
                        replaced.addClass(activeClass);
                        replaced.parent().addClass(focusClass);
                        optHolder.show().children('ul').css({ height: 'auto', overflow: 'hidden' });
                    }
                    return false;
                });
                selectBtn.click(function () {
                    if (optHolder.is(':visible')) {
                        optHolder.hide();
                        replaced.removeClass(activeClass);
                        replaced.parent().removeClass(focusClass);
                        if (typeof onShow == 'function') onShow(replaced)
                    }
                    else {
                        replaced.addClass(activeClass);
                        replaced.parent().addClass(focusClass);
                        optHolder.show().children('ul').css({ height: 'auto', overflow: 'hidden' });

                        if (typeof onHide == 'function') onHide(replaced)
                    }
                    return false;
                });
                $('body').click(function (e) {
                    if (!$(e.target).parents('div.select_wrap').length) {
                        optHolder.hide();
                        replaced.removeClass(activeClass);
                        replaced.parent().removeClass(focusClass);
                    }
                });
                select.addClass('outtaHere');
            } //
        }
    });
}




/* Copyright (c) 2009 Kelvin Luck (kelvin AT kelvinluck DOT com || http://www.kelvinluck.com)
* Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
* and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
*
* See http://kelvinluck.com/assets/jquery/jScrollPane/
* $Id: jScrollPane.js 93 2010-06-01 08:17:28Z kelvin.luck $
*/
; (function (a) { a.jScrollPane = { active: [] }; a.fn.jScrollPane = function (c) { c = a.extend({}, a.fn.jScrollPane.defaults, c); var b = function () { return false }; return this.each(function () { var t = a(this); var E = this; var an = 0; var L; var ao; var r; var ad = c.topCapHeight; var j; if (a(this).parent().is(".jScrollPaneContainer")) { j = a(this).parent(); an = c.maintainPosition ? t.position().top : 0; var q = a(this).parent(); L = q.innerWidth(); ao = q.outerHeight(); a(">.jScrollPaneTrack, >.jScrollArrowUp, >.jScrollArrowDown, >.jScrollCap", q).remove(); t.css({ top: 0 }) } else { t.data("originalStyleTag", t.attr("style")); t.css("overflow", "hidden"); this.originalPadding = t.css("paddingTop") + " " + t.css("paddingRight") + " " + t.css("paddingBottom") + " " + t.css("paddingLeft"); this.originalSidePaddingTotal = (parseInt(t.css("paddingLeft")) || 0) + (parseInt(t.css("paddingRight")) || 0); L = t.innerWidth(); ao = t.innerHeight(); j = a("<div></div>").attr({ className: "jScrollPaneContainer" }).css({ height: ao + "px", width: L + "px" }); if (c.enableKeyboardNavigation) { j.attr("tabindex", c.tabIndex) } t.wrap(j); j = t.parent(); a(document).bind("emchange", function (ap, aq, p) { t.jScrollPane(c) }) } r = ao; if (c.reinitialiseOnImageLoad) { var s = a.data(E, "jScrollPaneImagesToLoad") || a("img", t); var i = []; if (s.length) { s.each(function (p, ap) { a(this).bind("load readystatechange", function () { if (a.inArray(p, i) == -1) { i.push(ap); s = a.grep(s, function (at, ar) { return at != ap }); a.data(E, "jScrollPaneImagesToLoad", s); var aq = a.extend(c, { reinitialiseOnImageLoad: false }); t.jScrollPane(aq) } }).each(function (aq, ar) { if (this.complete || this.complete === undefined) { this.src = this.src } }) }) } } var Y = this.originalSidePaddingTotal; var aj = L - c.scrollbarWidth - c.scrollbarMargin - Y; var U = { height: "auto", width: aj + "px" }; if (c.scrollbarOnLeft) { U.paddingLeft = c.scrollbarMargin + c.scrollbarWidth + "px" } else { U.paddingRight = c.scrollbarMargin + "px" } t.css(U); var W = t.outerHeight(); var R = ao / W; var V = R < 0.99; j[V ? "addClass" : "removeClass"]("jScrollPaneScrollable"); if (V) { j.append(a("<div></div>").addClass("jScrollCap jScrollCapTop").css({ height: c.topCapHeight }), a("<div></div>").attr({ className: "jScrollPaneTrack" }).css({ width: c.scrollbarWidth + "px" }).append(a("<div></div>").attr({ className: "jScrollPaneDrag" }).css({ width: c.scrollbarWidth + "px" }).append(a("<div></div>").attr({ className: "jScrollPaneDragTop" }).css({ width: c.scrollbarWidth + "px" }), a("<div></div>").attr({ className: "jScrollPaneDragBottom" }).css({ width: c.scrollbarWidth + "px" }))), a("<div></div>").addClass("jScrollCap jScrollCapBottom").css({ height: c.bottomCapHeight })); var ak = a(">.jScrollPaneTrack", j); var u = a(">.jScrollPaneTrack .jScrollPaneDrag", j); var am; var g = []; var aa; var S = function () { if (aa > 4 || aa % 4 == 0) { ai(af + am * I) } aa++ }; if (c.enableKeyboardNavigation) { j.bind("keydown.jscrollpane", function (p) { switch (p.keyCode) { case 38: am = -1; aa = 0; S(); g[g.length] = setInterval(S, 100); return false; case 40: am = 1; aa = 0; S(); g[g.length] = setInterval(S, 100); return false; case 33: case 34: return false; default: } }).bind("keyup.jscrollpane", function (ap) { if (ap.keyCode == 38 || ap.keyCode == 40) { for (var p = 0; p < g.length; p++) { clearInterval(g[p]) } return false } }) } if (c.showArrows) { var P; var y; var o = function (p) { a("html").unbind("mouseup", o); P.removeClass("jScrollActiveArrowButton"); clearInterval(y) }; var H = function () { a("html").bind("mouseup", o); P.addClass("jScrollActiveArrowButton"); aa = 0; S(); y = setInterval(S, 100) }; j.append(a("<a></a>").attr({ href: "javascript:;", className: "jScrollArrowUp", tabindex: -1 }).css({ width: c.scrollbarWidth + "px", top: c.topCapHeight + "px" }).html("Scroll up").bind("mousedown", function () { P = a(this); am = -1; H(); this.blur(); return false }).bind("click", b), a("<a></a>").attr({ href: "javascript:;", className: "jScrollArrowDown", tabindex: -1 }).css({ width: c.scrollbarWidth + "px", bottom: c.bottomCapHeight + "px" }).html("Scroll down").bind("mousedown", function () { P = a(this); am = 1; H(); this.blur(); return false }).bind("click", b)); var v = a(">.jScrollArrowUp", j); var m = a(">.jScrollArrowDown", j) } if (c.arrowSize) { r = ao - c.arrowSize - c.arrowSize; ad += c.arrowSize } else { if (v) { var ab = v.height(); c.arrowSize = ab; r = ao - ab - m.height(); ad += ab } } r -= c.topCapHeight + c.bottomCapHeight; ak.css({ height: r + "px", top: ad + "px" }); var ag = a(this).css({ position: "absolute", overflow: "visible" }); var d; var F; var I; var af = 0; var C = R * ao / 2; var G = function (ap, ar) { var aq = ar == "X" ? "Left" : "Top"; return ap["page" + ar] || (ap["client" + ar] + (document.documentElement["scroll" + aq] || document.body["scroll" + aq])) || 0 }; var O = function () { return false }; var ae = function () { X(); d = u.offset(false); d.top -= af; F = r - u[0].offsetHeight; I = 2 * c.wheelSpeed * F / W }; var e = function (p) { ae(); C = G(p, "Y") - af - d.top; a("html").bind("mouseup", z).bind("mousemove", Q).bind("mouseleave", z); if (a.browser.msie) { a("html").bind("dragstart", O).bind("selectstart", O) } return false }; var z = function () { a("html").unbind("mouseup", z).unbind("mousemove", Q); C = R * ao / 2; if (a.browser.msie) { a("html").unbind("dragstart", O).unbind("selectstart", O) } }; var ai = function (ap) { j.scrollTop(0); ap = ap < 0 ? 0 : (ap > F ? F : ap); af = ap; u.css({ top: ap + "px" }); var aq = ap / F; t.data("jScrollPanePosition", (ao - W) * -aq); ag.css({ top: ((ao - W) * aq) + "px" }); t.trigger("scroll"); if (c.showArrows) { v[ap == 0 ? "addClass" : "removeClass"]("disabled"); m[ap == F ? "addClass" : "removeClass"]("disabled") } }; var Q = function (p) { ai(G(p, "Y") - d.top - C) }; var Z = Math.max(Math.min(R * (ao - c.arrowSize * 2), c.dragMaxHeight), c.dragMinHeight); u.css({ height: Z + "px" }).bind("mousedown", e); var T; var w; var l; var ac = function () { if (w > 8 || w % 4 == 0) { ai((af - ((af - l) / 2))) } w++ }; var al = function () { clearInterval(T); a("html").unbind("mouseup", al).unbind("mousemove", N) }; var N = function (p) { l = G(p, "Y") - d.top - C }; var A = function (p) { ae(); N(p); w = 0; a("html").bind("mouseup", al).bind("mousemove", N); T = setInterval(ac, 100); ac(); return false }; ak.bind("mousedown", A); j.bind("mousewheel", function (ap, ar) { ar = ar || (ap.wheelDelta ? ap.wheelDelta / 120 : (ap.detail) ? -ap.detail / 3 : 0); ae(); X(); var aq = af; ai(af - ar * I); var p = aq != af; return !p }); var f; var D; function J() { var p = (f - af) / c.animateStep; if (p > 1 || p < -1) { ai(af + p) } else { ai(f); X() } } var X = function () { if (D) { clearInterval(D); delete f } }; var ah = function (at, p) { if (typeof at == "string") { try { $e = a(at, t) } catch (ar) { return } if (!$e.length) { return } at = $e.offset().top - t.offset().top } X(); var aq = W - ao; at = at > aq ? aq : at; t.data("jScrollPaneMaxScroll", aq); var ap = at / aq * F; if (p || !c.animateTo) { ai(ap) } else { j.scrollTop(0); f = ap; D = setInterval(J, c.animateInterval) } }; t[0].scrollTo = ah; t[0].scrollBy = function (ap) { var p = -parseInt(ag.css("top")) || 0; ah(p + ap) }; ae(); ah(-an, true); a("*", this).bind("focus", function (au) { var at = a(this); var aw = 0; var ap = 100; while (at[0] != t[0]) { aw += at.position().top; at = at.offsetParent(); if (!ap--) { return } } var p = -parseInt(ag.css("top")) || 0; var av = p + ao; var ar = aw > p && aw < av; if (!ar) { var aq = aw - c.scrollbarMargin; if (aw > p) { aq += a(this).height() + 15 + c.scrollbarMargin - ao } ah(aq) } }); if (c.observeHash) { if (location.hash && location.hash.length > 1) { setTimeout(function () { ah(location.hash) }, a.browser.safari ? 100 : 0) } a(document).bind("click", function (ap) { $target = a(ap.target); if ($target.is("a")) { var p = $target.attr("href"); if (p && p.substr(0, 1) == "#" && p.length > 1) { setTimeout(function () { ah(p, !c.animateToInternalLinks) }, a.browser.safari ? 100 : 0) } } }) } function B(p) { a(document).bind("mousemove.jScrollPaneDragging", x); a(document).bind("mouseup.jScrollPaneDragging", n) } var M; var h; function K() { direction = M < 0 ? -1 : 1; t[0].scrollBy(M / 2) } function k() { if (h) { clearInterval(h); h = undefined } } function x(aq) { var ar = t.parent().offset().top; var p = ar + ao; var ap = G(aq, "Y"); M = ap < ar ? ap - ar : (ap > p ? ap - p : 0); if (M == 0) { k() } else { if (!h) { h = setInterval(K, 100) } } } function n(p) { a(document).unbind("mousemove.jScrollPaneDragging").unbind("mouseup.jScrollPaneDragging"); k() } j.bind("mousedown.jScrollPane", B); a.jScrollPane.active.push(t[0]) } else { t.css({ height: ao + "px", width: L - this.originalSidePaddingTotal + "px", padding: this.originalPadding }); t[0].scrollTo = t[0].scrollBy = function () { }; t.parent().unbind("mousewheel").unbind("mousedown.jScrollPane").unbind("keydown.jscrollpane").unbind("keyup.jscrollpane") } }) }; a.fn.jScrollPaneRemove = function () { a(this).each(function () { $this = a(this); var b = $this.parent(); if (b.is(".jScrollPaneContainer")) { $this.css({ top: "", height: "", width: "", padding: "", overflow: "", position: "" }); $this.attr("style", $this.data("originalStyleTag")); b.after($this).remove() } }) }; a.fn.jScrollPane.defaults = { scrollbarWidth: 10, scrollbarMargin: 5, wheelSpeed: 18, showArrows: false, arrowSize: 0, animateTo: false, dragMinHeight: 1, dragMaxHeight: 99999, animateInterval: 100, animateStep: 3, maintainPosition: true, scrollbarOnLeft: false, reinitialiseOnImageLoad: false, tabIndex: 0, enableKeyboardNavigation: true, animateToInternalLinks: false, topCapHeight: 0, bottomCapHeight: 0, observeHash: true }; a(window).bind("unload", function () { var c = a.jScrollPane.active; for (var b = 0; b < c.length; b++) { c[b].scrollTo = c[b].scrollBy = null } }) })(jQuery);
