(function ($) {


    $.fn.hoverIntent = function (f, g) {
        // default configuration options
        var cfg = {
            sensitivity: 1,
            interval: 100,
            timeout: 0
        };
        // override configuration options with user supplied object
        cfg = $.extend(cfg, g ? {
            over: f,
            out: g
        } : f);
        // instantiate variables
        // cX, cY = current X and Y position of mouse, updated by mousemove event
        // pX, pY = previous X and Y position of mouse, set by mouseover and polling interval
        var cX, cY, pX, pY;
        // A private function for getting mouse position
        var track = function (ev) {
                cX = ev.pageX;
                cY = ev.pageY;
            };
        // A private function for comparing current and previous mouse position
        var compare = function (ev, ob) {
                ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
                // compare mouse positions to see if they've crossed the threshold
                if ((Math.abs(pX - cX) + Math.abs(pY - cY)) < cfg.sensitivity) {
                    $j(ob).unbind("mousemove", track);
                    // set hoverIntent state to true (so mouseOut can be called)
                    ob.hoverIntent_s = 1;
                    return cfg.over.apply(ob, [ev]);
                } else {
                    // set previous coordinates for next time
                    pX = cX;
                    pY = cY;
                    // use self-calling timeout, guarantees intervals are spaced out properly (avoids JavaScript timer bugs)
                    ob.hoverIntent_t = setTimeout(function () {
                        compare(ev, ob);
                    }, cfg.interval);
                }
            };
        // A private function for delaying the mouseOut function
        var delay = function (ev, ob) {
                ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
                ob.hoverIntent_s = 0;
                return cfg.out.apply(ob, [ev]);
            };
        // A private function for handling mouse 'hovering'
        var handleHover = function (e) {
                // copy objects to be passed into t (required for event object to be passed in IE)
                var ev = jQuery.extend({}, e);
                var ob = this;
                // cancel hoverIntent timer if it exists
                if (ob.hoverIntent_t) {
                    ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
                }
                // if e.type == "mouseenter"
                if (e.type == "mouseenter") {
                    // set "previous" X and Y position based on initial entry point
                    pX = ev.pageX;
                    pY = ev.pageY;
                    // update "current" X and Y position based on mousemove
                    $j(ob).bind("mousemove", track);
                    // start polling interval (self-calling timeout) to compare mouse coordinates over time
                    if (ob.hoverIntent_s != 1) {
                        ob.hoverIntent_t = setTimeout(function () {
                            compare(ev, ob);
                        }, cfg.interval);
                    }
                    // else e.type == "mouseleave"
                } else {
                    // unbind expensive mousemove event
                    $j(ob).unbind("mousemove", track);
                    // if hoverIntent state is true, then call the mouseOut function after the specified delay
                    if (ob.hoverIntent_s == 1) {
                        ob.hoverIntent_t = setTimeout(function () {
                            delay(ev, ob);
                        }, cfg.timeout);
                    }
                }
            };
        // bind the function to the two event listeners
        return this.bind('mouseenter', handleHover).bind('mouseleave', handleHover);
    };
   

})(jQuery);
 //Print section function
    (function ($) {
        var counter = 0;
        var modes = {
            iframe: "iframe",
            popup: "popup"
        };
        var defaults = {
            mode: modes.iframe,
            popHt: 500,
            popWd: 400,
            popX: 200,
            popY: 200,
            popTitle: '',
            popClose: false
        };

        var settings = {}; //global settings
        $j.fn.printArea = function (options) {
            $.extend(settings, defaults, options);

            counter++;
            var idPrefix = "printArea_";
            $j("[id^=" + idPrefix + "]").remove();
            var ele = getFormData($j(this));

            settings.id = idPrefix + counter;

            var writeDoc;
            var printWindow;

            switch (settings.mode) {
            case modes.iframe:
                var f = new Iframe();
                writeDoc = f.doc;
                printWindow = f.contentWindow || f;
                break;
            case modes.popup:
                printWindow = new Popup();
                writeDoc = printWindow.doc;
            }

            writeDoc.open();
            writeDoc.write(docType() + "<html>" + getHead() + getBody(ele) + "</html>");
            writeDoc.close();

            printWindow.focus();
            printWindow.print();

            if (settings.mode == modes.popup && settings.popClose) printWindow.close();
        }

        function docType() {
            if (settings.mode == modes.iframe || !settings.strict) return "";

            var standard = settings.strict == false ? " Trasitional" : "";
            var dtd = settings.strict == false ? "loose" : "strict";

            return '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01' + standard + '//EN" "http://www.w3.org/TR/html4/' + dtd + '.dtd">';
        }

        function getHead() {
            var head = "<head><title>" + settings.popTitle + "</title>";
            $j(document).find("link").filter(function () {
                return $j(this).attr("rel").toLowerCase() == "stylesheet";
            }).filter(function () { // this filter contributed by "mindinquiring"
                var media = $(this).attr("media");
                return (media.toLowerCase() == "" || media.toLowerCase() == "print")
            }).each(function () {
                head += '<link type="text/css" rel="stylesheet" href="' + $j(this).attr("href") + '" >';
            });
            head += "</head>";
            return head;
        }

        function getBody(printElement) {
            return '<body><div class="' + $j(printElement).attr("class") + '">' + $j(printElement).html() + '</div></body>';
        }

        function getFormData(ele) {
            $j("input,select,textarea", ele).each(function () {
                // In cases where radio, checkboxes and select elements are selected and deselected, and the print
                // button is pressed between select/deselect, the print screen shows incorrectly selected elements.
                // To ensure that the correct inputs are selected, when eventually printed, we must inspect each dom element
                var type = $j(this).attr("type");
                if (type == "radio" || type == "checkbox") {
                    if ($j(this).is(":not(:checked)")) this.removeAttribute("checked");
                    else this.setAttribute("checked", true);
                } else if (type == "text") this.setAttribute("value", $j(this).val());
                else if (type == "select-multiple" || type == "select-one") $j(this).find("option").each(function () {
                    if ($j(this).is(":not(:selected)")) this.removeAttribute("selected");
                    else this.setAttribute("selected", true);
                });
                else if (type == "textarea") {
                    var v = $j(this).attr("value");
                    if ($.browser.mozilla) {
                        if (this.firstChild) this.firstChild.textContent = v;
                        else this.textContent = v;
                    } else this.innerHTML = v;
                }
            });
            return ele;
        }

        function Iframe() {
            var frameId = settings.id;
            var iframeStyle = 'border:0;position:absolute;width:0px;height:0px;left:0px;top:0px;';
            var iframe;

            try {
                iframe = document.createElement('iframe');
                document.body.appendChild(iframe);
                $j(iframe).attr({
                    style: iframeStyle,
                    id: frameId,
                    src: ""
                });
                iframe.doc = null;
                iframe.doc = iframe.contentDocument ? iframe.contentDocument : (iframe.contentWindow ? iframe.contentWindow.document : iframe.document);
            } catch (e) {
                throw e + ". iframes may not be supported in this browser.";
            }

            if (iframe.doc == null) throw "Cannot find document.";

            return iframe;
        }

        function Popup() {
            var windowAttr = "location=yes,statusbar=no,directories=no,menubar=no,titlebar=no,toolbar=no,dependent=no";
            windowAttr += ",width=" + settings.popWd + ",height=" + settings.popHt;
            windowAttr += ",resizable=yes,screenX=" + settings.popX + ",screenY=" + settings.popY + ",personalbar=no,scrollbars=no";

            var newWin = window.open("", "_blank", windowAttr);

            newWin.doc = newWin.document;

            return newWin;
        }
    })(jQuery);
    
