﻿

var Browser = {
    Version: function () {
        var version = 999; // we assume a sane browser
        if (navigator.appVersion.indexOf("MSIE") != -1) {
            // bah, IE again, lets downgrade version number
            version = parseFloat(navigator.appVersion.split("MSIE")[1]);
        }
        return version;
    },
    IsIE: function () {
        if (navigator.appVersion.indexOf("MSIE") != -1) {
            return true;
        }
        return false;
    }
}



$(document).ready(function () {

    $('#mega-menu-1').dcMegaMenu({
        speed: 'fast',
        effect: 'slide'
    }).show();

    $("#btnSearch").click(PerformSearch);

    $('#tbSearch').keypress(function (e) {
        if (e.which == 13) {
            e.preventDefault();
            PerformSearch();
        }
    });


    setupBody();

    CheckSearchHighlight();



});

function getParameterByName(name) {

    var match = RegExp('[?&]' + name + '=([^&]*)')
                    .exec(window.location.search);

    return match && decodeURIComponent(match[1].replace(/\+/g, ' '));

}

function PerformSearch() {

    var parameter = $("#tbSearch").val();
    if (parameter && jQuery.trim(parameter) !== "") {

        var url = "Search.aspx?Query=" + parameter;

        window.location.href = url;
    }
    
}

function CheckSearchHighlight() {

    var searchedFor = getParameterByName("search") || getParameterByName("Query");

    if (searchedFor) {
        
        $('#tbSearch').val(searchedFor);
        
        if (jQuery().highlight) {
            if (searchedFor) {
                var searchItems = searchedFor.split(" ");

                for (var i in searchItems) {
                    $("#main").highlight(searchItems[i]);
                }
            }
        }
    }

}


function setupBody() {

    //render a border around bevelled web parts
    var border = RUZEE.ShadedBorder.create({ corner: 8, shadow: 16, border: 1 });
    border.render($(".bevelDiv"));
    

    //make the admin panel show up when the user hovers over the 'hoverMe' div inside the web part
    $(".hoverMe").hover(
                function () {
                    $(this).find(".AdminButtons")
                    .css("width", $(this).width())
                    .slideDown('fast');
                }, function () {
                    $(this).find(".AdminButtons")
                    .slideUp('fast');
                }
            );


    $(".columnHover").hover(
                    function () {
                        $(this).find(".columnAdminInner").show();
                    },
                    function () {
                        $(this).find(".columnAdminInner").hide();
                    }
                );



    //make the "toggle bevel' button call the ToggleBevel action and then replace the webpart with the new html
    $(".toggleBevel").click(function () {

        var id = $(this).attr("data-PageControlID");

        var api = new serviceApi();

        var elm = $(this);
        api.toggleBevel(
                    {
                        //                        routeTable: routes,
                        id: id,
                        success: function (data) {
                            $(elm).closest(".webPart").html(data);
                            setupBody(); //call the setupBody method to make sure the UI gets borders, admin floats etc.
                        }
                    }

                );
    });

    
    
    
 

  
}
