Subversion Repositories Applications.wikini

Rev

Rev 6 | Blame | Compare with Previous | Last modification | View Log | RSS feed

/**
 * jQuery lightBox plugin
 * This jQuery plugin was inspired and based on Lightbox 2 by Lokesh Dhakar (http://www.huddletogether.com/projects/lightbox2/)
 * and adapted to me for use like a plugin from jQuery.
 * @name jquery-lightbox-0.4.js
 * @author Leandro Vieira Pinho - http://leandrovieira.com
 * @version 0.4
 * @date November 17, 2007
 * @category jQuery plugin
 * @copyright (c) 2007 Leandro Vieira Pinho (leandrovieira.com)
 * @license CC Attribution-No Derivative Works 2.5 Brazil - http://creativecommons.org/licenses/by-nd/2.5/br/deed.en_US
 * @example Visit http://leandrovieira.com/projects/jquery/lightbox/ for more informations about this jQuery plugin
 */

// Offering a Custom Alias suport - More info: http://docs.jquery.com/Plugins/Authoring#Custom_Alias
(function($) {
        /**
         */
        $.fn.lightBox = function(settings) {
                // Settings to configure the jQuery lightBox plugin how you like
                settings = jQuery.extend({
                        // Configuration related to overlay
                        overlayBgColor:                 '#000',         // (string) Background color to overlay; inform a hexadecimal value like: #RRGGBB. Where RR, GG, and BB are the hexadecimal values for the red, green, and blue values of the color.
                        overlayOpacity:                 0.8,            // (integer) Opacity value to overlay; inform: 0.X. Where X are number from 0 to 9
                        // Configuration related to images
                        imageLoading:                   'tools/galerie/actions/galerie/presentation/images/lightbox-ico-loading.gif',   // (string) Path and the name of the loading icon
                        imageBtnPrev:                   'tools/galerie/actions/galerie/presentation/images/lightbox-btn-prev.fr.gif',   // (string) Path and the name of the prev button image
                        imageBtnNext:                   'tools/galerie/actions/galerie/presentation/images/lightbox-btn-next.fr.gif',   // (string) Path and the name of the next button image
                        imageBtnClose:                  'tools/galerie/actions/galerie/presentation/images/lightbox-btn-close.fr.gif',  // (string) Path and the name of the close btn
                        imageBlank:                             'tools/galerie/actions/galerie/presentation/images/lightbox-blank.gif',         // (string) Path and the name of a blank image (one pixel)
                        // Configuration related to container image box
                        containerBorderSize:    10,                     // (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.
                        // Configuration related to texts in caption. For example: Image 2 of 8. You can alter either "Image" and "of" texts.
                        txtImage:                               'Image',        // (string) Specify text "Image"
                        txtOf:                                  'de',           // (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
                },settings);
                // Caching the jQuery object with all elements matched
                var jQueryMatchedObj = this; // This, in this context, refer to jQuery object
                /**
                 */
                function _initialize() {
                        _start(this,jQueryMatchedObj); // This, in this context, refer to object (link) which the user have clicked
                        return false; // Avoid the browser following the link
                };
                /**
                 */
                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(objClicked.getAttribute('href'),objClicked.getAttribute('title')));
                        } 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(jQueryMatchedObj[i].getAttribute('href'),jQueryMatchedObj[i].getAttribute('title')));
                                }
                        }
                        while ( settings.imageArray[settings.activeImage][0] != objClicked.getAttribute('href') ) {
                                settings.activeImage++;
                        }
                        // Call the function that prepares image exibition
                        _set_image_to_view();
                };
                /**
                 */
                function _set_interface() {
                        // Apply the HTML markup into body tag
                        $('body').append('<div id="jquery-overlay"></div><div id="jquery-lightbox"><div id="lightbox-container-image-box"><div id="lightbox-container-image"><img id="lightbox-image"><div style="" id="lightbox-nav"><a href="#" id="lightbox-nav-btnPrev"></a><a href="#" id="lightbox-nav-btnNext"></a></div><div id="lightbox-loading"><a href="#" id="lightbox-loading-link"><img src="' + settings.imageLoading + '"></a></div></div></div><div id="lightbox-container-image-data-box"><div id="lightbox-container-image-data"><div id="lightbox-image-details"><span id="lightbox-image-details-caption"></span><span id="lightbox-image-details-currentNumber"></span></div><div id="lightbox-secNav"><a href="#" id="lightbox-secNav-btnClose"><img src="' + settings.imageBtnClose + '"></a></div></div></div></div>');       
                        // Get page sizes
                        var arrPageSizes = ___getPageSize();
                        // Style overlay and show it
                        $('#jquery-overlay').css({
                                backgroundColor:        settings.overlayBgColor,
                                opacity:                        settings.overlayOpacity,
                                width:                          arrPageSizes[0],
                                height:                         arrPageSizes[1]
                        }).fadeIn();
                        // 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]
                        }).show();
                        // Assigning click events in elements to close overlay
                        $('#jquery-overlay,#jquery-lightbox').click(function() {
                                _finish();                                                                      
                        });
                        // 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();
                                // Style overlay and show it
                                $('#jquery-overlay').css({
                                        width:          arrPageSizes[0],
                                        height:         arrPageSizes[1]
                                });
                                // 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]
                                });
                        });
                };
                /**
                 */
                function _set_image_to_view() { // show the loading
                        // Show the loading
                        $('#lightbox-loading').show();
                        // Hide some elements
                        $('#lightbox-image,#lightbox-nav,#lightbox-nav-btnPrev,#lightbox-nav-btnNext,#lightbox-container-image-data-box,#lightbox-image-details-currentNumber').hide();
                        // Image preload process
                        var objImagePreloader = new Image();
                        objImagePreloader.onload = function() {
                                $('#lightbox-image').attr('src',settings.imageArray[settings.activeImage][0]);
                                // 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];
                };
                /**
                 */
                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-nav-btnPrev,#lightbox-nav-btnNext').css({ height: intImageHeight + (settings.containerBorderSize * 2) }); 
                        $('#lightbox-container-image-data-box').css({ width: intImageWidth });
                };
                /**
                 */
                function _show_image() {
                        $('#lightbox-loading').hide();
                        $('#lightbox-image').fadeIn(function() {
                                _show_image_data();
                                _set_navigation();
                        });
                        _preload_neighbor_images();
                };
                /**
                 */
                function _show_image_data() {
                        $('#lightbox-container-image-data-box').slideDown('fast');
                        $('#lightbox-image-details-caption').hide();
                        if ( settings.imageArray[settings.activeImage][1] ) {
                                $('#lightbox-image-details-caption').html(settings.imageArray[settings.activeImage][1]).show();
                        }
                        // 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();
                        }               
                };
                /**
                 */
                function _set_navigation() {
                        $('#lightbox-nav').show();

                        // Instead to define this configuration in CSS file, we define here. And it´s need to IE. Just.
                        $('#lightbox-nav-btnPrev,#lightbox-nav-btnNext').css({ 'background' : 'transparent url(' + settings.imageBlank + ') no-repeat' });
                        
                        // Show the prev button, if not the first image in set
                        if ( settings.activeImage != 0 ) {
                                // Show the images button for Next buttons
                                $('#lightbox-nav-btnPrev').unbind().hover(function() {
                                        $(this).css({ 'background' : 'url(' + settings.imageBtnPrev + ') left 15% no-repeat' });
                                },function() {
                                        $(this).css({ 'background' : 'transparent url(' + settings.imageBlank + ') no-repeat' });
                                }).show().bind('click',function() {
                                        settings.activeImage = settings.activeImage - 1;
                                        _set_image_to_view();
                                        return false;
                                });
                        }
                        
                        // Show the next button, if not the last image in set
                        if ( settings.activeImage != ( settings.imageArray.length -1 ) ) {
                                // Show the images button for Next buttons
                                $('#lightbox-nav-btnNext').unbind().hover(function() {
                                        $(this).css({ 'background' : 'url(' + settings.imageBtnNext + ') right 15% no-repeat' });
                                },function() {
                                        $(this).css({ 'background' : 'transparent url(' + settings.imageBlank + ') no-repeat' });
                                }).show().bind('click',function() {
                                        settings.activeImage = settings.activeImage + 1;
                                        _set_image_to_view();
                                        return false;
                                });
                        }
                        // Enable keyboard navigation
                        _enable_keyboard_navigation();
                };
                /**
                 */
                function _enable_keyboard_navigation() {
                        $(document).keydown(function(objEvent) {
                                _keyboard_action(objEvent);
                        });
                };
                /**
                 */
                function _disable_keyboard_navigation() {
                        $(document).unbind();
                };
                /**
                 */
                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();
                                }
                        }
                };
                /**
                 */
                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];
                        }
                };
                /**
                 */
                function _finish() {
                        $('#jquery-lightbox').remove();
                        $('#jquery-overlay').fadeOut(function() { $('#jquery-overlay').remove(); });
                        // Show some elements to avoid conflict with overlay in IE. These elements appear above the overlay.
                        $('embed, object, select').css({ 'visibility' : 'visible' });
                };
                /**
                 */
                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
                                if(document.documentElement.clientWidth){
                                        windowWidth = document.documentElement.clientWidth; 
                                } else {
                                        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;
                };
                /**
                 */
                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;
                };
                 /**
                  */
                 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