var timeout = 500;
var closetimer = 0;
var ddmenuitem = 0;

function jsddm_open() {
    jsddm_canceltimer();
    jsddm_close();
    ddmenuitem = $j(this).find('ul').css('visibility', 'visible');
}

function jsddm_close() {
    if (ddmenuitem) ddmenuitem.css('visibility', 'hidden');
}

function jsddm_timer() {
    closetimer = window.setTimeout(jsddm_close, timeout);
}

function jsddm_canceltimer() {
    if (closetimer) {
        window.clearTimeout(closetimer);
        closetimer = null;
    }
}


document.onclick = jsddm_close;

function showNumericError() {
    $j(".numeric-error-message").stop(true, true).show().delay(1500).fadeOut();
}

//start document ready
$j(document).ready(function () {

    $.fn.insertSharing = function () {

        var mailurl = "/EmailPage.aspx?url=" + window.location;
        //href="' + mailurl + '"
        $j("#tools li.email").html('<a class="modal" href="' + mailurl + '" target="_blank"></a>');

        $j("#tools li.print a").click(function () {
            printCall();
            return false;
        });
    };
   

    $.fn.insertSharing()

    jQuery.fn.forceNumeric = function () {

        return this.each(function () {
            $j(this).keydown(function (e) {
                var key = e.which || e.keyCode;

                if (!e.shiftKey && !e.altKey && !e.ctrlKey &&
                // numbers   
                key >= 48 && key <= 57 ||
                // Numeric keypad
                key >= 96 && key <= 105 ||
                // comma, period and minus, . on keypad
                key == 190 || key == 188 || key == 109 || key == 110 ||
                // Backspace and Tab and Enter
                key == 8 || key == 9 || key == 13 ||
                // Home and End
                key == 35 || key == 36 ||
                // left and right arrows
                key == 37 || key == 39 ||
                // Del and Ins
                key == 46 || key == 45)

                return true;
                showNumericError();
                return false;


            });
        });
    }


    $j('.print.list > a').click(function () {
        $j(".find-doc-results").printArea()
    })
    $j('.print.directions').click(function () {
        $j(".directions-list").printArea()
    })
    $j('#nav > li').bind('mouseover', jsddm_open)
    $j('#nav > li').bind('mouseout', jsddm_timer)
    $j('#zipcode').focus(function () {
        $j(this).val('')
    })
    $j('#zipcode').blur(function () {
        if ($j(this).val() == '') {
            $j(this).val('Enter Zip Code')
        }
    })
    $j('#signupField').focus(function () {
        $j(this).val('')
    })
    $j('#signupField').blur(function () {
        if ($j(this).val() == '') {
            $j(this).val('Enter your email address')
        }
    })
    //start jquery cookie function
    jQuery.cookie = function (name, value, options) {
        if (typeof value != 'undefined') {
            // name and value given, set cookie
            options = options || {};
            if (value === null) {
                value = '';
                options.expires = -1;
            }
            var expires = '';
            if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
                var date;
                if (typeof options.expires == 'number') {
                    date = new Date();
                    date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
                } else {
                    date = options.expires;
                }
                expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
            }
            // CAUTION: Needed to parenthesize options.path and options.domain
            // in the following expressions, otherwise they evaluate to undefined
            // in the packed version for some reason...
            var path = options.path ? '; path=' + (options.path) : '';
            var domain = options.domain ? '; domain=' + (options.domain) : '';
            var secure = options.secure ? '; secure' : '';
            document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
        } else {
            // only name given, get cookie
            var cookieValue = null;
            if (document.cookie && document.cookie != '') {
                var cookies = document.cookie.split(';');
                for (var i = 0; i < cookies.length; i++) {
                    var cookie = jQuery.trim(cookies[i]); // Does this cookie string begin with the name we want?
                    if (cookie.substring(0, name.length + 1) == (name + '=')) {
                        cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                        break;
                    }
                }
            }
            return cookieValue;
        }
    }; //end jquery cookie function
    (jQuery)
    var sitefunctions = {
        textresize: function () {
            // show text resizing links
            var $cookie_name = "synviscFontSize";
            var originalFontSize = $j(".resize-text").css("font-size"); //alert(originalFontSize);
            // if exists load saved value, otherwise store it
            if ($.cookie($cookie_name)) {
                var $getSize = $.cookie($cookie_name);
                $j(".resize-text").css({
                    fontSize: $getSize + ($getSize.indexOf("px") != -1 ? "" : "px")
                }); // IE fix for double "pxpx" error
            } else {
                $.cookie($cookie_name, originalFontSize);
            }
            // text "-" link
            $j("li.resize-norm").click(function () {
                $j(".resize-text").css("font-size", originalFontSize);
                $.cookie($cookie_name, originalFontSize);
                return false;
            }); // reset link
            $j("li.resize-lg").bind("click", function () {
                var currentFontSize = $j('.resize-text').css('font-size');
                var newFontSize = 16;
                $j(".resize-text").css("font-size", newFontSize);
                $.cookie($cookie_name, newFontSize);
                return false;
            });
        }
    }
    sitefunctions.textresize();
    $j('a.modal.knee-pain').colorbox({width:780, height:560, iframe:true});
    $j('a.asd').colorbox({width:566, height:160, iframe:true});
    $j('a.modal.textme').colorbox({width:580, height:360, iframe:true});
    $j('.email a.modal').colorbox({width:570, height:710, iframe:true});
    $j('.modalClose').click(function(){parent.jQuery.fn.colorbox.close();});
})

// prevent IE6 flicker
if (jQuery.browser.msie && jQuery.browser.version.substr(0, 1) == "6") {
    try {
        document.execCommand('BackgroundImageCache', false, true);
    } catch (e) {}
}

