﻿/* Set up Add2Any defaults */
_A2AHost = ((document.location.protocol == "https:") ? "https://http-s1.simplecdn.net/" : "http://") + "static.addtoany.com/";
a2a_linkname = $("#MetaTitle").attr("content");
a2a_linkurl = location.href;
a2a_show_title=1;
a2a_color_main="dbdbdb";
a2a_color_border="a1a1a1";
a2a_color_link_text="008bab";
a2a_color_link_text_hover="008bab";
a2a_color_bg="ffffff";
a2a_color_arrow="008bab";
a2a_color_arrow_hover="008bab";
a2a_onclick=1;
a2a_orientation="down";
a2a_num_services=6;

var CPActivePanel = new Array();


/*
=======================================================================
JQUERY FUNCTIONS
=======================================================================
*/

$.fn.slideFadeToggle = function(speed, easing, callback) {
    return this.animate({opacity: 'toggle', height: 'toggle'}, speed, easing, callback);
};

$.fn.slideFadeShow = function(speed, easing, callback) {
    if($.browser.msie && 2 == 1)
        return this.animate({height: 'show'}, speed, easing, callback);
     else
        return this.animate({opacity: 'show', height: 'show'}, speed, easing, callback);
};

$.fn.slideFadeHide = function(speed, easing, callback) {
    if($.browser.msie && 2 == 1)
        return this.animate({height: 'hide'}, speed, easing, callback);
    else
        return this.animate({opacity: 'hide', height: 'hide'}, speed, easing, callback);
};



$.fn.Tabalyzer = function(options) {

	$.fn.Tabalyzer.defaults = {
	    ServiceURL: null
	};
	
	var o = $.extend({}, $.fn.Tabalyzer.defaults, options);

	return this.each(function() {
		var TabContainer = $(this);
		
		TabContainer.find("li").each(function() {
			var URL = $(this).children("a");
			if(URL.attr("href").substring(0, 1) == "#") {
			    //Referencing a layer
			    $(this).attr("title", TabContainer.attr("id") + "|" + $(this).attr("id") + "|" + URL.attr("href"));
			    $(this).children("a").attr("href", "javascript:void(0);");
			    
			    $(this).click(function() { $.fn.Tabalyzer.showTab($(this).attr("title")); });
			}
			else {
			    //Treat as a URL
			    $(this).click(function() { document.location = $(this).children("a").attr("href"); });
			}
			
		});
    });
};

$.fn.Tabalyzer.showTab = function() {
    if(arguments.length != 1) return;
    if(arguments[0].indexOf("|") == -1) return;
    var TabContainer = $(("#" + arguments[0]).split("|", 3)[0]);
    
	$.fn.Tabalyzer.showTab.settings = {
	    clickedTab: arguments[0]
	};
	
    //Find active tab and de-active it
    TabContainer.find("li").each(function() {
        var o = $.fn.Tabalyzer.showTab.settings;
        if($(this).attr("title") != o.clickedTab) {
            //This item isn't the one that was clicked
            $(this).removeClass("Active");
            $($(this).attr("title").split("|", 3)[2]).hide();
        }
        else {
            //This is the item that was clicked
            $(this).addClass("Active");
            $((o.clickedTab).split("|", 3)[2]).show();
        }
    });
};


$.preloadImages = function() {
    for(var i = 0; i < arguments.length; i++) {
        $("<img>").attr("src", arguments[i]);
    }
}

$.watermarkBox = function() {
    $.watermarkBox.Watermarks = { }
    
    $("input[class*=Watermarked]").each(function() {
        $.watermarkBox.Watermarks[$(this).attr("ID")] = { Text : $(this).val(), Class : "Watermarked" }
        
        $(this).focus(function() {
            if($(this).val() == "" || $(this).val() == $.watermarkBox.Watermarks[$(this).attr("ID")].Text) $(this).val("").removeClass($.watermarkBox.Watermarks[$(this).attr("ID")].Class);
        });
        
        $(this).blur(function() {
            if($(this).val() == "" || $(this).val() == $.watermarkBox.Watermarks[$(this).attr("ID")].Text) $(this).val($.watermarkBox.Watermarks[$(this).attr("ID")].Text).addClass($.watermarkBox.Watermarks[$(this).attr("ID")].Class);
        });
   });


}