/**
 * jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
 *
 * Uses the built In easIng capabilities added In jQuery 1.1
 * to offer multiple easIng options
 *
 * @copyright (c) 2007 George Smith
 * @license Licensed under the MIT License: http://www.opensource.org/licenses/mit-license.php
 */

// t: current time, b: begInnIng value, c: change In value, d: duration
jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend( jQuery.easing,
{
        def: 'easeOutQuad',
        swing: function (x, t, b, c, d) {
                //alert(jQuery.easing.default);
                return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
        },
        easeInQuad: function (x, t, b, c, d) {
                return c*(t/=d)*t + b;
        },
        easeOutQuad: function (x, t, b, c, d) {
                return -c *(t/=d)*(t-2) + b;
        },
        easeInOutQuad: function (x, t, b, c, d) {
                if ((t/=d/2) < 1) return c/2*t*t + b;
                return -c/2 * ((--t)*(t-2) - 1) + b;
        },
        easeInCubic: function (x, t, b, c, d) {
                return c*(t/=d)*t*t + b;
        },
        easeOutCubic: function (x, t, b, c, d) {
                return c*((t=t/d-1)*t*t + 1) + b;
        },
        easeInOutCubic: function (x, t, b, c, d) {
                if ((t/=d/2) < 1) return c/2*t*t*t + b;
                return c/2*((t-=2)*t*t + 2) + b;
        },
        easeInQuart: function (x, t, b, c, d) {
                return c*(t/=d)*t*t*t + b;
        },
        easeOutQuart: function (x, t, b, c, d) {
                return -c * ((t=t/d-1)*t*t*t - 1) + b;
        },
        easeInOutQuart: function (x, t, b, c, d) {
                if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
                return -c/2 * ((t-=2)*t*t*t - 2) + b;
        },
        easeInQuint: function (x, t, b, c, d) {
                return c*(t/=d)*t*t*t*t + b;
        },
        easeOutQuint: function (x, t, b, c, d) {
                return c*((t=t/d-1)*t*t*t*t + 1) + b;
        },
        easeInOutQuint: function (x, t, b, c, d) {
                if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
                return c/2*((t-=2)*t*t*t*t + 2) + b;
        },
        easeInSine: function (x, t, b, c, d) {
                return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
        },
        easeOutSine: function (x, t, b, c, d) {
                return c * Math.sin(t/d * (Math.PI/2)) + b;
        },
        easeInOutSine: function (x, t, b, c, d) {
                return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
        },
        easeInExpo: function (x, t, b, c, d) {
                return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
        },
        easeOutExpo: function (x, t, b, c, d) {
                return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
        },
        easeInOutExpo: function (x, t, b, c, d) {
                if (t==0) return b;
                if (t==d) return b+c;
                if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
                return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
        },
        easeInCirc: function (x, t, b, c, d) {
                return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
        },
        easeOutCirc: function (x, t, b, c, d) {
                return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
        },
        easeInOutCirc: function (x, t, b, c, d) {
                if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
                return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
        },
        easeInElastic: function (x, t, b, c, d) {
                var s=1.70158;var p=0;var a=c;
                if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
                if (a < Math.abs(c)) { a=c; var s=p/4; }
                else var s = p/(2*Math.PI) * Math.asin (c/a);
                return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
        },
        easeOutElastic: function (x, t, b, c, d) {
                var s=1.70158;var p=0;var a=c;
                if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
                if (a < Math.abs(c)) { a=c; var s=p/4; }
                else var s = p/(2*Math.PI) * Math.asin (c/a);
                return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
        },
        easeInOutElastic: function (x, t, b, c, d) {
                var s=1.70158;var p=0;var a=c;
                if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
                if (a < Math.abs(c)) { a=c; var s=p/4; }
                else var s = p/(2*Math.PI) * Math.asin (c/a);
                if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
                return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
        },
        easeInBack: function (x, t, b, c, d, s) {
                if (s == undefined) s = 1.70158;
                return c*(t/=d)*t*((s+1)*t - s) + b;
        },
        easeOutBack: function (x, t, b, c, d, s) {
                if (s == undefined) s = 1.70158;
                return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
        },
        easeInOutBack: function (x, t, b, c, d, s) {
                if (s == undefined) s = 1.70158; 
                if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
                return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
        },
        easeInBounce: function (x, t, b, c, d) {
                return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
        },
        easeOutBounce: function (x, t, b, c, d) {
                if ((t/=d) < (1/2.75)) {
                        return c*(7.5625*t*t) + b;
                } else if (t < (2/2.75)) {
                        return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
                } else if (t < (2.5/2.75)) {
                        return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
                } else {
                        return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
                }
        },
        easeInOutBounce: function (x, t, b, c, d) {
                if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
                return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
        }
});

