﻿var Site = {
    init: function() {
        Site.TextSize.init();

//        if ($.browser.msie && $.browser.version.substr(0, 1) < 7) {
//            Site.Suckerfish.init();
//        }
    },

    TextSize: {
        opts: { expires: 30, path: "/" },
        cookieName: "botoxtxt",
        sizes: ["1.45em", "1.65em", "1.95em"],

        init: function() {
            this.scale = $.cookie(this.cookieName);
            if (this.scale == null) this.scale = "0";

            this.scale = parseInt(this.scale);

            this.targeted = $("#siteBody");

            this.toggles = $("#utilText .txtSize");
            var self = this;
            this.toggles.click(function() {
                var index = $(this).index();
                self.setScale(index);
            });

            this.setScale(this.scale);
        },

        toggleActive: function(index) {
            $(this.toggles[this.scale]).removeClass("active");
            $(this.toggles[index]).addClass("active");
        },

        setScale: function(index) {
            this.targeted.css("font-size", this.sizes[index]);
            this.toggleActive(index);
            $.cookie(this.cookieName, index + "", this.opts);
            this.scale = index;
        }
    },

    Toggles: {
        activeClass: "active",
        toggleSelector: ".navTabs ul li",
        toggledSelector: ".tabbedItem",

        init: function() {
            this.toggles = $(this.toggleSelector);
            this.toggled = $(this.toggledSelector);

            this.toggles.each(jQuery.proxy(function(index, el) {
                el = $(el);
                var togd = $(this.toggled[index]);

                el.find("a").attr("href", "javascript:void(0);");

                var self = this;
                el.click(function() {
                    self.toggleItem(index);
                });

                if (index != 0) togd.hide()
                else el.addClass("active")

            }, this));


            this.curr = 0;
        },

        toggleItem: function(index) {
            if (index === this.curr) return;

            $(this.toggles[this.curr]).removeClass("active");
            $(this.toggled[this.curr]).hide();

            $(this.toggles[index]).addClass("active");
            $(this.toggled[index]).show();

            this.curr = index;
        }

    },

    Suckerfish: {
        selector: "#nav li.item",
        init: function() {
            var lis = $(this.selector);
            var flyouts = [];
            var btns = [];

            lis.each(function(index, el) {
                el = $(el);
                flyouts.push(el.find(".flyout"));
                btns.push(el.find(".btn"));

                el.bind({
                    mouseenter: function() {
                        el.addClass("over");
                        flyouts[index].css("visibility", "visible");
                    },
                    mouseleave: function() {
                        el.removeClass("over");
                        flyouts[index].css("visibility", "");
                    }
                });

            });
        }
    }

};

$(document).ready(function() {
    Site.init();

    Sys.Mvc.ValidatorRegistry.validators["boolean"] = function(rule) {
        return function(value, context) {
            var elem = $(context.fieldContext.elements);

            if (elem.is('[type="checkbox"]')) {
                if (elem.is(':checked'))
                    return true;

                return rule.ErrorMessage;
            }

            if (elem.val())
                return true;

            return rule.ErrorMessage;
        }
    };

});

function videoOnStop(id) {
    $.post('/home.aspx/videowatched');
}


function submitFindDoctor(btn) {
    $(btn).attr("onclick", "");
	
    var myform = $("<form>").attr({"action":"/findadoctor.aspx", "method":"get"}).css("visibility","hidden");
    var inputs = $("#findDoctorForm input").clone();
	
    $("body").append(myform);		
    myform.append(inputs);
    myform.submit();
};

function submitOmnitureLink(linkEvent) {
    var s = s_gi(s_account);
    s.linkTrackVars = 'events';
    s.tl(this,'o',linkEvent);
}