$(document).ready(function () {
    if (top.frames.length != 0) {
        //alert(top.frames.length);
        top.location=self.document.location;
        return;
    }

    //Add watermarking to the Quick Tix Code box
    $.watermarkBox();

    //Load Add2Any script if Add2Any object exists
    if ($("[class*=a2a_dd]").html() != null) {
        $.getScript(_A2AHost + "/menu/page.js");
    }


    //Set up image hovers on any image containing a class reference called "Hover"
    //1. Preload the images
    $("img[class*=Hover]").each(function () {
        $.preloadImages($(this).attr("src"), $(this).attr("src").substr(0, $(this).attr("src").lastIndexOf(".")) + "_h" + $(this).attr("src").substr($(this).attr("src").lastIndexOf(".")));
    });

    //2. Set up hover events
    $("img[class*=Hover]").hover(function () {
        $(this).attr("src", $(this).attr("src").substr(0, $(this).attr("src").lastIndexOf(".")) + "_h" + $(this).attr("src").substr($(this).attr("src").lastIndexOf(".")));
    }, function () {
        $(this).attr("src", $(this).attr("src").replace("_h.", "."));
    });

    //Set up the functionality for the toolbar buttons
    var originalFontSize = $("#Details p").css("font-size");

    $("#Btn_Text_Increase").click(function () {
        $("[class*=TextSizeChangeable]").each(function () {
            var currentFontSize = $(this).css("font-size");
            var currentFontSizeNum = parseFloat(currentFontSize, 10);
            var newFontSize = currentFontSizeNum * 1.2;
            $(this).css("font-size", newFontSize);
        });
        return false;
    });

    $("#Btn_Text_Decrease").click(function () {
        $("[class*=TextSizeChangeable]").each(function () {
            var currentFontSize = $(this).css("font-size");
            var currentFontSizeNum = parseFloat(currentFontSize, 10);
            var newFontSize = currentFontSizeNum * 0.8;
            $(this).css('font-size', newFontSize);
        });
        return false;
    });


    //Set up collapsible panels for membership selection
    $('[class*=CollapsiblePanels]').find('a').each(function () {
        $(this).click(function () {
            if ($(this).next('div').css('display') == 'none') {
                if (window.CPActivePanel.length > 0) {
                    $(window.CPActivePanel[1]).slideFadeHide(400);
                    $(window.CPActivePanel[0]).removeClass('Panels_Memberships_Div_Open');
                    $(window.CPActivePanel[2]).hide();
                }
                $(this).next('div').slideFadeShow(400)
                $(this).next('div').next('div').show()
                $(this).addClass('Panels_Memberships_Div_Open');
                window.CPActivePanel = [$(this), $(this).next('div'), $(this).next('div').next('div')];
            }
            else {
                $(this).next('div').slideFadeHide(400);
                $(this).next('div').next('div').slideFadeHide(275);
                $(this).removeClass('Panels_Memberships_Div_Open');
            }
        });
    });

    if ($.browser.msie) {
        $('[class*=IEReposition]').each(function () {
            $(this).css('top', '-10px');
        });
    }


    //Quick Tix and Search Box enter key handlers
    $(".QuickTixTextBox").keypress(function (e) { if (e.keyCode == 13) { $(".QuickTixSearchButton").click(); return false; } });
    $(".FreeTextSearchBox").keypress(function (e) { if (e.keyCode == 13) { $(".FreeTextSearchButton").click(); return false; } });


    if (typeof (Sys) != "undefined") Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
    MLCControl.Init();

});



function EndRequestHandler() {

    MLCControl.Init();
}

var LastFundItemID = "";

var MLCControl = {
    Init: function () {
        //Fund Designation Stuff
        $("[class*=Dropdown_FundList]").change(function () {
            var ID = $(this).val();
            var ShowTick = false;
            $("[class*=FundListItem" + LastFundItemID + "]").hide();
            $("[class*=FundListDescriptionsTick]").hide();
            $("[class*=FundListItem" + ID + "]").each(function () {
                $(this).slideFadeShow();
                $("[class*=FundListDescriptionsTick]").show();
            });
            LastFundItemID = ID;
        });

        $("[name$=DonationAmount]").focus(function () {
            $("[name$=List_MemberLevels]").attr("checked", "checked");
        });

        $("[name$=DonationAmount]").blur(function () {
            MLCControl.FixNameDesignationCopy(MLCControl.GetDonationAmount());
        });

        $("[name$=List_MemberLevels]").click(function () {
            MLCControl.FixNameDesignationCopy(MLCControl.GetDonationAmount());
        });
    },
    GetDonationAmount: function () {
        var A = 0;
        $("[name$=List_MemberLevels]").each(function () {
            var C = $(this).attr("checked");
            if (C == "checked" || C == true) {
                var V = $(this).val();
                var i = V.indexOf("|");
                A = (i > -1) ? parseInt(V.substr(i + 1)) : 0;
            }
        });
        var B = $("[name$=DonationAmount]").val();
        return (A > 0) ? A : ((parseInt(B) > 0) ? parseInt(B) : 0);
    },
    FixNameDesignationCopy: function (A) {
        switch (true) {
            case (A >= 175 && A < 600):
                if (!$("[class*=PanelNameRecognition]").is(":visible")) $("[class*=PanelNameRecognition]").show();
                if (!$("[class*=PanelOnWebsiteOnly]").is(":visible")) $("[class*=PanelOnWebsiteOnly]").slideFadeShow();
                if ($("[class*=PanelOnWebsiteAndPlaque]").is(":visible")) $("[class*=PanelOnWebsiteAndPlaque]").slideFadeHide();
                break;
            case (A >= 600):
                if (!$("[class*=PanelNameRecognition]").is(":visible")) $("[class*=PanelNameRecognition]").show();
                if ($("[class*=PanelOnWebsiteOnly]").is(":visible")) $("[class*=PanelOnWebsiteOnly]").slideFadeHide();
                if (!$("[class*=PanelOnWebsiteAndPlaque]").is(":visible")) $("[class*=PanelOnWebsiteAndPlaque]").slideFadeShow();
                break;
            default:
                $("[class*=PanelNameRecognition]").slideFadeHide();
                $("[class*=PanelOnWebsiteOnly]").hide();
                $("[class*=PanelOnWebsiteAndPlaque]").hide();
                break;
        }
    }
};