/**
 * jQuery SliderViewer Plugin
 * @name jquery.slideviewer.1.1.js
 * @author Gian Carlo Mingati - http://www.gcmingati.net/wordpress/wp-content/lab/jquery/imagestrip/imageslide-plugin.html
 * @version 1.1
 * @date October 6, 2007
 * @category jQuery plugin
 * @copyright (c) 2007 Gian Carlo Mingati (gcmingati.net)
 * @license ?
 * @example Visit http://www.gcmingati.net/wordpress/wp-content/lab/jquery/imagestrip/imageslide-plugin.html for more informations about this jQuery plugin
 */

jQuery(function(){
        jQuery("div.svw").prepend("<img src='http://www.gcmingati.net/wordpress/wp-content/uploads/svwloader.gif' class='ldrgif' alt='loading...'/ >"); 
});
var j = 0;
jQuery.fn.slideView = function(settings) {
          settings = jQuery.extend({
     easeFunc: "easeInOutExpo", /* <-- easing function names changed in jquery.easing.1.2.js */
     easeTime: 750,
     largeur: 0,
     toolTip: true
  }, settings);
        return this.each(function(){
                var container = jQuery(this);
                container.find("img.ldrgif").remove(); // removes the preloader gif
                container.removeClass("svw").addClass("stripViewer");
                var pictWidth = container.find("img").width();
                if (settings.largeur != 0) {
                        // Comme IE 6 et 7 pose problème nous utilisons une largeur spécifié par le squelette...
                        pictWidth = settings.largeur;
                }
                var pictHeight = container.find("img").height();
                var pictEls = container.find("li").size();
                var stripViewerWidth = pictWidth*pictEls;
                container.find("ul").css("width" , stripViewerWidth); //assegnamo la larghezza alla lista UL
                container.css("width" , pictWidth);
                container.css("height" , pictHeight);
                container.each(function(i) {
                        jQuery(this).after("<div id='stripTransmitter" + j + "' class='stripTransmitter'><ul><\/ul><\/div>");
                        jQuery(this).find("li").each(function(n) {
                                                // Si l'image n'a pas de commentaire, on laisse vide. Sinon, on met le commentaire dans le title.
                                                if (jQuery(this).find("img").attr("title") == undefined) {
                                                        jQuery("div#stripTransmitter" + j + " ul").append("<li><a title=' ' href='#'>"+(n+1)+"<\/a><\/li>");
                                                } else {
                                                        jQuery("div#stripTransmitter" + j + " ul").append("<li><a title='" + jQuery(this).find("img").attr("title") + "' href='#'>"+(n+1)+"<\/a><\/li>");
                                                }
                                                                                                                                                
                                });
                        // Insertion de l'emplacement des commentaires.
                        jQuery("div#stripTransmitter" + j).after("<p id='galerieCommentaire" + j + "' class='galerieCommentaire'><\/p>");
                        jQuery("p#galerieCommentaire"+j).css("width", pictWidth);
                        jQuery("div#stripTransmitter" + j + " a").each(function(z) {
                                jQuery(this).bind("click", function(){
                                jQuery(this).addClass("current").parent().parent().find("a").not(jQuery(this)).removeClass("current"); // wow!
                                var cnt = - (pictWidth*z);
                                // Originale : jQuery(this).parent().parent().parent().prev('.stripViewer').find("ul").animate({ left: cnt}, settings.easeTime, settings.easeFunc);
                                jQuery(this).parent().parent().parent().prevAll('.stripViewer').find("ul").animate({ left: cnt}, settings.easeTime, settings.easeFunc);
                                // Sur clic d'un numéro d'image, affichage de la valeur du title de l'image dans l'espace commentaire
                                jQuery(this).parent().parent().parent().next(".galerieCommentaire").html(jQuery(this).attr("title"));
                                return false;
                                   });
                                });
                        jQuery("div#stripTransmitter" + j).css("width" , pictWidth);
                        jQuery("div#stripTransmitter" + j + " a:firsts").addClass("current");
                        
                        // Quand la galerie est chargée, avant les clics sur les numéros d'image, on affiche l'attribut title du premier élément
                        jQuery("p#galerieCommentaire" + j).html(jQuery("div#stripTransmitter" + j + " a:eq(0)").attr("title"));
                        
                        if(settings.toolTip){
                                container.next(".stripTransmitter ul").find("a").tooltip();
                        }
                                
                        });
                j++;
  });   
};

