﻿/**
* NSCC-lightbox jQuery plugin
* This jQuery plugin was based on Leandro Vieira Pinho's jQuery lightbox plugin version 0.5 (http://leandrovieira.com)
* THIS PLUGIN HAS BEEN MODIFIED SUBSTANTIALLY
* DO NOT TRY TO "UPGRADE" BY OVERWRITING THIS WITH A NEWER COPY OF THE ORIGINAL PLUGIN
* @date 24/02/2010
* @category jQuery plugin
* @copyright (c) 2008 this modification might have to be free based on the originial license agreement
*/

// Offering a Custom Alias suport - More info: http://docs.jquery.com/Plugins/Authoring#Custom_Alias
(function($) {
    /**
    * $ is an alias to jQuery object
    *
    */
    $.fn.lightBox = function(settings) {
        // Settings to configure the jQuery lightBox plugin how you like
        settings = jQuery.extend({
        	showCopyright: true,
            // Configuration related to navigation
            fixedNavigation: true, 	// (boolean) Boolean that informs if the navigation (next and prev button) will be fixed or not in the interface.
            // Configuration related to images
            imageLoading: '/Style Library/Images/lightbox-ico-loading.gif', 	// (string) Path and the name of the loading icon
            imageBlank: '/Style Library/Images/lightbox-blank.gif', 		// (string) Path and the name of a blank image (one pixel)
            contentDefaultWidth: 400,
            contentDefaultHeight: 0,
            // Configuration related to container image box
            containerBorderSize: 0, 		// (integer) If you adjust the padding in the CSS for the container, #lightbox-container-image-box, you will need to update this value
            containerResizeSpeed: 400, 	// (integer) Specify the resize duration of container image. These number are miliseconds. 400 is default.
            moveToLightBoxSpeed: 1000,
            // Configuration related to texts in caption. For example: Image 2 of 8. You can alter either "Image" and "of" texts.
            txtImage: '', // (string) Specify text "Image"
            txtOf: 'of', 	// (string) Specify text "of"
            // Configuration related to keyboard navigation
            keyToClose: 'c', 	// (string) (c = close) Letter to close the jQuery lightBox interface. Beyond this letter, the letter X and the SCAPE key is used to.
            keyToPrev: 'p', 	// (string) (p = previous) Letter to show the previous image
            keyToNext: 'n', 	// (string) (n = next) Letter to show the next image.
            // Don´t alter these variables in any way
            imageArray: [],
            activeImage: 0,
            groupName: '',
            clickX: 0,
            clickY: 0,
            fixedLocationOffset: 0,
            fixedLocation: false
        }, settings);
        
        var styleWidthOffset = 35;
        
        // Caching the jQuery object with all elements matched
        var jQueryMatchedObj = this; // This, in this context, refer to jQuery object
        /**
        * Initializing the plugin calling the start function
        *
        * @return boolean false
        */
        function _initialize(e) {
            if (settings.fixedLocation) {
   	            var arrPageScroll = ___getPageScroll();
                settings.clickX = e.clientX + arrPageScroll[0];
                settings.clickY = e.clientY + arrPageScroll[1];
            }
			
			if ( $('#jquery-lightbox').length ){
	            $('#jquery-lightbox').remove();
			}
			
            jQueryMatchedObj = $("#" + settings.groupName + " div[title ='entry']");
            if (jQueryMatchedObj.length > 0) {
                _start(jQueryMatchedObj[0], jQueryMatchedObj); // This, in this context, refer to object (link) which the user have clicked
                return false; // Avoid the browser following the link
            }
        }
        /**
        * Start the jQuery lightBox plugin
        *
        * @param object objClicked The object (link) whick the user have clicked
        * @param object jQueryMatchedObj The jQuery object with all elements matched
        */
        function _start(objClicked, jQueryMatchedObj) {
            // Hime some elements to avoid conflict with overlay in IE. These elements appear above the overlay.
            $('embed, object, select').css({ 'visibility': 'hidden' });
            // Call the function to create the markup structure; style some elements; assign events in some elements.
            _set_interface();
            // Unset total images in imageArray
            settings.imageArray.length = 0;
            // Unset image active information
            settings.activeImage = 0;
            // We have an image set? Or just an image? Let´s see it.
            if (jQueryMatchedObj.length == 1) {
                settings.imageArray.push(new Array(
                        $("div[title='imageURL']", jQueryMatchedObj[0])[0].innerHTML,
                        $("div[title='caption']", jQueryMatchedObj[0])[0].innerHTML,
                        $("div[title='order']", jQueryMatchedObj[0])[0].innerHTML,
                        $("div[title='imageAlt']", jQueryMatchedObj[0])[0].innerHTML,
                        $("div[title='text']", jQueryMatchedObj[0])[0].innerHTML));
            } else {

                // Add an Array (as many as we have), with href and title atributes, inside the Array that storage the images references
                for (var i = 0; i < jQueryMatchedObj.length; i++) {
                    settings.imageArray.push(new Array(
                        $("div[title='imageURL']", jQueryMatchedObj[i])[0].innerHTML,
                        $("div[title='caption']", jQueryMatchedObj[i])[0].innerHTML,
                        $("div[title='order']", jQueryMatchedObj[i])[0].innerHTML,
                        $("div[title='imageAlt']", jQueryMatchedObj[i])[0].innerHTML,
                        $("div[title='text']", jQueryMatchedObj[i])[0].innerHTML));
                }

                settings.imageArray.sort(function(a, b) { return a[2] - b[2]; });

            }
            // Call the function that prepares image exibition
            _set_image_to_view();
        }
        /**
        * Create the jQuery lightBox plugin interface
        *
        * The HTML markup will be like that:
			 <div id="jquery-lightbox">
            <div class="lightbox-tl">
                <div class="lightbox-tr"></div>
            </div>
            <div class="lightbox-bl">
                <div class="lightbox-br">
                	<div id="lightbox-data-title-bar"><a id="lightbox-secNav-btnClose" class="close_link" title="" href="#">Close this window</a>
                	</div>
                    <div id="lightbox-container-image-box">
                        <img id="lightbox-image" />
                        <div id="lightbox-loading">
                            <a href="#" id="lightbox-loading-link"><img src="' + settings.imageLoading + '"></a>
                        </div>
                    </div>
                   <div id="lightbox-container-image-data-box">
                        <div id="lightbox-data-title-bar">
                            
                            <h3 id="lightbox-data-title"></h3>
                        </div>
                        <div id="lightbox-image-details-caption"></div>
                        <div id="lightbox-navigation-controls">
                            <ul>
                                <li class="first" id="lightboxCopyright">Copyright &copy; 2009 North Shore City Ltd. All rights reserved.</li>
                                <li class="page-counter"><span id="lightbox-image-details-currentNumber"></span></li>
                                <li>
                                    <a id="lightbox-nav-btnPrev" class="previous" title="" href="#">PREVIOUS</a>
                                    <a id="lightbox-nav-btnNext" class="next" title="" href="#">NEXT</a>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>');
		*/
        function _set_interface() {
            // Apply the HTML markup into body tag
            $('body').append('<div id="jquery-lightbox"><div class="lightbox-tl"><div class="lightbox-tr"></div></div><div class="lightbox-bl"><div class="lightbox-br"><div id="lightbox-data-title-bar"><a id="lightbox-secNav-btnClose" class="close_link" title="" href="#">Close this window</a></div><div id="lightbox-container-image-box"><img id="lightbox-image" /><div id="lightbox-loading"><a href="#" id="lightbox-loading-link"><img src="' + settings.imageLoading + '"></a></div></div><div id="lightbox-container-image-data-box"><div id="lightbox-data-title-bar"><h3 id="lightbox-data-title"></h3></div><div id="lightbox-image-details-caption"></div><div id="lightbox-navigation-controls"><ul><li class="first" id="lightboxCopyright">Copyright &copy; 2009 North Shore City Ltd. All rights reserved.</li><li><a id="lightbox-nav-btnPrev" class="previous" title="" href="#">PREVIOUS</a><a id="lightbox-nav-btnNext" class="next" title="" href="#">NEXT</a></li><li class="page-counter"><span id="lightbox-image-details-currentNumber"></span></li></ul></div></div></div></div></div>');
            // Get page sizes
            var arrPageSizes = ___getPageSize();
            // Get page scroll
            var arrPageScroll = ___getPageScroll();
            // Calculate top and left offset for the jquery-lightbox div object and show it
            var tempy = 0;
            var tempx = 0;
            var off = 0;
            if (settings.fixedLocation) {            
            		tempy = settings.clickY;
            		tempx = settings.clickX;
            		//if (tempy > 1000)
            		//{
            		// 	off = -580;	
            		//}
            		
					$('#jquery-lightbox').css({
                	top: tempy + off, 
                	left: tempx + settings.fixedLocationOffset }).show();
			}
			else{
	            $('#jquery-lightbox').css({
	                top: arrPageScroll[1] + (arrPageSizes[3] / 10),
	                left: arrPageScroll[0]
	            }).show();
			}
            // Assign the _finish function to lightbox-loading-link and lightbox-secNav-btnClose objects
            $('#lightbox-loading-link,#lightbox-secNav-btnClose').click(function() {
                _finish();
                return false;
            });
            // If window was resized, calculate the new overlay dimensions
            $(window).resize(function() {
                // Get page sizes
                var arrPageSizes = ___getPageSize();
                // Get page scroll
                var arrPageScroll = ___getPageScroll();
                // Calculate top and left offset for the jquery-lightbox div object and show it
                $('#jquery-lightbox').css({
                    top: arrPageScroll[1] + (arrPageSizes[3] / 10),
                    left: arrPageScroll[0]
                });
            });
        }
        /**
        * Prepares image exibition; doing a image´s preloader to calculate it´s size
        *
        */
        function _set_image_to_view() { // show the loading
            if (settings.activeImage >= 0 && settings.activeImage < settings.imageArray.length) {
                // Show the loading
                $('#lightbox-loading').show();
                $('#lightbox-image,#lightbox-container-image-data-box,#lightbox-image-details-currentNumber').hide();
                if (settings.imageArray[settings.activeImage][0].length > 0) {
                    // Image preload process
                    var objImagePreloader = new Image();
                    objImagePreloader.onload = function() {
                        $('#lightbox-image').attr('src', settings.imageArray[settings.activeImage][0]);
                        $('#lightbox-image').attr('alt', settings.imageArray[settings.activeImage][3]);
                        // Perfomance an effect in the image container resizing it
                        _resize_container_image_box(objImagePreloader.width, objImagePreloader.height);
                        //	clear onLoad, IE behaves irratically with animated gifs otherwise
                        objImagePreloader.onload = function() { };
                    };
                    objImagePreloader.src = settings.imageArray[settings.activeImage][0];
                }
                else {
                    // Image preload process
                    var objImagePreloader = new Image();
                    objImagePreloader.onload = function() {
                        $('#lightbox-image').attr('src', settings.imageBlank);
                        // Perfomance an effect in the image container resizing it
                        _resize_container_image_box(settings.contentDefaultWidth, settings.contentDefaultHeight);
                        //	clear onLoad, IE behaves irratically with animated gifs otherwise
                        objImagePreloader.onload = function() { };
                    };
                    objImagePreloader.src = settings.imageBlank;
                }
            }
            else {
                _finish();
            }
        };
        /**
        * Perfomance an effect in the image container resizing it
        *
        * @param integer intImageWidth The image´s width that will be showed
        * @param integer intImageHeight The image´s height that will be showed
        */
        function _resize_container_image_box(intImageWidth, intImageHeight) {
            // Get current width and height
            var intCurrentWidth = $('#lightbox-container-image-box').width();
            var intCurrentHeight = $('#lightbox-container-image-box').height();
            // Get the width and height of the selected image plus the padding
            var intWidth = (intImageWidth + (settings.containerBorderSize * 2)); // Plus the image´s width and the left and right padding value
            var intHeight = (intImageHeight + (settings.containerBorderSize * 2)); // Plus the image´s height and the left and right padding value
            // Diferences
            var intDiffW = intCurrentWidth - intWidth;
            var intDiffH = intCurrentHeight - intHeight;
            // Perfomance the effect
            $('#lightbox-container-image-box').animate({ width: intWidth, height: intHeight }, settings.containerResizeSpeed, function() { _show_image(); });
            if ((intDiffW == 0) && (intDiffH == 0)) {
                if ($.browser.msie) {
                    ___pause(250);
                } else {
                    ___pause(100);
                }
            }
            $('#lightbox-container-image-data-box').css({ width: intImageWidth });
            
            if (settings.fixedLocation) {
            		//if (settings.clickY > 1000)
            		//{
					   //$('#jquery-lightbox').css({ 'position': 'fixed', top: settings.clickY - 580, left: settings.clickX + settings.fixedLocationOffset });
					//   $('#jquery-lightbox').animate({top: (arrPageSizes[2]-intWidth)/2 }, settings.containerResizeSpeed);
	
            		//}
            		//else
            		//{
            			//$('#jquery-lightbox').css({ 'position': 'fixed', top: settings.clickY + settings.fixedLocationOffset, left: settings.clickX + settings.fixedLocationOffset });
					//	$('#jquery-lightbox').animate({top: (arrPageSizes[2]-intWidth)/2 }, settings.containerResizeSpeed);
            		//}

               // $('#jquery-lightbox').animate({top: (arrPageSizes[2]-intWidth)/2 }, settings.containerResizeSpeed);
            //$('#jquery-lightbox').css({width:(styleWidthOffset+intImageWidth + (settings.containerBorderSize * 2))});

            }
            else{
           		var arrPageSizes = ___getPageSize();
            	$('#jquery-lightbox').animate({left: (arrPageSizes[2]-intWidth)/2 }, settings.containerResizeSpeed);

	            }
     		$('#jquery-lightbox').css({width:(styleWidthOffset+intImageWidth + (settings.containerBorderSize * 2))});

        };
        /**
        * Show the prepared image
        *
        */
        function _show_image() {
            $('#lightbox-loading').hide();
            $('#lightbox-image').fadeIn(function() {
                _show_image_data();
                _set_navigation();
            });
            
            _preload_neighbor_images();
        };
        /**
        * Show the image information
        *
        */
        function _show_image_data() {
        	var lightboxHeight = $('#jquery-lightbox').outerHeight(true);
        	$('#lightbox-data-title').html("");
            $('#lightbox-image-details-caption').html("");
            $('#lightbox-image-details-currentNumber').html("");
            $('#lightbox-container-image-data-box').slideDown(1);
            $('#lightbox-image-details-caption').hide();
            if (settings.imageArray[settings.activeImage][1]) {
            	$('#lightbox-data-title').html(settings.imageArray[settings.activeImage][1]);
            }
            lightboxHeight = lightboxHeight + $('#lightbox-data-title-bar').outerHeight(true);
            
            if (settings.imageArray[settings.activeImage][4]) {
                $('#lightbox-image-details-caption').html(settings.imageArray[settings.activeImage][4]).show(); 
            }
            lightboxHeight = lightboxHeight + $('#lightbox-image-details-caption').outerHeight(true);
            
           // If we have a image set, display 'Image X of X'
            if (settings.imageArray.length > 1) {
                $('#lightbox-image-details-currentNumber').html(settings.txtImage + ' ' + (settings.activeImage + 1) + ' ' + settings.txtOf + ' ' + settings.imageArray.length).show();
            }
            
            if(!settings.showCopyright){
            	if(settings.imageArray.length == 1){
	            	$('#lightbox-navigation-controls').hide();
            	}
            	else{
            		$('#lightboxCopyright').hide();
            		$('#lightbox-navigation-controls ul li[class="page-counter"]').css({'border-left':'none'});
             		lightboxHeight = lightboxHeight + $('#lightbox-navigation-controls').outerHeight(true);            
           		}            	
            }
            else{
             	lightboxHeight = lightboxHeight + $('#lightbox-navigation-controls').outerHeight(true);            
            }

			if(settings.fixedLocation){
				var lightboxPivot = settings.clickY + settings.fixedLocationOffset;
           		var lightbox= $('#jquery-lightbox');
           		var lightboxTop = lightbox.offset().top;
                // Get page sizes
            	var arrPageSizes = ___getPageSize();
            	// Get page scroll
            	var arrPageScroll = ___getPageScroll();
            	// Setting the screen up
            		tempy = settings.clickY;
            		tempx = settings.clickX;
            		if (tempy > 800)
            		{
            		 	off = -lightboxHeight;	
            		
            		
						$('#jquery-lightbox').css({
                		top: tempy + off, 
                		left: tempx + settings.fixedLocationOffset }).show();
                	}
            	//setting the screen up
                var spaceAvailableAbove = lightboxPivot - arrPageScroll[1];
                var spaceAvailableBelow = arrPageSizes[3] - spaceAvailableAbove;
                //alert("spaceAvailableBelow "+spaceAvailableBelow+" lightboxHeight:"+lightboxHeight);
        		//alert(spaceAvailableAbove > lightboxHeight);
                //if(spaceAvailableBelow >= lightboxHeight){   
	             //   var newScrollTop = lightboxPivot - arrPageSizes[3];
            	//	$('html,body').animate({ scrollTop: newScrollTop }, settings.moveToLightBoxSpeed);
         	
        		//}
        		//else if(spaceAvailableBelow < lightboxHeight){
        		//    $('#jquery-lightbox').css({top: lightboxPivot - lightboxHeight});
        		//	var newScrollTop = lightboxHeight - arrPageSizes[3];
            	//	$('html,body').animate({ scrollTop: newScrollTop }, settings.moveToLightBoxSpeed);

        		//}
        		//else{
        			if (tempy > 800)
            		{
            			//if ((arrPageSizes[3] = 800) && (lightboxHeight > 620)) 
            			//{
            			//	var newScrollTop = 100;
	            		//	$('html,body').animate({ scrollTop: newScrollTop }, settings.moveToLightBoxSpeed);
						//}
						//else
						//{
	            			var newScrollTop = lightboxPivot - arrPageSizes[3];
	            			$('html,body').animate({ scrollTop: newScrollTop }, settings.moveToLightBoxSpeed);
            			//}

            		}
            		else
            		{
            			if ((arrPageSizes[3] <= 1024) && (lightboxHeight > 620)) 
            			{
            				//var newScrollTop = lightboxPivot + lightboxHeight - arrPageSizes[3] - 50;
            				var newScrollTop = 200;
	            			$('html,body').animate({ scrollTop: newScrollTop }, settings.moveToLightBoxSpeed);           				
            			}            			
            			else
            			{
	            			var newScrollTop = lightboxPivot + lightboxHeight - arrPageSizes[3];
	            			$('html,body').animate({ scrollTop: newScrollTop }, settings.moveToLightBoxSpeed);
            			}
            		}
        		//}

                /*alert("solid content: " +$('#jquery-lightbox').outerHeight(true)+
                " title:"+$('#lightbox-data-title-bar').outerHeight(true)+
                " caption: "+$('#lightbox-image-details-caption').outerHeight(true) + 
                " navigation:"+$('#lightbox-navigation-controls').outerHeight(true)+
                " total height:"+lightboxHeight);*/

           
            }
            

        }
        /**
        * Display the button navigations
        *
        */
        function _set_navigation() {

            // Show the prev button, if not the first image in set
            if (settings.activeImage != 0) {
                $('#lightbox-nav-btnPrev')
                	.show()
                	.unbind()
					.bind('click', function() {
					    settings.activeImage = settings.activeImage - 1;
					    _set_image_to_view();
					    return false;
					});
            }
            else{
            	$('#lightbox-nav-btnPrev').hide();
            }

            // Show the next button, if not the last image in set
            if (settings.activeImage != (settings.imageArray.length - 1)) {
                $('#lightbox-nav-btnNext')
                	.show()
					.unbind()
					.bind('click', function() {
					    settings.activeImage = settings.activeImage + 1;
					    _set_image_to_view();
					    return false;
					});
            }
            else{
            	$('#lightbox-nav-btnNext').hide();
            }
            // Enable keyboard navigation
            //_enable_keyboard_navigation();
        }
        /**
        * Enable a support to keyboard navigation
        *
        */
        function _enable_keyboard_navigation() {
            $(document).keydown(function(objEvent) {
                _keyboard_action(objEvent);
            });
        }
        /**
        * Disable the support to keyboard navigation
        *
        */
        function _disable_keyboard_navigation() {
            $(document).unbind();
        }
        /**
        * Perform the keyboard actions
        *
        */
        function _keyboard_action(objEvent) {
            // To ie
            if (objEvent == null) {
                keycode = event.keyCode;
                escapeKey = 27;
                // To Mozilla
            } else {
                keycode = objEvent.keyCode;
                escapeKey = objEvent.DOM_VK_ESCAPE;
            }
            // Get the key in lower case form
            key = String.fromCharCode(keycode).toLowerCase();
            // Verify the keys to close the ligthBox
            if ((key == settings.keyToClose) || (key == 'x') || (keycode == escapeKey)) {
                _finish();
            }
            // Verify the key to show the previous image
            if ((key == settings.keyToPrev) || (keycode == 37)) {
                // If we´re not showing the first image, call the previous
                if (settings.activeImage != 0) {
                    settings.activeImage = settings.activeImage - 1;
                    _set_image_to_view();
                    _disable_keyboard_navigation();
                }
            }
            // Verify the key to show the next image
            if ((key == settings.keyToNext) || (keycode == 39)) {
                // If we´re not showing the last image, call the next
                if (settings.activeImage != (settings.imageArray.length - 1)) {
                    settings.activeImage = settings.activeImage + 1;
                    _set_image_to_view();
                    _disable_keyboard_navigation();
                }
            }
        }
        /**
        * Preload prev and next images being showed
        *
        */
        function _preload_neighbor_images() {
            if ((settings.imageArray.length - 1) > settings.activeImage) {
                objNext = new Image();
                objNext.src = settings.imageArray[settings.activeImage + 1][0];
            }
            if (settings.activeImage > 0) {
                objPrev = new Image();
                objPrev.src = settings.imageArray[settings.activeImage - 1][0];
            }
        }
        /**
        * Remove jQuery lightBox plugin HTML markup
        *
        */
        function _finish() {
            $('#jquery-lightbox').fadeOut(function() { $('#jquery-lightbox').remove(); });
            // Show some elements to avoid conflict with overlay in IE. These elements appear above the overlay.
            $('embed, object, select').css({ 'visibility': 'visible' });
        }
        /**
        / THIRD FUNCTION
        * getPageSize() by quirksmode.com
        *
        * @return Array Return an array with page width, height and window width, height
        */
        function ___getPageSize() {
            var xScroll, yScroll;
            if (window.innerHeight && window.scrollMaxY) {
                xScroll = window.innerWidth + window.scrollMaxX;
                yScroll = window.innerHeight + window.scrollMaxY;
            } else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
                xScroll = document.body.scrollWidth;
                yScroll = document.body.scrollHeight;
            } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
                xScroll = document.body.offsetWidth;
                yScroll = document.body.offsetHeight;
            }
            var windowWidth, windowHeight;
            if (self.innerHeight) {	// all except Explorer
                windowWidth = self.innerWidth;
                windowHeight = self.innerHeight;
            } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
                windowWidth = document.documentElement.clientWidth;
                windowHeight = document.documentElement.clientHeight;
            } else if (document.body) { // other Explorers
                windowWidth = document.body.clientWidth;
                windowHeight = document.body.clientHeight;
            }
            // for small pages with total height less then height of the viewport
            if (yScroll < windowHeight) {
                pageHeight = windowHeight;
            } else {
                pageHeight = yScroll;
            }
            // for small pages with total width less then width of the viewport
            if (xScroll < windowWidth) {
                pageWidth = xScroll;
            } else {
                pageWidth = windowWidth;
            }
            arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight);
            return arrayPageSize;
        };
        /**
        / THIRD FUNCTION
        * getPageScroll() by quirksmode.com
        *
        * @return Array Return an array with x,y page scroll values.
        */
        function ___getPageScroll() {
            var xScroll, yScroll;
            if (self.pageYOffset) {
                yScroll = self.pageYOffset;
                xScroll = self.pageXOffset;
            } else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
                yScroll = document.documentElement.scrollTop;
                xScroll = document.documentElement.scrollLeft;
            } else if (document.body) {// all other Explorers
                yScroll = document.body.scrollTop;
                xScroll = document.body.scrollLeft;
            }
            arrayPageScroll = new Array(xScroll, yScroll);
            return arrayPageScroll;
        };
        /**
        * Stop the code execution from a escified time in milisecond
        *
        */
        function ___pause(ms) {
            var date = new Date();
            curDate = null;
            do { var curDate = new Date(); }
            while (curDate - date < ms);
        };
        // Return the jQuery object for chaining. The unbind method is used to avoid click conflict when the plugin is called more than once
        return this.unbind('click').click(_initialize);
    };
})(jQuery);                          // Call and execute the function immediately passing the jQuery object

