﻿/* ******************************************************************************************* */
/* jQuery Support */
/* ******************************************************************************************* */


$(document).ready(
    function() {
        var after_type_cast = {};
        var before_type_cast = {};
        var cached = false;

        jQuery.query = function(cast) {
            if (!cached) {
                // remove leading ? and trailing &
                var q = location.search.replace(/^\?/, '').replace(/\&$/, '').split('&');
                for (var i = q.length - 1; i >= 0; i--) {
                    var p = q[i].split('='), key = p[0], val = p[1];
                    before_type_cast[key] = val;
                    // convert floats
                    if (/^[0-9.]+$/.test(val))
                        val = parseFloat(val);
                    // convert booleans
                    if (/^(true|false)$/.test(val))
                        val = (val == 'true');
                    // ingnore empty values
                    if (val)
                        after_type_cast[key] = val;
                }
                cached = true;
            }
            return cast === false ? before_type_cast : after_type_cast;
        };
        if ($("input.clsSearchTextBox").html() != null) {
            if ($.query().q != null)
                $("input.clsSearchTextBox").val($.query().q);
            $("input.clsSearchTextBox").bind("onkeydown", function(e) {
                var key = 0;
                e = (window.event) ? event : e;
                key = (e.keyCode) ? e.keyCode : e.charCode;
                var obj = document.getElementById('ctl00_txtSearchBox');
                if (e.keyCode == 13) {
                    obj.focus();
                    var v = $("#ctl00_txtSearchBox");
                    window.location = "/search-results.aspx?q=" + v.val();
                }
                return false;
            });

            $("input.clsSearchButton").bind("click", function(e) {
                var v = $("input#ctl00_txtSearchBox");
                window.location = "/search-results.aspx?q=" + v.val();
                return false;
            });

        }
        $("a.ExpandDescriptions").bind("click", function(e) {
            $("div.EventSummary").toggle();
            return false;
        });


        // IE Headaches for the Main Nav
        var isProductBoxes = $(".clsProductBox");

        if (isProductBoxes.html() != null) {
            $("div.clsProductBox").bind("mouseenter", function() {
                $(this).addClass("clsProductBoxSelected");
            }).bind("mouseleave", function() {
                $(this).removeClass("clsProductBoxSelected");
            });

            $("div.clsProductBox").bind("click", function(e) {
                window.location = $(this).attr("href");
                return false;
            });
        }

        $(".FAQ a.Question").bind("click", function(e) {
            var par = $(this).parent();
            $(par).find("div.Answer").toggle();
            return false;
        });
        $(".DMSSearch a.DMSAdvancedSearchLink").bind("click", function(e) {
            var par = $(this).parent();
            $(par).find("div.DMSAdvancedSearchOptions").toggle();
            return false;
        });

        $("a.photoGallery").bind("click", function(e) {
            var flashvars = {};
            flashvars.paramXMLPath = "http://unity.hexagroup.com/App_Themes/UnityChurch/flash/param.xml";
            flashvars.xmlFilePath = $(this).attr("href");

            var params = {};

            params.mediaPlayerScale = "1";
            params.contentAreaBackgroundAlpha = "1";
            params.contentAreaBackgroundColor = "0x000000";
            params.galleryBackgroundColor = "0x000000";
            params.allowfullscreen = "true";

            var attributes = {};
            attributes.id = "photogallery";
            swfobject.embedSWF("/app_common/flash/slideshowpro.swf", "photogallery", "808px", "456px", "9.0.0", false, flashvars, params, attributes);
            tb_show('', '#TB_inline?width=808&height=486&inlineId=galleryContent&modal=true');
            return false;
        });

        //        $("a.calculator").bind("click", function(e) {
        //            var href = $(this).attr("href");
        //            var title = $(this).attr("title");
        //            tb_show(title, href);
        //            return false;
        //        });
        //        $("input#SearchResultState1").bind("click", function(e) {
        //            $("span.ResultItem").show();
        //        });
        //        $("input#SearchResultState2").bind("click", function(e) {
        //            $("span.ResultItem").hide();
        //        });
        //        $("a.CloseDialog").bind("click", function(e) {
        //            //var htmlData = '<div id="galleryContent" style="background-color: #000;"><div id="TB_caption">Photo Gallery</div><div id="TB_closeWindow"><a href="#" id="TB_closeWindowButton" title="Close" class="CloseDialog">close</a></div><div id="photogallery"></div></div>';
        //            //$("div#galleryContainer").html(htmlData);
        //        });

    }
);

/* ******************************************************************************************* */
/* General Support */
/* ******************************************************************************************* */
function OnChangeQuicklinks(dropdown)
{
    top.location.href = dropdown.value;
    return true;
}

function detectOnState(ele, className) {
    var onObject = document.getElementById(ele);
    if (navigator.appName.indexOf("Microsoft") != -1)
        onObject.className = className;
    else
        onObject.setAttribute("class", className);
}
function detectOffState(ele, className) {
    var OffObject = document.getElementById(ele);
    if (navigator.appName.indexOf("Microsoft") != -1)
        OffObject.className = className;
    else
        OffObject.setAttribute("class", className);
}