﻿/// <reference path="http://ajax.aspnetcdn.com/ajax/$/$-1.4.4-vsdoc.js" />
/* ------------------------------------------------------------------------
Class: weboltgallery
Use: Lightbox clone for jQuery
Author: Stephane Caron (http://www.no-margin-for-errors.com)
Version: 3.0.1
------------------------------------------------------------------------- */

(function ($) {
   $.weboltgallery = { version: '1.0' };

   $.fn.weboltgallery = function (pp_settings) {

      pp_settings = jQuery.extend({
         openmodal: true, /* apertura modale */
         navciclo: false, /* nav ciclico */
         hasdettagli: false, /* se ci sono dettagli  */
         hoverimage: false, /* appaiono le frecce sopra l'immagine*/
         tipovista: "orizzontale", /* orizzontale, verticale */
         hasscheda: true, /*true/false se ha la scheda predispongo il link */
         hascatalogo: true, /*true/false se ha il catalogo predispongo il link */
         animation_speed: 'fast', /* fast/slow/normal */
         slideshow: false, /* false OR interval time in ms */
         autoplay_slideshow: false, /* true/false */
         opacity: 0.80, /* Value between 0 and 1 */
         show_title: true, /* true/false */
         allow_resize: true, /* Resize the photos bigger than viewport. true/false */
         default_width: 472,
         default_height: 396,
         testo_slider: "",
         testo_dettagli: "Dettagli",
         container: "galleria",
         navlength: 800,
         itemWidth: 78 + 10, /* con spazio di separazione*/
         itemHeight: 78 + 10, /* con spazio di separazione*/
         counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
         theme: 'facebook', /* light_rounded / dark_rounded / light_square / dark_square / facebook */
         hideflash: false, /* Hides all the flash object on a page, set to TRUE if flash appears over weboltgallery */
         wmode: 'opaque', /* Set the flash wmode attribute */
         autoplay: true, /* Automatically start videos: True/False */
         modal: false, /* If set to true, only the close button will close the window */
         overlay_gallery: true, /* If set to true, a gallery will overlay the fullscreen image on mouse over */
         keyboard_shortcuts: true, /* Set to false if you open forms inside weboltgallery */
         changepicturecallback: function () { }, /* Called everytime an item is shown/changed */
         callback2: function () { }, /* Called when weboltgallery is closed */
         markup: '<div class="pp_sfondo"> \
               <div class="container_dati"> \
<div class="pp_content_container"> \
<div class="pp_content"> \
<div class="pp_loaderIcon"></div> \
<div class="pp_fade"> \
<a href="#" class="pp_expand" title="Expand the image">Expand</a> \
<div class="pp_hoverContainer"> \
<a class="pp_next" href="#">next</a> \
<a class="pp_previous" href="#">previous</a> \
</div> \
<div id="pp_full_res"></div>\
<div class="pp_descrizione_gallery"> \
</div>\
<div class="pp_details clearfix"> \
<p class="pp_description"></p> \
<div class="pp_nav"> \
<a href="#" class="pp_arrow_previous">Previous</a> \
<p class="currentTextHolder">0/0</p> \
<a href="#" class="pp_arrow_next">Next</a> \
</div> \
</div> \
</div> \
</div> \
</div> \
</div> \
</div> \
<div class="collegamentigallery"></div>',
         gallery_markup: '<div class="pp_gallery"> \
<div class="pp_sfondo_nav"> \
<a href="#" class="pp_arrow_previous">Previous</a> \
<ul> \
{gallery} \
</ul> \
<a href="#" class="pp_arrow_next">Next</a> \
</div> \
</div>',
         image_markup: '<img id="fullResImage" src="" alt=""/>',
         flash_markup: '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="{width}" height="{height}"><param name="wmode" value="{wmode}" /><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="{path}" /><embed src="{path}" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="{width}" height="{height}" wmode="{wmode}"></embed></object>',
         quicktime_markup: '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" height="{height}" width="{width}"><param name="src" value="{path}"><param name="autoplay" value="{autoplay}"><param name="type" value="video/quicktime"><embed src="{path}" height="{height}" width="{width}" autoplay="{autoplay}" type="video/quicktime" pluginspage="http://www.apple.com/quicktime/download/"></embed></object>',
         iframe_markup: '<iframe src ="{path}" width="{width}" height="{height}" frameborder="no"></iframe>',
         inline_markup: '<div class="pp_inline clearfix">{content}</div>',
         dettagli_markup: '<div class="pp_dettagli_gallery"> \
<div class="pp_dettagli_sfondo_nav"> \
<a href="#" class="pp_dettagli_arrow_previous">Previous</a> \
<ul> \
{dettagli} \
</ul> \
<a href="#" class="pp_dettagli_arrow_next">Next</a> \
</div> \
</div>',
         custom_markup: ''
      }, pp_settings);

      // Global variables accessible only by weboltgallery
      var matchedObjects = this, percentBased = false, correctSizes, pp_open, _temptitolo, _tempdescrizione, _tempcollegamenti,viewnav,

      // weboltgallery container specific
pp_contentHeight, pp_contentWidth, pp_containerHeight, pp_containerWidth, pp_descrizione_gallery,
titolo, descrizione, corrente = 0,

      // Window size

windowHeight = $(window).height(), windowWidth = $(window).width(),

      // Global elements
pp_slideshow;

      var altezza = 0;
      doresize = true, scroll_pos = _get_scroll();
      var dettagli = "";
      // Window/Keyboard events
      $(window).unbind('resize').resize(function () { _center_overlay(); _resize_overlay(); });

      /**
      * Initialize weboltgallery.
      */
      $.weboltgallery.initialize = function () {


         settings = pp_settings;

         if ($.browser.msie && parseInt($.browser.version) == 6) settings.theme = "light_square"; // Fallback to a supported theme for IE6


         _buildOverlay(this); // Build the overlay {this} being the caller

         if (settings.allow_resize)
            $(window).scroll(function () { _center_overlay(); });

        // _center_overlay();


         set_position = jQuery.inArray($(this).find('a.immaginegrande').attr('src'), pp_images); // Define where in the array the clicked item is positionned
         set_positionDettaglio = 0;
         $.weboltgallery.open();

         return false;
      };



      /**
      * Opens the weboltgallery modal box.
      * @param image {String,Array} Full path to the image to be open, can also be an array containing full images paths.
      * @param title {String,Array} The title to be displayed with the picture, can also be an array containing all the titles.
      * @param description {String,Array} The description to be displayed with the picture, can also be an array containing all the descriptions.
      */
      $.weboltgallery.open = function (event) {



         corrente = (pp_idimmagine[set_position]);

         window.location.hash = corrente.substring(3);

         //document.documentElement.scrollTop = 0;

         if (typeof settings == "undefined") { // Means it's an API call, need to manually get the settings and set the variables
            settings = pp_settings;
            if ($.browser.msie && $.browser.version == 6) settings.theme = "light_square"; // Fallback to a supported theme for IE6
            //_buildOverlay(event.target); // Build the overlay {this} being the caller
            pp_images = $.makeArray(arguments[0]);
            pp_titles = (arguments[1]) ? $.makeArray(arguments[1]) : $.makeArray("");
            pp_descriptions = (arguments[2]) ? $.makeArray(arguments[2]) : $.makeArray("");
            isSet = (pp_images.length > 1) ? true : false;
            set_position = 0;
         }


         if ($.browser.msie && $.browser.version == 6) $('select').css('visibility', 'hidden'); // To fix the bug with IE select boxes

         if (settings.hideflash) $('object,embed').css('visibility', 'hidden'); // Hide the flash

        


         $pp_descrizione_gallery.css('opacity', 0).show();

         // Display the current position

         $pp_sfondo.find('.currentTextHolder').text((set_position + 1) + settings.counter_separator_label + $(pp_images).size());

         // Set the description
         $pp_sfondo.find('.pp_description').html(settings.testo_slider);

         // Set the description

         $pp_descrizione_gallery.html(unescape(pp_descriptions[set_position]));

         //$pp_dettagli_gallery.html(unescape(pp_dettagligallery[set_position]));


         // Get the dimensions
         movie_width = (parseFloat(grab_param('width', pp_images[set_position]))) ? grab_param('width', pp_images[set_position]) : settings.default_width.toString();
         movie_height = (parseFloat(grab_param('height', pp_images[set_position]))) ? grab_param('height', pp_images[set_position]) : settings.default_height.toString();



         // If the size is % based, calculate according to window dimensions
         if (movie_width.indexOf('%') != -1 || movie_height.indexOf('%') != -1) {
            movie_height = parseFloat(($(window).height() * parseFloat(movie_height) / 100) - 150);
            movie_width = parseFloat(($(window).width() * parseFloat(movie_width) / 100) - 150);
            percentBased = true;
         } else {
            percentBased = false;
         }



         // Fade the holder
         $pp_sfondo.fadeIn(function () {
            imgPreloader = "";


            // Inject the proper content
            switch (_getFileType(pp_images[set_position])) {
               case 'image':
                  imgPreloader = new Image();

                  // Preload the neighbour images
                  nextImage = new Image();
                  if (isSet && set_position > $(pp_images).size()) nextImage.src = pp_images[set_position + 1];
                  prevImage = new Image();
                  if (isSet && pp_images[set_position - 1]) prevImage.src = pp_images[set_position - 1];


                  $pp_sfondo.find('#pp_full_res')[0].innerHTML = settings.image_markup;
                  $pp_sfondo.find('#fullResImage').attr('src', pp_images[set_position]);
                  $pp_sfondo.find('#fullResImage').attr('alt', pp_alttext[set_position]);
                  if (settings.hasdettagli) _insert_dettagli();



                  //alert($pp_sfondo.find('.pp_descrizione_gallery').height());
                  imgPreloader.onload = function () {
                     // Fit item to viewport
                     correctSizes = _fitToViewport(imgPreloader.width, imgPreloader.height);

                     _showContent();
                  };

                  imgPreloader.onerror = function () {
                     alert('Image cannot be loaded. Make sure the path is correct and image exist.');
                     $.weboltgallery.close();
                  };

                  imgPreloader.src = pp_images[set_position];
                  break;

               case 'youtube':
                  correctSizes = _fitToViewport(movie_width, movie_height); // Fit item to viewport

                  movie = 'http://www.youtube.com/v/' + grab_param('v', pp_images[set_position]);
                  if (settings.autoplay) movie += "&autoplay=1";

                  toInject = settings.flash_markup.replace(/{width}/g, correctSizes['width']).replace(/{height}/g, correctSizes['height']).replace(/{wmode}/g, settings.wmode).replace(/{path}/g, movie);
                  break;

               case 'vimeo':
                  correctSizes = _fitToViewport(movie_width, movie_height); // Fit item to viewport

                  movie_id = pp_images[set_position];
                  var regExp = /http:\/\/(www\.)?vimeo.com\/(\d+)/;
                  var match = movie_id.match(regExp);

                  movie = 'http://player.vimeo.com/video/' + match[2] + '?title=0&amp;byline=0&amp;portrait=0';
                  if (settings.autoplay) movie += "&autoplay=1;";

                  vimeo_width = correctSizes['width'] + '/embed/?moog_width=' + correctSizes['width'];

                  toInject = settings.iframe_markup.replace(/{width}/g, vimeo_width).replace(/{height}/g, correctSizes['height']).replace(/{path}/g, movie);
                  break;

               case 'quicktime':
                  correctSizes = _fitToViewport(movie_width, movie_height); // Fit item to viewport
                  correctSizes['height'] += 15; correctSizes['contentHeight'] += 15; correctSizes['containerHeight'] += 15; // Add space for the control bar

                  toInject = settings.quicktime_markup.replace(/{width}/g, correctSizes['width']).replace(/{height}/g, correctSizes['height']).replace(/{wmode}/g, settings.wmode).replace(/{path}/g, pp_images[set_position]).replace(/{autoplay}/g, settings.autoplay);
                  break;

               case 'flash':
                  correctSizes = _fitToViewport(movie_width, movie_height); // Fit item to viewport

                  flash_vars = pp_images[set_position];
                  flash_vars = flash_vars.substring(pp_images[set_position].indexOf('flashvars') + 10, pp_images[set_position].length);

                  filename = pp_images[set_position];
                  filename = filename.substring(0, filename.indexOf('?'));

                  toInject = settings.flash_markup.replace(/{width}/g, correctSizes['width']).replace(/{height}/g, correctSizes['height']).replace(/{wmode}/g, settings.wmode).replace(/{path}/g, filename + '?' + flash_vars);
                  break;

               case 'iframe':
                  correctSizes = _fitToViewport(movie_width, movie_height); // Fit item to viewport

                  frame_url = pp_images[set_position];
                  frame_url = frame_url.substr(0, frame_url.indexOf('iframe') - 1);

                  toInject = settings.iframe_markup.replace(/{width}/g, correctSizes['width']).replace(/{height}/g, correctSizes['height']).replace(/{path}/g, frame_url);
                  break;

               case 'custom':
                  correctSizes = _fitToViewport(movie_width, movie_height); // Fit item to viewport

                  toInject = settings.custom_markup;
                  break;

               case 'inline':
                  // to get the item height clone it, apply default width, wrap it in the weboltgallery containers , then delete
                  myClone = $(pp_images[set_position]).clone().css({ 'width': settings.default_width }).wrapInner('<div id="pp_full_res"><div class="pp_inline clearfix"></div></div>').appendTo($('body'));
                  correctSizes = _fitToViewport($(myClone).width(), $(myClone).height());
                  $(myClone).remove();
                  toInject = settings.inline_markup.replace(/{content}/g, $(pp_images[set_position]).html());
                  break;
            };


            if (!imgPreloader) {
               $pp_sfondo.find('#pp_full_res')[0].innerHTML = toInject;


               // Show content
               _showContent();
            };
         });

		  _checkPosition($(pp_images).size()); // Hide the next/previous links if on first or last images.
         $pp_sfondo.find('.pp_collegamenti').html("");

         return false;
      };



      /**
      * Change page in the weboltgallery modal box
      * @param direction {String} Direction of the paging, previous or next.
      */
      $.weboltgallery.changePage = function (direction) {
         currentGalleryPage = 0;
         if (direction == 'previous') {

            set_position--;
            if (set_position < 0) {
               set_position = 0;
               return;
            };
         } else if (direction == 'next') {

            set_position++;
            if (set_position > $(pp_images).size() - 1) {
               set_position = 0;
            }
         } else {
            set_position = direction;
         };

         if (!doresize) doresize = true; // Allow the resizing of the images
         $('.pp_contract').removeClass('pp_contract').addClass('pp_expand');

         _hideContent(function () {
            $.weboltgallery.open();
         });
      };

      /**
      * Change page in the weboltgallery modal box
      * @param direction {String} Direction of the paging, previous or next.
      */
      $.weboltgallery.changePageDettagli = function (direction, numeroelementi) {
         if (direction == 'previous') {

            set_positionDettaglio--;
            if (set_positionDettaglio < 0) {
               set_positionDettaglio = 0;
               return;
            };
         } else if (direction == 'next') {

            set_positionDettaglio++;

            if (set_positionDettaglio > numeroelementi) {
               set_positionDettaglio = 0;
            }
         } else {
            set_positionDettaglio = direction;
         };


      };
      /**
      * Change gallery page in the weboltgallery modal box
      * @param direction {String} Direction of the paging, previous or next.
      */
      $.weboltgallery.changeGalleryPage = function (direction) {
         if (settings.tipovista == "orizzontale") {
            if (direction == 'next') {
               currentGalleryPage++;

               if (currentGalleryPage > totalPage) {
                  if (settings.navciclo)
                  { currentGalleryPage = 0; }
                  else
                  { currentGalleryPage = totalPage; }
               };
            } else if (direction == 'previous') {
               currentGalleryPage--;

               if (currentGalleryPage < 0) {
                  if (settings.navciclo) {
                     currentGalleryPage = totalPage;

                  } else {
                     currentGalleryPage = 0;
                  }

               };
            } else {
               currentGalleryPage = direction;
            };
         }

         if (settings.tipovista == "verticale") {
            if (direction == 'next') {
               currentGalleryPage++;

               if (currentGalleryPage > totalPageVerticale) {
                  if (settings.navciclo)
                  { currentGalleryPage = 0; }
                  else
                  { currentGalleryPage = totalPageVerticale; }
               };
            } else if (direction == 'previous') {
               currentGalleryPage--;

               if (currentGalleryPage < 0) {
                  if (settings.navciclo) {
                     currentGalleryPage = totalPageVerticale;

                  } else {
                     currentGalleryPage = 0;
                  }

               };
            } else {
               currentGalleryPage = direction;
            };
         }
         // Slide the pages, if we're on the last page, find out how many items we need to slide. To make sure we don't have an empty space.
         if (settings.tipovista == "orizzontale") {
            if (settings.navciclo)
               itemsToSlide = (currentGalleryPage == totalPage) ? pp_images.length - ((totalPage) * itemsPerPage) : itemsPerPage;
            else {
               itemsToSlide = itemsPerPage;
            }
         }
         if (settings.tipovista == "verticale") {
            if (settings.navciclo)
               itemsToSlideVerticale = (currentGalleryPage == totalPageVerticale) ? pp_images.length - ((totalPageVerticale) * itemsPerPageVerticale) : itemsPerPageVerticale;
            else {
               itemsToSlideVerticale = itemsPerPageVerticale;
            }
         }
         if (settings.tipovista == "orizzontale") {
            $pp_sfondo.find('.pp_gallery li').each(function (i) {
               $(this).animate({
                  'left': (i * itemWidth) - ((itemsToSlide * itemWidth) * currentGalleryPage)
               });
            });
         }
         if (settings.tipovista == "verticale") {
            $pp_sfondo.find('.pp_gallery li').each(function (i) {
               $(this).animate({
                  'top': (i * itemHeight) - ((itemsToSlideVerticale * itemHeight) * currentGalleryPage)
               });
            });
         }

         if (currentGalleryPage == 0) {

            $pp_sfondo.find('.pp_gallery .pp_arrow_previous').addClass('disabled');
         }
         else
         { $pp_sfondo.find('.pp_gallery .pp_arrow_previous.disabled').removeClass('disabled'); }


         if (currentGalleryPage == totalPage) {

            $pp_sfondo.find('.pp_gallery .pp_arrow_next').addClass('disabled');
         }
         else
         { $pp_sfondo.find('.pp_gallery .pp_arrow_next.disabled').removeClass('disabled'); }


      };

      $.weboltgallery.changeDettagliPage = function (direction) {
         if (direction == 'next') {
            currentDettagliPage++;
            if (currentDettagliPage > totalPageDet) {
               if (settings.navciclo)
               { currentDettagliPage = 0; }
               else
               { currentDettagliPage = totalPageDet; }
            };
         } else if (direction == 'previous') {
            currentDettagliPage--;

            if (currentDettagliPage < 0) {
               if (settings.navciclo) {
                  currentDettagliPage = totalPageDet;
               } else {
                  currentDettagliPage = 0;
               }

            };
         } else {
            currentDettagliPage = direction;
         };

         if (currentDettagliPage == 0) {

            $pp_sfondo.find('.pp_dettagli_gallery .pp_dettagli_arrow_previous').addClass('disabled');
         }
         else
         { $pp_sfondo.find('.pp_dettagli_gallery .pp_dettagli_arrow_previous.disabled').removeClass('disabled'); }


         if (currentDettagliPage == totalPageDet) {

            $pp_sfondo.find('.pp_dettagli_gallery .pp_dettagli_arrow_next').addClass('disabled');
         }
         else
         { $pp_sfondo.find('.pp_dettagli_gallery .pp_dettagli_arrow_next.disabled').removeClass('disabled'); }

         if (settings.navciclo)
            itemsDetToSlide = (currentDettagliPage == totalPageDet) ? numerodettagli - ((totalPageDet) * itemsDetPerPage) : itemsDetPerPage;
         else {
            itemsDetToSlide = itemsDetPerPage;
         }


         $pp_sfondo.find('.pp_dettagli_gallery li').each(function (i) {
            $(this).animate({
               'left': (i * itemDetWidth) - ((itemsDetToSlide * itemDetWidth) * currentDettagliPage)
            }, 0);
         });
         // Slide the pages, if we're on the last page, find out how many items we need to slide. To make sure we don't have an empty space.
         // if (settings.navciclo)
         // itemsDetToSlide = (currentDettagliPage == totalPageDet) ? numerodettagli - ((totalPageDett) * itemsDetPerPage) : itemsDetPerPage;
         // else {
         itemsDetToSlide = itemsDetPerPage;
         // }

         $pp_sfondo.find('.pp_dettagli_gallery li').each(function (i) {
            $(this).animate({
               'left': (i * itemDetWidth) - ((itemsDetToSlide * itemDetWidth) * currentDettagliPage)
            });
         });
      };
      /**
      * Start the slideshow...
      */
      $.weboltgallery.startSlideshow = function () {
         if (typeof pp_slideshow == 'undefined') {
            $pp_sfondo.find('.pp_play').unbind('click').removeClass('pp_play').addClass('pp_pause').click(function () {
               $.weboltgallery.stopSlideshow();
               return false;
            });
            pp_slideshow = setInterval($.weboltgallery.startSlideshow, settings.slideshow);
         } else {
            $.weboltgallery.changePage('next');
         };
      }


      /**
      * Stop the slideshow...
      */
      $.weboltgallery.stopSlideshow = function () {
         $pp_sfondo.find('.pp_pause').unbind('click').removeClass('pp_pause').addClass('pp_play').click(function () {
            $.weboltgallery.startSlideshow();
            return false;
         });
         clearInterval(pp_slideshow);
         pp_slideshow = undefined;
      }


      /**
      * Closes weboltgallery.
      */
      $.weboltgallery.close = function () {

         clearInterval(pp_slideshow);

         $pp_sfondo.stop().find('object,embed').css('visibility', 'hidden');
         $('div.pp_sfondo,div.pp_descrizione_gallery,.pp_fade').fadeOut(settings.animation_speed, function () {
            $(this).remove();
         });
         $pp_sfondo.fadeOut(settings.animation_speed, function () {

            if ($.browser.msie && $.browser.version == 6) $('select').css('visibility', 'visible'); // To fix the bug with IE select boxes

            if (settings.hideflash) $('object,embed').css('visibility', 'visible'); // Show the flash

            $(this).remove(); // No more need for the weboltgallery markup

            $(window).unbind('scroll');

            settings.callback2();

            doresize = true;

            pp_open = false;

            delete settings;

         });

         document.location.hash = '#';
         return false;
      };

      /**
      * Set the proper sizes on the containers and animate the content in.
      */
      _showContent = function () {
         $('.pp_loaderIcon').hide();

        // $pp_sfondo.find('.pp_fade').fadeTo(settings.animation_speed, 1);

         // Calculate the opened top position of the pic holder
         // projectedTop = scroll_pos['scrollTop'] + ((windowHeight / 2) - (correctSizes['containerHeight'] / 2));
         // if (projectedTop < 0) projectedTop = 0;

         $pp_descrizione_gallery.css('opacity', 1).show();

		 $pp_sfondo.find('.pp_gallery').css("visibility","visible");
         $pp_sfondo.find('.container_dati').fadeIn(settings.animation_speed); // Fade the new content
         // Show the nav

         if (isSet && _getFileType(pp_images[set_position]) == "image") { $pp_sfondo.find('.pp_hoverContainer').show(); } else { $pp_sfondo.find('.pp_hoverContainer').hide(); }

         if (correctSizes['resized']) $('a.pp_expand,a.pp_contract').fadeIn(settings.animation_speed); // Fade the resizing link if the image is resized

         if (settings.autoplay_slideshow && !pp_slideshow && !pp_open) $.weboltgallery.startSlideshow();
         settings.changepicturecallback(); // Callback!
         pp_open = true;
         // });

         _insert_gallery();
		 (viewnav)? $('.pp_nav').show() : $('.pp_nav').hide();
         //_insert_dettagli();

         Hover();

      };

      /**
      * Hide the content...DUH!
      */
      function _hideContent(callback2) {


         // Fade out the current picture

         $pp_sfondo.find('#pp_full_res object,#pp_full_res embed, .pp_gallery').css('visibility', 'hidden');
        //$pp_sfondo.find('.pp_fade ').fadeOut(settings.animation_speed, function () {
         $('.pp_loaderIcon').show();

         callback2();
         //  });
      };

      /**
      * Check the item position in the gallery array, hide or show the navigation links
      * @param setCount {integer} The total number of items in the set
      */
      function _checkPosition(setCount) {
         // If at the end, hide the next link


         if (set_position == setCount - 1) {
            $pp_sfondo.find('a.pp_next').css('visibility', 'hidden');
            $pp_sfondo.find('a.pp_next').addClass('disabled').unbind('click');
         } else {
            $pp_sfondo.find('a.pp_next').css('visibility', 'visible');
            $pp_sfondo.find('a.pp_next.disabled').removeClass('disabled').bind('click', function () {
               $.weboltgallery.changePage('next');
               return false;
            });
         };

         // If at the beginning, hide the previous link
         if (set_position == 0) {

            $pp_sfondo
.find('a.pp_previous')
.css('visibility', 'hidden')
.addClass('disabled')
.unbind('click');
         } else {
            $pp_sfondo.find('a.pp_previous.disabled')
.css('visibility', 'visible')
.removeClass('disabled')
.bind('click', function () {
   $.weboltgallery.changePage('previous');
   return false;
});
         };

         (setCount > 1) ? viewnav=true:viewnav=false; // Hide the bottom nav if it's not a set.
      };

      /**
      * Resize the item dimensions if it's bigger than the viewport
      * @param width {integer} Width of the item to be opened
      * @param height {integer} Height of the item to be opened
      * @return An array containin the "fitted" dimensions
      */
      function _fitToViewport(width, height) {
         resized = false;
         _getDimensions(width, height);

         // Define them in case there's no resize needed
         imageWidth = width, imageHeight = height;

         if (((pp_descrizione_galleryWidth > windowWidth) || (pp_descrizione_galleryHeight > windowHeight))
&& doresize && settings.allow_resize && !percentBased) {
            resized = true, fitting = false;

            while (!fitting) {
               if ((pp_containerWidth > windowWidth)) {
                  imageWidth = (windowWidth - 200);
                  imageHeight = (height / width) * imageWidth;
               } else if ((pp_containerHeight > windowHeight)) {
                  imageHeight = (windowHeight - 200);
                  imageWidth = (width / height) * imageHeight;
                  //alert(imageWidth + " imageHeight: " + imageHeight);
               } else {
                  fitting = true;
               };

               pp_descrizione_galleryHeight = imageHeight, pp_descrizione_galleryWidth = imageWidth;
            };

            _getDimensions(imageWidth, imageHeight);
         };


         //         if (pp_contentHeight >= pp_descrizione_galleryHeight)
         //            pp_descrizione_galleryHeight = pp_containerHeight
         //         else
         //            pp_contentHeight = pp_descrizione_galleryHeight

         return {
            width: Math.floor(imageWidth),
            height: Math.floor(imageHeight),
            containerHeight: Math.floor(pp_containerHeight),
            containerWidth: Math.floor(pp_containerWidth), //+ 40, // 40 behind the side padding
            contentHeight: Math.floor(pp_contentHeight),
            contentWidth: Math.floor(pp_contentWidth),
            descrizione_galleryHeight: Math.floor(pp_descrizione_galleryHeight),
            descrizione_gallerytWidth: Math.floor(pp_descrizione_galleryWidth),
            resized: resized
         };
      };

      /**
      * Get the containers dimensions according to the item size
      * @param width {integer} Width of the item to be opened
      * @param height {integer} Height of the item to be opened
      */
      function _getDimensions(width, height) {
         width = parseFloat(width);
         height = parseFloat(height);


         // Get the details height, to do so, I need to clone it since it's invisible
         $pp_details = $pp_sfondo.find('.pp_details');
         $pp_details.width(width);
         detailsHeight = parseFloat($pp_details.css('marginTop')) + parseFloat($pp_details.css('marginBottom'));
         $pp_details = $pp_details.clone().appendTo($('body')).css({
            'position': 'absolute',
            'top': -10000
         });

         detailsHeight += $pp_details.height();
         detailsHeight = (detailsHeight <= 34) ? 36 : detailsHeight; // Min-height for the details
         if ($.browser.msie && $.browser.version == 7) detailsHeight += 8;
         $pp_details.remove();


         // Get the container size, to resize the holder to the right dimensions
         pp_contentHeight = height + detailsHeight;
         pp_contentWidth = width;

         pp_containerHeight = pp_contentHeight;

         pp_containerWidth = width;
         pp_descrizione_galleryHeight = $pp_descrizione_gallery.height();
         pp_descrizione_galleryWidth = $pp_descrizione_gallery.width();


      }

      function _getFileType(itemSrc) {
         if (itemSrc.match(/youtube\.com\/watch/i)) {
            return 'youtube';
         } else if (itemSrc.match(/vimeo\.com/i)) {
            return 'vimeo';
         } else if (itemSrc.indexOf('.mov') != -1) {
            return 'quicktime';
         } else if (itemSrc.indexOf('.swf') != -1) {
            return 'flash';
         } else if (itemSrc.indexOf('iframe') != -1) {
            return 'iframe';
         } else if (itemSrc.indexOf('custom') != -1) {
            return 'custom';
         } else if (itemSrc.substr(0, 1) == '#') {
            return 'inline';
         } else {
            return 'image';
         };
      };

      function _center_overlay() {
         if (doresize && typeof $pp_sfondo != 'undefined') {
            scroll_pos = _get_scroll();


            titleHeight = contentHeight = $pp_sfondo.height(), contentwidth = $pp_sfondo.width();


            projectedTop = (windowHeight / 2) + scroll_pos['scrollTop'] - (contentHeight / 2);

            //alert(projectedTop);

            // $pp_sfondo.css({
            // 'top': 0, //projectedTop,
            // 'left': 173//(windowWidth / 2) + scroll_pos['scrollLeft'] - (contentwidth/2 )
            // });
         };
      };

      function _get_scroll() {
         if (self.pageYOffset) {
            return { scrollTop: self.pageYOffset, scrollLeft: self.pageXOffset };
         } else if (document.documentElement && document.documentElement.scrollTop) { // Explorer 6 Strict
            return { scrollTop: document.documentElement.scrollTop, scrollLeft: document.documentElement.scrollLeft };
         } else if (document.body) {// all other Explorers
            return { scrollTop: document.body.scrollTop, scrollLeft: document.body.scrollLeft };
         };
      };

      function _resize_overlay() {
         windowHeight = $(window).height(), windowWidth = $(window).width();
         //alert("cucu");
         //if (typeof $pp_overlay != "undefined") $pp_overlay.height($(document).height());
      };



      function _insert_gallery() {
         if (isSet && settings.overlay_gallery && _getFileType(pp_images[set_position]) == "image") {

            Hover();

            itemWidth = settings.itemWidth // 52 beign the thumb width, 5 being the right margin.
            navWidth = (settings.theme == "facebook") ? 58 : 38; // Define the arrow width depending on the theme
            navWidth = (settings.theme == "leverplan") ? 78 : navWidth; // Define the arrow width depending on the theme

            itemHeight = settings.itemHeight // 52 beign the thumb width, 5 being the right margin.
            navHeight = (settings.theme == "facebook") ? 58 : 38; // Define the arrow width depending on the theme
            navHeight = (settings.theme == "esempi") ? 78 : navHeight; // Define the arrow width depending on the theme

            itemsPerPage = Math.floor((settings.navlength - navWidth) / itemWidth);
            itemsPerPageVerticale = Math.floor((settings.navlength - navHeight) / itemHeight);

            //itemsPerPage = Math.floor((722 - navWidth) / itemWidth);
            itemsPerPage = (itemsPerPage < pp_images.length) ? itemsPerPage : pp_images.length;
            itemsPerPageVerticale = (itemsPerPageVerticale < pp_images.length) ? itemsPerPageVerticale : pp_images.length;

            totalPage = Math.ceil(pp_images.length / itemsPerPage) - 1;
            totalPageVerticale = Math.ceil(pp_images.length / itemsPerPageVerticale) - 1;

            // Hide the nav in the case there's no need for links
            if (settings.tipovista == "orizzontale") {
               if (totalPage == 0) {
                  navWidth = 0; // No nav means no width!
                  $pp_sfondo.find('.pp_gallery .pp_arrow_next,.pp_gallery .pp_arrow_previous').hide();
               } else {
                  $pp_sfondo.find('.pp_gallery .pp_arrow_next,.pp_gallery .pp_arrow_previous').show();
               };
            }
            if (settings.tipovista == "verticale") {
               if (totalPageVerticale == 0) {
                  navWidth = 0; // No nav means no width!
                  $pp_sfondo.find('.pp_gallery .pp_arrow_next,.pp_gallery .pp_arrow_previous').hide();
               } else {
                  $pp_sfondo.find('.pp_gallery .pp_arrow_next,.pp_gallery .pp_arrow_previous').show();
               };
            }
            galleryWidth = itemsPerPage * itemWidth + navWidth;
            galleryHeight = itemsPerPageVerticale * itemHeight + navHeight;



            // Set the proper width to the gallery items
            //            $pp_sfondo.find('.pp_gallery').width(galleryWidth).css('margin-left', -(galleryWidth / 2));
            //            $pp_sfondo.find('.pp_gallery').width(galleryWidth).css('margin-left', -(350));

            if (settings.tipovista == "orizzontale") {
               $pp_sfondo.find('.pp_gallery ul').width(itemsPerPage * itemWidth).find('li.selected').removeClass('selected');
            }
            else if (settings.tipovista == "verticale") {
               $pp_sfondo.find('.pp_gallery ul').height(itemsPerPageVerticale * itemHeight).find('li.selected').removeClass('selected');
            }
            goToPage = (Math.floor(set_position / itemsPerPage) <= totalPage) ? Math.floor(set_position / itemsPerPage) : totalPage;
            goToPageVerticale = (Math.floor(set_position / itemsPerPageVerticale) <= totalPageVerticale) ? Math.floor(set_position / itemsPerPageVerticale) : totalPageVerticale;
            if (settings.tipovista == "orizzontale") {
               if (itemsPerPage) {
                  $pp_sfondo.find('.pp_gallery').hide().show().removeClass('disabled');
               } else {
                  $pp_sfondo.find('.pp_gallery').hide().addClass('disabled');
               }
            }

            if (settings.tipovista == "verticale") {
               if (itemsPerPageVerticale) {
                  $pp_sfondo.find('.pp_gallery').hide().show().removeClass('disabled');
               } else {
                  $pp_sfondo.find('.pp_gallery').hide().addClass('disabled');
               }
            }
            if (settings.tipovista == "orizzontale") {
               $.weboltgallery.changeGalleryPage(goToPage);
            }
            else if (settings.tipovista == "verticale") {
               $.weboltgallery.changeGalleryPage(goToPageVerticale);
            }

            $pp_sfondo
.find('.pp_gallery ul li:eq(' + set_position + ')')
.addClass('selected');
         } else {
            $pp_sfondo.find('.pp_content').unbind('mouseenter mouseleave');
            $pp_sfondo.find('.pp_gallery').hide();
         }
      }

      function _insert_dettagli() {
         // Inject the dettagli!
         var numerodettagli;

         $.ajax({
            url: '/GalleryModule/Dettagli.ashx',
            dataType: 'json',
            data: "id=" + corrente.substring(3),
            success: function (data) {

               //$.getJSON('/GalleryModule/Dettagli.ashx', { id: corrente.substring(3) }, function (data) {

               _temptitolo = $pp_sfondo.find('.testo_titolo_gallery').html();
               _tempdescrizione = $pp_sfondo.find('.testo_descrizione_gallery').html();
               _tempcollegamenti = $pp_sfondo.find('.testo_collegamenti_gallery').html();

               $pp_sfondo.find('.pp_dettagli_gallery').remove();
               currentDettagliPage = 0;
               var toInject = "";
               numerodettagli = data.length;
               for (var i = 0; i < data.length; i++) {
                  // var regex = new RegExp("(.*?)\.(jpg|jpeg|png|gif)$");
                  // var results = regex.exec(pp_dettagligallery[i]);
                  var results = true;
                  if (!results) {
                     classname = 'default';
                  } else {
                     classname = '';
                  }

                  toInject += "<li class='" + classname + "'><a class='dettaglio'>" + (i + 1) + "</a></li>";

               };

               toInject = settings.dettagli_markup.replace(/{dettagli}/g, toInject);
               $pp_sfondo.find('#pp_full_res').after(toInject);


               $pp_sfondo.find('.pp_dettagli_gallery .pp_dettagli_arrow_next').click(function () {

                  $.weboltgallery.changeDettagliPage('next');
                  return false;
               });

               $pp_sfondo.find('.pp_dettagli_gallery .pp_dettagli_arrow_previous').click(function () {
                  $.weboltgallery.changeDettagliPage('previous');

                  return false;
               });




               itemDetWidth = 20 + 5 // 52 beign the thumb width, 5 being the right margin.
               navdetWidth = (settings.theme == "facebook") ? 58 : 38; // Define the arrow width depending on the theme
               navdetWidth = (settings.theme == "leverplan") ? 20 : navdetWidth; // Define the arrow width depending on the theme
               itemsDetPerPage = Math.floor((200 - navdetWidth) / itemDetWidth);

               //itemsPerPage = Math.floor((722 - navWidth) / itemWidth);
               itemsDetPerPage = (itemsDetPerPage < numerodettagli) ? itemsDetPerPage : numerodettagli;

               totalPageDet = Math.ceil(numerodettagli / itemsDetPerPage) - 1;


               // Hide the nav in the case there's no need for links
               if (totalPageDet == 0) {
                  navDetWidth = 0; // No nav means no width!
                  $pp_sfondo.find('.pp_dettagli_gallery .pp_dettagli_arrow_next,.pp_dettagli_gallery .pp_dettagli_arrow_previous').hide();
               } else {
                  $pp_sfondo.find('.pp_dettagli_gallery .pp_dettagli_arrow_next,.pp_dettagli_gallery .pp_dettagli_arrow_previous').show();
               };


               $pp_sfondo
.find('.pp_dettagli_gallery ul')
.width(itemsDetPerPage * itemDetWidth)
.find('li.selected')
.removeClass('selected');


               goToPageDett = (Math.floor(set_positionDettaglio / itemsDetPerPage) <= totalPageDet) ? Math.floor(set_positionDettaglio / itemsDetPerPage) : totalPageDet;


               if (itemsDetPerPage) {
                  $pp_sfondo.find('.pp_dettagli_gallery').hide().show().removeClass('disabled');
               } else {
                  $pp_sfondo.find('.pp_dettagli_gallery').hide().addClass('disabled');
               }



               $.weboltgallery.changeDettagliPage(goToPageDett);



               $pp_sfondo.find('.pp_dettagli_gallery ul li').each(function (i) {
                  $(this).css({
                     'position': 'absolute',
                     'left': i * itemDetWidth
                  });
                  // Dettaglio Click
                  $(this).find('a.dettaglio').unbind('click').click(function () {


                     set_positionDettaglio = i;
                     $pp_sfondo.find('.pp_dettagli_gallery ul li').removeClass("selected");
                     $pp_sfondo.find('#fullResImage').attr('src', data[i].Immagine.Src);
                     $pp_sfondo.find('#fullResImage').attr('alt', data[i].Immagine.Alttext);

                     var _titolo = "";
                     var _descrizione = "";
                     if (data[i].Titolo != null) {
                        _titolo = data[i].Titolo;
                        $pp_sfondo.find('.testo_titolo_gallery').html(_titolo);
                     }
                     else {
                        $pp_sfondo.find('.testo_titolo_gallery').html(_temptitolo);
                     }
                     if (data[i].Descrizione != null) {
                        _descrizione = data[i].Descrizione;
                        $pp_sfondo.find('.testo_descrizione_gallery').html(_descrizione);

                     }
                     else {
                        $pp_sfondo.find('.testo_titolo_gallery').html(_tempdescrizione);
                     }
                     if (data[i].Collegamenti.length > 0) {
                        var collegamenti = "<ul>";
                        for (var j = 0; j < data[i].Collegamenti.length; j++) {
                           collegamenti += "<li class='linkgallery" + j + "'>";
                           collegamenti += data[i].Collegamenti[j].Link
                           collegamenti += "</li>";
                        }
                        collegamenti += "<ul>"
                        $pp_sfondo.find('.testo_collegamenti_gallery').html(collegamenti);
                     }
                     else {
                        $pp_sfondo.find('.testo_collegamenti_gallery').html(_tempcollegamenti);
                     }

                     // if(_concateno.length>0)
                     // $pp_sfondo.find('.pp_descrizione_gallery').html(_concateno);

                     // $.weboltgallery.changePage(i);
                     // $.weboltgallery.stopSlideshow();



                     $pp_sfondo.find('.pp_dettagli_gallery ul li:eq(' + set_positionDettaglio + ')')
.addClass('selected');
                     return false;
                  });
               });



               $pp_sfondo.find('.pp_dettagli_sfondo_nav .pp_dettagli_arrow_previous').bind('click', function () {
                  $.weboltgallery.changePageDettagli('previous', numerodettagli);
                  //$.weboltgallery.stopSlideshow();
                  return false;
               });

               $pp_sfondo.find('.pp_dettagli_sfondo_nav .pp_dettagli_arrow_next').bind('click', function () {
                  $.weboltgallery.changePageDettagli('next', numerodettagli);
                  //$.weboltgallery.stopSlideshow();
                  return false;
               });

               // $pp_sfondo.find('.pp_dettagli_gallery').show() ;
            }


            // fine getJSON
         });
      }
      function _buildOverlay(caller) {
         // Find out if the picture is part of a set
         theRel = $(caller).attr('rel');

         galleryRegExp = /\[(?:.*)\]/;
         isSet = (galleryRegExp.exec(theRel)) ? true : false;

         pp_galleryname = (isSet) ? jQuery.map(matchedObjects, function (n, i) {

            if ($(n).attr('rel').indexOf(theRel) != -1) {
               return $(n).attr('rev');
            }
         }) : $.makeArray($(caller).attr('rev'));


         pp_idimmagine = (isSet) ? jQuery.map(matchedObjects, function (n, i) {
            if ($(n).attr('rel').indexOf(theRel) != -1) {
               return $(n).find('a.immaginegrande').attr('id');
            }
         }) : $.makeArray($(caller).find('a.immaginegrande').attr('id'));

         // Put the SRCs, TITLEs, ALTs into an array.
         pp_images = (isSet) ? jQuery.map(matchedObjects, function (n, i) {
            if ($(n).attr('rel').indexOf(theRel) != -1) {
               //alert($(n).find('a').attr('href'));
               return $(n).find('a.immaginegrande').attr('src');
            }
         }) : $.makeArray($(caller).find('a.immaginegrande').attr('src'));

         pp_alttext = (isSet) ? jQuery.map(matchedObjects, function (n, i) {
            if ($(n).attr('rel').indexOf(theRel) != -1) {
               // // // // // //alert($(n).find('a').attr('href'));
 return $(n).find('a.immaginegrande').attr('alt');
            }
          }) : $.makearray($(caller).find('a.immaginegrande').attr('alt'));


         pp_miniature = (isSet) ? jQuery.map(matchedObjects, function (n, i) {
            if ($(n).attr('rel').indexOf(theRel) != -1) {
               return $(n).find('div.miniaturagallery').attr('id');
            }
         }) : $.makeArray($(caller).find('div.miniaturagallery').attr('id'));

         // pp_miniature_width = (isSet) ? jQuery.map(matchedObjects, function (n, i) {
            // if ($(n).attr('rel').indexOf(theRel) != -1) {
               // return $(n).find('div.miniaturagallery').attr('width');
            // }
         // }) : $.makeArray($(caller).find('div.miniaturagallery').attr('width'));
		 
		  // pp_miniature_height = (isSet) ? jQuery.map(matchedObjects, function (n, i) {
            // if ($(n).attr('rel').indexOf(theRel) != -1) {
               // return $(n).find('div.miniaturagallery').attr('height');
            // }
         // }) : $.makeArray($(caller).find('div.miniaturagallery').attr('height'));


         pp_titles = (isSet) ? jQuery.map(matchedObjects, function (n, i) {
            if ($(n).attr('rel').indexOf(theRel) != -1)
               return ($(n).attr('title')) ? $(n).attr('title') : "";
         }) : $.makeArray($(caller).attr('title'));



         pp_descriptions = (isSet) ? jQuery.map(matchedObjects, function (n, i) {
            if ($(n).attr('rel').indexOf(theRel) != -1) {
               //return ($(n).attr('title')) ? $(n).attr('title') : "";

               return $.makeArray($(n).find('.descrizione_gallery').html());
            }
         }) : $.makeArray($(caller).find('.descrizione_gallery').html());


         $('div#' + settings.container).append(settings.markup); // Inject the markup
         $pp_sfondo = $('.pp_sfondo'),
         //$pp_pic_holder = $('.pp_pic_holder'),
         //$pp_overlay = $('div.pp_overlay'); // Set my global selectors

         //$pp_sfondo.find('.pp_content_container').after(settings.descrizione_markup);


         $pp_descrizione_gallery = $pp_sfondo.find('.pp_descrizione_gallery');
         $pp_dettagli_gallery = $pp_sfondo.find('.pp_dettagli_gallery');




         // Inject the inline gallery!
         if (isSet && settings.overlay_gallery) {
            currentGalleryPage = 0;
            toInject = "";
            for (var i = 0; i < pp_images.length; i++) {
               var regex = new RegExp("(.*?)\.(jpg|jpeg|png|gif)$");
               var results = regex.exec(pp_images[i]);

               if (!results) {
                  classname = 'default';
               } else {
                  classname = '';
               }

               toInject += "<li class='" + classname + "'><img class='click_miniatura' src='" + pp_miniature[i].substring(5) + "'  alt='' /></li>";

            };


            toInject = settings.gallery_markup.replace(/{gallery}/g, toInject);

            // appendo la gallery dopo le caratteristiche
            $pp_sfondo.find('.container_dati').after(toInject);


            $pp_sfondo.find('.pp_gallery .pp_arrow_next').click(function () {

               $.weboltgallery.changeGalleryPage('next');
               $.weboltgallery.stopSlideshow();
               return false;
            });

            $pp_sfondo.find('.pp_gallery .pp_arrow_previous').click(function () {

               $.weboltgallery.changeGalleryPage('previous');
               $.weboltgallery.stopSlideshow();

               return false;
            });

            // $pp_pic_holder.find('.pp_content').hover(
            // function(){
            // $pp_pic_holder.find('.pp_gallery:not(.disabled)').fadeIn();
            // },
            // function(){
            // $pp_pic_holder.find('.pp_gallery:not(.disabled)').fadeOut();
            // });





            if (settings.tipovista == "orizzontale") {
               itemWidth = settings.itemWidth; // 52 beign the thumb width, 5 being the right margin.
               $pp_sfondo.find('.pp_gallery ul li').each(function (i) {
                  $(this).css({
                     'position': 'absolute',
                     'left': i * itemWidth
                  });



                  $(this).find('img.click_miniatura').unbind('click').click(function () {
                     $.weboltgallery.changePage(i);
                     $.weboltgallery.stopSlideshow();
                     Hover();
                     return false;
                  });
               });
            } else if (settings.tipovista == "verticale") {
               itemHeight = settings.itemHeight; // 52 beign the thumb width, 5 being the right margin.

               $pp_sfondo.find('.pp_gallery ul li').each(function (i) {
                  $(this).css({
                     'position': 'absolute',
                     'top': i * itemHeight
                  });



                  $(this).find('img.click_miniatura').unbind('click').click(function () {
                     $.weboltgallery.changePage(i);
                     $.weboltgallery.stopSlideshow();
                     Hover();
                     return false;
                  });
               });
            }

         };




         // Inject the play/pause if it's a slideshow
         if (settings.slideshow) {
            $pp_sfondo.find('.pp_nav').prepend('<a href="#" class="pp_play">Play</a>')
            $pp_sfondo.find('.pp_nav .pp_play').click(function () {
               $.weboltgallery.startSlideshow();
               return false;
            });
         }
         $pp_sfondo.attr('class', 'pp_sfondo ' + settings.theme);



         //$('a.pp_close').bind('click', function () { $.weboltgallery.close(); return false; });

         $('a.pp_expand').bind('click', function (e) {
            // Expand the image
            if ($(this).hasClass('pp_expand')) {
               $(this).removeClass('pp_expand').addClass('pp_contract');
               doresize = false;
            } else {
               $(this).removeClass('pp_contract').addClass('pp_expand');
               doresize = true;
            };

            _hideContent(function () { $.weboltgallery.open(); });

            return false;
         });

         /* Navigazione dall'immagine grande */

         $pp_sfondo.find('.pp_previous, .pp_nav .pp_arrow_previous').bind('click', function () {
            $.weboltgallery.changePage('previous');
            $.weboltgallery.stopSlideshow();
            return false;
         });

         $pp_sfondo.find('.pp_next, .pp_nav .pp_arrow_next').bind('click', function () {
            $.weboltgallery.changePage('next');
            $.weboltgallery.stopSlideshow();
            return false;
         });

         if (!settings.hoverimage) {
            $pp_sfondo.find(".pp_hoverContainer").remove();
         }


         //_center_overlay(); // Center it
      };

      return this.unbind('click').click($.weboltgallery.initialize); // Return the jQuery object for chaining. The unbind method is used to avoid click conflict when the plugin is called more than once
   };

   function Hover() {


      jQuery(".immaginehover").hover(

function () {

   var ele = jQuery(this);
   var src = (ele).find("img").attr("src");
   var rev = (ele).find("img").attr("rev");

   ele.find("img").attr("src", rev);
   ele.find("img").attr("rev", src);


},
function () {
   var ele = jQuery(this);
   var src = (ele).find("img").attr("src");
   var rev = (ele).find("img").attr("rev");
   ele.find("img").attr("src", rev);
   ele.find("img").attr("rev", src);
});
   }
   function grab_param(name, url) {
      name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
      var regexS = "[\\?&]" + name + "=([^&#]*)";
      var regex = new RegExp(regexS);
      var results = regex.exec(url);
      return (results == null) ? "" : results[1];
   }

})(jQuery);
