Array.prototype.findIndex = function(value){
	var ctr = "";
	for (var i=0; i < this.length; i++) {
		// use === to check for Matches. ie. identical (===)
		if (this[i] == value) {
			return i;
		}
	}
	return ctr;
};


// This is used to show modal content on the about page
function showModalContent(url, returnUrl){
    $.ajax({
        type    : "GET",
        cache   : false,
        url     : url,
        dataType: 'html',
        success : function(data) {
            $.fancybox(
                data,
                {
                    'autoDimensions': false,
                    'autoScale'     : false,
                    'width'         : 550,
                    'height'        : 'auto',
                    'onComplete'    : function(){
                        // If there is an audio element in the ajaxed content
                        // initialize the audio player.
                        if($('#audio_container_ajax').length) {
                            initAudioPlayer($('#audio_container_ajax'));
                        }
                    },
                    'onCleanup'     : function(){
                        // stop the audio player before the modal closes otherwise
                        // IE throws a hissy fit
                        if($('#audio_container_ajax').length) {
                            audioPlayerClose($('#audio_container_ajax'));
                        }
                    },
                    'onClosed'      : function(){
                        // if(returnUrl != null && returnUrl != 'null'){
                        //     window.location.hash = returnUrl;
                        // }
                    }
                }
            );
        }
    });
}


// This creates overlays for non-active pages on the site so that users are unable 
// to click on elements in those pages.
function ClickBlocker() {
    $('.clickBlocker').height($('html').height());

    this.resize = function(){
        $('.clickBlocker').height($('html').height());
        $('.clickBlocker').width(($('html').width() - 940) / 2);
    };
    
    this.resize();
}


// Initialize the audio player
function initAudioPlayer(element) {
    element.find('.jp-jplayer').jPlayer({
        ready: function () {
            $(this).jPlayer("setMedia", {
                mp3: element.data('file')
            });
        },
        ended: function (event) {
            $(this).jPlayer("play");
        },
        play: function () {
            $(this).jPlayer("pauseOthers");
        },
        swfPath: "js/jPlayer",
        supplied: "mp3",
        cssSelectorAncestor: '#' + element.find('.jp-interface').attr('id')
    });
}

// Stop the audio player - to be used just before closing a modal window so 
// IE doesn't scream.
function audioPlayerClose(element) {
    element.find('.jp-jplayer').jPlayer('destroy');
}