/*
 * jQuery Tooltip plugin 1.2
 *
 * http://bassistance.de/jquery-plugins/jquery-plugin-tooltip/
 * http://docs.jquery.com/Plugins/Tooltip
 *
 * Copyright (c) 2006 - 2008 Jörn Zaefferer
 *
 * $Id: jquery.tooltip.js 4569 2008-01-31 19:36:35Z joern.zaefferer $
 * 
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 */
 
;(function($) {
        
                // the tooltip element
        var helper = {},
                // the current tooltipped element
                current,
                // the title of the current element, used for restoring
                title,
                // timeout id for delayed tooltips
                tID,
                // IE 5.5 or 6
                IE = $.browser.msie && /MSIE\s(5\.5|6\.)/.test(navigator.userAgent),
                // flag for mouse tracking
                track = false;
        
        $.tooltip = {
                blocked: false,
                defaults: {
                        delay: 200,
                        showURL: true,
                        extraClass: "",
                        top: 15,
                        left: 15,
                        id: "tooltip"
                },
                block: function() {
                        $.tooltip.blocked = !$.tooltip.blocked;
                }
        };
        
        $.fn.extend({
                tooltip: function(settings) {
                        settings = $.extend({}, $.tooltip.defaults, settings);
                        createHelper(settings);
                        return this.each(function() {
                                        $.data(this, "tooltip-settings", settings);
                                        // copy tooltip into its own expando and remove the title
                                        this.tooltipText = this.title;
                                        $(this).removeAttr("title");
                                        // also remove alt attribute to prevent default tooltip in IE
                                        this.alt = "";
                                })
                                .hover(save, hide)
                                .click(hide);
                },
                fixPNG: IE ? function() {
                        return this.each(function () {
                                var image = $(this).css('backgroundImage');
                                if (image.match(/^url\(["']?(.*\.png)["']?\)$/i)) {
                                        image = RegExp.$1;
                                        $(this).css({
                                                'backgroundImage': 'none',
                                                'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=crop, src='" + image + "')"
                                        }).each(function () {
                                                var position = $(this).css('position');
                                                if (position != 'absolute' && position != 'relative')
                                                        $(this).css('position', 'relative');
                                        });
                                }
                        });
                } : function() { return this; },
                unfixPNG: IE ? function() {
                        return this.each(function () {
                                $(this).css({'filter': '', backgroundImage: ''});
                        });
                } : function() { return this; },
                hideWhenEmpty: function() {
                        return this.each(function() {
                                $(this)[ $(this).html() ? "show" : "hide" ]();
                        });
                },
                url: function() {
                        return this.attr('href') || this.attr('src');
                }
        });
        
        function createHelper(settings) {
                // there can be only one tooltip helper
                if( helper.parent )
                        return;
                // create the helper, h3 for title, div for url
                helper.parent = $('<div id="' + settings.id + '"><h3></h3><div class="body"></div><div class="url"></div></div>')
                        // add to document
                        .appendTo(document.body)
                        // hide it at first
                        .hide();
                        
                // apply bgiframe if available
                if ( $.fn.bgiframe )
                        helper.parent.bgiframe();
                
                // save references to title and url elements
                helper.title = $('h3', helper.parent);
                helper.body = $('div.body', helper.parent);
                helper.url = $('div.url', helper.parent);
        }
        
        function settings(element) {
                return $.data(element, "tooltip-settings");
        }
        
        // main event handler to start showing tooltips
        function handle(event) {
                // show helper, either with timeout or on instant
                if( settings(this).delay )
                        tID = setTimeout(show, settings(this).delay);
                else
                        show();
                
                // if selected, update the helper position when the mouse moves
                track = !!settings(this).track;
                $(document.body).bind('mousemove', update);
                        
                // update at least once
                update(event);
        }
        
        // save elements title before the tooltip is displayed
        function save() {
                // if this is the current source, or it has no title (occurs with click event), stop
                if ( $.tooltip.blocked || this == current || (!this.tooltipText && !settings(this).bodyHandler) )
                        return;

                // save current
                current = this;
                title = this.tooltipText;
                
                if ( settings(this).bodyHandler ) {
                        helper.title.hide();
                        var bodyContent = settings(this).bodyHandler.call(this);
                        if (bodyContent.nodeType || bodyContent.jquery) {
                                helper.body.empty().append(bodyContent)
                        } else {
                                helper.body.html( bodyContent );
                        }
                        helper.body.show();
                } else if ( settings(this).showBody ) {
                        var parts = title.split(settings(this).showBody);
                        helper.title.html(parts.shift()).show();
                        helper.body.empty();
                        for(var i = 0, part; part = parts[i]; i++) {
                                if(i > 0)
                                        helper.body.append("<br/>");
                                helper.body.append(part);
                        }
                        helper.body.hideWhenEmpty();
                } else {
                        helper.title.html(title).show();
                        helper.body.hide();
                }
                
                // if element has href or src, add and show it, otherwise hide it
                if( settings(this).showURL && $(this).url() )
                        helper.url.html( $(this).url().replace('http://', '') ).show();
                else 
                        helper.url.hide();
                
                // add an optional class for this tip
                helper.parent.addClass(settings(this).extraClass);

                // fix PNG background for IE
                if (settings(this).fixPNG )
                        helper.parent.fixPNG();
                        
                handle.apply(this, arguments);
        }
        
        // delete timeout and show helper
        function show() {
                tID = null;
                helper.parent.show();
                update();
        }
        
        /**
         * callback for mousemove
         * updates the helper position
         * removes itself when no current element
         */
        function update(event)  {
                if($.tooltip.blocked)
                        return;
                
                // stop updating when tracking is disabled and the tooltip is visible
                if ( !track && helper.parent.is(":visible")) {
                        $(document.body).unbind('mousemove', update)
                }
                
                // if no current element is available, remove this listener
                if( current == null ) {
                        $(document.body).unbind('mousemove', update);
                        return; 
                }
                
                // remove position helper classes
                helper.parent.removeClass("viewport-right").removeClass("viewport-bottom");
                
                var left = helper.parent[0].offsetLeft;
                var top = helper.parent[0].offsetTop;
                if(event) {
                        // position the helper 15 pixel to bottom right, starting from mouse position
                        left = event.pageX + settings(current).left;
                        top = event.pageY + settings(current).top;
                        helper.parent.css({
                                left: left + 'px',
                                top: top + 'px'
                        });
                }
                
                var v = viewport(),
                        h = helper.parent[0];
                // check horizontal position
                if(v.x + v.cx < h.offsetLeft + h.offsetWidth) {
                        left -= h.offsetWidth + 20 + settings(current).left;
                        helper.parent.css({left: left + 'px'}).addClass("viewport-right");
                }
                // check vertical position
                if(v.y + v.cy < h.offsetTop + h.offsetHeight) {
                        top -= h.offsetHeight + 20 + settings(current).top;
                        helper.parent.css({top: top + 'px'}).addClass("viewport-bottom");
                }
        }
        
        function viewport() {
                return {
                        x: $(window).scrollLeft(),
                        y: $(window).scrollTop(),
                        cx: $(window).width(),
                        cy: $(window).height()
                };
        }
        
        // hide helper and restore added classes and the title
        function hide(event) {
                if($.tooltip.blocked)
                        return;
                // clear timeout if possible
                if(tID)
                        clearTimeout(tID);
                // no more current element
                current = null;
                
                helper.parent.hide().removeClass( settings(this).extraClass );
                
                if( settings(this).fixPNG )
                        helper.parent.unfixPNG();
        }
        
        $.fn.Tooltip = $.fn.tooltip;
        
})(jQuery);