﻿/* ******************************************************************************************* */
/* jQuery Support */
/* ******************************************************************************************* */
var currentFocus = null;
var currentMenu = null;

$(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.textbox").html() != null) {
            if ($.query().q != null)
                $("input.textbox").val($.query().q);
            $("input.textbox").bind("onkeydown", function(e) {
                var key = 0;
                e = (window.event) ? event : e;
                key = (e.keyCode) ? e.keyCode : e.charCode;
                var obj = document.getElementById('ctl00_SearchBox1_searchword');
                if (e.keyCode == 13) {
                    obj.focus();
                    var v = $("#ctl00_SearchBox1_searchword");
                    window.location = "/resources/search_results.aspx?q=" + v.val();
                }
                return false;
            });

            $("input.button").bind("click", function(e) {
            var v = $("input#ctl00_SearchBox1_searchword");
                window.location = "/resources/search_results.aspx?q=" + v.val();
                return false;
            });

        }
        $("a.ExpandDescriptions").bind("click", function(e) {
            $("div.EventSummary").toggle();
            return false;
        });


        $(':input').focus(function() {
            if (this.className != "textbox")
                currentFocus = this;
        }).blur(function() {
            currentFocus = null;
        });
        $(".clsMenuContainer .level1 li.TopLevel").bind("mouseenter", function() {
            if (currentFocus != null && currentMenu != null) {
                $(".clsMenuContainer div.level2").hide();
                $(".clsMenuContainer a.mainMenu").removeClass("selected");
            }
            $("div.level2", this).show();
            $(this).find("a.mainMenu").addClass("selected");
            currentMenu = this;
        }).bind("mouseleave", function() {
            if (currentFocus == null) {
                $(".clsMenuContainer div.level2").hide();
                $(this).find("a.mainMenu").removeClass("selected");
            } else {
                $("div.level2", this).show();
            }
        });

        $("input.service_button").bind("click", function(e) {
            var par = $(this).parent();
            if ($(par).find("select").val() != null) {
                if ($(par).find("select").val() != '') {
                    window.location = "/" + $(par).find("select").val() + ".aspx";
                }
            }
            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://www.unityhouston.org/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;
        });

if ($(".GOMFlashFeature").html()!=null){
$(".GOMFlashFeature").html("<div id='GOMFlashFeatureContainer'></div>");
            var flashvars = {};
            var params = {};
            var attributes = {};
            attributes.id = "GOMFlashFeatureContainer";
            swfobject.embedSWF("/App_Common/122/119/Library/5/GOM_feature.swf", "GOMFlashFeatureContainer", "230px", "360px", "9.0.0", false, flashvars, params, attributes);
}

        //        $("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);
}

//************************************************************************************************
function createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "expires=" + date.toGMTString();
    }
    else {
        var expires = "";
    }
    var strCreateCookie = name + "=" + value + "; " + expires + "; path=/;";
    document.cookie = strCreateCookie;
}

//************************************************************************************************
function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}
