/**
 * jQuery Galleriffic plugin
 *
 * Copyright (c) 2008 Trent Foley (http://trentacular.com)
 * Licensed under the MIT License:
 *   http://www.opensource.org/licenses/mit-license.php
 *
 * Much thanks to primary contributer Ponticlaro (http://www.ponticlaro.com)
 */
;(function($) {
  // Globally keep track of all images by their unique hash.  Each item is an image data object.
  var allImages = {};
  var imageCounter = 0;

  // Galleriffic static class
  $.galleriffic = {
    version: '2.0.1',

    // Strips invalid characters and any leading # characters
    normalizeHash: function(hash) {
      return hash.replace(/^.*#/, '').replace(/\?.*$/, '');
    },

    getImage: function(hash) {
      if (!hash)
        return undefined;

      hash = $.galleriffic.normalizeHash(hash);
      return allImages[hash];
    },

    // Global function that looks up an image by its hash and displays the image.
    // Returns false when an image is not found for the specified hash.
    // @param {String} hash This is the unique hash value assigned to an image.
    gotoImage: function(hash) {
      var imageData = $.galleriffic.getImage(hash);
      if (!imageData)
        return false;

      var gallery = imageData.gallery;
      gallery.gotoImage(imageData);
      
      return true;
    },

    // Removes an image from its respective gallery by its hash.
    // Returns false when an image is not found for the specified hash or the
    // specified owner gallery does match the located images gallery.
    // @param {String} hash This is the unique hash value assigned to an image.
    // @param {Object} ownerGallery (Optional) When supplied, the located images
    // gallery is verified to be the same as the specified owning gallery before
    // performing the remove operation.
    removeImageByHash: function(hash, ownerGallery) {
      var imageData = $.galleriffic.getImage(hash);
      if (!imageData)
        return false;

      var gallery = imageData.gallery;
      if (ownerGallery && ownerGallery != gallery)
        return false;

      return gallery.removeImageByIndex(imageData.index);
    }
  };

  var defaults = {
    delay:                     3000,
    numThumbs:                 20,
    preloadAhead:              40, // Set to -1 to preload all images
    enableTopPager:            false,
    enableBottomPager:         true,
    maxPagesToShow:            7,
    imageContainerSel:         '',
    captionContainerSel:       '',
    controlsContainerSel:      '',
    loadingContainerSel:       '',
    renderSSControls:          true,
    renderNavControls:         true,
    playLinkText:              'Play',
    pauseLinkText:             'Pause',
    prevLinkText:              'Previous',
    nextLinkText:              'Next',
    nextPageLinkText:          'Next &rsaquo;',
    prevPageLinkText:          '&lsaquo; Prev',
    enableHistory:             false,
    enableKeyboardNavigation:  true,
    autoStart:                 false,
    syncTransitions:           false,
    defaultTransitionDuration: 1000,
    onSlideChange:             undefined, // accepts a delegate like such: function(prevIndex, nextIndex) { ... }
    onTransitionOut:           undefined, // accepts a delegate like such: function(slide, caption, isSync, callback) { ... }
    onTransitionIn:            undefined, // accepts a delegate like such: function(slide, caption, isSync) { ... }
    onPageTransitionOut:       undefined, // accepts a delegate like such: function(callback) { ... }
    onPageTransitionIn:        undefined, // accepts a delegate like such: function() { ... }
    onImageAdded:              undefined, // accepts a delegate like such: function(imageData, $li) { ... }
    onImageRemoved:            undefined  // accepts a delegate like such: function(imageData, $li) { ... }
  };

  // Primary Galleriffic initialization function that should be called on the thumbnail container.
  $.fn.galleriffic = function(settings) {
    //  Extend Gallery Object
    $.extend(this, {
      // Returns the version of the script
      version: $.galleriffic.version,

      // Current state of the slideshow
      isSlideshowRunning: false,
      slideshowTimeout: undefined,

      // This function is attached to the click event of generated hyperlinks within the gallery
      clickHandler: function(e, link) {
        this.pause();

        if (!this.enableHistory) {
          // The href attribute holds the unique hash for an image
          var hash = $.galleriffic.normalizeHash($(link).attr('href'));
          $.galleriffic.gotoImage(hash);
          e.preventDefault();
        }
      },

      // Appends an image to the end of the set of images.  Argument listItem can be either a jQuery DOM element or arbitrary html.
      // @param listItem Either a jQuery object or a string of html of the list item that is to be added to the gallery.
      appendImage: function(listItem) {
        this.addImage(listItem, false, false);
        return this;
      },

      // Inserts an image into the set of images.  Argument listItem can be either a jQuery DOM element or arbitrary html.
      // @param listItem Either a jQuery object or a string of html of the list item that is to be added to the gallery.
      // @param {Integer} position The index within the gallery where the item shouold be added.
      insertImage: function(listItem, position) {
        this.addImage(listItem, false, true, position);
        return this;
      },

      // Adds an image to the gallery and optionally inserts/appends it to the DOM (thumbExists)
      // @param listItem Either a jQuery object or a string of html of the list item that is to be added to the gallery.
      // @param {Boolean} thumbExists Specifies whether the thumbnail already exists in the DOM or if it needs to be added.
      // @param {Boolean} insert Specifies whether the the image is appended to the end or inserted into the gallery.
      // @param {Integer} position The index within the gallery where the item shouold be added.
      addImage: function(listItem, thumbExists, insert, position) {
        var $li = ( typeof listItem === "string" ) ? $(listItem) : listItem;        
        var $aThumb = $li.find('a.thumb');
        var slideUrl = $aThumb.attr('href');
        var title = $aThumb.attr('title');
        var $caption = $li.find('.caption').remove();
        var hash = $aThumb.attr('name');

        // Increment the image counter
        imageCounter++;

        // Autogenerate a hash value if none is present or if it is a duplicate
        if (!hash || allImages[''+hash]) {
          hash = imageCounter;
        }

        // Set position to end when not specified
        if (!insert)
          position = this.data.length;
        
        var imageData = {
          title:title,
          slideUrl:slideUrl,
          caption:$caption,
          hash:hash,
          gallery:this,
          index:position
        };

        // Add the imageData to this gallery's array of images
        if (insert) {
          this.data.splice(position, 0, imageData);

          // Reset index value on all imageData objects
          this.updateIndices(position);
        }
        else {
          this.data.push(imageData);
        }

        var gallery = this;

        // Add the element to the DOM
        if (!thumbExists) {
          // Update thumbs passing in addition post transition out handler
          this.updateThumbs(function() {
            var $thumbsUl = gallery.find('ul.thumbs');
            if (insert)
              $thumbsUl.children(':eq('+position+')').before($li);
            else
              $thumbsUl.append($li);
            
            if (gallery.onImageAdded)
              gallery.onImageAdded(imageData, $li);
          });
        }

        // Register the image globally
        allImages[''+hash] = imageData;

        // Setup attributes and click handler
        $aThumb.attr('rel', 'history')
          .attr('href', '#'+hash)
          .removeAttr('name')
          .click(function(e) {
            gallery.clickHandler(e, this);
          });

        return this;
      },

      // Removes an image from the gallery based on its index.
      // Returns false when the index is out of range.
      removeImageByIndex: function(index) {
        if (index < 0 || index >= this.data.length)
          return false;
        
        var imageData = this.data[index];
        if (!imageData)
          return false;
        
        this.removeImage(imageData);
        
        return true;
      },

      // Convenience method that simply calls the global removeImageByHash method.
      removeImageByHash: function(hash) {
        return $.galleriffic.removeImageByHash(hash, this);
      },

      // Removes an image from the gallery.
      removeImage: function(imageData) {
        var index = imageData.index;
        
        // Remove the image from the gallery data array
        this.data.splice(index, 1);
        
        // Remove the global registration
        delete allImages[''+imageData.hash];
        
        // Remove the image's list item from the DOM
        this.updateThumbs(function() {
          var $li = gallery.find('ul.thumbs')
            .children(':eq('+index+')')
            .remove();

          if (gallery.onImageRemoved)
            gallery.onImageRemoved(imageData, $li);
        });

        // Update each image objects index value
        this.updateIndices(index);

        return this;
      },

      // Updates the index values of the each of the images in the gallery after the specified index
      updateIndices: function(startIndex) {
        for (i = startIndex; i < this.data.length; i++) {
          this.data[i].index = i;
        }
        
        return this;
      },

      // Scraped the thumbnail container for thumbs and adds each to the gallery
      initializeThumbs: function() {
        this.data = [];
        var gallery = this;

        this.find('ul.thumbs > li').each(function(i) {
          gallery.addImage($(this), true, false);
        });

        return this;
      },

      isPreloadComplete: false,

      // Initalizes the image preloader
      preloadInit: function() {
        if (this.preloadAhead == 0) return this;
        
        this.preloadStartIndex = this.currentImage.index;
        var nextIndex = this.getNextIndex(this.preloadStartIndex);
        return this.preloadRecursive(this.preloadStartIndex, nextIndex);
      },

      // Changes the location in the gallery the preloader should work
      // @param {Integer} index The index of the image where the preloader should restart at.
      preloadRelocate: function(index) {
        // By changing this startIndex, the current preload script will restart
        this.preloadStartIndex = index;
        return this;
      },

      // Recursive function that performs the image preloading
      // @param {Integer} startIndex The index of the first image the current preloader started on.
      // @param {Integer} currentIndex The index of the current image to preload.
      preloadRecursive: function(startIndex, currentIndex) {
        // Check if startIndex has been relocated
        if (startIndex != this.preloadStartIndex) {
          var nextIndex = this.getNextIndex(this.preloadStartIndex);
          return this.preloadRecursive(this.preloadStartIndex, nextIndex);
        }

        var gallery = this;

        // Now check for preloadAhead count
        var preloadCount = currentIndex - startIndex;
        if (preloadCount < 0)
          preloadCount = this.data.length-1-startIndex+currentIndex;
        if (this.preloadAhead >= 0 && preloadCount > this.preloadAhead) {
          // Do this in order to keep checking for relocated start index
          setTimeout(function() { gallery.preloadRecursive(startIndex, currentIndex); }, 500);
          return this;
        }

        var imageData = this.data[currentIndex];
        if (!imageData)
          return this;

        // If already loaded, continue
        if (imageData.image)
          return this.preloadNext(startIndex, currentIndex); 
        
        // Preload the image
        var image = new Image();
        
        image.onload = function() {
          imageData.image = this;
          gallery.preloadNext(startIndex, currentIndex);
        };

        image.alt = imageData.title;
        image.src = imageData.slideUrl;

        return this;
      },
      
      // Called by preloadRecursive in order to preload the next image after the previous has loaded.
      // @param {Integer} startIndex The index of the first image the current preloader started on.
      // @param {Integer} currentIndex The index of the current image to preload.
      preloadNext: function(startIndex, currentIndex) {
        var nextIndex = this.getNextIndex(currentIndex);
        if (nextIndex == startIndex) {
          this.isPreloadComplete = true;
        } else {
          // Use setTimeout to free up thread
          var gallery = this;
          setTimeout(function() { gallery.preloadRecursive(startIndex, nextIndex); }, 100);
        }

        return this;
      },

      // Safe way to get the next image index relative to the current image.
      // If the current image is the last, returns 0
      getNextIndex: function(index) {
        var nextIndex = index+1;
        if (nextIndex >= this.data.length)
          nextIndex = 0;
        return nextIndex;
      },

      // Safe way to get the previous image index relative to the current image.
      // If the current image is the first, return the index of the last image in the gallery.
      getPrevIndex: function(index) {
        var prevIndex = index-1;
        if (prevIndex < 0)
          prevIndex = this.data.length-1;
        return prevIndex;
      },

      // Pauses the slideshow
      pause: function() {
        this.isSlideshowRunning = false;
        if (this.slideshowTimeout) {
          clearTimeout(this.slideshowTimeout);
          this.slideshowTimeout = undefined;
        }

        if (this.$controlsContainer) {
          this.$controlsContainer
            .find('div.ss-controls a').removeClass().addClass('play')
            .attr('title', this.playLinkText)
            .attr('href', '#play')
            .html(this.playLinkText);
        }
        
        return this;
      },

      // Plays the slideshow
      play: function() {
        this.isSlideshowRunning = true;

        if (this.$controlsContainer) {
          this.$controlsContainer
            .find('div.ss-controls a').removeClass().addClass('pause')
            .attr('title', this.pauseLinkText)
            .attr('href', '#pause')
            .html(this.pauseLinkText);
        }

        if (!this.slideshowTimeout) {
          var gallery = this;
          this.slideshowTimeout = setTimeout(function() { gallery.ssAdvance(); }, this.delay);
        }

        return this;
      },

      // Toggles the state of the slideshow (playing/paused)
      toggleSlideshow: function() {
        if (this.isSlideshowRunning)
          this.pause();
        else
          this.play();

        return this;
      },

      // Advances the slideshow to the next image and delegates navigation to the
      // history plugin when history is enabled
      // enableHistory is true
      ssAdvance: function() {
        if (this.isSlideshowRunning)
          this.next(true);

        return this;
      },

      // Advances the gallery to the next image.
      // @param {Boolean} dontPause Specifies whether to pause the slideshow.
      // @param {Boolean} bypassHistory Specifies whether to delegate navigation to the history plugin when history is enabled.  
      next: function(dontPause, bypassHistory) {
        this.gotoIndex(this.getNextIndex(this.currentImage.index), dontPause, bypassHistory);
        return this;
      },

      // Navigates to the previous image in the gallery.
      // @param {Boolean} dontPause Specifies whether to pause the slideshow.
      // @param {Boolean} bypassHistory Specifies whether to delegate navigation to the history plugin when history is enabled.
      previous: function(dontPause, bypassHistory) {
        this.gotoIndex(this.getPrevIndex(this.currentImage.index), dontPause, bypassHistory);
        return this;
      },

      // Navigates to the next page in the gallery.
      // @param {Boolean} dontPause Specifies whether to pause the slideshow.
      // @param {Boolean} bypassHistory Specifies whether to delegate navigation to the history plugin when history is enabled.
      nextPage: function(dontPause, bypassHistory) {
        var page = this.getCurrentPage();
        var lastPage = this.getNumPages() - 1;
        if (page < lastPage) {
          var startIndex = page * this.numThumbs;
          var nextPage = startIndex + this.numThumbs;
          this.gotoIndex(nextPage, dontPause, bypassHistory);
        }

        return this;
      },

      // Navigates to the previous page in the gallery.
      // @param {Boolean} dontPause Specifies whether to pause the slideshow.
      // @param {Boolean} bypassHistory Specifies whether to delegate navigation to the history plugin when history is enabled.
      previousPage: function(dontPause, bypassHistory) {
        var page = this.getCurrentPage();
        if (page > 0) {
          var startIndex = page * this.numThumbs;
          var prevPage = startIndex - this.numThumbs;        
          this.gotoIndex(prevPage, dontPause, bypassHistory);
        }
        
        return this;
      },

      // Navigates to the image at the specified index in the gallery
      // @param {Integer} index The index of the image in the gallery to display.
      // @param {Boolean} dontPause Specifies whether to pause the slideshow.
      // @param {Boolean} bypassHistory Specifies whether to delegate navigation to the history plugin when history is enabled.
      gotoIndex: function(index, dontPause, bypassHistory) {
        if (!dontPause)
          this.pause();
        
        if (index < 0) index = 0;
        else if (index >= this.data.length) index = this.data.length-1;
        
        var imageData = this.data[index];
        
        if (!bypassHistory && this.enableHistory)
          $.historyLoad(String(imageData.hash));  // At the moment, historyLoad only accepts string arguments
        else
          this.gotoImage(imageData);

        return this;
      },

      // This function is garaunteed to be called anytime a gallery slide changes.
      // @param {Object} imageData An object holding the image metadata of the image to navigate to.
      gotoImage: function(imageData) {
        var index = imageData.index;

        if (this.onSlideChange)
          this.onSlideChange(this.currentImage.index, index);
        
        this.currentImage = imageData;
        this.preloadRelocate(index);
        
        this.refresh();
        
        return this;
      },

      // Returns the default transition duration value.  The value is halved when not
      // performing a synchronized transition.
      // @param {Boolean} isSync Specifies whether the transitions are synchronized.
      getDefaultTransitionDuration: function(isSync) {
        if (isSync)
          return this.defaultTransitionDuration;
        return this.defaultTransitionDuration / 2;
      },

      // Rebuilds the slideshow image and controls and performs transitions
      refresh: function() {
        var imageData = this.currentImage;
        if (!imageData)
          return this;

        var index = imageData.index;

        // Update Controls
        if (this.$controlsContainer) {
          this.$controlsContainer
            .find('div.nav-controls a.prev').attr('href', '#'+this.data[this.getPrevIndex(index)].hash).end()
            .find('div.nav-controls a.next').attr('href', '#'+this.data[this.getNextIndex(index)].hash);
        }

        var previousSlide = this.$imageContainer.find('span.current').addClass('previous').removeClass('current');
        var previousCaption = 0;

        if (this.$captionContainer) {
          previousCaption = this.$captionContainer.find('span.current').addClass('previous').removeClass('current');
        }

        // Perform transitions simultaneously if syncTransitions is true and the next image is already preloaded
        var isSync = this.syncTransitions && imageData.image;

        // Flag we are transitioning
        var isTransitioning = true;
        var gallery = this;

        var transitionOutCallback = function() {
          // Flag that the transition has completed
          isTransitioning = false;

          // Remove the old slide
          previousSlide.remove();

          // Remove old caption
          if (previousCaption)
            previousCaption.remove();

          if (!isSync) {
            if (imageData.image && imageData.hash == gallery.data[gallery.currentImage.index].hash) {
              gallery.buildImage(imageData, isSync);
            } else {
              // Show loading container
              if (gallery.$loadingContainer) {
                gallery.$loadingContainer.show();
              }
            }
          }
        };

        if (previousSlide.length == 0) {
          // For the first slide, the previous slide will be empty, so we will call the callback immediately
          transitionOutCallback();
        } else {
          if (this.onTransitionOut) {
            this.onTransitionOut(previousSlide, previousCaption, isSync, transitionOutCallback);
          } else {
            previousSlide.fadeTo(this.getDefaultTransitionDuration(isSync), 0.0, transitionOutCallback);
            if (previousCaption)
              previousCaption.fadeTo(this.getDefaultTransitionDuration(isSync), 0.0);
          }
        }

        // Go ahead and begin transitioning in of next image
        if (isSync)
          this.buildImage(imageData, isSync);

        if (!imageData.image) {
          var image = new Image();
          
          // Wire up mainImage onload event
          image.onload = function() {
            imageData.image = this;

            // Only build image if the out transition has completed and we are still on the same image hash
            if (!isTransitioning && imageData.hash == gallery.data[gallery.currentImage.index].hash) {
              gallery.buildImage(imageData, isSync);
            }
          };

          // set alt and src
          image.alt = imageData.title;
          image.src = imageData.slideUrl;
        }

        // This causes the preloader (if still running) to relocate out from the currentIndex
        this.relocatePreload = true;

        return this.syncThumbs();
      },

      // Called by the refresh method after the previous image has been transitioned out or at the same time
      // as the out transition when performing a synchronous transition.
      // @param {Object} imageData An object holding the image metadata of the image to build.
      // @param {Boolean} isSync Specifies whether the transitions are synchronized.
      buildImage: function(imageData, isSync) {
        var gallery = this;
        var nextIndex = this.getNextIndex(imageData.index);

        // Construct new hidden span for the image
        var newSlide = this.$imageContainer
          .append('<span class="image-wrapper current"><a class="advance-link" rel="history" href="#'+this.data[nextIndex].hash+'" title="'+imageData.title+'"></a></span>')
          .find('span.current').css('opacity', '0');
        
        newSlide.find('a')
          .append(imageData.image)
          .click(function(e) {
            gallery.clickHandler(e, this);
          });
        
        var newCaption = 0;
        if (this.$captionContainer) {
          // Construct new hidden caption for the image
          newCaption = this.$captionContainer
            .append('<span class="image-caption current"></span>')
            .find('span.current').css('opacity', '0')
            .append(imageData.caption);
        }

        // Hide the loading conatiner
        if (this.$loadingContainer) {
          this.$loadingContainer.hide();
        }

        // Transition in the new image
        if (this.onTransitionIn) {
          this.onTransitionIn(newSlide, newCaption, isSync);
        } else {
          newSlide.fadeTo(this.getDefaultTransitionDuration(isSync), 1.0);
          if (newCaption)
            newCaption.fadeTo(this.getDefaultTransitionDuration(isSync), 1.0);
        }
        
        if (this.isSlideshowRunning) {
          if (this.slideshowTimeout)
            clearTimeout(this.slideshowTimeout);

          this.slideshowTimeout = setTimeout(function() { gallery.ssAdvance(); }, this.delay);
        }

        return this;
      },

      // Returns the current page index that should be shown for the currentImage
      getCurrentPage: function() {
        return Math.floor(this.currentImage.index / this.numThumbs);
      },

      // Applies the selected class to the current image's corresponding thumbnail.
      // Also checks if the current page has changed and updates the displayed page of thumbnails if necessary.
      syncThumbs: function() {
        var page = this.getCurrentPage();
        if (page != this.displayedPage)
          this.updateThumbs();

        // Remove existing selected class and add selected class to new thumb
        var $thumbs = this.find('ul.thumbs').children();
        $thumbs.filter('.selected').removeClass('selected');
        $thumbs.eq(this.currentImage.index).addClass('selected');

        return this;
      },

      // Performs transitions on the thumbnails container and updates the set of
      // thumbnails that are to be displayed and the navigation controls.
      // @param {Delegate} postTransitionOutHandler An optional delegate that is called after
      // the thumbnails container has transitioned out and before the thumbnails are rebuilt.
      updateThumbs: function(postTransitionOutHandler) {
        var gallery = this;
        var transitionOutCallback = function() {
          // Call the Post-transition Out Handler
          if (postTransitionOutHandler)
            postTransitionOutHandler();
          
          gallery.rebuildThumbs();

          // Transition In the thumbsContainer
          if (gallery.onPageTransitionIn)
            gallery.onPageTransitionIn();
          else
            gallery.show();
        };

        // Transition Out the thumbsContainer
        if (this.onPageTransitionOut) {
          this.onPageTransitionOut(transitionOutCallback);
        } else {
          this.hide();
          transitionOutCallback();
        }

        return this;
      },

      // Updates the set of thumbnails that are to be displayed and the navigation controls.
      rebuildThumbs: function() {
        var needsPagination = this.data.length > this.numThumbs;

        // Rebuild top pager
        if (this.enableTopPager) {
          var $topPager = this.find('div.top');
          if ($topPager.length == 0)
            $topPager = this.prepend('<div class="top pagination"></div>').find('div.top');
          else
            $topPager.empty();

          if (needsPagination)
            this.buildPager($topPager);
        }

        // Rebuild bottom pager
        if (this.enableBottomPager) {
          var $bottomPager = this.find('div.bottom');
          if ($bottomPager.length == 0)
            $bottomPager = this.append('<div class="bottom pagination"></div>').find('div.bottom');
          else
            $bottomPager.empty();

          if (needsPagination)
            this.buildPager($bottomPager);
        }

        var page = this.getCurrentPage();
        var startIndex = page*this.numThumbs;
        var stopIndex = startIndex+this.numThumbs-1;
        if (stopIndex >= this.data.length)
          stopIndex = this.data.length-1;

        // Show/Hide thumbs
        var $thumbsUl = this.find('ul.thumbs');
        $thumbsUl.find('li').each(function(i) {
          var $li = $(this);
          if (i >= startIndex && i <= stopIndex) {
            $li.show();
          } else {
            $li.hide();
          }
        });

        this.displayedPage = page;

        // Remove the noscript class from the thumbs container ul
        $thumbsUl.removeClass('noscript');
        
        return this;
      },

      // Returns the total number of pages required to display all the thumbnails.
      getNumPages: function() {
        return Math.ceil(this.data.length/this.numThumbs);
      },

      // Rebuilds the pager control in the specified matched element.
      // @param {jQuery} pager A jQuery element set matching the particular pager to be rebuilt.
      buildPager: function(pager) {
        var gallery = this;
        var numPages = this.getNumPages();
        var page = this.getCurrentPage();
        var startIndex = page * this.numThumbs;
        var pagesRemaining = this.maxPagesToShow - 1;
        
        var pageNum = page - Math.floor((this.maxPagesToShow - 1) / 2) + 1;
        if (pageNum > 0) {
          var remainingPageCount = numPages - pageNum;
          if (remainingPageCount < pagesRemaining) {
            pageNum = pageNum - (pagesRemaining - remainingPageCount);
          }
        }

        if (pageNum < 0) {
          pageNum = 0;
        }

        // Prev Page Link
        if (page > 0) {
          var prevPage = startIndex - this.numThumbs;
          pager.append('<a rel="history" href="#'+this.data[prevPage].hash+'" title="'+this.prevPageLinkText+'">'+this.prevPageLinkText+'</a>');
        }

        // Create First Page link if needed
        if (pageNum > 0) {
          this.buildPageLink(pager, 0, numPages);
          if (pageNum > 1)
            pager.append('<span class="ellipsis">&hellip;</span>');
          
          pagesRemaining--;
        }

        // Page Index Links
        while (pagesRemaining > 0) {
          this.buildPageLink(pager, pageNum, numPages);
          pagesRemaining--;
          pageNum++;
        }

        // Create Last Page link if needed
        if (pageNum < numPages) {
          var lastPageNum = numPages - 1;
          if (pageNum < lastPageNum)
            pager.append('<span class="ellipsis">&hellip;</span>');

          this.buildPageLink(pager, lastPageNum, numPages);
        }

        // Next Page Link
        var nextPage = startIndex + this.numThumbs;
        if (nextPage < this.data.length) {
          pager.append('<a rel="history" href="#'+this.data[nextPage].hash+'" title="'+this.nextPageLinkText+'">'+this.nextPageLinkText+'</a>');
        }

        pager.find('a').click(function(e) {
          gallery.clickHandler(e, this);
        });

        return this;
      },

      // Builds a single page link within a pager.  This function is called by buildPager
      // @param {jQuery} pager A jQuery element set matching the particular pager to be rebuilt.
      // @param {Integer} pageNum The page number of the page link to build.
      // @param {Integer} numPages The total number of pages required to display all thumbnails.
      buildPageLink: function(pager, pageNum, numPages) {
        var pageLabel = pageNum + 1;
        var currentPage = this.getCurrentPage();
        if (pageNum == currentPage)
          pager.append('<span class="current">'+pageLabel+'</span>');
        else if (pageNum < numPages) {
          var imageIndex = pageNum*this.numThumbs;
          pager.append('<a rel="history" href="#'+this.data[imageIndex].hash+'" title="'+pageLabel+'">'+pageLabel+'</a>');
        }
        
        return this;
      }
    });

    // Now initialize the gallery
    $.extend(this, defaults, settings);
    
    // Verify the history plugin is available
    if (this.enableHistory && !$.historyInit)
      this.enableHistory = false;
    
    // Select containers
    if (this.imageContainerSel) this.$imageContainer = $(this.imageContainerSel);
    if (this.captionContainerSel) this.$captionContainer = $(this.captionContainerSel);
    if (this.loadingContainerSel) this.$loadingContainer = $(this.loadingContainerSel);

    // Initialize the thumbails
    this.initializeThumbs();
    
    if (this.maxPagesToShow < 3)
      this.maxPagesToShow = 3;

    this.displayedPage = -1;
    this.currentImage = this.data[0];
    var gallery = this;

    // Hide the loadingContainer
    if (this.$loadingContainer)
      this.$loadingContainer.hide();

    // Setup controls
    if (this.controlsContainerSel) {
      this.$controlsContainer = $(this.controlsContainerSel).empty();
      
      if (this.renderSSControls) {
        if (this.autoStart) {
          this.$controlsContainer
            .append('<div class="ss-controls"><a href="#pause" class="pause" title="'+this.pauseLinkText+'">'+this.pauseLinkText+'</a></div>');
        } else {
          this.$controlsContainer
            .append('<div class="ss-controls"><a href="#play" class="play" title="'+this.playLinkText+'">'+this.playLinkText+'</a></div>');
        }

        this.$controlsContainer.find('div.ss-controls a')
          .click(function(e) {
            gallery.toggleSlideshow();
            e.preventDefault();
            return false;
          });
      }
    
      if (this.renderNavControls) {
        this.$controlsContainer
          .append('<div class="nav-controls"><a class="prev" rel="history" title="'+this.prevLinkText+'">'+this.prevLinkText+'</a><a class="next" rel="history" title="'+this.nextLinkText+'">'+this.nextLinkText+'</a></div>')
          .find('div.nav-controls a')
          .click(function(e) {
            gallery.clickHandler(e, this);
          });
      }
    }

    var initFirstImage = !this.enableHistory || !location.hash;
    if (this.enableHistory && location.hash) {
      var hash = $.galleriffic.normalizeHash(location.hash);
      var imageData = allImages[hash];
      if (!imageData)
        initFirstImage = true;
    }

    // Setup gallery to show the first image
    if (initFirstImage)
      this.gotoIndex(0, false, true);

    // Setup Keyboard Navigation
    if (this.enableKeyboardNavigation) {
      $(document).keydown(function(e) {
        var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
        switch(key) {
          case 32: // space
            gallery.next();
            e.preventDefault();
            break;
          case 33: // Page Up
            gallery.previousPage();
            e.preventDefault();
            break;
          case 34: // Page Down
            gallery.nextPage();
            e.preventDefault();
            break;
          case 35: // End
            gallery.gotoIndex(gallery.data.length-1);
            e.preventDefault();
            break;
          case 36: // Home
            gallery.gotoIndex(0);
            e.preventDefault();
            break;
          case 37: // left arrow
            gallery.previous();
            e.preventDefault();
            break;
          case 39: // right arrow
            gallery.next();
            e.preventDefault();
            break;
        }
      });
    }

    // Auto start the slideshow
    if (this.autoStart)
      this.play();

    // Kickoff Image Preloader after 1 second
    setTimeout(function() { gallery.preloadInit(); }, 1000);

    return this;
  };
})(jQuery);



/*
 * jQuery history plugin
 * 
 * sample page: http://www.mikage.to/jquery/jquery_history.html
 *
 * Copyright (c) 2006-2009 Taku Sano (Mikage Sawatari)
 * Licensed under the MIT License:
 *   http://www.opensource.org/licenses/mit-license.php
 *
 * Modified by Lincoln Cooper to add Safari support and only call the callback once during initialization
 * for msie when no initial hash supplied.
 */


jQuery.extend({
  historyCurrentHash: undefined,
  historyCallback: undefined,
  historyIframeSrc: undefined,
  
  historyInit: function(callback, src){
    jQuery.historyCallback = callback;
    if (src) jQuery.historyIframeSrc = src;
    var current_hash = location.hash.replace(/\?.*$/, '');
    
    jQuery.historyCurrentHash = current_hash;
    // if ((jQuery.browser.msie) && (jQuery.browser.version < 8)) {
    if (jQuery.browser.msie) {
      // To stop the callback firing twice during initilization if no hash present
      if (jQuery.historyCurrentHash == '') {
      jQuery.historyCurrentHash = '#';
    }
    
      // add hidden iframe for IE
      jQuery("body").prepend('<iframe id="jQuery_history" style="display: none;"'+
        (jQuery.historyIframeSrc ? ' src="'+jQuery.historyIframeSrc+'"' : '')
        +'></iframe>'
      );
      var ihistory = jQuery("#jQuery_history")[0];
      var iframe = ihistory.contentWindow.document;
      iframe.open();
      iframe.close();
      iframe.location.hash = current_hash;
    }
    else if (jQuery.browser.safari) {
      // etablish back/forward stacks
      jQuery.historyBackStack = [];
      jQuery.historyBackStack.length = history.length;
      jQuery.historyForwardStack = [];
      jQuery.lastHistoryLength = history.length;
      
      jQuery.isFirst = true;
    }
    if(current_hash)
      jQuery.historyCallback(current_hash.replace(/^#/, ''));
    setInterval(jQuery.historyCheck, 100);
  },
  
  historyAddHistory: function(hash) {
    // This makes the looping function do something
    jQuery.historyBackStack.push(hash);
    
    jQuery.historyForwardStack.length = 0; // clear forwardStack (true click occured)
    this.isFirst = true;
  },
  
  historyCheck: function(){
    // if ((jQuery.browser.msie) && (jQuery.browser.version < 8)) {
    if (jQuery.browser.msie) {
      // On IE, check for location.hash of iframe
      var ihistory = jQuery("#jQuery_history")[0];
      var iframe = ihistory.contentDocument || ihistory.contentWindow.document;
      var current_hash = iframe.location.hash.replace(/\?.*$/, '');
      if(current_hash != jQuery.historyCurrentHash) {
      
        location.hash = current_hash;
        jQuery.historyCurrentHash = current_hash;
        jQuery.historyCallback(current_hash.replace(/^#/, ''));
        
      }
    } else if (jQuery.browser.safari) {
      if(jQuery.lastHistoryLength == history.length && jQuery.historyBackStack.length > jQuery.lastHistoryLength) {
        jQuery.historyBackStack.shift();
      }
      if (!jQuery.dontCheck) {
        var historyDelta = history.length - jQuery.historyBackStack.length;
        jQuery.lastHistoryLength = history.length;
        
        if (historyDelta) { // back or forward button has been pushed
          jQuery.isFirst = false;
          if (historyDelta < 0) { // back button has been pushed
            // move items to forward stack
            for (var i = 0; i < Math.abs(historyDelta); i++) jQuery.historyForwardStack.unshift(jQuery.historyBackStack.pop());
          } else { // forward button has been pushed
            // move items to back stack
            for (var i = 0; i < historyDelta; i++) jQuery.historyBackStack.push(jQuery.historyForwardStack.shift());
          }
          var cachedHash = jQuery.historyBackStack[jQuery.historyBackStack.length - 1];
          if (cachedHash != undefined) {
            jQuery.historyCurrentHash = location.hash.replace(/\?.*$/, '');
            jQuery.historyCallback(cachedHash);
          }
        } else if (jQuery.historyBackStack[jQuery.historyBackStack.length - 1] == undefined && !jQuery.isFirst) {
          // back button has been pushed to beginning and URL already pointed to hash (e.g. a bookmark)
          // document.URL doesn't change in Safari
          if (location.hash) {
            var current_hash = location.hash;
            jQuery.historyCallback(location.hash.replace(/^#/, ''));
          } else {
            var current_hash = '';
            jQuery.historyCallback('');
          }
          jQuery.isFirst = true;
        }
      }
    } else {
      // otherwise, check for location.hash
      var current_hash = location.hash.replace(/\?.*$/, '');
      if(current_hash != jQuery.historyCurrentHash) {
        jQuery.historyCurrentHash = current_hash;
        jQuery.historyCallback(current_hash.replace(/^#/, ''));
      }
    }
  },
  historyLoad: function(hash){
    var newhash;
    hash = decodeURIComponent(hash.replace(/\?.*$/, ''));
    
    if (jQuery.browser.safari) {
      newhash = hash;
    }
    else {
      newhash = '#' + hash;
      location.hash = newhash;
    }
    jQuery.historyCurrentHash = newhash;
    
    // if ((jQuery.browser.msie) && (jQuery.browser.version < 8)) {
    if (jQuery.browser.msie) {
      var ihistory = jQuery("#jQuery_history")[0];
      var iframe = ihistory.contentWindow.document;
      iframe.open();
      iframe.close();
      iframe.location.hash = newhash;
      jQuery.lastHistoryLength = history.length;
      jQuery.historyCallback(hash);
    }
    else if (jQuery.browser.safari) {
      jQuery.dontCheck = true;
      // Manually keep track of the history values for Safari
      this.historyAddHistory(hash);
      
      // Wait a while before allowing checking so that Safari has time to update the "history" object
      // correctly (otherwise the check loop would detect a false change in hash).
      var fn = function() {jQuery.dontCheck = false;};
      window.setTimeout(fn, 200);
      jQuery.historyCallback(hash);
      // N.B. "location.hash=" must be the last line of code for Safari as execution stops afterwards.
      //      By explicitly using the "location.hash" command (instead of using a variable set to "location.hash") the
      //      URL in the browser and the "history" object are both updated correctly.
      location.hash = newhash;
    }
    else {
      jQuery.historyCallback(hash);
    }
  }
});




/**
 * jQuery Opacity Rollover plugin
 *
 * Copyright (c) 2009 Trent Foley (http://trentacular.com)
 * Licensed under the MIT License:
 *   http://www.opensource.org/licenses/mit-license.php
 */
;(function($) {
  var defaults = {
    mouseOutOpacity:   0.67,
    mouseOverOpacity:  1.0,
    fadeSpeed:         'fast',
    exemptionSelector: '.selected'
  };

  $.fn.opacityrollover = function(settings) {
    // Initialize the effect
    $.extend(this, defaults, settings);

    var config = this;

    function fadeTo(element, opacity) {
      var $target = $(element);
      
      if (config.exemptionSelector)
        $target = $target.not(config.exemptionSelector);  
      
      $target.fadeTo(config.fadeSpeed, opacity);
    }

    this.css('opacity', this.mouseOutOpacity)
      .hover(
        function () {
          fadeTo(this, config.mouseOverOpacity);
        },
        function () {
          fadeTo(this, config.mouseOutOpacity);
        });

    return this;
  };
})(jQuery);




// ColorBox v1.3.19 - jQuery lightbox plugin
// (c) 2011 Jack Moore - jacklmoore.com
// License: http://www.opensource.org/licenses/mit-license.php
(function(a,b,c){function Z(c,d,e){var g=b.createElement(c);return d&&(g.id=f+d),e&&(g.style.cssText=e),a(g)}function $(a){var b=y.length,c=(Q+a)%b;return c<0?b+c:c}function _(a,b){return Math.round((/%/.test(a)?(b==="x"?z.width():z.height())/100:1)*parseInt(a,10))}function ba(a){return K.photo||/\.(gif|png|jpe?g|bmp|ico)((#|\?).*)?$/i.test(a)}function bb(){var b;K=a.extend({},a.data(P,e));for(b in K)a.isFunction(K[b])&&b.slice(0,2)!=="on"&&(K[b]=K[b].call(P));K.rel=K.rel||P.rel||"nofollow",K.href=K.href||a(P).attr("href"),K.title=K.title||P.title,typeof K.href=="string"&&(K.href=a.trim(K.href))}function bc(b,c){a.event.trigger(b),c&&c.call(P)}function bd(){var a,b=f+"Slideshow_",c="click."+f,d,e,g;K.slideshow&&y[1]?(d=function(){F.text(K.slideshowStop).unbind(c).bind(j,function(){if(K.loop||y[Q+1])a=setTimeout(W.next,K.slideshowSpeed)}).bind(i,function(){clearTimeout(a)}).one(c+" "+k,e),r.removeClass(b+"off").addClass(b+"on"),a=setTimeout(W.next,K.slideshowSpeed)},e=function(){clearTimeout(a),F.text(K.slideshowStart).unbind([j,i,k,c].join(" ")).one(c,function(){W.next(),d()}),r.removeClass(b+"on").addClass(b+"off")},K.slideshowAuto?d():e()):r.removeClass(b+"off "+b+"on")}function be(b){U||(P=b,bb(),y=a(P),Q=0,K.rel!=="nofollow"&&(y=a("."+g).filter(function(){var b=a.data(this,e).rel||this.rel;return b===K.rel}),Q=y.index(P),Q===-1&&(y=y.add(P),Q=y.length-1)),S||(S=T=!0,r.show(),K.returnFocus&&a(P).blur().one(l,function(){a(this).focus()}),q.css({opacity:+K.opacity,cursor:K.overlayClose?"pointer":"auto"}).show(),K.w=_(K.initialWidth,"x"),K.h=_(K.initialHeight,"y"),W.position(),o&&z.bind("resize."+p+" scroll."+p,function(){q.css({width:z.width(),height:z.height(),top:z.scrollTop(),left:z.scrollLeft()})}).trigger("resize."+p),bc(h,K.onOpen),J.add(D).hide(),I.html(K.close).show()),W.load(!0))}function bf(){!r&&b.body&&(Y=!1,z=a(c),r=Z(X).attr({id:e,"class":n?f+(o?"IE6":"IE"):""}).hide(),q=Z(X,"Overlay",o?"position:absolute":"").hide(),s=Z(X,"Wrapper"),t=Z(X,"Content").append(A=Z(X,"LoadedContent","width:0; height:0; overflow:hidden"),C=Z(X,"LoadingOverlay").add(Z(X,"LoadingGraphic")),D=Z(X,"Title"),E=Z(X,"Current"),G=Z(X,"Next"),H=Z(X,"Previous"),F=Z(X,"Slideshow").bind(h,bd),I=Z(X,"Close")),s.append(Z(X).append(Z(X,"TopLeft"),u=Z(X,"TopCenter"),Z(X,"TopRight")),Z(X,!1,"clear:left").append(v=Z(X,"MiddleLeft"),t,w=Z(X,"MiddleRight")),Z(X,!1,"clear:left").append(Z(X,"BottomLeft"),x=Z(X,"BottomCenter"),Z(X,"BottomRight"))).find("div div").css({"float":"left"}),B=Z(X,!1,"position:absolute; width:9999px; visibility:hidden; display:none"),J=G.add(H).add(E).add(F),a(b.body).append(q,r.append(s,B)))}function bg(){return r?(Y||(Y=!0,L=u.height()+x.height()+t.outerHeight(!0)-t.height(),M=v.width()+w.width()+t.outerWidth(!0)-t.width(),N=A.outerHeight(!0),O=A.outerWidth(!0),r.css({"padding-bottom":L,"padding-right":M}),G.click(function(){W.next()}),H.click(function(){W.prev()}),I.click(function(){W.close()}),q.click(function(){K.overlayClose&&W.close()}),a(b).bind("keydown."+f,function(a){var b=a.keyCode;S&&K.escKey&&b===27&&(a.preventDefault(),W.close()),S&&K.arrowKey&&y[1]&&(b===37?(a.preventDefault(),H.click()):b===39&&(a.preventDefault(),G.click()))}),a("."+g,b).live("click",function(a){a.which>1||a.shiftKey||a.altKey||a.metaKey||(a.preventDefault(),be(this))})),!0):!1}var d={transition:"elastic",speed:300,width:!1,initialWidth:"600",innerWidth:!1,maxWidth:!1,height:!1,initialHeight:"450",innerHeight:!1,maxHeight:!1,scalePhotos:!0,scrolling:!0,inline:!1,html:!1,iframe:!1,fastIframe:!0,photo:!1,href:!1,title:!1,rel:!1,opacity:.9,preloading:!0,current:"image {current} of {total}",previous:"previous",next:"next",close:"close",open:!1,returnFocus:!0,reposition:!0,loop:!0,slideshow:!1,slideshowAuto:!0,slideshowSpeed:2500,slideshowStart:"start slideshow",slideshowStop:"stop slideshow",onOpen:!1,onLoad:!1,onComplete:!1,onCleanup:!1,onClosed:!1,overlayClose:!0,escKey:!0,arrowKey:!0,top:!1,bottom:!1,left:!1,right:!1,fixed:!1,data:undefined},e="colorbox",f="cbox",g=f+"Element",h=f+"_open",i=f+"_load",j=f+"_complete",k=f+"_cleanup",l=f+"_closed",m=f+"_purge",n=!a.support.opacity&&!a.support.style,o=n&&!c.XMLHttpRequest,p=f+"_IE6",q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X="div",Y;if(a.colorbox)return;a(bf),W=a.fn[e]=a[e]=function(b,c){var f=this;b=b||{},bf();if(bg()){if(!f[0]){if(f.selector)return f;f=a("<a/>"),b.open=!0}c&&(b.onComplete=c),f.each(function(){a.data(this,e,a.extend({},a.data(this,e)||d,b))}).addClass(g),(a.isFunction(b.open)&&b.open.call(f)||b.open)&&be(f[0])}return f},W.position=function(a,b){function i(a){u[0].style.width=x[0].style.width=t[0].style.width=a.style.width,t[0].style.height=v[0].style.height=w[0].style.height=a.style.height}var c=0,d=0,e=r.offset(),g=z.scrollTop(),h=z.scrollLeft();z.unbind("resize."+f),r.css({top:-9e4,left:-9e4}),K.fixed&&!o?(e.top-=g,e.left-=h,r.css({position:"fixed"})):(c=g,d=h,r.css({position:"absolute"})),K.right!==!1?d+=Math.max(z.width()-K.w-O-M-_(K.right,"x"),0):K.left!==!1?d+=_(K.left,"x"):d+=Math.round(Math.max(z.width()-K.w-O-M,0)/2),K.bottom!==!1?c+=Math.max(z.height()-K.h-N-L-_(K.bottom,"y"),0):K.top!==!1?c+=_(K.top,"y"):c+=Math.round(Math.max(z.height()-K.h-N-L,0)/2),r.css({top:e.top,left:e.left}),a=r.width()===K.w+O&&r.height()===K.h+N?0:a||0,s[0].style.width=s[0].style.height="9999px",r.dequeue().animate({width:K.w+O,height:K.h+N,top:c,left:d},{duration:a,complete:function(){i(this),T=!1,s[0].style.width=K.w+O+M+"px",s[0].style.height=K.h+N+L+"px",K.reposition&&setTimeout(function(){z.bind("resize."+f,W.position)},1),b&&b()},step:function(){i(this)}})},W.resize=function(a){S&&(a=a||{},a.width&&(K.w=_(a.width,"x")-O-M),a.innerWidth&&(K.w=_(a.innerWidth,"x")),A.css({width:K.w}),a.height&&(K.h=_(a.height,"y")-N-L),a.innerHeight&&(K.h=_(a.innerHeight,"y")),!a.innerHeight&&!a.height&&(A.css({height:"auto"}),K.h=A.height()),A.css({height:K.h}),W.position(K.transition==="none"?0:K.speed))},W.prep=function(b){function g(){return K.w=K.w||A.width(),K.w=K.mw&&K.mw<K.w?K.mw:K.w,K.w}function h(){return K.h=K.h||A.height(),K.h=K.mh&&K.mh<K.h?K.mh:K.h,K.h}if(!S)return;var c,d=K.transition==="none"?0:K.speed;A.remove(),A=Z(X,"LoadedContent").append(b),A.hide().appendTo(B.show()).css({width:g(),overflow:K.scrolling?"auto":"hidden"}).css({height:h()}).prependTo(t),B.hide(),a(R).css({"float":"none"}),o&&a("select").not(r.find("select")).filter(function(){return this.style.visibility!=="hidden"}).css({visibility:"hidden"}).one(k,function(){this.style.visibility="inherit"}),c=function(){function q(){n&&r[0].style.removeAttribute("filter")}var b,c,g=y.length,h,i="frameBorder",k="allowTransparency",l,o,p;if(!S)return;l=function(){clearTimeout(V),C.hide(),bc(j,K.onComplete)},n&&R&&A.fadeIn(100),D.html(K.title).add(A).show();if(g>1){typeof K.current=="string"&&E.html(K.current.replace("{current}",Q+1).replace("{total}",g)).show(),G[K.loop||Q<g-1?"show":"hide"]().html(K.next),H[K.loop||Q?"show":"hide"]().html(K.previous),K.slideshow&&F.show();if(K.preloading){b=[$(-1),$(1)];while(c=y[b.pop()])o=a.data(c,e).href||c.href,a.isFunction(o)&&(o=o.call(c)),ba(o)&&(p=new Image,p.src=o)}}else J.hide();K.iframe?(h=Z("iframe")[0],i in h&&(h[i]=0),k in h&&(h[k]="true"),h.name=f+ +(new Date),K.fastIframe?l():a(h).one("load",l),h.src=K.href,K.scrolling||(h.scrolling="no"),a(h).addClass(f+"Iframe").appendTo(A).one(m,function(){h.src="//about:blank"})):l(),K.transition==="fade"?r.fadeTo(d,1,q):q()},K.transition==="fade"?r.fadeTo(d,0,function(){W.position(0,c)}):W.position(d,c)},W.load=function(b){var c,d,e=W.prep;T=!0,R=!1,P=y[Q],b||bb(),bc(m),bc(i,K.onLoad),K.h=K.height?_(K.height,"y")-N-L:K.innerHeight&&_(K.innerHeight,"y"),K.w=K.width?_(K.width,"x")-O-M:K.innerWidth&&_(K.innerWidth,"x"),K.mw=K.w,K.mh=K.h,K.maxWidth&&(K.mw=_(K.maxWidth,"x")-O-M,K.mw=K.w&&K.w<K.mw?K.w:K.mw),K.maxHeight&&(K.mh=_(K.maxHeight,"y")-N-L,K.mh=K.h&&K.h<K.mh?K.h:K.mh),c=K.href,V=setTimeout(function(){C.show()},100),K.inline?(Z(X).hide().insertBefore(a(c)[0]).one(m,function(){a(this).replaceWith(A.children())}),e(a(c))):K.iframe?e(" "):K.html?e(K.html):ba(c)?(a(R=new Image).addClass(f+"Photo").error(function(){K.title=!1,e(Z(X,"Error").text("This image could not be loaded"))}).load(function(){var a;R.onload=null,K.scalePhotos&&(d=function(){R.height-=R.height*a,R.width-=R.width*a},K.mw&&R.width>K.mw&&(a=(R.width-K.mw)/R.width,d()),K.mh&&R.height>K.mh&&(a=(R.height-K.mh)/R.height,d())),K.h&&(R.style.marginTop=Math.max(K.h-R.height,0)/2+"px"),y[1]&&(K.loop||y[Q+1])&&(R.style.cursor="pointer",R.onclick=function(){W.next()}),n&&(R.style.msInterpolationMode="bicubic"),setTimeout(function(){e(R)},1)}),setTimeout(function(){R.src=c},1)):c&&B.load(c,K.data,function(b,c,d){e(c==="error"?Z(X,"Error").text("Request unsuccessful: "+d.statusText):a(this).contents())})},W.next=function(){!T&&y[1]&&(K.loop||y[Q+1])&&(Q=$(1),W.load())},W.prev=function(){!T&&y[1]&&(K.loop||Q)&&(Q=$(-1),W.load())},W.close=function(){S&&!U&&(U=!0,S=!1,bc(k,K.onCleanup),z.unbind("."+f+" ."+p),q.fadeTo(200,0),r.stop().fadeTo(300,0,function(){r.add(q).css({opacity:1,cursor:"auto"}).hide(),bc(m),A.remove(),setTimeout(function(){U=!1,bc(l,K.onClosed)},1)}))},W.remove=function(){a([]).add(r).add(q).remove(),r=null,a("."+g).removeData(e).removeClass(g).die()},W.element=function(){return a(P)},W.settings=d})(jQuery,document,this);



/*
* Copyright (c) 2009 Simo Kinnunen.
* Licensed under the MIT license.
*
* @version 1.09i
*/
var Cufon = (function () { var m = function () { return m.replace.apply(null, arguments) }; var x = m.DOM = { ready: (function () { var C = false, E = { loaded: 1, complete: 1 }; var B = [], D = function () { if (C) { return } C = true; for (var F; F = B.shift(); F()) { } }; if (document.addEventListener) { document.addEventListener("DOMContentLoaded", D, false); window.addEventListener("pageshow", D, false) } if (!window.opera && document.readyState) { (function () { E[document.readyState] ? D() : setTimeout(arguments.callee, 10) })() } if (document.readyState && document.createStyleSheet) { (function () { try { document.body.doScroll("left"); D() } catch (F) { setTimeout(arguments.callee, 1) } })() } q(window, "load", D); return function (F) { if (!arguments.length) { D() } else { C ? F() : B.push(F) } } })(), root: function () { return document.documentElement || document.body } }; var n = m.CSS = { Size: function (C, B) { this.value = parseFloat(C); this.unit = String(C).match(/[a-z%]*$/)[0] || "px"; this.convert = function (D) { return D / B * this.value }; this.convertFrom = function (D) { return D / this.value * B }; this.toString = function () { return this.value + this.unit } }, addClass: function (C, B) { var D = C.className; C.className = D + (D && " ") + B; return C }, color: j(function (C) { var B = {}; B.color = C.replace(/^rgba\((.*?),\s*([\d.]+)\)/, function (E, D, F) { B.opacity = parseFloat(F); return "rgb(" + D + ")" }); return B }), fontStretch: j(function (B) { if (typeof B == "number") { return B } if (/%$/.test(B)) { return parseFloat(B) / 100 } return { "ultra-condensed": 0.5, "extra-condensed": 0.625, condensed: 0.75, "semi-condensed": 0.875, "semi-expanded": 1.125, expanded: 1.25, "extra-expanded": 1.5, "ultra-expanded": 2}[B] || 1 }), getStyle: function (C) { var B = document.defaultView; if (B && B.getComputedStyle) { return new a(B.getComputedStyle(C, null)) } if (C.currentStyle) { return new a(C.currentStyle) } return new a(C.style) }, gradient: j(function (F) { var G = { id: F, type: F.match(/^-([a-z]+)-gradient\(/)[1], stops: [] }, C = F.substr(F.indexOf("(")).match(/([\d.]+=)?(#[a-f0-9]+|[a-z]+\(.*?\)|[a-z]+)/ig); for (var E = 0, B = C.length, D; E < B; ++E) { D = C[E].split("=", 2).reverse(); G.stops.push([D[1] || E / (B - 1), D[0]]) } return G }), quotedList: j(function (E) { var D = [], C = /\s*((["'])([\s\S]*?[^\\])\2|[^,]+)\s*/g, B; while (B = C.exec(E)) { D.push(B[3] || B[1]) } return D }), recognizesMedia: j(function (G) { var E = document.createElement("style"), D, C, B; E.type = "text/css"; E.media = G; try { E.appendChild(document.createTextNode("/**/")) } catch (F) { } C = g("head")[0]; C.insertBefore(E, C.firstChild); D = (E.sheet || E.styleSheet); B = D && !D.disabled; C.removeChild(E); return B }), removeClass: function (D, C) { var B = RegExp("(?:^|\\s+)" + C + "(?=\\s|$)", "g"); D.className = D.className.replace(B, ""); return D }, supports: function (D, C) { var B = document.createElement("span").style; if (B[D] === undefined) { return false } B[D] = C; return B[D] === C }, textAlign: function (E, D, B, C) { if (D.get("textAlign") == "right") { if (B > 0) { E = " " + E } } else { if (B < C - 1) { E += " " } } return E }, textShadow: j(function (F) { if (F == "none") { return null } var E = [], G = {}, B, C = 0; var D = /(#[a-f0-9]+|[a-z]+\(.*?\)|[a-z]+)|(-?[\d.]+[a-z%]*)|,/ig; while (B = D.exec(F)) { if (B[0] == ",") { E.push(G); G = {}; C = 0 } else { if (B[1]) { G.color = B[1] } else { G[["offX", "offY", "blur"][C++]] = B[2] } } } E.push(G); return E }), textTransform: (function () { var B = { uppercase: function (C) { return C.toUpperCase() }, lowercase: function (C) { return C.toLowerCase() }, capitalize: function (C) { return C.replace(/\b./g, function (D) { return D.toUpperCase() }) } }; return function (E, D) { var C = B[D.get("textTransform")]; return C ? C(E) : E } })(), whiteSpace: (function () { var D = { inline: 1, "inline-block": 1, "run-in": 1 }; var C = /^\s+/, B = /\s+$/; return function (H, F, G, E) { if (E) { if (E.nodeName.toLowerCase() == "br") { H = H.replace(C, "") } } if (D[F.get("display")]) { return H } if (!G.previousSibling) { H = H.replace(C, "") } if (!G.nextSibling) { H = H.replace(B, "") } return H } })() }; n.ready = (function () { var B = !n.recognizesMedia("all"), E = false; var D = [], H = function () { B = true; for (var K; K = D.shift(); K()) { } }; var I = g("link"), J = g("style"); function C(K) { return K.disabled || G(K.sheet, K.media || "screen") } function G(M, P) { if (!n.recognizesMedia(P || "all")) { return true } if (!M || M.disabled) { return false } try { var Q = M.cssRules, O; if (Q) { search: for (var L = 0, K = Q.length; O = Q[L], L < K; ++L) { switch (O.type) { case 2: break; case 3: if (!G(O.styleSheet, O.media.mediaText)) { return false } break; default: break search } } } } catch (N) { } return true } function F() { if (document.createStyleSheet) { return true } var L, K; for (K = 0; L = I[K]; ++K) { if (L.rel.toLowerCase() == "stylesheet" && !C(L)) { return false } } for (K = 0; L = J[K]; ++K) { if (!C(L)) { return false } } return true } x.ready(function () { if (!E) { E = n.getStyle(document.body).isUsable() } if (B || (E && F())) { H() } else { setTimeout(arguments.callee, 10) } }); return function (K) { if (B) { K() } else { D.push(K) } } })(); function s(D) { var C = this.face = D.face, B = { "\u0020": 1, "\u00a0": 1, "\u3000": 1 }; this.glyphs = D.glyphs; this.w = D.w; this.baseSize = parseInt(C["units-per-em"], 10); this.family = C["font-family"].toLowerCase(); this.weight = C["font-weight"]; this.style = C["font-style"] || "normal"; this.viewBox = (function () { var F = C.bbox.split(/\s+/); var E = { minX: parseInt(F[0], 10), minY: parseInt(F[1], 10), maxX: parseInt(F[2], 10), maxY: parseInt(F[3], 10) }; E.width = E.maxX - E.minX; E.height = E.maxY - E.minY; E.toString = function () { return [this.minX, this.minY, this.width, this.height].join(" ") }; return E })(); this.ascent = -parseInt(C.ascent, 10); this.descent = -parseInt(C.descent, 10); this.height = -this.ascent + this.descent; this.spacing = function (L, N, E) { var O = this.glyphs, M, K, G, P = [], F = 0, J = -1, I = -1, H; while (H = L[++J]) { M = O[H] || this.missingGlyph; if (!M) { continue } if (K) { F -= G = K[H] || 0; P[I] -= G } F += P[++I] = ~ ~(M.w || this.w) + N + (B[H] ? E : 0); K = M.k } P.total = F; return P } } function f() { var C = {}, B = { oblique: "italic", italic: "oblique" }; this.add = function (D) { (C[D.style] || (C[D.style] = {}))[D.weight] = D }; this.get = function (H, I) { var G = C[H] || C[B[H]] || C.normal || C.italic || C.oblique; if (!G) { return null } I = { normal: 400, bold: 700}[I] || parseInt(I, 10); if (G[I]) { return G[I] } var E = { 1: 1, 99: 0}[I % 100], K = [], F, D; if (E === undefined) { E = I > 400 } if (I == 500) { I = 400 } for (var J in G) { if (!k(G, J)) { continue } J = parseInt(J, 10); if (!F || J < F) { F = J } if (!D || J > D) { D = J } K.push(J) } if (I < F) { I = F } if (I > D) { I = D } K.sort(function (M, L) { return (E ? (M >= I && L >= I) ? M < L : M > L : (M <= I && L <= I) ? M > L : M < L) ? -1 : 1 }); return G[K[0]] } } function r() { function D(F, G) { if (F.contains) { return F.contains(G) } return F.compareDocumentPosition(G) & 16 } function B(G) { var F = G.relatedTarget; if (!F || D(this, F)) { return } C(this, G.type == "mouseover") } function E(F) { C(this, F.type == "mouseenter") } function C(F, G) { setTimeout(function () { var H = d.get(F).options; m.replace(F, G ? h(H, H.hover) : H, true) }, 10) } this.attach = function (F) { if (F.onmouseenter === undefined) { q(F, "mouseover", B); q(F, "mouseout", B) } else { q(F, "mouseenter", E); q(F, "mouseleave", E) } } } function u() { var C = [], D = {}; function B(H) { var E = [], G; for (var F = 0; G = H[F]; ++F) { E[F] = C[D[G]] } return E } this.add = function (F, E) { D[F] = C.push(E) - 1 }; this.repeat = function () { var E = arguments.length ? B(arguments) : C, F; for (var G = 0; F = E[G++]; ) { m.replace(F[0], F[1], true) } } } function A() { var D = {}, B = 0; function C(E) { return E.cufid || (E.cufid = ++B) } this.get = function (E) { var F = C(E); return D[F] || (D[F] = {}) } } function a(B) { var D = {}, C = {}; this.extend = function (E) { for (var F in E) { if (k(E, F)) { D[F] = E[F] } } return this }; this.get = function (E) { return D[E] != undefined ? D[E] : B[E] }; this.getSize = function (F, E) { return C[F] || (C[F] = new n.Size(this.get(F), E)) }; this.isUsable = function () { return !!B } } function q(C, B, D) { if (C.addEventListener) { C.addEventListener(B, D, false) } else { if (C.attachEvent) { C.attachEvent("on" + B, function () { return D.call(C, window.event) }) } } } function v(C, B) { var D = d.get(C); if (D.options) { return C } if (B.hover && B.hoverables[C.nodeName.toLowerCase()]) { b.attach(C) } D.options = B; return C } function j(B) { var C = {}; return function (D) { if (!k(C, D)) { C[D] = B.apply(null, arguments) } return C[D] } } function c(F, E) { var B = n.quotedList(E.get("fontFamily").toLowerCase()), D; for (var C = 0; D = B[C]; ++C) { if (i[D]) { return i[D].get(E.get("fontStyle"), E.get("fontWeight")) } } return null } function g(B) { return document.getElementsByTagName(B) } function k(C, B) { return C.hasOwnProperty(B) } function h() { var C = {}, B, F; for (var E = 0, D = arguments.length; B = arguments[E], E < D; ++E) { for (F in B) { if (k(B, F)) { C[F] = B[F] } } } return C } function o(E, M, C, N, F, D) { var K = document.createDocumentFragment(), H; if (M === "") { return K } var L = N.separate; var I = M.split(p[L]), B = (L == "words"); if (B && t) { if (/^\s/.test(M)) { I.unshift("") } if (/\s$/.test(M)) { I.push("") } } for (var J = 0, G = I.length; J < G; ++J) { H = z[N.engine](E, B ? n.textAlign(I[J], C, J, G) : I[J], C, N, F, D, J < G - 1); if (H) { K.appendChild(H) } } return K } function l(D, M) { var C = D.nodeName.toLowerCase(); if (M.ignore[C]) { return } var E = !M.textless[C]; var B = n.getStyle(v(D, M)).extend(M); var F = c(D, B), G, K, I, H, L, J; if (!F) { return } for (G = D.firstChild; G; G = I) { K = G.nodeType; I = G.nextSibling; if (E && K == 3) { if (H) { H.appendData(G.data); D.removeChild(G) } else { H = G } if (I) { continue } } if (H) { D.replaceChild(o(F, n.whiteSpace(H.data, B, H, J), B, M, G, D), H); H = null } if (K == 1) { if (G.firstChild) { if (G.nodeName.toLowerCase() == "cufon") { z[M.engine](F, null, B, M, G, D) } else { arguments.callee(G, M) } } J = G } } } var t = " ".split(/\s+/).length == 0; var d = new A(); var b = new r(); var y = new u(); var e = false; var z = {}, i = {}, w = { autoDetect: false, engine: null, forceHitArea: false, hover: false, hoverables: { a: true }, ignore: { applet: 1, canvas: 1, col: 1, colgroup: 1, head: 1, iframe: 1, map: 1, optgroup: 1, option: 1, script: 1, select: 1, style: 1, textarea: 1, title: 1, pre: 1 }, printable: true, selector: (window.Sizzle || (window.jQuery && function (B) { return jQuery(B) }) || (window.dojo && dojo.query) || (window.Ext && Ext.query) || (window.YAHOO && YAHOO.util && YAHOO.util.Selector && YAHOO.util.Selector.query) || (window.$$ && function (B) { return $$(B) }) || (window.$ && function (B) { return $(B) }) || (document.querySelectorAll && function (B) { return document.querySelectorAll(B) }) || g), separate: "words", textless: { dl: 1, html: 1, ol: 1, table: 1, tbody: 1, thead: 1, tfoot: 1, tr: 1, ul: 1 }, textShadow: "none" }; var p = { words: /\s/.test("\u00a0") ? /[^\S\u00a0]+/ : /\s+/, characters: "", none: /^/ }; m.now = function () { x.ready(); return m }; m.refresh = function () { y.repeat.apply(y, arguments); return m }; m.registerEngine = function (C, B) { if (!B) { return m } z[C] = B; return m.set("engine", C) }; m.registerFont = function (D) { if (!D) { return m } var B = new s(D), C = B.family; if (!i[C]) { i[C] = new f() } i[C].add(B); return m.set("fontFamily", '"' + C + '"') }; m.replace = function (D, C, B) { C = h(w, C); if (!C.engine) { return m } if (!e) { n.addClass(x.root(), "cufon-active cufon-loading"); n.ready(function () { n.addClass(n.removeClass(x.root(), "cufon-loading"), "cufon-ready") }); e = true } if (C.hover) { C.forceHitArea = true } if (C.autoDetect) { delete C.fontFamily } if (typeof C.textShadow == "string") { C.textShadow = n.textShadow(C.textShadow) } if (typeof C.color == "string" && /^-/.test(C.color)) { C.textGradient = n.gradient(C.color) } else { delete C.textGradient } if (!B) { y.add(D, arguments) } if (D.nodeType || typeof D == "string") { D = [D] } n.ready(function () { for (var F = 0, E = D.length; F < E; ++F) { var G = D[F]; if (typeof G == "string") { m.replace(C.selector(G), C, true) } else { l(G, C) } } }); return m }; m.set = function (B, C) { w[B] = C; return m }; return m })(); Cufon.registerEngine("vml", (function () { var e = document.namespaces; if (!e) { return } e.add("cvml", "urn:schemas-microsoft-com:vml"); e = null; var b = document.createElement("cvml:shape"); b.style.behavior = "url(#default#VML)"; if (!b.coordsize) { return } b = null; var h = (document.documentMode || 0) < 8; document.write(('<style type="text/css">cufoncanvas{text-indent:0;}@media screen{cvml\\:shape,cvml\\:rect,cvml\\:fill,cvml\\:shadow{behavior:url(#default#VML);display:block;antialias:true;position:absolute;}cufoncanvas{position:absolute;text-align:left;}cufon{display:inline-block;position:relative;vertical-align:' + (h ? "middle" : "text-bottom") + ";}cufon cufontext{position:absolute;left:-10000in;font-size:1px;}a cufon{cursor:pointer}}@media print{cufon cufoncanvas{display:none;}}</style>").replace(/;/g, "!important;")); function c(i, j) { return a(i, /(?:em|ex|%)$|^[a-z-]+$/i.test(j) ? "1em" : j) } function a(l, m) { if (m === "0") { return 0 } if (/px$/i.test(m)) { return parseFloat(m) } var k = l.style.left, j = l.runtimeStyle.left; l.runtimeStyle.left = l.currentStyle.left; l.style.left = m.replace("%", "em"); var i = l.style.pixelLeft; l.style.left = k; l.runtimeStyle.left = j; return i } function f(l, k, j, n) { var i = "computed" + n, m = k[i]; if (isNaN(m)) { m = k.get(n); k[i] = m = (m == "normal") ? 0 : ~ ~j.convertFrom(a(l, m)) } return m } var g = {}; function d(p) { var q = p.id; if (!g[q]) { var n = p.stops, o = document.createElement("cvml:fill"), i = []; o.type = "gradient"; o.angle = 180; o.focus = "0"; o.method = "sigma"; o.color = n[0][1]; for (var m = 1, l = n.length - 1; m < l; ++m) { i.push(n[m][0] * 100 + "% " + n[m][1]) } o.colors = i.join(","); o.color2 = n[l][1]; g[q] = o } return g[q] } return function (ac, G, Y, C, K, ad, W) { var n = (G === null); if (n) { G = K.alt } var I = ac.viewBox; var p = Y.computedFontSize || (Y.computedFontSize = new Cufon.CSS.Size(c(ad, Y.get("fontSize")) + "px", ac.baseSize)); var y, q; if (n) { y = K; q = K.firstChild } else { y = document.createElement("cufon"); y.className = "cufon cufon-vml"; y.alt = G; q = document.createElement("cufoncanvas"); y.appendChild(q); if (C.printable) { var Z = document.createElement("cufontext"); Z.appendChild(document.createTextNode(G)); y.appendChild(Z) } if (!W) { y.appendChild(document.createElement("cvml:shape")) } } var ai = y.style; var R = q.style; var l = p.convert(I.height), af = Math.ceil(l); var V = af / l; var P = V * Cufon.CSS.fontStretch(Y.get("fontStretch")); var U = I.minX, T = I.minY; R.height = af; R.top = Math.round(p.convert(T - ac.ascent)); R.left = Math.round(p.convert(U)); ai.height = p.convert(ac.height) + "px"; var F = Y.get("color"); var ag = Cufon.CSS.textTransform(G, Y).split(""); var L = ac.spacing(ag, f(ad, Y, p, "letterSpacing"), f(ad, Y, p, "wordSpacing")); if (!L.length) { return null } var k = L.total; var x = -U + k + (I.width - L[L.length - 1]); var ah = p.convert(x * P), X = Math.round(ah); var O = x + "," + I.height, m; var J = "r" + O + "ns"; var u = C.textGradient && d(C.textGradient); var o = ac.glyphs, S = 0; var H = C.textShadow; var ab = -1, aa = 0, w; while (w = ag[++ab]) { var D = o[ag[ab]] || ac.missingGlyph, v; if (!D) { continue } if (n) { v = q.childNodes[aa]; while (v.firstChild) { v.removeChild(v.firstChild) } } else { v = document.createElement("cvml:shape"); q.appendChild(v) } v.stroked = "f"; v.coordsize = O; v.coordorigin = m = (U - S) + "," + T; v.path = (D.d ? "m" + D.d + "xe" : "") + "m" + m + J; v.fillcolor = F; if (u) { v.appendChild(u.cloneNode(false)) } var ae = v.style; ae.width = X; ae.height = af; if (H) { var s = H[0], r = H[1]; var B = Cufon.CSS.color(s.color), z; var N = document.createElement("cvml:shadow"); N.on = "t"; N.color = B.color; N.offset = s.offX + "," + s.offY; if (r) { z = Cufon.CSS.color(r.color); N.type = "double"; N.color2 = z.color; N.offset2 = r.offX + "," + r.offY } N.opacity = B.opacity || (z && z.opacity) || 1; v.appendChild(N) } S += L[aa++] } var M = v.nextSibling, t, A; if (C.forceHitArea) { if (!M) { M = document.createElement("cvml:rect"); M.stroked = "f"; M.className = "cufon-vml-cover"; t = document.createElement("cvml:fill"); t.opacity = 0; M.appendChild(t); q.appendChild(M) } A = M.style; A.width = X; A.height = af } else { if (M) { q.removeChild(M) } } ai.width = Math.max(Math.ceil(p.convert(k * P)), 0); if (h) { var Q = Y.computedYAdjust; if (Q === undefined) { var E = Y.get("lineHeight"); if (E == "normal") { E = "1em" } else { if (!isNaN(E)) { E += "em" } } Y.computedYAdjust = Q = 0.5 * (a(ad, E) - parseFloat(ai.height)) } if (Q) { ai.marginTop = Math.ceil(Q) + "px"; ai.marginBottom = Q + "px" } } return y } })()); Cufon.registerEngine("canvas", (function () { var b = document.createElement("canvas"); if (!b || !b.getContext || !b.getContext.apply) { return } b = null; var a = Cufon.CSS.supports("display", "inline-block"); var e = !a && (document.compatMode == "BackCompat" || /frameset|transitional/i.test(document.doctype.publicId)); var f = document.createElement("style"); f.type = "text/css"; f.appendChild(document.createTextNode(("cufon{text-indent:0;}@media screen,projection{cufon{display:inline;display:inline-block;position:relative;vertical-align:middle;" + (e ? "" : "font-size:1px;line-height:1px;") + "}cufon cufontext{display:-moz-inline-box;display:inline-block;width:0;height:0;overflow:hidden;text-indent:-10000in;}" + (a ? "cufon canvas{position:relative;}" : "cufon canvas{position:absolute;}") + "}@media print{cufon{padding:0;}cufon canvas{display:none;}}").replace(/;/g, "!important;"))); document.getElementsByTagName("head")[0].appendChild(f); function d(p, h) { var n = 0, m = 0; var g = [], o = /([mrvxe])([^a-z]*)/g, k; generate: for (var j = 0; k = o.exec(p); ++j) { var l = k[2].split(","); switch (k[1]) { case "v": g[j] = { m: "bezierCurveTo", a: [n + ~ ~l[0], m + ~ ~l[1], n + ~ ~l[2], m + ~ ~l[3], n += ~ ~l[4], m += ~ ~l[5]] }; break; case "r": g[j] = { m: "lineTo", a: [n += ~ ~l[0], m += ~ ~l[1]] }; break; case "m": g[j] = { m: "moveTo", a: [n = ~ ~l[0], m = ~ ~l[1]] }; break; case "x": g[j] = { m: "closePath" }; break; case "e": break generate } h[g[j].m].apply(h, g[j].a) } return g } function c(m, k) { for (var j = 0, h = m.length; j < h; ++j) { var g = m[j]; k[g.m].apply(k, g.a) } } return function (V, w, P, t, C, W) { var k = (w === null); if (k) { w = C.getAttribute("alt") } var A = V.viewBox; var m = P.getSize("fontSize", V.baseSize); var B = 0, O = 0, N = 0, u = 0; var z = t.textShadow, L = []; if (z) { for (var U = z.length; U--; ) { var F = z[U]; var K = m.convertFrom(parseFloat(F.offX)); var I = m.convertFrom(parseFloat(F.offY)); L[U] = [K, I]; if (I < B) { B = I } if (K > O) { O = K } if (I > N) { N = I } if (K < u) { u = K } } } var Z = Cufon.CSS.textTransform(w, P).split(""); var E = V.spacing(Z, ~ ~m.convertFrom(parseFloat(P.get("letterSpacing")) || 0), ~ ~m.convertFrom(parseFloat(P.get("wordSpacing")) || 0)); if (!E.length) { return null } var h = E.total; O += A.width - E[E.length - 1]; u += A.minX; var s, n; if (k) { s = C; n = C.firstChild } else { s = document.createElement("cufon"); s.className = "cufon cufon-canvas"; s.setAttribute("alt", w); n = document.createElement("canvas"); s.appendChild(n); if (t.printable) { var S = document.createElement("cufontext"); S.appendChild(document.createTextNode(w)); s.appendChild(S) } } var aa = s.style; var H = n.style; var j = m.convert(A.height); var Y = Math.ceil(j); var M = Y / j; var G = M * Cufon.CSS.fontStretch(P.get("fontStretch")); var J = h * G; var Q = Math.ceil(m.convert(J + O - u)); var o = Math.ceil(m.convert(A.height - B + N)); n.width = Q; n.height = o; H.width = Q + "px"; H.height = o + "px"; B += A.minY; H.top = Math.round(m.convert(B - V.ascent)) + "px"; H.left = Math.round(m.convert(u)) + "px"; var r = Math.max(Math.ceil(m.convert(J)), 0) + "px"; if (a) { aa.width = r; aa.height = m.convert(V.height) + "px" } else { aa.paddingLeft = r; aa.paddingBottom = (m.convert(V.height) - 1) + "px" } var X = n.getContext("2d"), D = j / A.height; X.scale(D, D * M); X.translate(-u, -B); X.save(); function T() { var x = V.glyphs, ab, l = -1, g = -1, y; X.scale(G, 1); while (y = Z[++l]) { var ab = x[Z[l]] || V.missingGlyph; if (!ab) { continue } if (ab.d) { X.beginPath(); if (ab.code) { c(ab.code, X) } else { ab.code = d("m" + ab.d, X) } X.fill() } X.translate(E[++g], 0) } X.restore() } if (z) { for (var U = z.length; U--; ) { var F = z[U]; X.save(); X.fillStyle = F.color; X.translate.apply(X, L[U]); T() } } var q = t.textGradient; if (q) { var v = q.stops, p = X.createLinearGradient(0, A.minY, 0, A.maxY); for (var U = 0, R = v.length; U < R; ++U) { p.addColorStop.apply(p, v[U]) } X.fillStyle = p } else { X.fillStyle = P.get("color") } T(); return s } })());



/*!
* The following copyright notice may not be removed under any circumstances.
* 
* Copyright:
* Copyright (c) 2009 Dave Crossland <dave@lab6.com>
*/
Cufon.registerFont({ "w": 228, "face": { "font-family": "font", "font-weight": 500, "font-stretch": "normal", "units-per-em": "360", "panose-1": "2 0 6 3 0 0 0 0 0 0", "ascent": "266", "descent": "-94", "x-height": "4", "bbox": "3 -282 370 95.4898", "underline-thickness": "20.3906", "underline-position": "-40.957", "unicode-range": "U+0020-U+007E" }, "glyphs": { " ": { "w": 98 }, "!": { "d": "40,0r0,-35r35,0r0,35r-35,0xm42,-81r0,-169r30,0r0,169r-30,0", "w": 114 }, "\"": { "d": "20,-190r0,-76r32,0r0,76r-32,0xm88,-190r0,-76r32,0r0,76r-32,0", "w": 139 }, "#": { "d": "8,-155r0,-26r56,0r0,-69r28,0r0,69r63,0r0,-69r28,0r0,69r56,0r0,26r-56,0r0,62r56,0r0,26r-56,0r0,72r-28,0r0,-72r-63,0r0,72r-28,0r0,-72r-56,0r0,-26r56,0r0,-62r-56,0xm92,-93r63,0r0,-62r-63,0r0,62", "w": 246 }, "$": { "d": "148,-131v47,21,22,92,-30,90r0,53r-21,0r0,-52v-17,0,-35,-4,-57,-13r8,-22v29,19,108,21,91,-26v-30,-25,-95,-16,-95,-68v0,-31,22,-43,53,-49r0,-48r21,0r0,46v25,1,24,2,47,7r-7,22v-33,-8,-79,-14,-84,19v7,28,54,25,74,41", "w": 210 }, "%": { "d": "15,0r170,-250r30,0r-170,250r-30,0xm57,-142v-25,-1,-40,-19,-40,-50v0,-28,17,-48,41,-48v28,0,39,20,40,48v0,27,-15,50,-41,50xm57,-223v-15,0,-23,12,-22,31v0,19,6,34,23,34v15,0,23,-13,22,-34v0,-18,-7,-31,-23,-31xm173,-12v-27,0,-40,-18,-40,-50v0,-27,16,-48,40,-48v27,0,40,20,40,48v0,28,-14,50,-40,50xm150,-62v0,19,6,34,23,34v16,0,23,-12,23,-33v0,-18,-5,-31,-23,-31v-16,0,-24,12,-23,30", "w": 233 }, "&": { "d": "94,8v-79,0,-72,-102,-25,-128v7,-5,12,-11,20,-15v-21,-20,-35,-35,-36,-62v-2,-33,34,-56,71,-56v62,0,76,69,31,95v-9,10,-18,14,-27,22r61,66r57,-63r16,17r-57,63r50,53r-35,0r-34,-35v-23,19,-47,43,-92,43xm105,-118v-17,19,-42,27,-44,60v-3,44,63,51,88,23r20,-18xm121,-228v-32,0,-53,36,-26,57r17,18v15,-15,42,-22,42,-48v0,-16,-15,-27,-33,-27", "w": 278 }, "'": { "d": "20,-190r0,-76r32,0r0,76r-32,0", "w": 70 }, "(": { "d": "94,72v-44,-66,-76,-178,-36,-271v12,-27,22,-52,35,-73r23,12v-23,42,-47,96,-47,159v0,62,24,116,47,158", "w": 130 }, ")": { "d": "37,-272v56,69,74,225,18,310v-5,9,-10,21,-18,34r-23,-15v24,-42,48,-95,47,-158v0,-63,-24,-117,-47,-159", "w": 130 }, "*": { "d": "32,-148r50,-25r-50,-25r14,-27r47,31r-3,-56r30,0r-3,56r47,-31r15,27r-51,25r51,25r-15,26r-47,-31r3,56r-30,0r3,-56r-47,31", "w": 209 }, "+": { "d": "22,-104r0,-24r88,0r0,-89r26,0r0,89r88,0r0,24r-88,0r0,89r-26,0r0,-89r-88,0", "w": 245 }, ",": { "d": "8,38r27,-68r32,0r-28,68r-31,0", "w": 100 }, "-": { "d": "31,-104r0,-24r151,0r0,24r-151,0", "w": 212 }, ".": { "d": "32,0r0,-37r36,0r0,37r-36,0", "w": 100 }, "\/": { "d": "7,16r87,-266r30,0r-87,266r-30,0", "w": 127 }, "0": { "d": "114,4v-67,0,-94,-59,-94,-132v1,-72,27,-125,94,-125v67,0,95,53,95,126v0,75,-26,131,-95,131xm114,-226v-91,2,-86,200,0,203v89,-4,89,-200,0,-203" }, "1": { "d": "44,-225v30,-10,51,-29,95,-25r0,224r58,0r0,26r-145,0r0,-26r58,0r0,-195r-55,21" }, "2": { "d": "145,-149v36,-31,7,-77,-38,-77v-17,0,-38,5,-65,15r-9,-23v67,-37,191,-14,156,71v-24,58,-96,71,-113,137r123,0r0,26r-159,0v6,-79,60,-110,105,-149" }, "3": { "d": "193,-77v1,79,-93,104,-162,71r8,-24v56,20,117,12,124,-40v-3,-39,-35,-50,-80,-50r0,-26v35,0,69,-10,69,-43v0,-46,-67,-44,-106,-22r-10,-24v54,-31,143,-24,146,41v1,28,-16,50,-38,57v30,9,48,26,49,60" }, "4": { "d": "21,-60r0,-20r101,-170r42,0r0,163r43,0r0,27r-43,0r0,60r-29,0r0,-60r-114,0xm55,-87r80,0r0,-134" }, "5": { "d": "200,-80v0,82,-89,93,-170,78r6,-27v56,12,133,11,133,-48v0,-57,-66,-59,-128,-50r0,-123r151,0r0,26r-122,0r0,69v69,-11,130,9,130,75" }, "6": { "d": "112,4v-62,0,-81,-42,-82,-106v-1,-100,48,-160,151,-148r-2,25v-73,-5,-110,24,-117,85v41,-47,141,-19,136,55v-3,53,-34,89,-86,89xm113,-139v-29,0,-54,26,-54,56v0,31,25,63,56,63v30,0,54,-30,54,-62v0,-32,-26,-57,-56,-57" }, "7": { "d": "23,-222r0,-28r182,0r0,19r-116,231r-35,0r115,-222r-146,0" }, "8": { "d": "115,4v-47,0,-89,-26,-89,-72v0,-33,23,-58,50,-71v-20,-11,-36,-26,-36,-54v0,-37,33,-60,73,-60v44,0,76,20,75,61v-1,28,-15,37,-35,53v29,13,49,32,49,67v0,49,-37,76,-87,76xm168,-88v-18,-49,-111,-47,-111,17v0,28,28,48,60,48v36,0,63,-29,51,-65xm113,-228v-41,0,-59,51,-20,67v10,4,17,7,30,11v13,-10,36,-17,36,-41v1,-23,-22,-37,-46,-37" }, "9": { "d": "165,-115v-41,46,-135,16,-135,-53v0,-46,41,-86,87,-85v60,1,81,45,81,106v0,99,-45,159,-151,148r2,-25v73,9,112,-27,116,-91xm113,-229v-27,-1,-54,29,-54,58v0,28,27,54,56,54v29,0,55,-25,54,-52v-1,-33,-24,-58,-56,-60" }, ":": { "d": "32,0r0,-37r36,0r0,37r-36,0xm32,-137r0,-38r36,0r0,38r-36,0", "w": 100 }, ";": { "d": "8,38r27,-68r32,0r-28,68r-31,0xm32,-137r0,-38r36,0r0,38r-36,0", "w": 100 }, "<": { "d": "18,-94r0,-29r153,-75r0,27r-123,62r123,59r0,29", "w": 188 }, "=": { "d": "38,-62r0,-26r169,0r0,26r-169,0xm38,-142r0,-26r169,0r0,26r-169,0", "w": 245 }, ">": { "d": "18,-21r0,-29r122,-59r-122,-62r0,-27r153,75r0,29", "w": 188 }, "?": { "d": "121,-170v25,-52,-53,-70,-94,-49r-9,-21v57,-30,159,-9,132,73v-14,42,-63,43,-63,98r-30,0v-2,-57,46,-64,64,-101xm55,0r0,-35r35,0r0,35r-35,0", "w": 183 }, "@": { "d": "241,59v-102,45,-214,-12,-209,-130v5,-111,57,-175,169,-175v98,0,147,52,144,153v-2,60,-18,110,-74,113v-21,0,-38,-14,-43,-30v-55,36,-123,-3,-123,-70v0,-68,62,-109,124,-79r4,-11r19,0r3,152v4,7,8,15,20,14v33,-5,39,-47,40,-86v0,-84,-37,-127,-122,-127v-89,0,-129,56,-132,140v-3,93,81,152,169,115xm225,-140v-46,-22,-92,3,-92,57v0,53,48,79,92,55r0,-112", "w": 368 }, "A": { "d": "23,0r89,-250r33,0r89,250r-30,0r-25,-73r-103,0r-26,73r-27,0xm85,-99r85,0r-43,-122", "w": 242 }, "B": { "d": "228,-76v-1,81,-91,79,-177,76r0,-250v72,0,156,-12,157,60v0,20,-18,45,-33,50v28,5,53,31,53,64xm81,-26v56,0,115,6,118,-47v-9,-51,-49,-53,-118,-47r0,94xm81,-143v46,-1,98,0,98,-45v0,-45,-52,-39,-98,-39r0,84", "w": 250 }, "C": { "d": "245,-12v-97,43,-197,-7,-197,-113v0,-102,99,-153,193,-113r-9,25v-79,-34,-154,7,-154,88v0,81,79,122,157,90", "w": 254 }, "D": { "d": "254,-133v0,115,-80,144,-203,133r0,-250v113,-6,203,7,203,117xm224,-127v-1,-80,-56,-104,-143,-97r0,198v87,6,144,-18,143,-101", "w": 282 }, "E": { "d": "51,0r0,-250r146,0r0,26r-116,0r0,82r107,0r0,27r-107,0r0,89r116,0r0,26r-146,0", "w": 225 }, "F": { "d": "51,0r0,-250r144,0r0,26r-114,0r0,82r104,0r0,27r-104,0r0,115r-30,0", "w": 219 }, "G": { "d": "162,4v-79,0,-121,-53,-124,-129v-5,-109,114,-158,204,-105r-12,22v-68,-38,-162,-6,-162,81v0,83,95,135,156,83r0,-63r-71,0r0,-25r100,0r0,98v-22,24,-49,38,-91,38", "w": 279 }, "H": { "d": "51,0r0,-250r30,0r0,108r134,0r0,-108r30,0r0,250r-30,0r0,-115r-134,0r0,115r-30,0", "w": 281 }, "I": { "d": "56,0r0,-250r30,0r0,250r-30,0", "w": 128 }, "J": { "d": "131,-75v3,65,-50,88,-111,74r4,-25v41,10,77,-4,77,-47r0,-177r30,0r0,175", "w": 167 }, "K": { "d": "51,0r0,-250r30,0r0,250r-30,0xm85,-128r106,-122r37,0r-105,119r112,131r-38,0", "w": 248 }, "L": { "d": "51,0r0,-250r30,0r0,224r112,0r0,26r-142,0", "w": 198 }, "M": { "d": "51,0r0,-250r42,0r80,152r82,-152r39,0r0,250r-30,0r0,-207r-76,135r-30,0r-77,-135r0,207r-30,0", "w": 330 }, "N": { "d": "51,0r0,-250r38,0r136,209r0,-209r30,0r0,250r-38,0r-136,-210r0,210r-30,0", "w": 291 }, "O": { "d": "154,2v-75,0,-116,-50,-116,-126v0,-78,42,-128,118,-128v75,0,116,49,116,124v0,77,-43,130,-118,130xm154,-226v-56,0,-86,40,-86,98v0,61,31,105,89,105v56,0,85,-43,85,-102v0,-61,-29,-101,-88,-101", "w": 296 }, "P": { "d": "178,-244v74,31,32,154,-47,140r-50,-1r0,105r-30,0r0,-250v42,3,90,-1,127,6xm187,-179v0,-51,-56,-45,-106,-45r0,93v51,2,106,5,106,-48", "w": 235 }, "Q": { "d": "156,2v-76,-2,-118,-49,-118,-126v0,-78,42,-123,118,-128v106,-7,148,138,90,214r32,31r-16,17r-33,-31v-20,16,-45,23,-73,23xm153,-226v-56,3,-82,41,-85,99v-4,81,77,131,142,87r-56,-52r18,-19r54,53v37,-63,9,-174,-73,-168", "w": 299 }, "R": { "d": "216,-181v0,41,-21,65,-56,74r70,107r-33,0r-68,-104r-48,0r0,104r-30,0r0,-250r116,2v33,6,49,30,49,67xm186,-178v0,-51,-54,-47,-105,-46r0,94v51,-1,105,6,105,-48", "w": 252 }, "S": { "d": "194,-114v52,47,-4,125,-76,118v-29,-3,-53,-9,-76,-17r11,-30v30,11,53,17,69,17v53,0,83,-53,33,-74v-41,-18,-108,-22,-108,-80v0,-70,90,-85,159,-62r-9,27v-50,-21,-136,-7,-111,48v24,27,80,27,108,53", "w": 238 }, "T": { "d": "15,-224r0,-26r197,0r0,26r-84,0r0,224r-30,0r0,-224r-83,0", "w": 212 }, "U": { "d": "146,4v-61,0,-95,-23,-95,-90r0,-164r30,0r0,162v-3,45,24,66,65,66v41,0,65,-21,65,-66r0,-162r30,0r0,179v-5,53,-38,75,-95,75", "w": 277 }, "V": { "d": "24,-250r36,0r71,218r72,-218r33,0r-87,250r-37,0", "w": 246 }, "W": { "d": "24,-250r32,0r63,210r63,-210r30,0r66,210r60,-210r32,0r-77,250r-32,0r-66,-209r-61,209r-31,0", "w": 380 }, "X": { "d": "20,0r90,-130r-80,-120r36,0r64,94r61,-94r34,0r-78,119r88,131r-38,0r-71,-105r-70,105r-36,0", "w": 240 }, "Y": { "d": "18,-250r35,0r64,103r64,-103r34,0r-85,132r0,118r-30,0r0,-118", "w": 221 }, "Z": { "d": "27,0r0,-20r154,-204r-149,0r0,-26r192,0r0,19r-157,205r161,0r0,26r-201,0", "w": 238 }, "[": { "d": "44,72r0,-338r81,0r0,27r-52,0r0,285r52,0r0,26r-81,0", "w": 133 }, "\\": { "d": "4,-250r29,0r88,266r-30,0", "w": 127 }, "]": { "d": "9,46r51,0r0,-285r-51,0r0,-27r80,0r0,338r-80,0r0,-26", "w": 133 }, "^": { "d": "78,-219r49,-52r45,50r-16,16r-31,-35r-32,35", "w": 259 }, "_": { "d": "26,0r0,-26r152,0r0,26r-152,0", "w": 203 }, "`": { "d": "48,-257r12,-22r89,55r-11,19", "w": 196 }, "a": { "d": "129,-16v-33,37,-107,19,-107,-30v0,-50,52,-52,105,-53v8,-58,-40,-62,-89,-46r-5,-21v51,-21,123,-16,123,50r0,116r-20,0xm127,-77v-37,1,-74,-1,-77,30v5,31,58,38,77,10r0,-40", "w": 187 }, "b": { "d": "185,-89v0,71,-65,116,-128,81v-1,10,-13,8,-24,8r0,-266r29,0r0,101v61,-32,123,4,123,76xm157,-84v0,-56,-46,-85,-95,-60r0,117v48,22,95,-3,95,-57", "w": 207 }, "c": { "d": "154,-6v-65,26,-131,-2,-131,-77v0,-78,66,-113,133,-83r-7,21v-49,-17,-98,-2,-98,56v0,58,45,81,96,63", "w": 175 }, "d": { "d": "150,-11v-58,37,-127,1,-127,-73v0,-73,58,-111,124,-84r0,-98r28,0r0,266r-19,0xm147,-146v-47,-23,-96,-1,-96,57v0,57,49,84,96,59r0,-116", "w": 208 }, "e": { "d": "161,-6v-67,26,-141,2,-138,-75v3,-57,29,-96,83,-96v57,0,68,43,65,104r-119,0v2,49,56,62,104,47xm52,-95r91,0v9,-66,-69,-73,-86,-27v-3,9,-5,17,-5,27", "w": 193 }, "f": { "d": "144,-223v-40,-12,-74,2,-66,50r58,0r0,22r-58,0r0,151r-29,0r0,-151r-25,0r0,-22r25,0v-9,-69,40,-91,100,-72", "w": 143 }, "g": { "d": "146,-8v-62,33,-124,-7,-124,-78v0,-73,66,-114,129,-77r4,-10r20,0r0,194v0,67,-77,91,-139,63r8,-21v55,22,111,0,102,-71xm146,-144v-49,-25,-95,0,-95,54v0,55,48,88,95,60r0,-114", "w": 206 }, "h": { "d": "33,0r0,-266r29,0r0,106v56,-35,116,-15,116,60r0,100r-30,0v-6,-56,21,-152,-39,-151v-13,0,-30,5,-47,14r0,137r-29,0", "w": 209 }, "i": { "d": "29,-217r0,-33r34,0r0,33r-34,0xm32,0r0,-173r28,0r0,173r-28,0", "w": 91 }, "j": { "d": "3,72v19,-9,29,-24,29,-45r0,-200r28,0r-3,227v-6,20,-22,32,-43,40xm29,-217r0,-33r34,0r0,33r-34,0", "w": 91 }, "k": { "d": "32,0r0,-266r28,0r0,266r-28,0xm63,-96r77,-81r32,0r-76,78r80,99r-34,0", "w": 188 }, "l": { "d": "35,0r0,-266r29,0r0,266r-29,0", "w": 98 }, "m": { "d": "137,0v-7,-55,24,-149,-36,-150v-10,0,-24,4,-41,13r0,137r-28,0r0,-173r20,0r6,14v36,-21,71,-27,96,1v54,-35,118,-23,118,54r0,104r-28,0v-8,-55,23,-149,-37,-150v-11,0,-25,4,-43,13v5,37,1,95,2,137r-29,0", "w": 304 }, "n": { "d": "58,-159v54,-35,117,-19,117,55r0,104r-29,0v-6,-56,21,-151,-39,-151v-13,0,-30,5,-47,14r0,137r-28,0r0,-173r20,0", "w": 206 }, "o": { "d": "105,4v-50,0,-82,-38,-82,-89v0,-53,33,-93,84,-92v50,0,83,35,83,87v0,54,-34,94,-85,94xm105,-152v-31,-1,-54,27,-54,62v0,36,22,69,57,69v34,0,55,-29,54,-64v-1,-39,-20,-66,-57,-67", "w": 212 }, "p": { "d": "184,-89v0,69,-60,114,-124,83r0,99r-28,0r0,-266v13,-1,24,-1,25,10v59,-36,127,0,127,74xm156,-84v0,-58,-48,-85,-96,-59r0,115v47,23,96,-1,96,-56", "w": 206 }, "q": { "d": "146,-9v-61,34,-124,-4,-124,-77v0,-72,65,-114,129,-77r4,-10r20,0r0,266r-29,0r0,-102xm146,-144v-49,-25,-95,-1,-95,55v0,58,48,83,95,59r0,-114", "w": 206 }, "r": { "d": "32,0r0,-173r20,0r5,13v23,-18,54,-23,82,-10r-9,23v-23,-8,-50,-6,-70,7r0,140r-28,0", "w": 140 }, "s": { "d": "158,-50v0,59,-83,65,-135,40r8,-21v32,19,111,18,91,-26v-29,-25,-95,-16,-95,-68v0,-52,73,-60,121,-45r-8,22v-33,-10,-78,-13,-83,21v20,40,101,23,101,77", "w": 178 }, "t": { "d": "124,-3v-50,17,-88,3,-88,-52r0,-96r-24,0r0,-22r24,0r0,-51r29,0r0,51r52,0r0,22r-52,0v6,55,-25,155,55,128", "w": 136 }, "u": { "d": "149,-15v-53,35,-117,22,-117,-55r0,-103r28,0v5,57,-21,152,40,151v13,0,29,-5,47,-14r0,-137r28,0r0,173r-20,0", "w": 206 }, "v": { "d": "12,-173r31,0r45,144r45,-144r30,0r-61,173r-30,0", "w": 174 }, "w": { "d": "10,-173r31,0r48,145r44,-145r28,0r47,145r47,-145r30,0r-63,173r-29,0r-46,-141r-46,141r-29,0", "w": 295 }, "x": { "d": "12,-173r33,0r49,68r47,-68r31,0r-64,88r60,85r-33,0r-46,-65r-45,65r-30,0r61,-85", "w": 183 }, "y": { "d": "9,-173r31,0r56,147r52,-147r30,0r-101,266r-31,0r35,-84", "w": 185 }, "z": { "d": "26,0r0,-15r95,-136r-95,0r0,-22r133,0r0,15r-95,135r99,0r0,23r-137,0", "w": 189 }, "{": { "d": "53,-97v51,25,11,138,77,147r-5,22v-49,-5,-64,-46,-66,-99v-1,-29,-15,-53,-43,-57r0,-25v74,-12,12,-148,109,-157r5,23v-29,5,-44,31,-44,62v0,43,-9,68,-33,84", "w": 139 }, "|": { "d": "63,54r0,-336r29,0r0,336r-29,0", "w": 155 }, "}": { "d": "87,-97v-51,-22,-10,-139,-77,-146r5,-23v43,6,64,38,65,89v1,32,14,65,45,68r0,25v-77,10,-10,148,-110,156r-5,-22v67,-8,25,-123,77,-147", "w": 139 }, "~": { "d": "117,-239v-15,-21,-37,-5,-35,21v-26,5,-17,-25,-9,-39v5,-10,11,-13,25,-14v31,-4,44,49,68,23r6,-23r18,2v4,47,-47,68,-73,30", "w": 245 }, "\u00a0": { "w": 98}} });



/*
* vertical news ticker
* Tadas Juozapaitis ( kasp3rito@gmail.com )
* http://plugins.jquery.com/project/vTicker
*/
(function (a) { a.fn.vTicker = function (b) { var c = { speed: 700, pause: 4000, showItems: 3, animation: "", mousePause: true, isPaused: false, direction: "up", height: 0 }; var b = a.extend(c, b); moveUp = function (g, d, e) { if (e.isPaused) { return } var f = g.children("ul"); var h = f.children("li:first").clone(true); if (e.height > 0) { d = f.children("li:first").height() } f.animate({ top: "-=" + d + "px" }, e.speed, function () { a(this).children("li:first").remove(); a(this).css("top", "0px") }); if (e.animation == "fade") { f.children("li:first").fadeOut(e.speed); if (e.height == 0) { f.children("li:eq(" + e.showItems + ")").hide().fadeIn(e.speed) } } h.appendTo(f) }; moveDown = function (g, d, e) { if (e.isPaused) { return } var f = g.children("ul"); var h = f.children("li:last").clone(true); if (e.height > 0) { d = f.children("li:first").height() } f.css("top", "-" + d + "px").prepend(h); f.animate({ top: 0 }, e.speed, function () { a(this).children("li:last").remove() }); if (e.animation == "fade") { if (e.height == 0) { f.children("li:eq(" + e.showItems + ")").fadeOut(e.speed) } f.children("li:first").hide().fadeIn(e.speed) } }; return this.each(function () { var f = a(this); var e = 0; f.css({ overflow: "hidden", position: "relative" }).children("ul").css({ position: "absolute", margin: 0, padding: 0 }).children("li").css({ margin: 0, padding: 0 }); if (b.height == 0) { f.children("ul").children("li").each(function () { if (a(this).height() > e) { e = a(this).height() } }); f.children("ul").children("li").each(function () { a(this).height(e) }); f.height(e * b.showItems) } else { f.height(b.height) } var d = setInterval(function () { if (b.direction == "up") { moveUp(f, e, b) } else { moveDown(f, e, b) } }, b.pause); if (b.mousePause) { f.bind("mouseenter", function () { b.isPaused = true }).bind("mouseleave", function () { b.isPaused = false }) } }) } })(jQuery);



/* Custom functions */
$(function () {

  // Home features
  $('#features article').mouseover(function () {
    $('#features article').stop().animate({ width: 210 }, 200);
    $('#features article div.expand').stop().animate({ height: 60 }, 200);
    $(this).stop().animate({ width: 330 }, 200);
    $('div.expand', this).stop().animate({ height: 340 }, 200, function () {
      $('.extra', this).fadeIn();
    });
  }).mouseout(function () {
    $('#features article').stop().animate({ width: 240 }, 200);
    $('#features article div.expand').stop().animate({ height: 60 }, 200, function () {
      $('.extra').hide();
    });
  });


  // Font replacement
  Cufon.replace('h1, h2, .rte h3, .rte h4, .font, .feature-bar');


  //Search input
  $('.search-input').focus(function () {
    if ($(this).attr('value') == 'Search') {
      $(this).attr('value', '');
    }
  });
  $('.search-input').blur(function () {
    if ($(this).attr('value') == '') {
      $(this).attr('value', 'Search');
    }
  });


  // Company news ticker
  $('.company-news').vTicker({
    speed: 1000,
    pause: 4000,
    animation: 'fade',
    mousePause: true,
    showItems: 3
  });


  // Open links in new window
  $('.new').attr('target','_blank');

  
  // Gallery modal window
  $('.modal').colorbox();
  $('.modal-live').live('click', function() {
    $.fn.colorbox({href:$(this).attr('href'), open:true, overlayOpacity: 0});
    return false;
  });

  
  // Gallery controls
  $('#controls').fadeTo(0,0);

  $('#slideshow, #controls').mouseover(function(){
    $('#controls').stop().fadeTo(200,0.8);
  }).mouseout(function(){
    $('#controls').stop().fadeTo(200,0);    
  });
  
  $('.thumbs li:nth-child(5n+1)').css('clear', 'both');

});
