if ((typeof (webBonesEnvironment) == 'undefined') || (webBonesEnvironment == null)) { webBonesEnvironment = new Array(); }

function getURLParameter(name) {
    return decodeURI(
        (RegExp(name + '=' + '(.+?)(&|$)').exec(location.search) || [, null])[1]
    );
}

function initJQueryBinding() {

    $.extend({
        getCurrentUrlVars: function () {
            var vars = [], hash;
            var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
            for (var i = 0; i < hashes.length; i++) {
                hash = hashes[i].split('=');
                vars.push(hash[0]);
                vars[hash[0]] = hash[1];
            }
            return vars;
        },
        getCurrentUrlVar: function (name) {
            return $.getCurrentUrlVars()[name];
        }
    });


    $.extend({
        getUrlVars: function (theUrl) {
            var vars = [], hash;
            var hashes = theUrl.slice(theUrl.indexOf('?') + 1).split('&');
            for (var i = 0; i < hashes.length; i++) {
                hash = hashes[i].split('=');
                vars.push(hash[0]);
                vars[hash[0]] = hash[1];
            }
            return vars;
        },
        getUrlVar: function (theUrl, name) {
            return $.getUrlVars(theUrl)[name];
        }
    });

    jQuery.fn.loadAsyncAjaxContent = function (onSuccess) {
        return this.each(function () {
            var containerRootTarget = this;
            var containerTarget = $(containerRootTarget);
            var referenceUrl = new String(containerTarget.attr('title'));
            if (referenceUrl != null && referenceUrl != '') {
                $.ajax({
                    url: referenceUrl,
                    async: true,
                    //cacheResponse: true, // uses the ajax cache plugin
                    //cacheResponseTimer: 500000,  // uses the ajax cache plugin
                    dataType: 'html',
                    success: function (data, textStatus, jqXHR) {
                        containerTarget.html(data);
                        bindToFancyBox();

                        if (typeof (onSuccess) != 'undefined' && onSuccess != null)
                            onSuccess(containerTarget, data, textStatus, jqXHR);
                    }
                });
            }
        });
    };

    $('.Accordion').accordion({ autoHeight: false });

    $('.AjaxAccordion').accordion({
        autoHeight: false,
        change: function (event, ui) {
            var url = ui.newHeader.find('a').attr('href');
            if (url != null) {
                var ajaxUrl = new String(url);
                if (ajaxUrl.indexOf('Modules/') >= 0) {
                    $.ajax({
                        url: ajaxUrl,
                        async: true,
                        //cacheResponse: true, // uses the ajax cache plugin
                        //cacheResponseTimer: 500000,  // uses the ajax cache plugin
                        dataType: 'html',
                        success: function (data, textStatus, jqXHR) {
                            ui.newContent.html(data);
                        }
                    });
                }
            }
        }
    });


    $('.AccordionCollapsible').accordion({ autoHeight: false, collapsible: true, active: false });
    $('.TabsNested').tabs();
    $('.TabsMain').tabs();
    $('.HideOnLoad').hide();

    $('#CarouselTOP').infiniteCarousel({
        transitionSpeed: 2000,
        displayTime: 5000,
        textholderHeight: .25,
        displayProgressBar: 1,
        displayThumbnailBackground: 1,
        thumbnailWidth: '80px',
        thumbnailHeight: '80px',
        thumbnailTextLineHeight: '130px',
        thumbnailFontSize: '16px'


    });

    $('#CarouselBOTTOM').infiniteCarousel({
        transitionSpeed: 2000,
        displayTime: 5000,
        textholderHeight: .25,
        displayProgressBar: 1,
        displayThumbnailBackground: 1,
        thumbnailWidth: '80px',
        thumbnailHeight: '80px',
        thumbnailTextLineHeight: '130px',
        thumbnailFontSize: '16px'
    });

    jQuery.fn.center = function () {
        this.css("position", "absolute");
        this.css("top", ($(window).height() - this.height()) / 2 + $(window).scrollTop() + "px");
        this.css("left", ($(window).width() - this.width()) / 2 + $(window).scrollLeft() + "px");
        return this;
    }

    $('.AjaxContainer').loadAsyncAjaxContent();
    bindToFancyBox();
    $('a.YoutubeContainer').youtubin();
}


function bindToFancyBox() {
    $("a.ImageThumbnail").fancybox({
        'type': 'image',
        'transitionIn': 'elastic',
        'transitionOut': 'elastic',
        'titlePosition': 'inside',
        'titleFormat': function (title, currentArray, currentIndex, currentOpts) {
            return (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '');
        }
    });

    $("a.ImageThumbnailNoBG").fancybox({
        'type': 'image',
        'transitionIn': 'elastic',
        'transitionOut': 'elastic',
        'titlePosition': 'inside',
        'titleFormat': function (title, currentArray, currentIndex, currentOpts) {
            return (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '');
        }
    });
}

//----------------
function postReloadContentOnly() {
    initJQueryBinding();
}
