﻿function getQuerystring(key, default_) {
    if (default_ == null) default_ = "";
    key = key.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regex = new RegExp("[\\?&]" + key + "=([^&#]*)");
    var qs = regex.exec(window.location.href);
    if (qs == null)
        return default_;
    else
        return qs[1];
}
function toggle_visibility(id) {
    var e = document.getElementById(id);
    if (e.style.display == 'block')
        e.style.display = 'none';
    else
        e.style.display = 'block';
}

function closebtn(id) {
    var e = document.getElementById(id);
    if (e.style.display == 'block')
        e.style.display = 'none';
    else
        e.style.display = 'block';
}


$(document).ready(function () {
    $(".calBox").hover(
      function () { $(this).children('.sfhover').show(); },
      function () { $(this).children('.sfhover').hide(); }
 );

});

var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(function () {
    $(".calBox").hover(
      function () { $(this).children('.sfhover').show(); },
      function () { $(this).children('.sfhover').hide(); }
 );
});

$(document).ready(function () {
    // $("#scrollContainer").mCustomScrollbar("vertical", 400, "easeOutCirc", 1.05, "auto", "yes", "yes", 10);
    // $('#scrollbar1').tinyscrollbar({ sizethumb: 20 });
    //$("#tab3").prettyScroll({ "scrollbarHeight": "300px" });
    //$("#tabContainer").prettyScroll({ "scrollbarHeight": "370px" });
    $("#tabContainer").tinyscrollbar({ sizethumb: 20 });
    
});

function changeUrl(type) {
    var url;
    if (type == 'Brief') { url = '/news-media/Daily-Brief'; }
    else if (type == 'Blog') { url = '/news-media/blog/'; }
    else if (type == 'Twitter') { url = 'http://www.twitter.com/PromaxBDA'; }
    else if (type == 'Facebook') { url = 'http://www.facebook.com/PromaxBDA'; }
    else if (type == 'LinkedIn') { url = 'http://www.linkedin.com/company/promaxBDA'; }

    $("#lnkAll").attr("href", url);

};

function expandTicker() {
    $("#stripContent").slideToggle("400");
    var txt = $("#lnkExpand").text() == 'Collapse' ? 'Expand' : 'Collapse';
    if (txt == 'Collapse') {

    }
    $("#lnkExpand").text(txt);
};

$(document).ready(function () {

    //When page loads...
    $(".tab_content").hide(); //Hide all content
    $("ul.tabs li:first").addClass("active").show(); //Activate first tab
    $(".tab_content:first").show(); //Show first tab content
    $("#tabContainer").tinyscrollbar_update();

    //On Click Event
    $(".showall").click(function () {
        $(".tab_content").show();
        $("ul.tabs li").removeClass("active");
        $("ul.tabs li").addClass("active");
    });

    //On Click Event
    $("ul.tabs li").click(function () {

        $("ul.tabs li").removeClass("active"); //Remove any "active" class
        $(this).addClass("active"); //Add "active" class to selected tab
        $(".tab_content").hide(); //Hide all tab content

        var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
        $(activeTab).fadeIn(); //Fade in the active ID content

        //readjust scrollbar
        //$(".scroll-bar").remove();
        $("#tabContainer").tinyscrollbar_update();
         //$("#tabContainer").prettyScroll({ "scrollbarHeight": "370px" });
        return false;
    });

});


//Events Page
$(document).ready(function () {
    $(".eventtext").hover(
      function () { $(this).children('.target').addClass('bfhover'); },
      function () { $(this).children('.target').removeClass('bfhover'); }
 );

});

(function ($) {
    /**
    * jQuery plugin to support "pretty scroll" using the jQuery UI slider.
    * @class
    * @param config
    */
    $.fn.prettyScroll = function (config) {
        var methods = {
            track: function () {
                var scroll = this.find(".scrollable");
                var contentHeight = scroll.attr("scrollHeight");
                var visibleHeight = scroll.attr("clientHeight");

                if (contentHeight <= visibleHeight) {
                    return; // Do nothing.
                }

                var delta = this.diff;
                this.diff = 0;
                var scrollbar = this.find(".scroll-bar");
                var value = scrollbar.slider("option", "value") + (delta * this.settings.pace);

                if (value > 100) { value = 100; }
                else if (value < 0) { value = 0; }

                scrollbar.slider("option", "value", value);
            }
        };

        return this.each(function () {
            var element = $(this);
            var timer;
            element.diff = 0; // Used to accumulate deltas when capturing mousewheel scroll to prevent excessive scrolling.

            element.settings = {
                scrollbarHeight: "300px", // the height of the scrollbar
                scrollbarSize: "6px", // the size of the scrollbar
                positionX: "5px", // the distance from the right of the container
                positionY: "15px", // the distance from the top of the container
                easing: "easeOutQuart", // the named easing effect from jQuery UI
                pace: 20 // affects the mousewheel increment
            };

            if (config) {
                $.extend(element.settings, config);
            }

            // Add the scrollbar container
            element.css("position", "relative").append("<div class='scroll-bar' style='position:absolute; height:"
                    + element.settings.scrollbarHeight
                    + "; font-size:" + element.settings.scrollbarSize
                    + "; top:" + element.settings.positionY
                    + "; right:" + element.settings.positionX + ";'></div>");

            // Hook up the mousewheel
            element.mousewheel(function (event, delta) {
                clearTimeout(timer);
                element.diff += delta;
                timer = setTimeout(jQuery.proxy(methods.track, element), 100);
            });

            // Initialize the slider
            element.find(".scroll-bar").slider({
                orientation: "vertical",
                range: "min",
                min: 0,
                max: 100,
                value: 100,
                change: function (event, ui) {
                    // Calculate and set the scrolling position.
                    var scroll = element.find(".scrollable");
                    var contentHeight = scroll.attr("scrollHeight");
                    var visibleHeight = scroll.attr("clientHeight");
                    var sliderValue = ui.value;

                    var target = Math.ceil((100 - sliderValue) * (contentHeight - visibleHeight) / 100);

                    scroll.animate(
                            { "scrollTop": target },
                            'fast',
                            element.settings.easing
                        );
                }
            });

            /**
            * context is the item which was clicked.
            */
            element.bind("scrollTo", function (e, context) {
                //.scrollTop($this.offset().top)

                var scroll = element.find(".scrollable");
                var contextTop = context.offset().top;
                var contentHeight = scroll.attr("scrollHeight");
                var visibleHeight = scroll.attr("clientHeight");
                var target = Math.ceil((contextTop / contentHeight) * 100);

                if (contentHeight <= visibleHeight) {
                    target = 0;
                }

                element.find(".scroll-bar").slider("option", "value", 100 - target);
            });
        });
    }
})(jQuery);

/*-------------------------------------------------------------------------------------
>	(2) Call code here
-------------------------------------------------------------------------------------*/
//$(function () {
//    /*
//    Settings and defaults:

//    scrollbarHeight: "300px", // the height of the scrollbar
//    scrollbarSize: "6px", // the size of the scrollbar
//    positionX: "5px", // the distance from the right of the container
//    positionY: "15px", // the distance from the top of the container
//    easing: "easeOutQuart", // the named easing effect from jQuery UI
//    pace: 20 // affects the mousewheel increment
//    */
//    $("#tab1, #tab2, #tab3").prettyScroll();

//});

