home *** CD-ROM | disk | FTP | other *** search
/ PC go! 2011 October / PCgo_1011_CD.iso / interface / js / lightwindow.js < prev    next >
Encoding:
Text File  |  2009-10-14  |  62.3 KB  |  1,919 lines

  1. // lightwindow.js v2.0
  2. //
  3. // Copyright (c) 2007 stickmanlabs
  4. // Author: Kevin P Miller | http://www.stickmanlabs.com
  5. // 
  6. // LightWindow is freely distributable under the terms of an MIT-style license.
  7. //
  8. // I don't care what you think about the file size...
  9. //   Be a pro: 
  10. //        http://www.thinkvitamin.com/features/webapps/serving-javascript-fast
  11. //      http://rakaz.nl/item/make_your_pages_load_faster_by_combining_and_compressing_javascript_and_css_files
  12. //
  13.  
  14. /*-----------------------------------------------------------------------------------------------*/
  15.  
  16. if(typeof Effect == 'undefined')
  17.   throw("lightwindow.js requires including script.aculo.us' effects.js library!");
  18.  
  19. // This will stop image flickering in IE6 when elements with images are moved
  20. try {
  21.     document.execCommand("BackgroundImageCache", false, true);
  22. } catch(e) {}
  23.  
  24. var lightwindow = Class.create();    
  25. lightwindow.prototype = {
  26.     //
  27.     //    Setup Variables
  28.     //
  29.     element : null,
  30.     contentToFetch : null,
  31.     windowActive : false,
  32.     dataEffects : [],
  33.     dimensions : {
  34.     cruft : null,
  35.     container : null,
  36.     viewport : {
  37.     height : null,
  38.     width : null,
  39.     offsetTop : null,
  40.     offsetLeft : null
  41.         }
  42.     },
  43.     pagePosition : {
  44.         x : 0,
  45.         y : 0
  46.     },
  47.     pageDimensions : {
  48.         width : null,
  49.         height : null
  50.     },
  51.     preloadImage : [],
  52.     preloadedImage : [],
  53.     galleries : [],
  54.     resizeTo : {
  55.         height : null,
  56.         heightPercent : null,
  57.         width : null,
  58.         widthPercent : null,
  59.         fixedTop : null,
  60.         fixedLeft : null
  61.     },
  62.     scrollbarOffset : 18,
  63.     navigationObservers : {
  64.         previous : null,
  65.         next : null
  66.     },
  67.     containerChange : {
  68.         height : 0,
  69.         width : 0
  70.     },
  71.     activeGallery : false,
  72.     galleryLocation : {
  73.         current : 0,
  74.         total : 0
  75.     },
  76.     //
  77.     //    Initialize the lightwindow.
  78.     //
  79.     initialize : function(options) {
  80.         this.options = Object.extend({
  81.             resizeSpeed : 8,
  82.             contentOffset : {
  83.                 height : 20,
  84.                 width : 20
  85.             },
  86.             dimensions : {
  87.                 image : {height : 250, width : 250},
  88.                 page : {height : 250, width : 250},
  89.                 inline : {height : 250, width : 250},
  90.                 media : {height : 250, width : 250},
  91.                 external : {height : 250, width : 250},
  92.                 titleHeight : 25
  93.             },
  94.             classNames : {    
  95.                 standard : 'lightwindow',
  96.                 action : 'lightwindow_action'
  97.             },
  98.             fileTypes : {
  99.                 page : ['asp', 'aspx', 'cgi', 'cfm', 'htm', 'html', 'pl', 'php4', 'php3', 'php', 'php5', 'phtml', 'rhtml', 'shtml', 'txt', 'vbs', 'rb'],
  100.                 media : ['aif', 'aiff', 'asf', 'avi', 'divx', 'm1v', 'm2a', 'm2v', 'm3u', 'mid', 'midi', 'mov', 'moov', 'movie', 'mp2', 'mp3', 'mpa', 'mpa', 'mpe', 'mpeg', 'mpg', 'mpg', 'mpga', 'pps', 'qt', 'rm', 'ram', 'swf', 'viv', 'vivo', 'wav'],
  101.                 image : ['bmp', 'gif', 'jpg', 'png', 'tiff']
  102.             },
  103.             mimeTypes : {
  104.                 avi : 'video/avi',
  105.                 aif : 'audio/aiff',
  106.                 aiff : 'audio/aiff',
  107.                 gif : 'image/gif',
  108.                 bmp : 'image/bmp',
  109.                 jpeg : 'image/jpeg',
  110.                 m1v : 'video/mpeg',
  111.                 m2a : 'audio/mpeg',
  112.                 m2v : 'video/mpeg',
  113.                 m3u : 'audio/x-mpequrl',
  114.                 mid : 'audio/x-midi',
  115.                 midi : 'audio/x-midi',
  116.                 mjpg : 'video/x-motion-jpeg',
  117.                 moov : 'video/quicktime',
  118.                 mov : 'video/quicktime',
  119.                 movie : 'video/x-sgi-movie',
  120.                 mp2 : 'audio/mpeg',
  121.                 mp3 : 'audio/mpeg3',
  122.                 mpa : 'audio/mpeg',
  123.                 mpa : 'video/mpeg',
  124.                 mpe : 'video/mpeg',
  125.                 mpeg : 'video/mpeg',
  126.                 mpg : 'audio/mpeg',
  127.                 mpg : 'video/mpeg',
  128.                 mpga : 'audio/mpeg',
  129.                 pdf : 'application/pdf',
  130.                 png : 'image/png',
  131.                 pps : 'application/mspowerpoint',
  132.                 qt : 'video/quicktime',
  133.                 ram : 'audio/x-pn-realaudio-plugin',
  134.                 rm : 'application/vnd.rn-realmedia',
  135.                 swf    : 'application/x-shockwave-flash',
  136.                 tiff : 'image/tiff',
  137.                 viv : 'video/vivo',
  138.                 vivo : 'video/vivo',
  139.                 wav : 'audio/wav',
  140.                 wmv : 'application/x-mplayer2'            
  141.             },    
  142.             classids : {
  143.                 mov : 'clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B',
  144.                 swf : 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000',
  145.                 wmv : 'clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6'
  146.             },
  147.             codebases : {
  148.                 mov : 'http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0',
  149.                 swf : 'http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0',
  150.                 wmv : 'http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715'
  151.             },    
  152.             viewportPadding : 10,
  153.             EOLASFix : 'swf,wmv,fla,flv',
  154.             overlay : {
  155.                 opacity : 0.7,
  156.                 image : 'images/black.png',
  157.                 presetImage : 'images/black-70.png'
  158.             },
  159.             skin :     {
  160.                 main :     '<div id="lightwindow_container" >'+
  161.                             '<div id="lightwindow_title_bar" >'+
  162.                                 '<div id="lightwindow_title_bar_inner" >'+
  163.                                     '<span id="lightwindow_title_bar_title"></span>'+
  164.                                     '<a id="lightwindow_title_bar_close_link" >Schließen</a>'+// Anpassen
  165.                                 '</div>'+
  166.                             '</div>'+
  167.                             '<div id="lightwindow_stage" >'+
  168.                                 '<div id="lightwindow_contents" >'+
  169.                                 '</div>'+
  170.                                 '<div id="lightwindow_navigation" >'+
  171.                                     '<a href="#" id="lightwindow_previous" >'+
  172.                                         '<span id="lightwindow_previous_title"></span>'+
  173.                                     '</a>'+
  174.                                     '<a href="#" id="lightwindow_next" >'+
  175.                                         '<span id="lightwindow_next_title"></span>'+
  176.                                     '</a>'+
  177.                                     '<iframe name="lightwindow_navigation_shim" id="lightwindow_navigation_shim" src="javascript:false;" frameBorder="0" scrolling="no"></iframe>'+
  178.                                 '</div>'+                                
  179.                                 '<div id="lightwindow_galleries">'+
  180.                                     '<div id="lightwindow_galleries_tab_container" >'+
  181.                                         '<a href="#" id="lightwindow_galleries_tab" >'+
  182.                                             '<span id="lightwindow_galleries_tab_span" class="up" >Galleries</span>'+
  183.                                         '</a>'+
  184.                                     '</div>'+
  185.                                     '<div id="lightwindow_galleries_list" >'+
  186.                                     '</div>'+
  187.                                 '</div>'+
  188.                             '</div>'+
  189.                             '<div id="lightwindow_data_slide" >'+
  190.                                 '<div id="lightwindow_data_slide_inner" >'+
  191.                                     '<div id="lightwindow_data_details" >'+
  192.                                         '<div id="lightwindow_data_gallery_container" >'+
  193.                                             '<span id="lightwindow_data_gallery_current"></span>'+
  194.                                             ' von '+//anpassen 
  195.                                             '<span id="lightwindow_data_gallery_total"></span>'+
  196.                                         '</div>'+
  197.                                     '</div>'+
  198.                                 '</div>'+
  199.                             '</div>'+
  200.                         '</div>',    
  201.                 loading :     '<div id="lightwindow_loading">'+
  202.                                 '<img src="images/ajax-loading.gif" alt="loading" />'+
  203.                                 '<span>Lade Daten - <a href="javascript: myLightWindow.deactivate();">Abbrechen</a></span>'+        //anpassen
  204.                                 '<iframe name="lightwindow_loading_shim" id="lightwindow_loading_shim" src="javascript:false;" frameBorder="0" scrolling="no"></iframe>'+
  205.                             '</div>',
  206.                 iframe :     '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'+
  207.                             '<html xmlns="http://www.w3.org/1999/xhtml">'+
  208.                                 '<body>'+
  209.                                     '{body_replace}'+
  210.                                 '</body>'+
  211.                             '</html>',
  212.                 gallery : {
  213.                     top :        '<div class="lightwindow_galleries_list">'+
  214.                                     '<h1>{gallery_title_replace}</h1>'+
  215.                                     '<ul>',
  216.                     middle :             '<li>'+
  217.                                             '{gallery_link_replace}'+
  218.                                         '</li>',
  219.                     bottom :         '</ul>'+
  220.                                 '</div>'
  221.                 }
  222.             },
  223.             formMethod : 'get',
  224.             hideFlash : false,
  225.             hideGalleryTab : false,
  226.             showTitleBar : true,
  227.             animationHandler : false,
  228.             navigationHandler : false,
  229.             transitionHandler : false,
  230.             finalAnimationHandler : false,
  231.             formHandler : false,
  232.             galleryAnimationHandler : false,
  233.             showGalleryCount : true
  234.         }, options || {});
  235.         this.duration = ((11-this.options.resizeSpeed)*0.15);
  236.         this._setupLinks();
  237.         this._getScroll();
  238.         this._getPageDimensions();
  239.         this._browserDimensions();
  240.         this._addLightWindowMarkup(false);
  241.         this._setupDimensions(); 
  242.         this.buildGalleryList();
  243.     },
  244.     //
  245.     //    Activate the lightwindow.
  246.     //
  247.     activate : function(e, link){        
  248.         // Clear out the window Contents
  249.         this._clearWindowContents(true);
  250.             
  251.         // Add back in out loading panel
  252.         this._addLoadingWindowMarkup();
  253.  
  254.         // Setup the element properties
  255.         this._setupWindowElements(link);
  256.         
  257.         // Setup everything
  258.         this._getScroll();
  259.         this._browserDimensions();
  260.         this._setupDimensions();
  261.         this._toggleTroubleElements('hidden', false);
  262.         this._displayLightWindow('block', 'hidden');
  263.         this._setStatus(true);
  264.         this._monitorKeyboard(true);
  265.         this._prepareIE(true);
  266.         this._loadWindow();
  267.     },
  268.     //
  269.     //    Turn off the window
  270.     //
  271.     deactivate : function(){
  272.         // The window is not active
  273.         this.windowActive = false;
  274.         
  275.         // There is no longer a gallery active
  276.         this.activeGallery = false;
  277.         if (!this.options.hideGalleryTab) {
  278.             this._handleGalleryAnimation(false);
  279.         }
  280.         
  281.         // Kill the animation
  282.         this.animating = false;
  283.         
  284.         // Clear our element
  285.         this.element = null;
  286.         
  287.         // hide the window.
  288.         this._displayLightWindow('none', 'visible');
  289.         
  290.         // Clear out the window Contents
  291.         this._clearWindowContents(false);
  292.         
  293.         // Stop all animation
  294.         var queue = Effect.Queues.get('lightwindowAnimation').each(function(e){e.cancel();});
  295.         
  296.         // Undo the setup
  297.         this._prepareIE(false);
  298.         this._setupDimensions();
  299.         this._toggleTroubleElements('visible', false);    
  300.         this._monitorKeyboard(false);    
  301.     },
  302.     //
  303.     //  Initialize specific window
  304.     //
  305.     createWindow : function(element, attributes) {
  306.         this._processLink($(element));
  307.     },
  308.     //
  309.     //  Open a Window from a hash of attributes
  310.     //
  311.     activateWindow : function(options) {
  312.         this.element = Object.extend({
  313.             href : null,
  314.             title : null,
  315.             author : null,
  316.             caption : null,
  317.             rel : null,
  318.             top : null,
  319.             left : null,
  320.             type : null,
  321.             showImages : null,
  322.             height : null,
  323.             width : null,
  324.             loadingAnimation : null,
  325.             iframeEmbed : null,
  326.             form : null
  327.         }, options || {});
  328.         
  329.         // Set the window type
  330.         this.contentToFetch = this.element.href;
  331.         this.windowType = this.element.type ? this.element.type : this._fileType(this.element.href);    
  332.         
  333.         // Clear out the window Contents
  334.         this._clearWindowContents(true);
  335.             
  336.         // Add back in out loading panel
  337.         this._addLoadingWindowMarkup();
  338.         
  339.         // Setup everything
  340.         this._getScroll();
  341.         this._browserDimensions();
  342.         this._setupDimensions();
  343.         this._toggleTroubleElements('hidden', false);
  344.         this._displayLightWindow('block', 'hidden');
  345.         this._setStatus(true);
  346.         this._monitorKeyboard(true);
  347.         this._prepareIE(true);
  348.         this._loadWindow();
  349.     },
  350.     //
  351.     //  Fire off our Form handler
  352.     //
  353.     submitForm : function(e) {
  354.         if (this.options.formHandler) {
  355.             this.options.formHandler(e);
  356.         } else {
  357.             this._defaultFormHandler(e);
  358.         }
  359.     },
  360.     //
  361.     //    Reload the window with another location
  362.     //
  363.     openWindow : function(element) {
  364.         var element = $(element);
  365.  
  366.         // The window is active
  367.         this.windowActive = true;
  368.         
  369.         // Clear out the window Contents
  370.         this._clearWindowContents(true);
  371.         
  372.         // Add back in out loading panel
  373.         this._addLoadingWindowMarkup();
  374.         
  375.         // Setup the element properties
  376.         this._setupWindowElements(element);
  377.  
  378.         this._setStatus(true);
  379.         this._handleTransition();
  380.     },
  381.     //
  382.     //  Navigate the window
  383.     //
  384.     navigateWindow : function(direction) {
  385.         this._handleNavigation(false);
  386.         if (direction == 'previous') {
  387.             this.openWindow(this.navigationObservers.previous);
  388.         } else if (direction == 'next'){ 
  389.             this.openWindow(this.navigationObservers.next);
  390.         }
  391.     },
  392.     //
  393.     //  Build the Gallery List and Load it
  394.     //
  395.     buildGalleryList : function() {
  396.         var output = '';
  397.         var galleryLink;
  398.         for (i in this.galleries) {
  399.             if (typeof this.galleries[i] == 'object') {
  400.                 output += (this.options.skin.gallery.top).replace('{gallery_title_replace}', unescape(i));
  401.                 for (j in this.galleries[i]) {
  402.                     if (typeof this.galleries[i][j] == 'object') {                        
  403.                         galleryLink = '<a href="#" id="lightwindow_gallery_'+i+'_'+j+'" >'+unescape(j)+'</a>';
  404.                         output += (this.options.skin.gallery.middle).replace('{gallery_link_replace}', galleryLink);
  405.                     }
  406.                 }
  407.                 output += this.options.skin.gallery.bottom;
  408.             }
  409.         }
  410.         new Insertion.Top('lightwindow_galleries_list', output);
  411.         
  412.         // Attach Events
  413.         for (i in this.galleries) {
  414.             if (typeof this.galleries[i] == 'object') {
  415.                 for (j in this.galleries[i]) {
  416.                     if (typeof this.galleries[i][j] == 'object') {
  417.                         Event.observe($('lightwindow_gallery_'+i+'_'+j), 'click', this.openWindow.bind(this, this.galleries[i][j][0]), false);
  418.                         $('lightwindow_gallery_'+i+'_'+j).onclick = function() {return false;};    
  419.                     }
  420.                 }
  421.             }
  422.         }
  423.     },
  424.     // 
  425.     //  Set Links Up
  426.     //
  427.     _setupLinks : function() {
  428.         var links = $$('.'+this.options.classNames.standard);
  429.         links.each(function(link) {
  430.             this._processLink(link);
  431.         }.bind(this));    
  432.     },
  433.     //
  434.     //  Process a Link
  435.     //
  436.     _processLink : function(link) {
  437.         if ((this._fileType(link.getAttribute('href')) == 'image' || this._fileType(link.getAttribute('href')) == 'media')) {
  438.             if (gallery = this._getGalleryInfo(link.rel)) {
  439.                 if (!this.galleries[gallery[0]]) {
  440.                     this.galleries[gallery[0]] = new Array();
  441.                 }
  442.                 if (!this.galleries[gallery[0]][gallery[1]]) {
  443.                     this.galleries[gallery[0]][gallery[1]] = new Array();
  444.                 }
  445.                 this.galleries[gallery[0]][gallery[1]].push(link);
  446.             }
  447.         }
  448.         
  449.         // Take care of our inline content
  450.         var url = link.getAttribute('href');
  451.         if (url.indexOf('?') > -1) {
  452.             url = url.substring(0, url.indexOf('?'));
  453.         }
  454.         
  455.         var container = url.substring(url.indexOf('#')+1);
  456.         if($(container)) {
  457.             $(container).setStyle({
  458.                 display : 'none'
  459.             });
  460.         }
  461.         
  462.         Event.observe(link, 'click', this.activate.bindAsEventListener(this, link), false);
  463.         link.onclick = function() {return false;};        
  464.     },
  465.     //
  466.     //    Setup our actions
  467.     //
  468.     _setupActions : function() {
  469.         var links = $$('#lightwindow_container .'+this.options.classNames.action);
  470.         links.each(function(link) {
  471.             Event.observe(link, 'click', this[link.getAttribute('rel')].bindAsEventListener(this, link), false);
  472.             link.onclick = function() {return false;};
  473.         }.bind(this));
  474.     },
  475.     //
  476.     //    Add the markup to the page.
  477.     //
  478.     _addLightWindowMarkup : function(rebuild) {
  479.         var overlay = Element.extend(document.createElement('div'));
  480.         overlay.setAttribute('id', 'lightwindow_overlay');        
  481.         // FF Mac has a problem with putting Flash above a layer without a 100% opacity background, so we need to use a pre-made
  482.         if (Prototype.Browser.Gecko) {
  483.             overlay.setStyle({
  484.                 backgroundImage: 'url('+this.options.overlay.presetImage+')',
  485.                 backgroundRepeat: 'repeat',
  486.                 height: this.pageDimensions.height+'px'
  487.             });            
  488.         } else {
  489.             overlay.setStyle({
  490.                 opacity: this.options.overlay.opacity,
  491.                 backgroundImage: 'url('+this.options.overlay.image+')',
  492.                 backgroundRepeat: 'repeat',
  493.                 height: this.pageDimensions.height+'px'
  494.             });
  495.         }
  496.         
  497.         var lw = document.createElement('div');
  498.         lw.setAttribute('id', 'lightwindow');
  499.         lw.innerHTML = this.options.skin.main;
  500.         
  501.         var body = document.getElementsByTagName('body')[0];
  502.         body.appendChild(overlay);
  503.         body.appendChild(lw);    
  504.                 
  505.         if ($('lightwindow_title_bar_close_link')) {
  506.             Event.observe('lightwindow_title_bar_close_link', 'click', this.deactivate.bindAsEventListener(this));
  507.             $('lightwindow_title_bar_close_link').onclick = function() {return false;};
  508.         }
  509.             
  510.         Event.observe($('lightwindow_previous'), 'click', this.navigateWindow.bind(this, 'previous'), false);
  511.         $('lightwindow_previous').onclick = function() {return false;};        
  512.         Event.observe($('lightwindow_next'), 'click', this.navigateWindow.bind(this, 'next'), false);
  513.         $('lightwindow_next').onclick = function() {return false;};
  514.  
  515.         if (!this.options.hideGalleryTab) {
  516.             Event.observe($('lightwindow_galleries_tab'), 'click', this._handleGalleryAnimation.bind(this, true), false);
  517.             $('lightwindow_galleries_tab').onclick = function() {return false;};
  518.         }
  519.         
  520.         // Because we use position absolute, kill the scroll Wheel on animations
  521.         if (Prototype.Browser.IE) {
  522.             Event.observe(document, 'mousewheel', this._stopScrolling.bindAsEventListener(this), false);
  523.         } else {
  524.             Event.observe(window, 'DOMMouseScroll', this._stopScrolling.bindAsEventListener(this), false);
  525.         }
  526.                 
  527.         Event.observe(overlay, 'click', this.deactivate.bindAsEventListener(this), false);
  528.         overlay.onclick = function() {return false;};
  529.     },
  530.     //
  531.     //  Add loading window markup
  532.     //
  533.     _addLoadingWindowMarkup : function() {
  534.         $('lightwindow_contents').innerHTML += this.options.skin.loading;
  535.     },
  536.     //
  537.     //  Setup the window elements
  538.     //
  539.     _setupWindowElements : function(link) {
  540.         this.element = link;
  541.         this.element.title = null ? '' : link.getAttribute('title');
  542.         this.element.author = null ? '' : link.getAttribute('author');
  543.         this.element.caption = null ? '' : link.getAttribute('caption');
  544.         this.element.rel = null ? '' : link.getAttribute('rel');
  545.         this.element.params = null ? '' : link.getAttribute('params');
  546.  
  547.         // Set the window type
  548.         this.contentToFetch = this.element.href;
  549.         this.windowType = this._getParameter('lightwindow_type') ? this._getParameter('lightwindow_type') : this._fileType(this.contentToFetch);    
  550.     },
  551.     //
  552.     //  Clear the window contents out
  553.     //
  554.     _clearWindowContents : function(contents) {
  555.         // If there is an iframe, its got to go
  556.         if ($('lightwindow_iframe')) {
  557.             Element.remove($('lightwindow_iframe'));
  558.         }
  559.  
  560.         // Stop playing an object if its still around
  561.         if ($('lightwindow_media_primary')) {
  562.             try {
  563.                 $('lightwindow_media_primary').Stop();
  564.             } catch(e) {}
  565.             Element.remove($('lightwindow_media_primary'));
  566.         }
  567.  
  568.         // Stop playing an object if its still around        
  569.         if ($('lightwindow_media_secondary')) {
  570.             try {
  571.                 $('lightwindow_media_secondary').Stop();
  572.             } catch(e) {}
  573.             Element.remove($('lightwindow_media_secondary'));
  574.         }
  575.         
  576.         this.activeGallery = false;
  577.         this._handleNavigation(this.activeGallery);
  578.         
  579.         if (contents) {
  580.             // Empty the contents
  581.             $('lightwindow_contents').innerHTML = '';
  582.             
  583.             // Reset the scroll bars
  584.             $('lightwindow_contents').setStyle({
  585.                 overflow: 'hidden'
  586.             });        
  587.             
  588.             if (!this.windowActive) {
  589.                 $('lightwindow_data_slide_inner').setStyle({
  590.                     display: 'none'
  591.                 });
  592.  
  593.                 $('lightwindow_title_bar_title').innerHTML = '';
  594.             }
  595.  
  596.             // Because of browser differences and to maintain flexible captions we need to reset this height at close
  597.             $('lightwindow_data_slide').setStyle({
  598.                 height: 'auto'
  599.             });
  600.         }
  601.         
  602.         this.resizeTo.height = null;
  603.         this.resizeTo.width = null;
  604.     },
  605.     //
  606.     //    Set the status of our animation to keep things from getting clunky
  607.     //
  608.     _setStatus : function(status) {
  609.         this.animating = status;
  610.         if (status) {
  611.             Element.show('lightwindow_loading');
  612.         }
  613.         if (!(/MSIE 6./i.test(navigator.userAgent))) {
  614.             this._fixedWindow(status);
  615.         }
  616.     },
  617.     //
  618.     //  Make this window Fixed
  619.     //
  620.     _fixedWindow : function(status) {
  621.         if (status) {
  622.             if (this.windowActive) {
  623.                 this._getScroll();
  624.                 $('lightwindow').setStyle({
  625.                     position: 'absolute',
  626.                     top: parseFloat($('lightwindow').getStyle('top'))+this.pagePosition.y+'px',
  627.                     left: parseFloat($('lightwindow').getStyle('left'))+this.pagePosition.x+'px'
  628.                 });        
  629.             } else {
  630.                 $('lightwindow').setStyle({
  631.                     position: 'absolute'
  632.                 });                        
  633.             }
  634.         } else {
  635.             if (this.windowActive) {
  636.                 this._getScroll();
  637.                 $('lightwindow').setStyle({
  638.                     position: 'fixed',
  639.                     top: parseFloat($('lightwindow').getStyle('top'))-this.pagePosition.y+'px',
  640.                     left: parseFloat($('lightwindow').getStyle('left'))-this.pagePosition.x+'px'
  641.                 });        
  642.             } else {
  643.                 if ($('lightwindow_iframe')) {
  644.                     // Ideally here we would set a 50% value for top and left, but Safari rears it ugly head again and we need to do it by pixels
  645.                     this._browserDimensions();
  646.                 }
  647.                 $('lightwindow').setStyle({
  648.                     position: 'fixed',
  649.                     top: (parseFloat(this._getParameter('lightwindow_top')) ? parseFloat(this._getParameter('lightwindow_top'))+'px' : this.dimensions.viewport.height/2+'px'),
  650.                     left: (parseFloat(this._getParameter('lightwindow_left')) ? parseFloat(this._getParameter('lightwindow_left'))+'px' : this.dimensions.viewport.width/2+'px')
  651.                 });
  652.             }
  653.         }
  654.     },
  655.     //
  656.     //    Prepare the window for IE.
  657.     //
  658.     _prepareIE : function(setup) {
  659.         if (Prototype.Browser.IE) {
  660.             var height, overflowX, overflowY;
  661.             if (setup) { 
  662.                 var height = '100%';
  663.             } else {
  664.                 var height = 'auto';
  665.             }
  666.             var body = document.getElementsByTagName('body')[0];
  667.             var html = document.getElementsByTagName('html')[0];
  668.             html.style.height = body.style.height = height;
  669.         }
  670.     },
  671.     _stopScrolling : function(e) {
  672.         if (this.animating) {
  673.             if (e.preventDefault) {
  674.                 e.preventDefault();
  675.             }
  676.             e.returnValue = false;        
  677.         }
  678.     },
  679.     //
  680.     //    Get the scroll for the page.
  681.     //
  682.     _getScroll : function(){
  683.           if(typeof(window.pageYOffset) == 'number') {
  684.             this.pagePosition.x = window.pageXOffset;
  685.             this.pagePosition.y = window.pageYOffset;
  686.           } else if(document.body && (document.body.scrollLeft || document.body.scrollTop)) {
  687.                this.pagePosition.x = document.body.scrollLeft;
  688.             this.pagePosition.y = document.body.scrollTop;
  689.         } else if(document.documentElement) {
  690.             this.pagePosition.x = document.documentElement.scrollLeft;
  691.             this.pagePosition.y = document.documentElement.scrollTop;
  692.           }
  693.     },
  694.     //
  695.     //    Reset the scroll.
  696.     //
  697.     _setScroll : function(x, y) {
  698.         document.documentElement.scrollLeft = x; 
  699.         document.documentElement.scrollTop = y; 
  700.     },
  701.     //
  702.     //    Hide Selects from the page because of IE.
  703.     //     We could use iframe shims instead here but why add all the extra markup for one browser when this is much easier and cleaner
  704.     //
  705.     _toggleTroubleElements : function(visibility, content){
  706.         
  707.         if (content) {
  708.             var selects = $('lightwindow_contents').getElementsByTagName('select');
  709.         } else {
  710.             var selects = document.getElementsByTagName('select');
  711.         }
  712.         
  713.         for(var i = 0; i < selects.length; i++) {
  714.             selects[i].style.visibility = visibility;
  715.         }
  716.         
  717.         if (!content) {
  718.             if (this.options.hideFlash){
  719.                 var objects = document.getElementsByTagName('object');
  720.                 for (i = 0; i != objects.length; i++) {
  721.                     objects[i].style.visibility = visibility;
  722.                 }
  723.                 var embeds = document.getElementsByTagName('embed');
  724.                 for (i = 0; i != embeds.length; i++) {
  725.                     embeds[i].style.visibility = visibility;
  726.                 }
  727.             }
  728.             var iframes = document.getElementsByTagName('iframe');
  729.             for (i = 0; i != iframes.length; i++) {
  730.                 iframes[i].style.visibility = visibility;
  731.             }
  732.         }
  733.     },
  734.     // 
  735.     //  Get the actual page size
  736.     //
  737.     _getPageDimensions : function() {
  738.         var xScroll, yScroll;
  739.         if (window.innerHeight && window.scrollMaxY) {    
  740.             xScroll = document.body.scrollWidth;
  741.             yScroll = window.innerHeight + window.scrollMaxY;
  742.         } else if (document.body.scrollHeight > document.body.offsetHeight){ 
  743.             xScroll = document.body.scrollWidth;
  744.             yScroll = document.body.scrollHeight;
  745.         } else { 
  746.             xScroll = document.body.offsetWidth;
  747.             yScroll = document.body.offsetHeight;
  748.         }
  749.  
  750.         var windowWidth, windowHeight;
  751.         if (self.innerHeight) {    
  752.             windowWidth = self.innerWidth;
  753.             windowHeight = self.innerHeight;
  754.         } else if (document.documentElement && document.documentElement.clientHeight) { 
  755.             windowWidth = document.documentElement.clientWidth;
  756.             windowHeight = document.documentElement.clientHeight;
  757.         } else if (document.body) { 
  758.             windowWidth = document.body.clientWidth;
  759.             windowHeight = document.body.clientHeight;
  760.         }    
  761.  
  762.         if(yScroll < windowHeight){
  763.             this.pageDimensions.height = windowHeight;
  764.         } else { 
  765.             this.pageDimensions.height = yScroll;
  766.         }
  767.  
  768.         if(xScroll < windowWidth){    
  769.             this.pageDimensions.width = windowWidth;
  770.         } else {
  771.             this.pageDimensions.width = xScroll;
  772.         }
  773.     },
  774.     //
  775.     //    Display the lightWindow.
  776.     //
  777.     _displayLightWindow : function(display, visibility) {
  778.         $('lightwindow_overlay').style.display = $('lightwindow').style.display = $('lightwindow_container').style.display = display;    
  779.         $('lightwindow_overlay').style.visibility = $('lightwindow').style.visibility = $('lightwindow_container').style.visibility = visibility;
  780.     },
  781.     //
  782.     //    Setup Dimensions of lightwindow.
  783.  
  784.     //
  785.     _setupDimensions : function() {
  786.  
  787.         var originalHeight, originalWidth;
  788.         switch (this.windowType) {
  789.             case 'page' :
  790.                 originalHeight = this.options.dimensions.page.height;
  791.                 originalWidth = this.options.dimensions.page.width;
  792.                 break;
  793.  
  794.             case 'image' :
  795.                 originalHeight = this.options.dimensions.image.height;
  796.                 originalWidth = this.options.dimensions.image.width;
  797.                 break;
  798.                 
  799.             case 'media' :
  800.                 originalHeight = this.options.dimensions.media.height;
  801.                 originalWidth = this.options.dimensions.media.width;
  802.                 break;
  803.             
  804.             case 'external' : 
  805.                 originalHeight = this.options.dimensions.external.height;
  806.                 originalWidth = this.options.dimensions.external.width;
  807.                 break;
  808.                 
  809.             case 'inline' :
  810.                 originalHeight = this.options.dimensions.inline.height;
  811.                 originalWidth = this.options.dimensions.inline.width;
  812.                 break;
  813.                 
  814.             default :
  815.                 originalHeight = this.options.dimensions.page.height;
  816.                 originalWidth = this.options.dimensions.page.width;
  817.                 break;
  818.                 
  819.         }
  820.  
  821.         var offsetHeight = this._getParameter('lightwindow_top') ? parseFloat(this._getParameter('lightwindow_top'))+this.pagePosition.y : this.dimensions.viewport.height/2+this.pagePosition.y;
  822.         var offsetWidth = this._getParameter('lightwindow_left') ? parseFloat(this._getParameter('lightwindow_left'))+this.pagePosition.x : this.dimensions.viewport.width/2+this.pagePosition.x;
  823.         
  824.         // So if a theme has say shadowed edges, they should be consistant and take care of in the contentOffset
  825.         $('lightwindow').setStyle({
  826.             top: offsetHeight+'px',
  827.             left: offsetWidth+'px'
  828.         });
  829.         
  830.         $('lightwindow_container').setStyle({
  831.             height: originalHeight+'px',
  832.             width: originalWidth+'px',
  833.             left: -(originalWidth/2)+'px',
  834.             top: -(originalHeight/2)+'px'
  835.         });
  836.  
  837.         $('lightwindow_contents').setStyle({
  838.             height: originalHeight+'px',
  839.             width: originalWidth+'px'
  840.         });
  841.     },
  842.     //
  843.     //    Get the type of file.
  844.     //
  845.     _fileType : function(url) {
  846.         var image = new RegExp("[^\.]\.("+this.options.fileTypes.image.join('|')+")\s*$", "i");
  847.         if (image.test(url)) return 'image';
  848.         if (url.indexOf('#') > -1 && (document.domain == this._getDomain(url))) return 'inline';        
  849.         if (url.indexOf('?') > -1) url = url.substring(0, url.indexOf('?'));
  850.         var type = 'unknown';
  851.         var page = new RegExp("[^\.]\.("+this.options.fileTypes.page.join('|')+")\s*$", "i");
  852.         var media = new RegExp("[^\.]\.("+this.options.fileTypes.media.join('|')+")\s*$", "i");
  853.         if (document.domain != this._getDomain(url)) type = 'external';
  854.           if (media.test(url)) type = 'media';
  855.         if (type == 'external' || type == 'media') return type;
  856.           if (page.test(url) || url.substr((url.length-1), url.length) == '/') type = 'page';
  857.         return type;
  858.     },
  859.     //
  860.     //  Get file Extension
  861.     //
  862.     _fileExtension : function(url) {
  863.         if (url.indexOf('?') > -1) {
  864.             url = url.substring(0, url.indexOf('?'));
  865.         }
  866.         var extenstion = '';
  867.         for (var x = (url.length-1); x > -1; x--) {
  868.             if (url.charAt(x) == '.') {
  869.                 return extenstion;
  870.             }
  871.             extenstion = url.charAt(x)+extenstion;
  872.         }
  873.     },
  874.     //
  875.     //    Monitor the keyboard while this lightwindow is up
  876.     //
  877.     _monitorKeyboard : function(status) {
  878.         if (status) document.onkeydown = this._eventKeypress.bind(this); 
  879.         else document.onkeydown = '';
  880.     },
  881.     //
  882.     //  Perform keyboard actions
  883.     //
  884.     _eventKeypress : function(e) {
  885.         if (e == null) {
  886.             var keycode = event.keyCode;
  887.         } else {
  888.             var keycode = e.which;
  889.         }
  890.         
  891.         switch (keycode) { 
  892.             case 27: 
  893.                 this.deactivate(); 
  894.                 break;
  895.             
  896.             case 13:
  897.                 return;
  898.                 
  899.             default:
  900.                 break;
  901.         }
  902.     
  903.         // Gotta stop those quick fingers
  904.         if (this.animating) {
  905.             return false;
  906.         }
  907.         
  908.         switch (String.fromCharCode(keycode).toLowerCase()) {
  909.             case 'p':
  910.                 if (this.navigationObservers.previous) {
  911.                     this.navigateWindow('previous');
  912.                 }
  913.                 break;
  914.                 
  915.             case 'n':
  916.                 if (this.navigationObservers.next) {
  917.                     this.navigateWindow('next');
  918.                 }
  919.                 break;
  920.                 
  921.             default:
  922.                 break;
  923.         }
  924.     },
  925.     //
  926.     //    Get Gallery Information
  927.     //
  928.     _getGalleryInfo : function(rel) {
  929.         if (!rel) return false;
  930.         if (rel.indexOf('[') > -1) {
  931.             return new Array(escape(rel.substring(0, rel.indexOf('['))), escape(rel.substring(rel.indexOf('[')+1, rel.indexOf(']'))));
  932.         } else {
  933.             return false;
  934.         }
  935.     },
  936.     //
  937.     //    Get the domain from a string.
  938.     //
  939.     _getDomain : function(url) {    
  940.         var leadSlashes = url.indexOf('//');
  941.         var domainStart = leadSlashes+2;
  942.         var withoutResource = url.substring(domainStart, url.length);
  943.         var nextSlash = withoutResource.indexOf('/');
  944.         var domain = withoutResource.substring(0, nextSlash);
  945.         if (domain.indexOf(':') > -1){
  946.             var portColon = domain.indexOf(':');
  947.             domain = domain.substring(0, portColon);
  948.            }
  949.         return domain;
  950.     },
  951.     //
  952.     //    Get the value from the params attribute string.
  953.     //
  954.     _getParameter : function(parameter, parameters) {
  955.         if (!this.element) return false;
  956.         if (parameter == 'lightwindow_top' && this.element.top) {
  957.             return unescape(this.element.top);
  958.         } else if (parameter == 'lightwindow_left' && this.element.left) {
  959.             return unescape(this.element.left);
  960.         } else if (parameter == 'lightwindow_type' && this.element.type) {
  961.             return unescape(this.element.type);
  962.         } else if (parameter == 'lightwindow_show_images' && this.element.showImages) {
  963.             return unescape(this.element.showImages);
  964.         } else if (parameter == 'lightwindow_height' && this.element.height) {
  965.             return unescape(this.element.height);
  966.         } else if (parameter == 'lightwindow_width' && this.element.width) {
  967.             return unescape(this.element.width);
  968.         } else if (parameter == 'lightwindow_loading_animation' && this.element.loadingAnimation) {
  969.             return unescape(this.element.loadingAnimation);
  970.         } else if (parameter == 'lightwindow_iframe_embed' && this.element.iframeEmbed) {
  971.             return unescape(this.element.iframeEmbed);
  972.         } else if (parameter == 'lightwindow_form' && this.element.form) {
  973.             return unescape(this.element.form);
  974.         } else {
  975.             if (!parameters) {
  976.                 if (this.element.params) parameters = this.element.params;
  977.                 else return;
  978.             }
  979.             var value;
  980.             var parameterArray = parameters.split(',');
  981.             var compareString = parameter+'=';
  982.             var compareLength = compareString.length;
  983.             for (var i = 0; i < parameterArray.length; i++) {
  984.                 if (parameterArray[i].substr(0, compareLength) == compareString) {
  985.                     var currentParameter = parameterArray[i].split('=');
  986.                     value = currentParameter[1];
  987.                     break;
  988.                 }
  989.             }
  990.             if (!value) return false;
  991.             else return unescape(value);
  992.         }
  993.     },
  994.     //
  995.     //  Get the Browser Viewport Dimensions
  996.     //
  997.     _browserDimensions : function() {
  998.         if (Prototype.Browser.IE) {
  999.             this.dimensions.viewport.height = document.documentElement.clientHeight;
  1000.             this.dimensions.viewport.width = document.documentElement.clientWidth;   
  1001.         } else {
  1002.             this.dimensions.viewport.height = window.innerHeight;
  1003.             this.dimensions.viewport.width = document.width || document.body.offsetWidth;
  1004.         }
  1005.     },
  1006.     //
  1007.     //  Get the scrollbar offset, I don't like this method but there is really no other way I can find.
  1008.     //
  1009.     _getScrollerWidth : function() {
  1010.         var scrollDiv = Element.extend(document.createElement('div'));
  1011.         scrollDiv.setAttribute('id', 'lightwindow_scroll_div');
  1012.         scrollDiv.setStyle({
  1013.             position: 'absolute',
  1014.             top: '-10000px',
  1015.             left: '-10000px',
  1016.             width: '100px',
  1017.             height: '100px',
  1018.             overflow: 'hidden'
  1019.         });
  1020.  
  1021.  
  1022.  
  1023.         var contentDiv = Element.extend(document.createElement('div'));
  1024.         contentDiv.setAttribute('id', 'lightwindow_content_scroll_div');
  1025.         contentDiv.setStyle({
  1026.             width: '100%',
  1027.             height: '200px'
  1028.         });
  1029.  
  1030.         scrollDiv.appendChild(contentDiv);
  1031.  
  1032.         var body = document.getElementsByTagName('body')[0];
  1033.         body.appendChild(scrollDiv);
  1034.  
  1035.         var noScroll = $('lightwindow_content_scroll_div').offsetWidth;
  1036.         scrollDiv.style.overflow = 'auto';
  1037.         var withScroll = $('lightwindow_content_scroll_div').offsetWidth;
  1038.  
  1039.            Element.remove($('lightwindow_scroll_div'));
  1040.  
  1041.         this.scrollbarOffset = noScroll-withScroll;
  1042.     },
  1043.     
  1044.  
  1045.     //
  1046.     //  Add a param to an object dynamically created
  1047.     //
  1048.     _addParamToObject : function(name, value, object, id) {
  1049.         var param = document.createElement('param');
  1050.         param.setAttribute('value', value);
  1051.         param.setAttribute('name', name);
  1052.         if (id) {
  1053.             param.setAttribute('id', id);
  1054.         }
  1055.         object.appendChild(param);
  1056.         return object;
  1057.     },
  1058.     //
  1059.     //  Get the outer HTML of an object CROSS BROWSER
  1060.     //
  1061.     _outerHTML : function(object) {
  1062.          if (Prototype.Browser.IE) {
  1063.             return object.outerHTML;
  1064.         } else {
  1065.             var clone = object.cloneNode(true);
  1066.             var cloneDiv = document.createElement('div');
  1067.             cloneDiv.appendChild(clone);
  1068.             return cloneDiv.innerHTML;
  1069.         }
  1070.     },
  1071.     //
  1072.     //  Convert an object to markup
  1073.     //
  1074.     _convertToMarkup : function(object, closeTag) {
  1075.         var markup = this._outerHTML(object).replace('</'+closeTag+'>', '');
  1076.         if (Prototype.Browser.IE) {
  1077.             for (var i = 0; i < object.childNodes.length; i++){
  1078.                 markup += this._outerHTML(object.childNodes[i]);
  1079.             }
  1080.             markup += '</'+closeTag+'>';
  1081.         }
  1082.         return markup;
  1083.     },
  1084.     //
  1085.     //  Depending what type of browser it is we have to append the object differently... DAMN YOU IE!!
  1086.     //
  1087.     _appendObject : function(object, closeTag, appendTo) {
  1088.         if (Prototype.Browser.IE) {
  1089.             appendTo.innerHTML += this._convertToMarkup(object, closeTag);
  1090.             
  1091.             // Fix the Eolas activate thing but only for specified media, for example doing this to a quicktime film breaks it.
  1092.             if (this.options.EOLASFix.indexOf(this._fileType(this.element.href)) > -1) {
  1093.                 var objectElements = document.getElementsByTagName('object');
  1094.                 for (var i = 0; i < objectElements.length; i++) {
  1095.                     if (objectElements[i].getAttribute("data")) objectElements[i].removeAttribute('data');
  1096.                     objectElements[i].outerHTML = objectElements[i].outerHTML;
  1097.                     objectElements[i].style.visibility = "visible";
  1098.                 }
  1099.             }
  1100.         } else {
  1101.             appendTo.appendChild(object);    
  1102.         }    
  1103.     },
  1104.     //
  1105.     //  Add in iframe
  1106.     //
  1107.     _appendIframe : function(scroll) {
  1108.         var iframe = document.createElement('iframe');
  1109.         iframe.setAttribute('id', 'lightwindow_iframe');
  1110.         iframe.setAttribute('name', 'lightwindow_iframe');
  1111.         iframe.setAttribute('src', 'about:blank');
  1112.         iframe.setAttribute('height', '100%');
  1113.         iframe.setAttribute('width', '100%');
  1114.         iframe.setAttribute('frameborder', '0');
  1115.         iframe.setAttribute('marginwidth', '0');
  1116.         iframe.setAttribute('marginheight', '0');
  1117.         iframe.setAttribute('scrolling', scroll);    
  1118.         
  1119.         this._appendObject(iframe, 'iframe', $('lightwindow_contents'));
  1120.     },
  1121.     //
  1122.     //  Write Content to the iframe using the skin
  1123.     //
  1124.     _writeToIframe : function(content) {
  1125.         var template = this.options.skin.iframe;
  1126.         template = template.replace('{body_replace}', content); 
  1127.         if ($('lightwindow_iframe').contentWindow){
  1128.             $('lightwindow_iframe').contentWindow.document.open();
  1129.             $('lightwindow_iframe').contentWindow.document.write(template);
  1130.             $('lightwindow_iframe').contentWindow.document.close();
  1131.         } else {
  1132.             $('lightwindow_iframe').contentDocument.open();
  1133.             $('lightwindow_iframe').contentDocument.write(template);
  1134.             $('lightwindow_iframe').contentDocument.close();
  1135.         }
  1136.     },
  1137.     //
  1138.     //  Load the window Information
  1139.     //  
  1140.     _loadWindow : function() {
  1141.         switch (this.windowType) {
  1142.             case 'image' :
  1143.  
  1144.                 var current = 0;
  1145.                 var images = [];
  1146.                 this.checkImage = [];
  1147.                 this.resizeTo.height = this.resizeTo.width = 0;
  1148.                 this.imageCount = this._getParameter('lightwindow_show_images') ? parseInt(this._getParameter('lightwindow_show_images')) : 1;
  1149.  
  1150.                 // If there is a gallery get it
  1151.                 if (gallery = this._getGalleryInfo(this.element.rel)) {    
  1152.                     for (current = 0; current < this.galleries[gallery[0]][gallery[1]].length; current++) {
  1153.                         if (this.contentToFetch.indexOf(this.galleries[gallery[0]][gallery[1]][current].href) > -1) {
  1154.                             break;
  1155.                         }
  1156.                     }
  1157.                     if (this.galleries[gallery[0]][gallery[1]][current-this.imageCount]) {
  1158.                         this.navigationObservers.previous = this.galleries[gallery[0]][gallery[1]][current-this.imageCount];
  1159.                     } else {
  1160.                         this.navigationObservers.previous = false;
  1161.                     }
  1162.                     if (this.galleries[gallery[0]][gallery[1]][current+this.imageCount]) {
  1163.                         this.navigationObservers.next = this.galleries[gallery[0]][gallery[1]][current+this.imageCount];
  1164.                     } else {
  1165.                         this.navigationObservers.next = false;
  1166.                     }
  1167.                     
  1168.                     this.activeGallery = true;
  1169.                 } else {
  1170.                     this.navigationObservers.previous = false;
  1171.                     this.navigationObservers.next = false;                    
  1172.  
  1173.                     this.activeGallery = false;
  1174.                 }
  1175.                 
  1176.                 for (var i = current; i < (current+this.imageCount); i++) {
  1177.         
  1178.                     if (gallery && this.galleries[gallery[0]][gallery[1]][i]) {
  1179.                         this.contentToFetch = this.galleries[gallery[0]][gallery[1]][i].href;
  1180.                         
  1181.                         this.galleryLocation = {current: (i+1)/this.imageCount, total: (this.galleries[gallery[0]][gallery[1]].length)/this.imageCount};
  1182.                                             
  1183.                         if (!this.galleries[gallery[0]][gallery[1]][i+this.imageCount]) {
  1184.                             $('lightwindow_next').setStyle({
  1185.                                 display: 'none'
  1186.                             });
  1187.                         } else {
  1188.                             $('lightwindow_next').setStyle({
  1189.                                 display: 'block'
  1190.                             });
  1191.                             $('lightwindow_next_title').innerHTML = this.galleries[gallery[0]][gallery[1]][i+this.imageCount].title;
  1192.                         }
  1193.                         
  1194.                         if (!this.galleries[gallery[0]][gallery[1]][i-this.imageCount]) {
  1195.                             $('lightwindow_previous').setStyle({
  1196.                                 display: 'none'
  1197.                             });
  1198.                         } else {
  1199.                             $('lightwindow_previous').setStyle({
  1200.                                 display: 'block'
  1201.                             });
  1202.                             $('lightwindow_previous_title').innerHTML = this.galleries[gallery[0]][gallery[1]][i-this.imageCount].title;
  1203.                         }
  1204.                     }
  1205.  
  1206.                     images[i] = document.createElement('img');
  1207.                     images[i].setAttribute('id', 'lightwindow_image_'+i);
  1208.                     images[i].setAttribute('border', '0');
  1209.                     images[i].setAttribute('src', this.contentToFetch);
  1210.                     $('lightwindow_contents').appendChild(images[i]);
  1211.  
  1212.                     // We have to do this instead of .onload 
  1213.                     this.checkImage[i] = new PeriodicalExecuter(function(i) {
  1214.                         if (!(typeof $('lightwindow_image_'+i).naturalWidth != "undefined" && $('lightwindow_image_'+i).naturalWidth == 0)) {
  1215.     
  1216.                             this.checkImage[i].stop();
  1217.     
  1218.                             var imageHeight = $('lightwindow_image_'+i).getHeight();
  1219.                             if (imageHeight > this.resizeTo.height) {
  1220.                                 this.resizeTo.height = imageHeight;
  1221.                             }
  1222.                             this.resizeTo.width += $('lightwindow_image_'+i).getWidth();
  1223.                             this.imageCount--;
  1224.     
  1225.                             $('lightwindow_image_'+i).setStyle({
  1226.                                 height: '100%'
  1227.                             });
  1228.     
  1229.                              if (this.imageCount == 0) {
  1230.                                 this._processWindow();
  1231.                              }
  1232.                         }
  1233.                     
  1234.                     }.bind(this, i), 1);            
  1235.                 }
  1236.  
  1237.  
  1238.             break;
  1239.         
  1240.         case 'media' :            
  1241.         
  1242.             var current = 0;
  1243.             this.resizeTo.height = this.resizeTo.width = 0;
  1244.  
  1245.             // If there is a gallery get it
  1246.             if (gallery = this._getGalleryInfo(this.element.rel)) {    
  1247.                 for (current = 0; current < this.galleries[gallery[0]][gallery[1]].length; current++) {
  1248.                     if (this.contentToFetch.indexOf(this.galleries[gallery[0]][gallery[1]][current].href) > -1) {
  1249.                         break;
  1250.                     }
  1251.                 }
  1252.                 
  1253.                 if (this.galleries[gallery[0]][gallery[1]][current-1]) {
  1254.                     this.navigationObservers.previous = this.galleries[gallery[0]][gallery[1]][current-1];
  1255.                 } else {
  1256.                     this.navigationObservers.previous = false;
  1257.                 }
  1258.                 if (this.galleries[gallery[0]][gallery[1]][current+1]) {
  1259.                     this.navigationObservers.next = this.galleries[gallery[0]][gallery[1]][current+1];
  1260.                 } else {
  1261.                     this.navigationObservers.next = false;
  1262.                 }
  1263.         
  1264.                 this.activeGallery = true;
  1265.             } else {
  1266.                 this.navigationObservers.previous = false;
  1267.                 this.navigationObservers.next = false;
  1268.                 
  1269.                 this.activeGallery = false;
  1270.             }
  1271.         
  1272.  
  1273.             if (gallery && this.galleries[gallery[0]][gallery[1]][current]) {
  1274.                 this.contentToFetch = this.galleries[gallery[0]][gallery[1]][current].href;
  1275.  
  1276.                 this.galleryLocation = {current: current+1, total: this.galleries[gallery[0]][gallery[1]].length};
  1277.                 
  1278.                 if (!this.galleries[gallery[0]][gallery[1]][current+1]) {
  1279.                     $('lightwindow_next').setStyle({
  1280.                         display: 'none'
  1281.                     });
  1282.                 } else {
  1283.                     $('lightwindow_next').setStyle({
  1284.                         display: 'block'
  1285.                     });
  1286.                     $('lightwindow_next_title').innerHTML = this.galleries[gallery[0]][gallery[1]][current+1].title;
  1287.                 }
  1288.                 
  1289.                 if (!this.galleries[gallery[0]][gallery[1]][current-1]) {
  1290.                     $('lightwindow_previous').setStyle({
  1291.                         display: 'none'
  1292.                     });
  1293.                 } else {
  1294.                     $('lightwindow_previous').setStyle({
  1295.                         display: 'block'
  1296.                     });
  1297.                     $('lightwindow_previous_title').innerHTML = this.galleries[gallery[0]][gallery[1]][current-1].title;
  1298.                 }
  1299.             }
  1300.             
  1301.             if (this._getParameter('lightwindow_iframe_embed')) {
  1302.                 this.resizeTo.height = this.dimensions.viewport.height;
  1303.                 this.resizeTo.width = this.dimensions.viewport.width;    
  1304.             } else {
  1305.                 this.resizeTo.height = this._getParameter('lightwindow_height');
  1306.                 this.resizeTo.width = this._getParameter('lightwindow_width');                
  1307.             }
  1308.             
  1309.             this._processWindow();
  1310.             
  1311.             break;
  1312.  
  1313.         case 'external' :        
  1314.  
  1315.             this._appendIframe('auto');
  1316.  
  1317.             this.resizeTo.height = this.dimensions.viewport.height;
  1318.             this.resizeTo.width = this.dimensions.viewport.width;
  1319.                         
  1320.             this._processWindow();
  1321.  
  1322.             break;
  1323.                 
  1324.         case 'page' :    
  1325.             
  1326.             var newAJAX = new Ajax.Request(
  1327.                 this.contentToFetch, {
  1328.                     method: 'get', 
  1329.                     parameters: '', 
  1330.                     onComplete: function(response) {
  1331.                         $('lightwindow_contents').innerHTML += response.responseText;
  1332.                         this.resizeTo.height = $('lightwindow_contents').scrollHeight+(this.options.contentOffset.height);
  1333.                         this.resizeTo.width = $('lightwindow_contents').scrollWidth+(this.options.contentOffset.width);
  1334.                         this._processWindow();
  1335.                     }.bind(this)
  1336.                 }
  1337.             );
  1338.             
  1339.             break;
  1340.             
  1341.         case 'inline' : 
  1342.         
  1343.             var content = this.contentToFetch;
  1344.             if (content.indexOf('?') > -1) {
  1345.                 content = content.substring(0, content.indexOf('?'));
  1346.             }
  1347.             content = content.substring(content.indexOf('#')+1);
  1348.             
  1349.             new Insertion.Top($('lightwindow_contents'), $(content).innerHTML);
  1350.             
  1351.             this.resizeTo.height = $('lightwindow_contents').scrollHeight+(this.options.contentOffset.height);
  1352.             this.resizeTo.width = $('lightwindow_contents').scrollWidth+(this.options.contentOffset.width);
  1353.             
  1354.             this._toggleTroubleElements('hidden', true);             
  1355.             this._processWindow();
  1356.             
  1357.             break;
  1358.             
  1359.         default : 
  1360.             throw("Page Type could not be determined, please amend this lightwindow URL "+this.contentToFetch);
  1361.             break;
  1362.         }
  1363.     },
  1364.     //
  1365.     //  Resize the Window to fit the viewport if necessary
  1366.     //
  1367.     _resizeWindowToFit : function() {
  1368.         if (this.resizeTo.height+this.dimensions.cruft.height > this.dimensions.viewport.height) {
  1369.             var heightRatio = this.resizeTo.height/this.resizeTo.width;
  1370.             this.resizeTo.height = this.dimensions.viewport.height-this.dimensions.cruft.height-(2*this.options.viewportPadding);
  1371.             // We only care about ratio's with this window type            
  1372.             if (this.windowType == 'image' || (this.windowType == 'media' && !this._getParameter('lightwindow_iframe_embed'))) {
  1373.                 this.resizeTo.width = this.resizeTo.height/heightRatio;
  1374.                 $('lightwindow_data_slide_inner').setStyle({
  1375.                     width: this.resizeTo.width+'px'
  1376.                 });            
  1377.             }
  1378.         } 
  1379.         if (this.resizeTo.width+this.dimensions.cruft.width > this.dimensions.viewport.width) {
  1380.             var widthRatio = this.resizeTo.width/this.resizeTo.height;
  1381.             this.resizeTo.width = this.dimensions.viewport.width-2*this.dimensions.cruft.width-(2*this.options.viewportPadding);
  1382.             // We only care about ratio's with this window type
  1383.             if (this.windowType == 'image' || (this.windowType == 'media' && !this._getParameter('lightwindow_iframe_embed'))) {
  1384.                 this.resizeTo.height = this.resizeTo.width/widthRatio;
  1385.                 $('lightwindow_data_slide_inner').setStyle({
  1386.                     height: this.resizeTo.height+'px'
  1387.                 });
  1388.             }
  1389.         }
  1390.             
  1391.     },
  1392.     //
  1393.     //  Set the Window to a preset size
  1394.     //
  1395.     _presetWindowSize : function() {
  1396.         if (this._getParameter('lightwindow_height')) {
  1397.             this.resizeTo.height = parseFloat(this._getParameter('lightwindow_height'));
  1398.         }
  1399.         if (this._getParameter('lightwindow_width')) {
  1400.             this.resizeTo.width = parseFloat(this._getParameter('lightwindow_width'));
  1401.         }
  1402.     },
  1403.     //
  1404.     //  Process the Window
  1405.     //
  1406.     _processWindow : function() {
  1407.         // Clean out our effects
  1408.         this.dimensions.dataEffects = [];
  1409.  
  1410.         // Set up the data-slide if we have caption information
  1411.         if (this.element.caption || this.element.author || (this.activeGallery && this.options.showGalleryCount)) {
  1412.             if (this.activeGallery && this.options.showGalleryCount) {
  1413.                 $('lightwindow_data_gallery_current').innerHTML = this.galleryLocation.current;
  1414.                 $('lightwindow_data_gallery_total').innerHTML = this.galleryLocation.total;
  1415.                 $('lightwindow_data_gallery_container').setStyle({
  1416.                     display: 'block'
  1417.                 });
  1418.             } else {
  1419.                 $('lightwindow_data_gallery_container').setStyle({
  1420.                     display: 'none'
  1421.                 });                
  1422.             }
  1423.  
  1424.             $('lightwindow_data_slide_inner').setStyle({
  1425.                 width: this.resizeTo.width+'px',
  1426.                 height: 'auto',
  1427.                 visibility: 'visible',
  1428.                 display: 'block'
  1429.             });
  1430.             $('lightwindow_data_slide').setStyle({
  1431.                 height: $('lightwindow_data_slide').getHeight()+'px',
  1432.                 width: '1px',
  1433.                 overflow: 'hidden',
  1434.                 display: 'block'
  1435.             });
  1436.         } else {
  1437.             $('lightwindow_data_slide').setStyle({
  1438.                 display: 'none',
  1439.                 width: 'auto'
  1440.             });
  1441.             $('lightwindow_data_slide_inner').setStyle({
  1442.                 display: 'none',
  1443.                 visibility: 'hidden',
  1444.                 width: this.resizeTo.width+'px',
  1445.                 height: '0px'
  1446.             });
  1447.         }
  1448.                 
  1449.         if (this.element.title != 'null') {        
  1450.             $('lightwindow_title_bar_title').innerHTML = this.element.title;
  1451.         } else {
  1452.             $('lightwindow_title_bar_title').innerHTML = '';
  1453.         }
  1454.         
  1455.         var originalContainerDimensions = {height: $('lightwindow_container').getHeight(), width: $('lightwindow_container').getWidth()};
  1456.         // Position the window
  1457.         $('lightwindow_container').setStyle({
  1458.             height: 'auto',
  1459.             // We need to set the width to a px not auto as opera has problems with it
  1460.             width: $('lightwindow_container').getWidth()+this.options.contentOffset.width-(this.windowActive ? this.options.contentOffset.width : 0)+'px'
  1461.         });
  1462.         var newContainerDimensions = {height: $('lightwindow_container').getHeight(), width: $('lightwindow_container').getWidth()};
  1463.          
  1464.         // We need to record the container dimension changes
  1465.         this.containerChange = {height: originalContainerDimensions.height-newContainerDimensions.height, width: originalContainerDimensions.width-newContainerDimensions.width};
  1466.  
  1467.         // Get out general dimensions
  1468.         this.dimensions.container = {height: $('lightwindow_container').getHeight(), width: $('lightwindow_container').getWidth()};
  1469.         this.dimensions.cruft = {height: this.dimensions.container.height-$('lightwindow_contents').getHeight()+this.options.contentOffset.height, width: this.dimensions.container.width-$('lightwindow_contents').getWidth()+this.options.contentOffset.width};
  1470.         
  1471.         // Set Sizes if we need too
  1472.         this._presetWindowSize();
  1473.         this._resizeWindowToFit(); // Even if the window is preset we still don't want it to go outside of the viewport
  1474.  
  1475.         if (!this.windowActive) {
  1476.             // Position the window
  1477.                $('lightwindow_container').setStyle({
  1478.                 left: -(this.dimensions.container.width/2)+'px',
  1479.                 top: -(this.dimensions.container.height/2)+'px'
  1480.             });
  1481.         }
  1482.            $('lightwindow_container').setStyle({
  1483.             height: this.dimensions.container.height+'px',
  1484.             width: this.dimensions.container.width+'px'
  1485.         });
  1486.         
  1487.         // We are ready, lets show this puppy off!
  1488.         this._displayLightWindow('block', 'visible');
  1489.         this._animateLightWindow();
  1490.     },
  1491.     //
  1492.     //  Fire off our animation handler
  1493.     //
  1494.     _animateLightWindow : function() {
  1495.         if (this.options.animationHandler) {
  1496.             this.options.animationHandler().bind(this);
  1497.         } else {
  1498.             this._defaultAnimationHandler();
  1499.         }
  1500.     },
  1501.     //
  1502.     //  Fire off our transition handler
  1503.     //
  1504.     _handleNavigation : function(display) {
  1505.         if (this.options.navigationHandler) {
  1506.             this.options.navigationHandler().bind(this, display);
  1507.         } else {
  1508.             this._defaultDisplayNavigation(display);
  1509.         }
  1510.     },
  1511.     //
  1512.     //  Fire off our transition handler
  1513.     //
  1514.     _handleTransition : function() {
  1515.         if (this.options.transitionHandler) {
  1516.             this.options.transitionHandler().bind(this);
  1517.         } else {
  1518.             this._defaultTransitionHandler();
  1519.         }
  1520.     },
  1521.     //
  1522.     //  Handle the finish of the window animation
  1523.     // 
  1524.     _handleFinalWindowAnimation : function(delay) {
  1525.         if (this.options.finalAnimationHandler) {
  1526.             this.options.finalAnimationHandler().bind(this, delay);
  1527.         } else {
  1528.             this._defaultfinalWindowAnimationHandler(delay);
  1529.         }        
  1530.     },
  1531.     //
  1532.     //  Handle the gallery Animation
  1533.     // 
  1534.     _handleGalleryAnimation : function(list) {
  1535.         if (this.options.galleryAnimationHandler) {
  1536.             this.options.galleryAnimationHandler().bind(this, list);
  1537.         } else {
  1538.             this._defaultGalleryAnimationHandler(list);
  1539.         }        
  1540.     },
  1541.     //
  1542.     //  Display the navigation 
  1543.     //
  1544.     _defaultDisplayNavigation : function(display) {
  1545.         if (display) {
  1546.             $('lightwindow_navigation').setStyle({
  1547.                 display: 'block',
  1548.                 height: $('lightwindow_contents').getHeight()+'px',
  1549.                 width: '100%',
  1550.                 marginTop: this.options.dimensions.titleHeight+'px'
  1551.             });            
  1552.         } else {
  1553.             $('lightwindow_navigation').setStyle({
  1554.                 display: 'none',
  1555.                 height: 'auto',
  1556.                 width: 'auto'
  1557.             });            
  1558.         }
  1559.     },
  1560.     //
  1561.     //  This is the default animation handler for LightWindow
  1562.     //
  1563.     _defaultAnimationHandler : function() {    
  1564.         // Now that we have figures out the cruft lets make the caption go away and add its effects
  1565.         if (this.element.caption || this.element.author || (this.activeGallery && this.options.showGalleryCount)) {
  1566.             $('lightwindow_data_slide').setStyle({
  1567.                 display: 'none',
  1568.                 width: 'auto'
  1569.             });
  1570.             this.dimensions.dataEffects.push(
  1571.                 new Effect.SlideDown('lightwindow_data_slide', {sync: true}),
  1572.                 new Effect.Appear('lightwindow_data_slide', {sync: true, from: 0.0, to: 1.0})
  1573.             );
  1574.         }
  1575.  
  1576.         // Set up the Title if we have one
  1577.         $('lightwindow_title_bar_inner').setStyle({
  1578.             height: '0px',
  1579.             marginTop: this.options.dimensions.titleHeight+'px'
  1580.         });
  1581.         
  1582.         // We always want the title bar as well
  1583.         this.dimensions.dataEffects.push(
  1584.             new Effect.Morph('lightwindow_title_bar_inner', {sync: true, style: {height: this.options.dimensions.titleHeight+'px', marginTop: '0px'}}),
  1585.              new Effect.Appear('lightwindow_title_bar_inner', {sync: true, from: 0.0, to: 1.0})
  1586.         );        
  1587.         
  1588.         if (!this.options.hideGalleryTab) {
  1589.             this._handleGalleryAnimation(false);
  1590.             if ($('lightwindow_galleries_tab_container').getHeight() == 0) {
  1591.                 this.dimensions.dataEffects.push(
  1592.                     new Effect.Morph('lightwindow_galleries_tab_container', {sync: true, style: {height: '20px', marginTop: '0px'}})
  1593.                 );
  1594.                 $('lightwindow_galleries').setStyle({
  1595.                     width: '0px'
  1596.                 });
  1597.             }
  1598.         }
  1599.         
  1600.         var resized = false;
  1601.         var ratio = this.dimensions.container.width-$('lightwindow_contents').getWidth()+this.resizeTo.width+this.options.contentOffset.width;
  1602.         if (ratio != $('lightwindow_container').getWidth()) {
  1603.             new Effect.Parallel([
  1604.                     new Effect.Scale('lightwindow_contents', 100*(this.resizeTo.width/$('lightwindow_contents').getWidth()), {scaleFrom: 100*($('lightwindow_contents').getWidth()/($('lightwindow_contents').getWidth()+(this.options.contentOffset.width))), sync: true,  scaleY: false, scaleContent: false}),
  1605.                     new Effect.Scale('lightwindow_container', 100*(ratio/(this.dimensions.container.width)), {sync: true, scaleY: false, scaleFromCenter: true, scaleContent: false})
  1606.                 ], {
  1607.                     duration: this.duration, 
  1608.                     delay: 0.25,
  1609.                     queue: {position: 'end', scope: 'lightwindowAnimation'}
  1610.                 }
  1611.             );        
  1612.         }
  1613.         
  1614.         ratio = this.dimensions.container.height-$('lightwindow_contents').getHeight()+this.resizeTo.height+this.options.contentOffset.height;
  1615.         if (ratio != $('lightwindow_container').getHeight()) {
  1616.             new Effect.Parallel([
  1617.                     new Effect.Scale('lightwindow_contents', 100*(this.resizeTo.height/$('lightwindow_contents').getHeight()), {scaleFrom: 100*($('lightwindow_contents').getHeight()/($('lightwindow_contents').getHeight()+(this.options.contentOffset.height))), sync: true, scaleX: false, scaleContent: false}),
  1618.                     new Effect.Scale('lightwindow_container', 100*(ratio/(this.dimensions.container.height)), {sync: true, scaleX: false, scaleFromCenter: true, scaleContent: false})
  1619.                 ], {
  1620.                     duration: this.duration, 
  1621.                     afterFinish: function() {                
  1622.                         if (this.dimensions.dataEffects.length > 0) {
  1623.                             if (!this.options.hideGalleryTab) {
  1624.                                 $('lightwindow_galleries').setStyle({
  1625.                                     width: this.resizeTo.width+'px'
  1626.                                 });
  1627.                             }
  1628.                             new Effect.Parallel(this.dimensions.dataEffects, {
  1629.                                     duration: this.duration,
  1630.                                     afterFinish: function() {
  1631.                                         this._finishWindow();
  1632.                                     }.bind(this),
  1633.                                     queue: {position: 'end', scope: 'lightwindowAnimation'} 
  1634.                                 }
  1635.                             );
  1636.                         }
  1637.                     }.bind(this), 
  1638.                     queue: {position: 'end', scope: 'lightwindowAnimation'} 
  1639.                 }
  1640.             );
  1641.             resized = true;
  1642.         }
  1643.         
  1644.         // We need to do our data effect since there was no resizing
  1645.         if (!resized && this.dimensions.dataEffects.length > 0) {    
  1646.             new Effect.Parallel(this.dimensions.dataEffects, {
  1647.                     duration: this.duration,
  1648.                     beforeStart: function() {
  1649.                         if (!this.options.hideGalleryTab) {
  1650.                             $('lightwindow_galleries').setStyle({
  1651.                                 width: this.resizeTo.width+'px'
  1652.                             });
  1653.                         }
  1654.                         if (this.containerChange.height != 0 || this.containerChange.width != 0) {
  1655.                             new Effect.MoveBy('lightwindow_container', this.containerChange.height, this.containerChange.width, {transition: Effect.Transitions.sinoidal});
  1656.                         }
  1657.                     }.bind(this),            
  1658.                     afterFinish: function() {
  1659.                         this._finishWindow();
  1660.                     }.bind(this),
  1661.                     queue: {position: 'end', scope: 'lightwindowAnimation'} 
  1662.                 }
  1663.             );
  1664.         }            
  1665.         
  1666.     },
  1667.     //
  1668.     //  Finish up Window Animation
  1669.     //
  1670.     _defaultfinalWindowAnimationHandler : function(delay) {
  1671.         if (this.windowType == 'media' || this._getParameter('lightwindow_loading_animation')) {    
  1672.             // Because of major flickering with the overlay we just hide it in this case
  1673.             Element.hide('lightwindow_loading');
  1674.             this._handleNavigation(this.activeGallery);
  1675.             this._setStatus(false);
  1676.         } else {
  1677.             Effect.Fade('lightwindow_loading', {
  1678.                 duration: 0.75,
  1679.                 delay: 1.0, 
  1680.                 afterFinish: function() {
  1681.                     // Just in case we need some scroll goodness (this also avoids the swiss cheese effect)
  1682.                     if (this.windowType != 'image' && this.windowType != 'media' && this.windowType != 'external') {
  1683.                         $('lightwindow_contents').setStyle({
  1684.                             overflow: 'auto'
  1685.                         });
  1686.                     }
  1687.                     this._handleNavigation(this.activeGallery);
  1688.                     this._defaultGalleryAnimationHandler();
  1689.                     this._setStatus(false);
  1690.                 }.bind(this),
  1691.                 queue: {position: 'end', scope: 'lightwindowAnimation'}
  1692.             });
  1693.         }
  1694.     },
  1695.     //
  1696.     //  Handle the gallery Animation
  1697.     //
  1698.     _defaultGalleryAnimationHandler : function(list) {
  1699.         if (this.activeGallery) {
  1700.             $('lightwindow_galleries').setStyle({
  1701.                 display: 'block',
  1702.                 marginBottom: $('lightwindow_data_slide').getHeight()+this.options.contentOffset.height/2+'px'
  1703.             });
  1704.             $('lightwindow_navigation').setStyle({
  1705.                 height: $('lightwindow_contents').getHeight()-20+'px'
  1706.             });
  1707.         } else {
  1708.             $('lightwindow_galleries').setStyle({
  1709.                 display: 'none'
  1710.             });    
  1711.             $('lightwindow_galleries_tab_container').setStyle({
  1712.                 height: '0px',
  1713.                 marginTop: '20px'
  1714.             });
  1715.             $('lightwindow_galleries_list').setStyle({
  1716.                 height: '0px'
  1717.             });
  1718.             return false;
  1719.         }
  1720.         
  1721.         if (list) {
  1722.             if ($('lightwindow_galleries_list').getHeight() == 0) {
  1723.                 var height = $('lightwindow_contents').getHeight()*0.80;
  1724.                 $('lightwindow_galleries_tab_span').className = 'down';
  1725.             } else {
  1726.                 var height = 0;
  1727.                 $('lightwindow_galleries_tab_span').className = 'up';
  1728.             }
  1729.  
  1730.             new Effect.Morph('lightwindow_galleries_list', {
  1731.                 duration: this.duration,
  1732.                 transition: Effect.Transitions.sinoidal,
  1733.                 style: {height: height+'px'},
  1734.                 beforeStart: function() {
  1735.                     $('lightwindow_galleries_list').setStyle({
  1736.                         overflow: 'hidden'
  1737.                     });                    
  1738.                 },
  1739.                 afterFinish: function() {
  1740.                     $('lightwindow_galleries_list').setStyle({
  1741.                         overflow: 'auto'
  1742.                     });
  1743.                 },
  1744.                 queue: {position: 'end', scope: 'lightwindowAnimation'}
  1745.             });    
  1746.         }
  1747.         
  1748.         
  1749.     },
  1750.     //
  1751.     //  Default Transition Handler
  1752.     //
  1753.     _defaultTransitionHandler : function() {
  1754.         // Clean out our effects
  1755.         this.dimensions.dataEffects = [];
  1756.  
  1757.         // Now that we have figures out the cruft lets make the caption go away and add its effects
  1758.         if ($('lightwindow_data_slide').getStyle('display') != 'none') {
  1759.             this.dimensions.dataEffects.push(
  1760.                 new Effect.SlideUp('lightwindow_data_slide', {sync: true}),
  1761.                 new Effect.Fade('lightwindow_data_slide', {sync: true, from: 1.0, to: 0.0})
  1762.             );
  1763.         }
  1764.         
  1765.         if (!this.options.hideGalleryTab) {
  1766.             if ($('lightwindow_galleries').getHeight() != 0 && !this.options.hideGalleryTab) {
  1767.                 this.dimensions.dataEffects.push(
  1768.                     new Effect.Morph('lightwindow_galleries_tab_container', {sync: true, style: {height: '0px', marginTop: '20px'}})
  1769.                 );
  1770.             }
  1771.             
  1772.             if ($('lightwindow_galleries_list').getHeight() != 0) {
  1773.                 $('lightwindow_galleries_tab_span').className = 'up';
  1774.                 this.dimensions.dataEffects.push(
  1775.                     new Effect.Morph('lightwindow_galleries_list', {
  1776.                         sync: true, 
  1777.                         style: {height: '0px'},
  1778.                         transition: Effect.Transitions.sinoidal,
  1779.                         beforeStart: function() {
  1780.                             $('lightwindow_galleries_list').setStyle({
  1781.                                 overflow: 'hidden'
  1782.                             });                    
  1783.                         },
  1784.                         afterFinish: function() {
  1785.                             $('lightwindow_galleries_list').setStyle({
  1786.                                 overflow: 'auto'
  1787.                             });
  1788.                         }
  1789.                     })
  1790.                 );
  1791.             }
  1792.         }
  1793.         
  1794.         // We always want the title bar as well
  1795.         this.dimensions.dataEffects.push(
  1796.             new Effect.Morph('lightwindow_title_bar_inner', {sync: true, style: {height: '0px', marginTop: this.options.dimensions.titleHeight+'px'}}),
  1797.              new Effect.Fade('lightwindow_title_bar_inner', {sync: true, from: 1.0, to: 0.0})
  1798.         );
  1799.  
  1800.         new Effect.Parallel(this.dimensions.dataEffects, {
  1801.                 duration: this.duration,
  1802.                 afterFinish: function() {
  1803.                     this._loadWindow();
  1804.                 }.bind(this),
  1805.                 queue: {position: 'end', scope: 'lightwindowAnimation'} 
  1806.             }
  1807.         );    
  1808.     },
  1809.     //
  1810.     //    Default Form handler for LightWindow
  1811.     //
  1812.     _defaultFormHandler : function(e) {
  1813.         var element = Event.element(e).parentNode;
  1814.         var parameterString = Form.serialize(this._getParameter('lightwindow_form', element.getAttribute('params')));
  1815.         if (this.options.formMethod == 'post') {
  1816.             var newAJAX = new Ajax.Request(element.href, { 
  1817.                 method: 'post', 
  1818.                 postBody: parameterString, 
  1819.                 onComplete: this.openWindow.bind(this, element)
  1820.             });
  1821.         } else if (this.options.formMethod == 'get') {
  1822.             var newAJAX = new Ajax.Request(element.href, { 
  1823.                 method: 'get', 
  1824.                 parameters: parameterString, 
  1825.                 onComplete: this.openWindow.bind(this, element)
  1826.             });
  1827.         }
  1828.     },
  1829.     // 
  1830.     //  Wrap everything up
  1831.     //
  1832.     _finishWindow : function() {
  1833.         if (this.windowType == 'external') {
  1834.             // We set the externals source here because it allows for a much smoother animation
  1835.             $('lightwindow_iframe').setAttribute('src', this.element.href);
  1836.             this._handleFinalWindowAnimation(1);    
  1837.         } else if (this.windowType == 'media') {
  1838.  
  1839.             var outerObject = document.createElement('object');
  1840.             outerObject.setAttribute('classid', this.options.classids[this._fileExtension(this.contentToFetch)]);
  1841.             outerObject.setAttribute('codebase', this.options.codebases[this._fileExtension(this.contentToFetch)]);
  1842.             outerObject.setAttribute('id', 'lightwindow_media_primary');
  1843.             outerObject.setAttribute('name', 'lightwindow_media_primary');
  1844.             outerObject.setAttribute('width', this.resizeTo.width);
  1845.             outerObject.setAttribute('height', this.resizeTo.height);
  1846.             outerObject = this._addParamToObject('movie', this.contentToFetch, outerObject);
  1847.             outerObject = this._addParamToObject('src', this.contentToFetch, outerObject);
  1848.             outerObject = this._addParamToObject('controller', 'true', outerObject);
  1849.             outerObject = this._addParamToObject('wmode', 'transparent', outerObject);
  1850.             outerObject = this._addParamToObject('cache', 'false', outerObject);
  1851.             outerObject = this._addParamToObject('quality', 'high', outerObject);
  1852.  
  1853.             if (!Prototype.Browser.IE) {
  1854.                 var innerObject = document.createElement('object');
  1855.                 innerObject.setAttribute('type', this.options.mimeTypes[this._fileExtension(this.contentToFetch)]);
  1856.                 innerObject.setAttribute('data', this.contentToFetch);
  1857.                 innerObject.setAttribute('id', 'lightwindow_media_secondary');
  1858.                 innerObject.setAttribute('name', 'lightwindow_media_secondary');
  1859.                 innerObject.setAttribute('width', this.resizeTo.width);
  1860.                 innerObject.setAttribute('height', this.resizeTo.height);
  1861.                 innerObject = this._addParamToObject('controller', 'true', innerObject);
  1862.                 innerObject = this._addParamToObject('wmode', 'transparent', innerObject);
  1863.                 innerObject = this._addParamToObject('cache', 'false', innerObject);
  1864.                 innerObject = this._addParamToObject('quality', 'high', innerObject);
  1865.             
  1866.                 outerObject.appendChild(innerObject);
  1867.             }    
  1868.             
  1869.             if (this._getParameter('lightwindow_iframe_embed')) {
  1870.                 this._appendIframe('no');
  1871.                 this._writeToIframe(this._convertToMarkup(outerObject, 'object'));
  1872.             } else {
  1873.                 this._appendObject(outerObject, 'object', $('lightwindow_contents'));
  1874.             }
  1875.  
  1876.             this._handleFinalWindowAnimation(0);
  1877.         } else {
  1878.             this._handleFinalWindowAnimation(0);
  1879.         }
  1880.  
  1881.         // Initialize any actions
  1882.         this._setupActions();
  1883.     }
  1884. }
  1885.  
  1886. /*-----------------------------------------------------------------------------------------------*/
  1887.  
  1888. Event.observe(window, 'load', lightwindowInit, false);
  1889.  
  1890. //
  1891. //    Set up all of our links
  1892. //
  1893. /*
  1894. var myLightWindow = null;
  1895. function lightwindowInit() {
  1896.     myLightWindow = new lightwindow();
  1897. }
  1898. */
  1899. var myLightWindow = null;
  1900. function lightwindowInit() {
  1901.     myLightWindow = new lightwindow();
  1902.  
  1903.     // The following was added to run code immediately
  1904.     // after this library loads and instantiates the
  1905.     // myLightWindow object.
  1906.     // ***********************
  1907.     // In the code on the main page weΓÇÖll need to create a
  1908.     // lightWindow_DoneLoading() function that catches
  1909.     // the the pseudo-event.
  1910.     // ***********************
  1911.     // Not elegant.
  1912.     // Tightly coupled.
  1913.     // But at least we check for the existence of
  1914.     // the lightWindow_DoneLoading() function before
  1915.     // we try calling it.
  1916.     if(('function' == typeof window.lightWindow_DoneLoading)){
  1917.         lightWindow_DoneLoading();
  1918.     }
  1919. }