﻿/*
extensions - 1.1.0

A collection of Prototype-based external libraries built mostly by others (but freely available and editable
through MIT-style licensing).  These will serve as the effects for all client-based effects.

Change History:

1.1.0 - 12/29/2008
Added Prototype Showcase (by Victor Stanciu, http://dev.victorstanciu.ro/experimente/prototype-showcase/).
Added Prototype Carousel (by Victor Stanciu, http://dev.victorstanciu.ro/experimente/prototype-carousel/en/)

1.0.1 - 12/29/2008
Tweaks made to lightwindow for proprietary backward compatibility with moodalbox .

1.0.0 - 12/29/2008
Final list of prototype extensions is complete and committed.  The list is as follows:
- Loading - click any element and produce an AJAX-like loading symbol above if (z-index + 1)
This has been tweaked from the original Protoload (see comments below)
- Tips - put a tip on any element based on class name.
Original design, pretty good considering this is the first version
- Watermark - input watermarker
This has been tweaked from the original undefaultvalue (see comments below)
- Fader - fade a container's child elements in and out
Original design, not the best, but good for a first version
- SkyByte libraries - for mouse effects and drag/drop/resize capabilities
SkyByte verbatim libraries, nothing changed
- LightWindow - modal box for lots of different media types
Tweaked version of the original lightwindow (see comments below)

*/


/*  LoadView
*   Nathan Rose, 12/21/2008
*
*   Based on Protoload (Andreas Kalsch, http://aka-fotos.de/protoload/) with some changes thrown in.
*
*   Major Changes:
*   -  completely prototypey, made the code smaller and got rid of offset bug
*/
Loading = {
    showLoading: function(element, loadingImageSrc) {
        $(element)._waiting = true;

        if (!$(element)._loading) {
            var loading = new Element('div');
            $$('body')[0].appendChild(loading);

            loading.setStyle({
                display: 'none',
                zIndex: $(element).getStyle('zIndex') + 1,
                position: 'absolute',
                left: $(element).cumulativeOffset()[0] + 'px',
                top: $(element).cumulativeOffset()[1] + 'px',
                height: $(element).getHeight() + 'px',
                width: $(element).getWidth() + 'px',
                lineHeight: $(element).getHeight() + 'px',
                textAlign: 'center',
                margin: 'auto',
                verticalAlign: 'middle',
                backgroundColor: '#ffffff',
                backgroundImage: 'url(' + loadingImageSrc + ')',
                backgroundPosition: 'center center',
                backgroundRepeat: 'no-repeat'
            });

            $(element)._loading = loading.identify();

            if (typeof Effect == 'undefined') {
                loading.setOpacity(0.6);
                loading.show();
            }
            else {
                loading.appear({ duration: 0.4, to: 0.6 });
            }
        }
    },

    hideLoading: function(element) {
        if ($(element)._waiting) {
            if (typeof Effect == 'undefined') {
                $($(element)._loading).hide();
            }
            else {
                $($(element)._loading).fade({
                    duration: 0.4,
                    afterFinish: function() {
                        $(element).waiting = false;

                        $($(element)._loading).remove();
                        $(element)._loading = null;
                    }
                });
            }

        }
    }
};

if (Prototype) {
    Element.addMethods(Loading);
    Object.extend(Element, Loading);
}



/*  Tips
*   Nathan Rose, 12/22/2008
*
*   TODO:  Documentation
*
*/
Tips = Class.create({
    initialize: function(element, className) {
        this.element = element;

        //  Make sure we replace all titles and alts with blank strings, 
        //  fill custom element attributes with these values instead
        if (this.element.tagName.toLowerCase() == 'a') {
            this._title = element.title;
            this._tip = element.rel;
            this.element.title = '';
            this.element.rel = '';

            //            if (this.element.firstDescendant().tagName.toLowerCase() == 'img') {
            //                this.element.firstDescendant().alt = '';
            //            }
        }
        else if (this.element.tagName.toLowerCase() == 'img') {
            this._tip = element.alt;
            this.element.alt = '';
        }
        this._tipID = '';
        this._tipClass = className;
        this._tipOffsetX = 20;
        this._tipOffsetY = 25;

        element.observe('mouseover', this.onMouseOver.bind(this));
        element.observe('mousemove', this.onMouseMove.bind(this));
        element.observe('mouseout', this.onMouseOut.bind(this));
    },

    onMouseOver: function(event) {
        if (this._tipID == '') {
            var tip = document.body.appendChild(this.getTipBody(this._title, this._tip));
            this._tipID = tip.identify();

            this.setTipPosition(event);

            if (typeof Effect == 'undefined') {
                tip.show().delay(0.2);
            }
            else {
                tip.appear({ delay: 0.2, duration: 0.2 });
            }
        }
    },

    onMouseMove: function(event) {
        if (this._tipID != '') {
            this.setTipPosition(event);
        }
    },

    onMouseOut: function(event) {
        if (this._tipID != '') {
            var tip = $(this._tipID);
            var tipID = this._tipID;
            this._tipID = '';
            if (typeof Effect == 'undefined') {
                tip.hide();
            }
            else {
                tip.fade({
                    duration: 0.2,
                    afterFinish: function(tipID) {
                        $(tipID.element).remove();
                    }
                });
            }
        }
    },

    getTipBody: function(title, tip) {
        //  The div style is completely dependent upon what was passed into the constructor
        //  Be sure to set your div.<className>, div.<className> h3 and div.<className> div
        //  in your stylesheets.
        var container = new Element('div', { style: 'display: none;' }).addClassName(this._tipClass);
        var title = new Element('div').update(title);
        var tip = new Element('span').update(tip);

        container.appendChild(title);
        container.appendChild(tip);

        return container;
    },

    setTipPosition: function(event) {
        $(this._tipID).setStyle({
            position: 'absolute',
            left: (event.pointerX() + this._tipOffsetX) + 'px',
            top: (event.pointerY() + this._tipOffsetY) + 'px'
        });
    }
});


/*  Watermark
*   Nathan Rose, 12/24/2008
*
*   Based on Default Value (by Jan Jarfalk, http://www.unwrongest.com/projects/default-value-prototype/)
*
*/
Watermark = Class.create({
    initialize: function(element, className) {
        this.element = element;

        this._watermarkText = (element.title.strip() || 'Enter your text');
        this._watermarkClass = className;

        //  NR:  12/30/2008
        //  Small bug fix
        //if ((this.element.value == 'undefined') || (this.element.value.strip().length == 0)) this.element.value = this._watermarkText;

        if (this.element.value.strip().length == 0 || this.element.value == 'undefined' || this.element.value == this._watermarkText) {
            this.element.value = this._watermarkText;
            this.element.addClassName(this._watermarkClass);
        }

        if (this.element.value.strip().length > 0 && this.element.value != this._watermarkText) {
            this.element.removeClassName(this._watermarkClass);
        }

        element.observe('click', this.onClick.bind(this));
        element.observe('blur', this.onBlur.bind(this));
    },

    onFocus: function(event) {
        if (this.element.value == this._watermarkText) {
            this.element.value = '';
            this.element.removeClassName(this._watermarkClass);
        }
    },

    onClick: function(event) {
        if (this.element.value == this._watermarkText) {
            this.element.value = '';
            this.element.removeClassName(this._watermarkClass);
        }
    },

    onBlur: function(event) {
        if ((this.element.value.strip().length <= 0) || (this.element.value == this._watermarkText)) {
            this.element.value = this._watermarkText;
            this.element.addClassName(this._watermarkClass);
        }
    }
});


/*  Fader
*   Nathan Rose, 12/27/2008
*
*   Fades all elements in a container in and out based on their index in the container childElements array.
*
*/
Fader = Class.create({
    initialize: function(container, fadeDuration, staticDuration) {
        this.container = $(container);
        this.currentIndex = 0;
        this.childElements = this.container.childElements();
        this.fadeDuration = fadeDuration;
        this.staticDuration = staticDuration;
        this.mouseOver = false;

        this.container.setStyle({ position: 'relative' });
        if (this.container.tagName.toLowerCase() == 'ul') this.container.setStyle({ listStyleType: 'none', margin: '0px', padding: '0px' });

        this.container.observe('mouseover', this.onMouseOver.bind(this));
        this.container.observe('mouseout', this.onMouseOut.bind(this));

        this.childElements.each(function(e) {
            e.setStyle({ position: 'absolute' });
            if (this.currentIndex++ > 0) {
                e.hide();
            }
        } .bind(this));

        this.currentIndex = 0;

        new PeriodicalExecuter(function() {
            if (!this.mouseover) {
                this.childElements[this.currentIndex].fade({ duration: this.fadeDuration });
                if (this.currentIndex == this.childElements.length - 1) {
                    this.currentIndex = 0;
                }
                else {
                    this.currentIndex++;
                }
                this.childElements[this.currentIndex].appear({ duration: this.fadeDuration });
            }
        } .bind(this), this.staticDuration);
    },

    onMouseOver: function(event) {
        this.mouseover = true;
    },

    onMouseOut: function(event) {
        this.mouseover = false;
    }
});

/*******************************************************************************************************************************************************************/
/*                                                                         SkyByte Library                                                                         */
/*******************************************************************************************************************************************************************/


/*  SkyByte.js v1.0-beta, May 17 2007
*  (c) 2007 Aleksandras Ilarionovas (Alex)
*
*  SkyByte.js is freely distributable under the terms of an MIT-style license.
*  For details, see the SkyByte.net web site: http://www.skybyte.net/scripts/
*
*--------------------------------------------------------------------------*/

if (typeof Prototype === 'undefined') { throw ("SkyByte.js requires Prototype.js library"); }
var SkyByte = { Version: '1.2' };

//--------------------------------------------------------------------------
var Browser = {
    cursor: function(cur) { document.body.style.cursor = cur; }
};
function debug(o) { s = ''; for (var n in o) { s += n + ':' + o[n] + '\n'; } alert(s); }

//--------------------------------------------------------------------------
// Syntax: Mouse.start(object: optional) where object._mouseMove(e) = callback function or empty parameter
//         Mouse.stop(object: optional)
// Return: Mouse.x, Mouse.y = current mouse coordinates
var Mouse = {
    callbacks: [], x: 0, y: 0, event: null,
    start: function(obj) { //start callback or just start observing mouse coordinates
        obj = obj || 'global';
        if (this.callbacks.length === 0) {
            this.eventMouseMove = this._mouseMove.bindAsEventListener(this); Event.observe(document, "mousemove", this.eventMouseMove);
        }
        var found = this.callbacks.detect(function(d) { return d == obj; });
        if (!found) { this.callbacks.push(obj); }
    },
    stop: function(obj) { //stop callback or stop observing all
        obj = obj || 'global';
        this.callbacks = this.callbacks.reject(function(d) { return d == obj; });
        if (this.callbacks.length === 0) {
            Event.stopObserving(document, "mousemove", this.eventMouseMove);
        }
    },
    _mouseMove: function(e) {
        var o, i; this.x = Event.pointerX(e); this.y = Event.pointerY(e); this.event = e;
        if (Mouse.callbacks) {
            for (i = 0, len = Mouse.callbacks.length; i < len; ++i) {
                o = Mouse.callbacks[i];
                if (typeof o == 'object') { o._mouseMove(e); }
            }
        }
    }
};
//--------------------------------------------------------------------------
Object.extend(Element, {
    add: function(el, attr, style, opt) {
        var d;
        for (var n in opt) { val = opt[n]; if (n == 'clone') { d = val.cloneNode(true); } }
        if (!d) { d = document.createElement(el); }
        for (n in attr) { d.setAttribute(n, attr[n]); }
        for (n in style) { d.style[n.camelize()] = style[n]; }
        for (n in opt) {
            val = opt[n];
            switch (n) {
                case 'a': if (typeof val == 'string') { val = $(val); } d = val.appendChild(d); break;
                case 'c': d.className = val; break;
                case 'id': d.id = val; break;
                case 'txt': //IE6 bug: The innerHTML property of the TABLE, TFOOT, THEAD, and TR elements are read-only.
                    if (d.tagName == "TABLE" || d.tagName == "TFOOT" || d.tagName == "THEAD" || d.tagName == "TR") {

                    } else if (d.innerHTML) { d.innerHTML = val; }
                    break;
            }
        } return d;
    },
    rem: function(el) { if (el.parentNode) { d = el.parentNode.removeChild(el); return d; } },
    putAt: function(target, c) {
        if (target) {
            target.style.left = c.x + 'px';
            target.style.top = c.y + 'px';
        }
    },
    showAt: function(target, c) {
        if (target) {
            target.style.left = c.x + 'px';
            target.style.top = c.y + 'px';
            target.style.width = c.w + 'px';
            target.style.height = c.h + 'px';
        }
    },
    xywh: function(el) {  //x,y,width,height
        var d = Element.getDimensions(el); 	//={w,h} of the object
        var c = Position.cumulativeOffset(el); //={x,y} absolute offset from the top-left corner
        return { x: c[0], y: c[1], w: d.width, h: d.height };
    },
    wh: function(el) {	//=width/height
        var d = Element.getDimensions(el); 	//={w,h} of the object
        return { w: d.width, h: d.height };
    }
});

/*  SkyByteDD.js v1.0-beta, May 17 2007
*  (c) 2007 Aleksandras Ilarionovas (Alex)
*
*  SkyByteDD.js is freely distributable under the terms of an MIT-style license.
*  For details, see the SkyByte.net web site: http://www.skybyte.net/scripts/
*
*--------------------------------------------------------------------------*/

if (typeof Prototype == 'undefined') { throw ("SkyByteDD.js requires Prototype.js library"); }
else if (typeof SkyByte == 'undefined') { throw ("SkyByteDD.js requires SkyByte.js library"); }

var SkyByteDD = { Version: '1.2' };

var Drags = {
    drag: null,
    drags: [],
    hide: { x: -100, y: -100, w: 0, h: 0 },
    register: function(obj) {
        if (this.drags.length === 0) {
            Mouse.start(this);
            this.eventMouseUp = this._mouseUp.bindAsEventListener(this); Event.observe(document, "mouseup", this.eventMouseUp);
            if (navigator.appVersion.match(/\bMSIE\b/)) {
                this.eventMouseOver = this._mouseOver.bindAsEventListener(this);
                this.eventMouseOut = this._mouseOut.bindAsEventListener(this);
            }
            this.div = Element.add('div', {}, {}, { a: document.body, c: 'dragmove' });
            document.body.onselectstart = function() { return false; }; //disable selection in IE
        }
        this.drags.push(obj);
    },
    unregister: function(el) {
        this.drags = this.drags.reject(function(d) { return d.element == el; });
    },
    is_drag: function(el) {
        return this.drags.detect(function(d) { return d.element == el; });
    },
    destroy: function() {
        var i, o, len;
        if (this.drags.length > 0) {
            this.drag = null; //could be that elements activated with Drags.activate(el) function
            $A(this.drags).each(function(o) {
                if (typeof o.destroy === 'function') { o.destroy(); } //so they don't have destroy function from the start
            });
        }
        if (this.drags.length === 0 && this.div) {
            Element.rem(this.div); Mouse.stop(this);
            Event.stopObserving(document, "mouseup", this.eventMouseUp);
        }
    },
    activate: function(drag, e) {
        this.drag = drag; this.drag.IE = false;
        if (this.drag.element.tagName === 'IMG' && navigator.appVersion.match(/\bMSIE\b/)) {
            //IE6 fix: when dragging images, loosing mouseover/mouseout event, so we fire those events on entire document
            this.drag.IE = true;
            Event.observe(document, "mouseover", this.eventMouseOver);
            Event.observe(document, "mouseout", this.eventMouseOut);
        }
    },
    deactivate: function() {
        if (this.drag.IE) {
            Event.stopObserving(document, "mouseover", this.eventMouseOver);
            Event.stopObserving(document, "mouseout", this.eventMouseOut);
        }
        this.drag = null;
    },
    //--------------------IE only----------------------
    //IE6 ugly walkaround: manually detect if drop zone is over mouse and fire event
    _mouseOver: function(e) {
        var d = Drops.is_drop(Event.element(e));
        if (d) {
            Drops.drop = d;
            Drops.show_frame();
        }
    },
    //IE6 ugly walkaround
    _mouseOut: function(e) {
        if (Drops && Drops.lastActive && typeof Drops.lastActive.options.mouseOut === 'function') {
            Drops.lastActive.options.mouseOut(Drops.lastActive.element);
            Drops.lastActive = null;
        }
        Drops.hide_frame();
        Drops.drop = null;
    },
    //--------------------ALL Other--------------------
    _mouseMove: function(e) {
        if (!this.drag) { return; }
        this.drag._mouseMove(e); //Call MouseMove
        Event.stop(e);
    },
    _mouseUp: function(e) {
        if (!this.drag) { return; }
        this.drag._mouseUp(e);  //Call MouseUp
        this.drag = null;
        Event.stop(e);
    }
};
//---------------------------------------------------------------------------------------------

var Drag = Class.create();
Drag.prototype = {
    initialize: function(el) {
        this.element = $(el);
        this.options = Object.extend({
            self: false,
            classname: 'drag',
            caption: '', 	//moving...
            affect: false 	//set different rules for all drop zones
        }, arguments[1] || {});
        if (this.options.self) {
            this.options.self = this.element.parentNode; Element.makePositioned(this.options.self);
        }
        this.eventMouseDown = this._mouseDown.bindAsEventListener(this); Event.observe(this.element, "mousedown", this.eventMouseDown);
        Drags.register(this);
    },
    destroy: function() {
        Event.stopObserving(this.element, "mousedown", this.eventMouseDown);
        Drags.unregister(this.element);
    },
    currentDelta: function() {
        return ([
	  parseInt(Element.getStyle(this.options.self, 'left') || '0'),
	  parseInt(Element.getStyle(this.options.self, 'top') || '0')]);
    },
    _mouseDown: function(e) {
        var el, pointer, pos;
        if (this.options.self) {
            el = this.options.self;
            pointer = [Mouse.x, Mouse.y];
            pos = Position.cumulativeOffset(el);
            this.offset = [0, 1].map(function(i) { return (pointer[i] - pos[i]); });
        }

        Browser.cursor('default');
        Drops.affect = this.options.affect; //tell Drops that this element needs different rules
        Drags.activate(this);
        Event.stop(e);
    },
    _mouseUp: function(e) {
        var ok;
        //.........call drop function when mouse released
        Element.putAt(Drags.div, Drags.hide);
        if (this.element && Drops.drop && (this.element != Drops.drop.element)) {
            if (Drops.drop.options.accept === this.element.tagName) { ok = true; }
            if (Drops.drop.options.accept === '') { ok = true; }
            if (Drops.affect) { ok = true; }
            if (ok) {
                if (typeof Drops.drop.options.mouseUp === 'function') {
                    Drops.drop.options.mouseUp(Drops.drop.element, this.element);
                }
            }
        }
        //.........
        Drops.affect = false; //tell Drops to return to normal state
        Drags.deactivate();
        Drops.hide_frame();
        //Event.stop(e); //already stopped
    },
    _mouseMove: function(e) {
        var ok, d, pos, point, p, style, el, div, caption;
        if (this.options.self) {
            el = this.options.self;
            pos = Position.cumulativeOffset(el);
            d = this.currentDelta();
            pos[0] -= d[0]; pos[1] -= d[1];
            point = []; point.push(Mouse.x); point.push(Mouse.y);
            p = [0, 1].map(function(i) { return (point[i] - pos[i] - this.offset[i]) } .bind(this));
            style = el.style;
            style.left = p[0] + "px";
            style.top = p[1] + "px";
        } else {
            //.........set default drag style and caption
            div = Drags.div; div.className = 'dragmove'; caption = this.options.caption;
            if (this.element && Drops.drop && (this.element != Drops.drop.element)) {
                if (Drops.drop.options.accept && Drops.drop.options.accept === this.element.tagName) { ok = true; }
                if (Drops.drop.options.accept === '') { ok = true; }
                if (Drops.affect) { ok = true; }
                if (ok) {
                    cap = Drops.drop.options.caption;
                    if (cap) { caption = cap; } //take message from Drop Area?
                    div.className = this.options.classname;
                    if (typeof Drops.drop.options.mouseOver === 'function') {
                        Drops.lastActive = Drops.drop;
                        Drops.drop.options.mouseOver(Drops.drop.element, this.element);
                    }
                }
            }
            //.........place div at cursor
            div.innerHTML = caption; Mouse.x += 15; Mouse.y += 10; Element.putAt(div, Mouse);
            //.........
        }
        //Event.stop(e); //already stopped
    }

};

//---------------------------------------------------------------------------------------------
var Drops = {
    lastActive: null,
    frameactive: null,
    drop: null,
    affect: null,
    drops: [],
    hide: { x: -10, y: -10, w: 0, h: 0 },
    register: function(obj) {
        if (this.drops.length === 0) {
            this.L = Element.add('div', {}, {}, { a: document.body, c: 'drop' });
            this.R = Element.add('div', {}, {}, { a: document.body, c: 'drop' });
            this.T = Element.add('div', {}, {}, { a: document.body, c: 'drop' });
            this.B = Element.add('div', {}, {}, { a: document.body, c: 'drop' });
        }
        this.drops.push(obj);
    },
    unregister: function(el) {
        this.hide_frame(); //hide frame if mouse over zone
        this.drops = this.drops.reject(function(d) { return d.element == el; });
    },
    destroy: function() {
        var i, o, len;
        if (this.drops.length > 0) {
            Element.rem(this.L); Element.rem(this.R); Element.rem(this.T); Element.rem(this.B);
            $A(this.drops).each(function(o) {
                if (typeof o.destroy === 'function') { o.destroy(); } //so they don't have destroy function from the start
            });
            this.drop = null;
            this.hide_frame(); //hide frame if mouse over zone
        }
    },
    is_drop: function(el) {
        return this.drops.detect(function(d) { return d.element == el; });
    },
    show_frame: function() {
        this.frameactive = true;
        var pointer = Element.xywh(this.drop.element);
        this.L.className = this.drop.options.classname;
        this.R.className = this.drop.options.classname;
        this.T.className = this.drop.options.classname;
        this.B.className = this.drop.options.classname;
        Element.showAt(this.L, { x: pointer.x, y: pointer.y, w: 1, h: pointer.h });
        Element.showAt(this.R, { x: (pointer.x + pointer.w), y: pointer.y, w: 1, h: pointer.h });
        Element.showAt(this.T, { x: pointer.x, y: pointer.y, w: pointer.w, h: 1 });
        Element.showAt(this.B, { x: pointer.x, y: (pointer.y + pointer.h), w: pointer.w, h: 1 });
    },
    hide_frame: function() {
        if (this.drops.length > 0 && this.frameactive) {
            this.frameactive = false;
            Element.showAt(this.L, this.hide);
            Element.showAt(this.R, this.hide);
            Element.showAt(this.T, this.hide);
            Element.showAt(this.B, this.hide);
        }
    }
};

//---------------------------------------------------------------------------------------------
var Drop = Class.create();
Drop.prototype = {
    initialize: function(el) {
        this.element = $(el);
        this.options = Object.extend({
            caption: '', 	//drop here
            classname: 'drop',
            accept: this.element.tagName,
            mouseUp: null,
            mouseOver: null,
            mouseOut: null
        }, arguments[1] || {});
        this.eventMouseOver = this._mouseOver.bindAsEventListener(this); Event.observe(this.element, "mouseover", this.eventMouseOver);
        this.eventMouseOut = this._mouseOut.bindAsEventListener(this); Event.observe(this.element, "mouseout", this.eventMouseOut);
        Drops.register(this);
    },
    destroy: function() {
        Event.stopObserving(this.element, "mouseover", this.eventMouseOver);
        Event.stopObserving(this.element, "mouseout", this.eventMouseOut);
        Drops.unregister(this.element);
    },
    _mouseOver: function(e) {
        var d = Drops.is_drop(Event.element(e));
        if (!d) { d = Drops.is_drop(this.element); }
        if (d) {
            Drops.drop = d;
            Drops.show_frame();
        }
        Event.stop(e);
    },
    _mouseOut: function(e) {
        if (Drops.lastActive && typeof Drops.lastActive.options.mouseOut === 'function') {
            Drops.lastActive.options.mouseOut(Drops.lastActive.element);
            Drops.lastActive = null;
        }
        Drops.drop = null;
        Drops.hide_frame();
        Event.stop(e);
    }
};
//---------------------------------------------------------------------------------------------

/*  SkyByteRS.js, May 17 2007
*  (c) 2007 Aleksandras Ilarionovas (Alex)
*
*  SkyByteRS.js is freely distributable under the terms of an MIT-style license.
*  For details, see the SkyByte.net web site: http://www.skybyte.net/scripts/
*
*--------------------------------------------------------------------------*/
if (!Prototype) { throw ("SkyByteRS.js requires Prototype.js library"); }
else if (!SkyByte) { throw ("SkyByteRS.js requires SkyByte.js library"); }
else if (!SkyByteDD) { throw ("SkyByteRS.js requires SkyByteDD.js library"); }

var SkyByteRS = { Version: '1.2.3' };

var Resizes = {
    resizes: [],
    resize: {},
    resizing: null,
    frameactive: false,
    register: function(obj) {
        if (this.resizes.length === 0) {

            this.L = Element.add('div', {}, { position: 'absolute', top: '-50px', left: '-50px' }, { c: 'resizel', a: document.body });
            this.R = Element.add('div', {}, { position: 'absolute', top: '-50px', left: '-50px' }, { c: 'resizer', a: document.body });
            this.T = Element.add('div', {}, { position: 'absolute', top: '-50px', left: '-50px' }, { c: 'resizet', a: document.body });
            this.B = Element.add('div', {}, { position: 'absolute', top: '-50px', left: '-50px' }, { c: 'resizeb', a: document.body });
            this.box = Element.add('div', {}, { position: 'absolute', top: '-50px', left: '-50px' }, { c: 'resizebox', a: document.body });

            this.TM = Element.add('div', {}, { cursor: 's-resize', overflow: 'hidden', position: 'absolute', top: '-50px', left: '-50px' }, { c: 'resizeknob', a: document.body }); Drags.register(this.TM);
            this.BM = Element.add('div', {}, { cursor: 's-resize', overflow: 'hidden', position: 'absolute', top: '-50px', left: '-50px' }, { c: 'resizeknob', a: document.body }); Drags.register(this.BM);
            this.LT = Element.add('div', {}, { cursor: 'se-resize', overflow: 'hidden', position: 'absolute', top: '-50px', left: '-50px' }, { c: 'resizeknob', a: document.body }); Drags.register(this.LT);
            this.LM = Element.add('div', {}, { cursor: 'e-resize', overflow: 'hidden', position: 'absolute', top: '-50px', left: '-50px' }, { c: 'resizeknob', a: document.body }); Drags.register(this.LM);
            this.LB = Element.add('div', {}, { cursor: 'ne-resize', overflow: 'hidden', position: 'absolute', top: '-50px', left: '-50px' }, { c: 'resizeknob', a: document.body }); Drags.register(this.LB);
            this.RT = Element.add('div', {}, { cursor: 'sw-resize', overflow: 'hidden', position: 'absolute', top: '-50px', left: '-50px' }, { c: 'resizeknob', a: document.body }); Drags.register(this.RT);
            this.RM = Element.add('div', {}, { cursor: 'e-resize', overflow: 'hidden', position: 'absolute', top: '-50px', left: '-50px' }, { c: 'resizeknob', a: document.body }); Drags.register(this.RM);
            this.RB = Element.add('div', {}, { cursor: 'nw-resize', overflow: 'hidden', position: 'absolute', top: '-50px', left: '-50px' }, { c: 'resizeknob', a: document.body }); Drags.register(this.RB);

            this.eventMouseDown = this._mouseDown.bindAsEventListener(this); //knob event
            this.eventMouseOver = this._mouseOver.bindAsEventListener(this); //knob event
            this.eventMouseOut = this._mouseOut.bindAsEventListener(this); //knob event
            this.eventClick = this._observeClick.bindAsEventListener(this); Event.observe(document, "mousedown", this.eventClick); //catch clicks outside element

            Event.observe(this.TM, "mousedown", this.eventMouseDown); Event.observe(this.TM, "mouseover", this.eventMouseOver); Event.observe(this.TM, "mouseout", this.eventMouseOut);
            Event.observe(this.BM, "mousedown", this.eventMouseDown); Event.observe(this.BM, "mouseover", this.eventMouseOver); Event.observe(this.BM, "mouseout", this.eventMouseOut);
            Event.observe(this.LT, "mousedown", this.eventMouseDown); Event.observe(this.LT, "mouseover", this.eventMouseOver); Event.observe(this.LT, "mouseout", this.eventMouseOut);
            Event.observe(this.LM, "mousedown", this.eventMouseDown); Event.observe(this.LM, "mouseover", this.eventMouseOver); Event.observe(this.LM, "mouseout", this.eventMouseOut);
            Event.observe(this.LB, "mousedown", this.eventMouseDown); Event.observe(this.LB, "mouseover", this.eventMouseOver); Event.observe(this.LB, "mouseout", this.eventMouseOut);
            Event.observe(this.RT, "mousedown", this.eventMouseDown); Event.observe(this.RT, "mouseover", this.eventMouseOver); Event.observe(this.RT, "mouseout", this.eventMouseOut);
            Event.observe(this.RM, "mousedown", this.eventMouseDown); Event.observe(this.RM, "mouseover", this.eventMouseOver); Event.observe(this.RM, "mouseout", this.eventMouseOut);
            Event.observe(this.RB, "mousedown", this.eventMouseDown); Event.observe(this.RB, "mouseover", this.eventMouseOver); Event.observe(this.RB, "mouseout", this.eventMouseOut);
        }

        this.resizes.push(obj);
    },
    unregister: function(el) {
        this.hide_frame();
        this.resizes = this.resizes.reject(function(d) { return d.element == el; });
    },
    destroy: function() {
        var i, o;
        if (this.resizes.length > 0) {
            $A(this.resizes).each(function(o) {
                if (o.destroy) { o.destroy(); }
            });
        }
        if (this.resizes.length === 0 && this.TM) {
            this.resize = {};
            Element.rem(this.T); Element.rem(this.B); Element.rem(this.L); Element.rem(this.R);
            Drags.unregister(this.TM); Element.rem(this.TM);
            Drags.unregister(this.TB); Element.rem(this.BM);
            Drags.unregister(this.LT); Element.rem(this.LT);
            Drags.unregister(this.LM); Element.rem(this.LM);
            Drags.unregister(this.LB); Element.rem(this.LB);
            Drags.unregister(this.RT); Element.rem(this.RT);
            Drags.unregister(this.RM); Element.rem(this.RM);
            Drags.unregister(this.RB); Element.rem(this.RB);
            Event.stopObserving(this, "mousedown", this.eventMouseDown);
            Event.stopObserving(this, "mouseover", this.eventMouseOver);
            Event.stopObserving(this, "mouseout", this.eventMouseOut);
            Event.stopObserving(document, "mousedown", this.eventClick);
        }
        this.hide_frame();
    },
    is_resize: function(el) {
        return this.resizes.detect(function(d) { return d.element == el; });
    },
    activate: function(el) {
        var r = Resizes.is_resize(el); if (!r) { return; }
        Resizes.resize = r; this.element = el;
        this.show_frame(Element.xywh(this.element));
    },
    deactivate: function() {
        this.hide_frame();
    },
    show_frame: function(c) {
        var opt = this.resize.options; if (this.resizes.length == 0) { return; }
        this.frameactive = true;
        if (opt.indicator == true) {
            this.box.innerHTML = c.w + 'x' + c.h; var bb = Element.wh(this.box);
            Element.putAt(this.box, { x: c.x + (c.w / 2) - (bb.w / 2), y: c.y + (c.h / 2) - (bb.h / 2) });
        }
        Element.showAt(this.L, { x: c.x, y: c.y, w: 1, h: c.h });
        Element.showAt(this.R, { x: (c.x + c.w), y: c.y, w: 1, h: c.h });
        Element.showAt(this.T, { x: c.x, y: c.y, w: c.w, h: 1 });
        Element.showAt(this.B, { x: c.x, y: (c.y + c.h), w: c.w, h: 1 });

        Element.putAt(this.TM, { x: c.x + ((c.w / 2) - 4), y: (c.y - 2) });
        Element.putAt(this.BM, { x: c.x + ((c.w / 2) - 4), y: c.y + (c.h - 4) });
        Element.putAt(this.LT, { x: (c.x - 3), y: (c.y - 2) });
        Element.putAt(this.LM, { x: (c.x - 3), y: c.y + ((c.h / 2) - 3) });
        Element.putAt(this.LB, { x: (c.x - 3), y: c.y + (c.h - 4) });
        Element.putAt(this.RT, { x: c.x + (c.w - 4), y: (c.y - 2) });
        Element.putAt(this.RM, { x: c.x + (c.w - 4), y: c.y + ((c.h / 2) - 3) });
        Element.putAt(this.RB, { x: c.x + (c.w - 4), y: c.y + (c.h - 4) });
    },
    hide_frame: function() {
        if (this.frameactive) {
            this.show_frame({ x: -50, y: -50, w: 10, h: 10 }); this.frameactive = false;
        }
    },
    border: function(el) {
        var cl = Element.add('div', {}, { background: 'red', border: '0', margin: 0, padding: 0, visibility: 'hidden' }, { clone: el, a: el.parentNode });
        var cwh = Element.wh(cl); var ewh = Element.wh(el); Element.rem(cl);
        return { w: (ewh.w - cwh.w), h: (ewh.h - cwh.h) };
    },
    minmax: function(src) {
        var i, o, xy;
        var minW = 0; var minH = 0; var maxW = 0; var maxH = 0;
        //1. find parent outer dimensions 760px;
        var div0 = Element.add('div', {}, {}, { a: src.parentNode }); var parXY = Element.wh(div0); Element.rem(div0);

        //2. find owner inner dimensions 300px;
        var div1 = Element.add('div', {}, { position: 'absolute', top: '0px', left: '0px' }, { a: document.body });
        var div2 = Element.add('div', {}, { width: 'auto', height: 'auto', float: 'left' }, { clone: src, txt: '', a: div1 });

        //3. find owner margins
        var outXY = Element.xywh(div1); var innXY = Element.xywh(div2); Element.rem(div1);
        var ml = innXY.x; var mt = innXY.y; var mr = outXY.w - (innXY.x + innXY.w); var mb = outXY.h - (innXY.y + innXY.h);

        //4. find owner inner dimensions 300px;
        var ownXY = Element.xywh(src);  //target element dimensions
        var els = src.getElementsByTagName('*');
        for (i = 0, len = els.length; i < len; ++i) {
            o = els[i];
            xy = Element.xywh(o); mW = xy.x + xy.w; mH = xy.y + xy.h; if (mW > minW) { minW = mW; } if (mH > minH) { minH = mH; }
        }

        var a = {};
        a.minW = minW - ownXY.x; if (a.minW < 0) { a.minW = 0; }
        a.minH = minH - ownXY.y; if (a.minH < 0) { a.minH = 0; }
        a.maxW = (parXY.w - mr - ml); a.maxH = (parXY.h - mt - mb); //= maxW(760) - margin left - margin right = 740
        a.w = ownXY.w; a.h = ownXY.h;
        //IE bug: element "margin:0 auto;" will return huge margins, [ ...300...] [element] [...300...]
        if (a.maxW <= 0 || a.maxW < ownXY.w) { a.maxW = parXY.w; } //=parXY.w 
        if (a.maxH <= 0 || a.maxH < ownXY.h) { a.maxH = 0; } //=parXY.h  
        return a;
    },
    _mouseMove: function(e) {
        var rA; if (!this.init) { return; }
        var opt = this.resize.options;
        var m0 = this.init.mouse;
        var mm = this.init.wh;
        var mb = this.init.border;
        var mx = this.init.minmax;
        var pr = opt.proportional;
        var dX = (m0.x - Mouse.x); var dY = (m0.y - Mouse.y); if (mm.h > 0) { rA = (mm.w / mm.h); } else { rA = 1; }
        var newX = (mm.w - dX); var newY = (mm.h - dY);
        switch (this.init.knob) {
            case this.RM: newX = (mm.w - dX); newY = mm.h; break;
            case this.LM: newX = (mm.w + dX); newY = mm.h; break;
            case this.TM: newX = mm.w; newY = (mm.h + dY); break;
            case this.BM: newX = mm.w; newY = (mm.h - dY); break;
            case this.RT: if (pr) { newX = Math.round((mm.w - (dX * rA))); newY = (mm.h - dX); } break;
            case this.LT: if (pr) { dX = -dX; newX = Math.round((mm.w - (dX * rA))); newY = (mm.h - dX); } break;
            case this.RB: if (pr) { newX = Math.round((mm.w - (dX * rA))); newY = (mm.h - dX); } break;
            case this.LB: if (pr) { dX = -dX; newX = Math.round((mm.w - (dX * rA))); newY = (mm.h - dX); } break;
        }
        //control inner and outer dimensions
        if (mx.minW) { if (newX <= mx.minW) { newX = mx.minW; } }
        if (mx.minH) { if (newY <= mx.minH) { newY = mx.minH; } }
        if (mx.maxW) { if (newX >= mx.maxW) { newX = mx.maxW; } }
        if (mx.maxH) { if (newY >= mx.maxH) { newY = mx.maxH; } }

        newX = newX - mb.w; if (newX < 0) { newX = 0; }
        newY = newY - mb.h; if (newY < 0) { newY = 0; }

        this.element.style.width = newX + 'px';
        this.element.style.height = newY + 'px';
        var p = Element.xywh(this.element);
        this.show_frame(p);
        if (typeof opt.mouseMove === 'function') { opt.mouseMove(this.element); }
        return p;
    },
    _mouseDown: function(e) {
        var src = Event.element(e); Event.stop(e);
        if (src.className != 'resizeknob') { return; }
        switch (src) {
            case this.TM: Drags.activate(this); break;
            case this.BM: Drags.activate(this); break;
            case this.LT: Drags.activate(this); break;
            case this.LM: Drags.activate(this); break;
            case this.LB: Drags.activate(this); break;
            case this.RT: Drags.activate(this); break;
            case this.RM: Drags.activate(this); break;
            case this.RB: Drags.activate(this); break;
        }
        var mx = this.minmax(this.element); var opt = this.resize.options;
        if (opt.min.w) { mx.minW = opt.min.w; }
        if (opt.min.h) { mx.minH = opt.min.h; }
        if (opt.max.w) { mx.maxW = opt.max.w; }
        if (opt.max.h) { mx.maxH = opt.max.h; }
        this.init = {
            knob: src,
            mouse: { x: Mouse.x, y: Mouse.y },
            wh: { w: mx.w, h: mx.h },
            border: this.border(this.element),
            minmax: mx
        };
        if (typeof opt.startResize === 'function') { opt.startResize(this.element); }
    },
    _observeClick: function(e) {
        var el, click;
        if (!this.frameactive) { return; }
        var src = Event.element(e);
        var r = Resizes.is_resize(this.element);
        if (r) {
            click = r.options.click;
            if (click == true) {
                if (src != this.element) { this.deactivate(); }
            } else if (click == false) {
                //do not destroy selection
            } else {
                el = $(click); if (el == src) { this.deactivate(); }
            }
        }
    },
    _mouseUp: function(e) {
        var opt = this.resize.options;
        if (typeof opt.endResize === 'function') { opt.endResize(this.element); }
        this.init = false; Browser.cursor('default');
    },
    _mouseOver: function(e) {
        var src = Event.element(e); if (src.className === 'resizeknob') { src.style.background = 'black'; }
    },
    _mouseOut: function(e) {
        var src = Event.element(e); if (src.className === 'resizeknob') { src.style.background = 'white'; }
    }

};

//----------------------------------------------------------------------------

var Resize = Class.create();
Resize.prototype = {
    initialize: function(el) {
        this.element = $(el);
        this.options = Object.extend({
            event: 'mousedown',
            startResize: null,
            mouseMove: null,
            endResize: null,
            indicator: true,
            click: true,
            proportional: true,
            min: { w: 0, h: 0 },
            max: { w: 0, h: 0 }
        }, arguments[1] || {});
        //check for min, max here once, because we may want to pass initial element dimensions, before resizing it
        if (typeof this.options.min === 'function') {
            this.options.min = this.options.min(this); if (!this.options.min) { this.options.min = { w: 0, h: 0 }; }
        }
        if (typeof this.options.max === 'function') {
            this.options.max = this.options.max(this); if (!this.options.max) { this.options.max = { w: 0, h: 0 }; }
        }
        this.eventActivate = this.activate.bindAsEventListener(this); Event.observe(this.element, this.options.event, this.eventActivate);
        Resizes.register(this);
    },
    activate: function(e) {
        var el = Event.element(e);
        Resizes.activate(el);
    },
    destroy: function() {
        Event.stopObserving(this.element, this.options.event, this.eventActivate);
        Resizes.unregister(this.element);
    }
};

//----------------------------------------------------------------------------



//  Nathan Rose
//  12/29/2008
//  Made the following changes to the original source code
//
//  - Made lightwindow instantiate from rel="lightwindow <lightwindow params>" instead of from class name
//    Note:  I did not strip out any of the old code for variable class names, just overwrote how it processes
//           the anchor links.
//    Note:  I also needed proprietary backward compatibility with moodalbox, so the first argument in the
//           rel can also equal "moodalbox" to instantiate correctly.  This will be taken out as soon as I
//           can fully unit-test all clients and remove old references to moodalbox.
//  - Parameters (options) are now pulled from the rel as well instead of the non-standards "params" attribute.
//    I am sticking to XHTML standard as closely as possible, so I took out all logic for the "params",
//    "caption" and "author" attributes.  Sorry, Kevin.
//  - Swapped the title and caption so the title now appears below the lightwindow instead of next to the
//    close button.  I found that sometimes the title was really long and overwrote the close button, especially
//    when clients are careless and do not properly populate their meta tags and titles.
//  - Tweaked the default animation slightly so it does not have separate animations for width and height, only
//    a single animation for both.  Also increased the duration slightly to make things a little less choppy.
//    Again, sorry, Kevin.
//
//
//  One more note:  Like Kevin suggests, be a pro.  Compress your Javascript.  :)
//
//  Original author comments are below:
//
//  --------------------------------------------------------------------------------------------------------------
//
// lightwindow.js v2.0
//
// Copyright (c) 2007 stickmanlabs
// Author: Kevin P Miller | http://www.stickmanlabs.com
// 
// LightWindow is freely distributable under the terms of an MIT-style license.
//
// I don't care what you think about the file size...
//   Be a pro: 
//	    http://www.thinkvitamin.com/features/webapps/serving-javascript-fast
//      http://rakaz.nl/item/make_your_pages_load_faster_by_combining_and_compressing_javascript_and_css_files
//

/*-----------------------------------------------------------------------------------------------*/

if (typeof Effect == 'undefined')
    throw ("lightwindow.js requires including script.aculo.us' effects.js library!");

// This will stop image flickering in IE6 when elements with images are moved
try {
    document.execCommand("BackgroundImageCache", false, true);
} catch (e) { }

var lightwindow = Class.create();
lightwindow.prototype = {
    //  NR:  12/29/2008
    //  Image source
    loadingImageSrc: '/images/design/loadingMedium.gif',
    overlayImageSrc: '/images/lightwindow/black.png',
    overlayPresetImageSrc: '/images/lightwindow/black-70.png',

    //
    //	Setup Variables
    //
    element: null,
    contentToFetch: null,
    windowActive: false,
    dataEffects: [],
    dimensions: {
        cruft: null,
        container: null,
        viewport: {
            height: null,
            width: null,
            offsetTop: null,
            offsetLeft: null
        }
    },
    pagePosition: {
        x: 0,
        y: 0
    },
    pageDimensions: {
        width: null,
        height: null
    },
    preloadImage: [],
    preloadedImage: [],
    galleries: [],
    resizeTo: {
        height: null,
        heightPercent: null,
        width: null,
        widthPercent: null,
        fixedTop: null,
        fixedLeft: null
    },
    scrollbarOffset: 18,
    navigationObservers: {
        previous: null,
        next: null
    },
    containerChange: {
        height: 0,
        width: 0
    },
    activeGallery: false,
    galleryLocation: {
        current: 0,
        total: 0
    },
    //
    //	Initialize the lightwindow.
    //
    initialize: function(options) {
        this.options = Object.extend({
            resizeSpeed: 7,
            contentOffset: {
                height: 20,
                width: 20
            },
            dimensions: {
                image: { height: 250, width: 250 },
                page: { height: 250, width: 250 },
                inline: { height: 250, width: 250 },
                media: { height: 250, width: 250 },
                external: { height: 250, width: 250 },
                titleHeight: 25
            },
            classNames: {
                standard: 'lightwindow',
                action: 'lightwindow_action'
            },
            fileTypes: {
                page: ['asp', 'aspx', 'cgi', 'cfm', 'htm', 'html', 'pl', 'php4', 'php3', 'php', 'php5', 'phtml', 'rhtml', 'shtml', 'txt', 'vbs', 'rb'],
                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'],
                image: ['bmp', 'gif', 'jpg', 'png', 'tiff']
            },
            mimeTypes: {
                avi: 'video/avi',
                aif: 'audio/aiff',
                aiff: 'audio/aiff',
                gif: 'image/gif',
                bmp: 'image/bmp',
                jpeg: 'image/jpeg',
                m1v: 'video/mpeg',
                m2a: 'audio/mpeg',
                m2v: 'video/mpeg',
                m3u: 'audio/x-mpequrl',
                mid: 'audio/x-midi',
                midi: 'audio/x-midi',
                mjpg: 'video/x-motion-jpeg',
                moov: 'video/quicktime',
                mov: 'video/quicktime',
                movie: 'video/x-sgi-movie',
                mp2: 'audio/mpeg',
                mp3: 'audio/mpeg3',
                mpa: 'audio/mpeg',
                mpa: 'video/mpeg',
                mpe: 'video/mpeg',
                mpeg: 'video/mpeg',
                mpg: 'audio/mpeg',
                mpg: 'video/mpeg',
                mpga: 'audio/mpeg',
                pdf: 'application/pdf',
                png: 'image/png',
                pps: 'application/mspowerpoint',
                qt: 'video/quicktime',
                ram: 'audio/x-pn-realaudio-plugin',
                rm: 'application/vnd.rn-realmedia',
                swf: 'application/x-shockwave-flash',
                tiff: 'image/tiff',
                viv: 'video/vivo',
                vivo: 'video/vivo',
                wav: 'audio/wav',
                wmv: 'application/x-mplayer2'
            },
            classids: {
                mov: 'clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B',
                swf: 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000',
                wmv: 'clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6'
            },
            codebases: {
                mov: 'http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0',
                swf: 'http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0',
                wmv: 'http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715'
            },
            viewportPadding: 10,
            EOLASFix: 'swf,wmv,fla,flv',
            overlay: {
                opacity: 0.7,
                image: this.overlayImageSrc,
                presetImage: this.overlayPresetImageSrc
            },
            skin: {
                main: '<div id="lightwindow_container" >' +
							'<div id="lightwindow_title_bar" >' +
								'<div id="lightwindow_title_bar_inner" >' +
									'<span id="lightwindow_title_bar_title"></span>' +
									'<a id="lightwindow_title_bar_close_link" >close</a>' +
								'</div>' +
							'</div>' +
							'<div id="lightwindow_stage" >' +
								'<div id="lightwindow_contents" >' +
								'</div>' +
								'<div id="lightwindow_navigation" >' +
									'<a href="#" id="lightwindow_previous" >' +
										'<span id="lightwindow_previous_title"></span>' +
									'</a>' +
									'<a href="#" id="lightwindow_next" >' +
										'<span id="lightwindow_next_title"></span>' +
									'</a>' +
									'<iframe name="lightwindow_navigation_shim" id="lightwindow_navigation_shim" src="javascript:false;" frameBorder="0" scrolling="no"></iframe>' +
								'</div>' +
								'<div id="lightwindow_galleries">' +
									'<div id="lightwindow_galleries_tab_container" >' +
										'<a href="#" id="lightwindow_galleries_tab" >' +
											'<span id="lightwindow_galleries_tab_span" class="up" >Galleries</span>' +
										'</a>' +
									'</div>' +
									'<div id="lightwindow_galleries_list" >' +
									'</div>' +
								'</div>' +
							'</div>' +
							'<div id="lightwindow_data_slide" >' +
								'<div id="lightwindow_data_slide_inner" >' +
									'<div id="lightwindow_data_details" >' +
										'<div id="lightwindow_data_gallery_container" >' +
											'<span id="lightwindow_data_gallery_current"></span>' +
											' of ' +
											'<span id="lightwindow_data_gallery_total"></span>' +
										'</div>' +
										'<div id="lightwindow_data_author_container" >' +
											'by <span id="lightwindow_data_author"></span>' +
										'</div>' +
									'</div>' +
									'<div id="lightwindow_data_caption" >' +
									'</div>' +
								'</div>' +
							'</div>' +
						'</div>',
                loading: '<div id="lightwindow_loading" >' +
								'<img src="' + this.loadingImageSrc + '" alt="loading" />' +
								'<span>Loading or <a href="javascript: myLightWindow.deactivate();">Cancel</a></span>' +
								'<iframe name="lightwindow_loading_shim" id="lightwindow_loading_shim" src="javascript:false;" frameBorder="0" scrolling="no"></iframe>' +
							'</div>',
                iframe: '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' +
							'<html xmlns="http://www.w3.org/1999/xhtml">' +
								'<body>' +
									'{body_replace}' +
								'</body>' +
							'</html>',
                gallery: {
                    top: '<div class="lightwindow_galleries_list">' +
									'<h1>{gallery_title_replace}</h1>' +
									'<ul>',
                    middle: '<li>' +
											'{gallery_link_replace}' +
										'</li>',
                    bottom: '</ul>' +
								'</div>'
                }
            },
            formMethod: 'get',
            hideFlash: false,
            hideGalleryTab: false,
            showTitleBar: true,
            animationHandler: false,
            navigationHandler: false,
            transitionHandler: false,
            finalAnimationHandler: false,
            formHandler: false,
            galleryAnimationHandler: false,
            showGalleryCount: true
        }, options || {});
        this.duration = ((11 - this.options.resizeSpeed) * 0.15);
        this._setupLinks();
        this._getScroll();
        this._getPageDimensions();
        this._browserDimensions();
        this._addLightWindowMarkup(false);
        this._setupDimensions();
        this.buildGalleryList();
    },
    //
    //	Activate the lightwindow.
    //
    activate: function(e, link) {
        // Clear out the window Contents
        this._clearWindowContents(true);

        // Add back in out loading panel
        this._addLoadingWindowMarkup();

        // Setup the element properties
        this._setupWindowElements(link);

        // Setup everything
        this._getScroll();
        this._browserDimensions();
        this._setupDimensions();
        this._toggleTroubleElements('hidden', false);
        this._displayLightWindow('block', 'hidden');
        this._setStatus(true);
        this._monitorKeyboard(true);
        this._prepareIE(true);
        this._loadWindow();
    },
    //
    //	Turn off the window
    //
    deactivate: function() {
        // The window is not active
        this.windowActive = false;

        // There is no longer a gallery active
        this.activeGallery = false;
        if (!this.options.hideGalleryTab) {
            this._handleGalleryAnimation(false);
        }

        // Kill the animation
        this.animating = false;

        // Clear our element
        this.element = null;

        // hide the window.
        this._displayLightWindow('none', 'visible');

        // Clear out the window Contents
        this._clearWindowContents(false);

        // Stop all animation
        var queue = Effect.Queues.get('lightwindowAnimation').each(function(e) { e.cancel(); });

        // Undo the setup
        this._prepareIE(false);
        this._setupDimensions();
        this._toggleTroubleElements('visible', false);
        this._monitorKeyboard(false);
    },
    //
    //  Initialize specific window
    //
    createWindow: function(element, attributes) {
        this._processLink($(element));
    },
    //
    //  Open a Window from a hash of attributes
    //
    activateWindow: function(options) {
        this.element = Object.extend({
            href: null,
            title: null,
            author: null,
            caption: null,
            rel: null,
            top: null,
            left: null,
            type: null,
            showImages: null,
            height: null,
            width: null,
            loadingAnimation: null,
            iframeEmbed: null,
            form: null
        }, options || {});

        // Set the window type
        this.contentToFetch = this.element.href;
        this.windowType = this.element.type ? this.element.type : this._fileType(this.element.href);

        // Clear out the window Contents
        this._clearWindowContents(true);

        // Add back in out loading panel
        this._addLoadingWindowMarkup();

        // Setup everything
        this._getScroll();
        this._browserDimensions();
        this._setupDimensions();
        this._toggleTroubleElements('hidden', false);
        this._displayLightWindow('block', 'hidden');
        this._setStatus(true);
        this._monitorKeyboard(true);
        this._prepareIE(true);
        this._loadWindow();
    },
    //
    //  Fire off our Form handler
    //
    submitForm: function(e) {
        if (this.options.formHandler) {
            this.options.formHandler(e);
        } else {
            this._defaultFormHandler(e);
        }
    },
    //
    //	Reload the window with another location
    //
    openWindow: function(element) {
        var element = $(element);

        // The window is active
        this.windowActive = true;

        // Clear out the window Contents
        this._clearWindowContents(true);

        // Add back in out loading panel
        this._addLoadingWindowMarkup();

        // Setup the element properties
        this._setupWindowElements(element);

        this._setStatus(true);
        this._handleTransition();
    },
    //
    //  Navigate the window
    //
    navigateWindow: function(direction) {
        this._handleNavigation(false);
        if (direction == 'previous') {
            this.openWindow(this.navigationObservers.previous);
        } else if (direction == 'next') {
            this.openWindow(this.navigationObservers.next);
        }
    },
    //
    //  Build the Gallery List and Load it
    //
    buildGalleryList: function() {
        var output = '';
        var galleryLink;
        for (i in this.galleries) {
            if (typeof this.galleries[i] == 'object') {
                output += (this.options.skin.gallery.top).replace('{gallery_title_replace}', unescape(i));
                for (j in this.galleries[i]) {
                    if (typeof this.galleries[i][j] == 'object') {
                        galleryLink = '<a href="#" id="lightwindow_gallery_' + i + '_' + j + '" >' + unescape(j) + '</a>';
                        output += (this.options.skin.gallery.middle).replace('{gallery_link_replace}', galleryLink);
                    }
                }
                output += this.options.skin.gallery.bottom;
            }
        }
        new Insertion.Top('lightwindow_galleries_list', output);

        // Attach Events
        for (i in this.galleries) {
            if (typeof this.galleries[i] == 'object') {
                for (j in this.galleries[i]) {
                    if (typeof this.galleries[i][j] == 'object') {
                        Event.observe($('lightwindow_gallery_' + i + '_' + j), 'click', this.openWindow.bind(this, this.galleries[i][j][0]), false);
                        $('lightwindow_gallery_' + i + '_' + j).onclick = function() { return false; };
                    }
                }
            }
        }
    },
    // 
    //  Set Links Up
    //
    _setupLinks: function() {
        //  NR:  12/29/2008
        //  Custom implementation (look for instances of [rel~=lightwindow], [rel~=moodalbox], and [class=lightwindow])
        //  We will phase each of these out, leaving (eventually) only [rel~=lightwindow]
        $$('[rel~=lightwindow]').each(function(link) {
            this._processLink(link);
        } .bind(this));

        $$('[rel~=moodalbox]').each(function(link) {
            this._processLink(link);
        } .bind(this));

        $$('.' + this.options.classNames.standard).each(function(link) {
            this._processLink(link);
        } .bind(this));

        //      var links = $$('.'+this.options.classNames.standard);
        //      links.each(function(link) {
        //          this._processLink(link);
        //      } .bind(this));
    },
    //
    //  Process a Link
    //
    _processLink: function(link) {
        if ((this._fileType(link.getAttribute('href')) == 'image' || this._fileType(link.getAttribute('href')) == 'media')) {
            //  NR:  12/29/2008
            //  Galleries now use the rev attribute to set gallery info (rel is used for instantiation)
            if (gallery = this._getGalleryInfo(link.rev)) {
                //if (gallery = this._getGalleryInfo(link.rel)) {
                if (!this.galleries[gallery[0]]) {
                    this.galleries[gallery[0]] = new Array();
                }
                if (!this.galleries[gallery[0]][gallery[1]]) {
                    this.galleries[gallery[0]][gallery[1]] = new Array();
                }
                this.galleries[gallery[0]][gallery[1]].push(link);
            }
        }

        // Take care of our inline content
        var url = link.getAttribute('href');
        if (url.indexOf('?') > -1) {
            url = url.substring(0, url.indexOf('?'));
        }

        var container = url.substring(url.indexOf('#') + 1);
        if ($(container)) {
            $(container).setStyle({
                display: 'none'
            });
        }

        Event.observe(link, 'click', this.activate.bindAsEventListener(this, link), false);
        link.onclick = function() { return false; };
    },
    //
    //	Setup our actions
    //
    _setupActions: function() {
        var links = $$('#lightwindow_container .' + this.options.classNames.action);
        links.each(function(link) {
            Event.observe(link, 'click', this[link.getAttribute('rel')].bindAsEventListener(this, link), false);
            link.onclick = function() { return false; };
        } .bind(this));
    },
    //
    //	Add the markup to the page.
    //
    _addLightWindowMarkup: function(rebuild) {
        var overlay = Element.extend(document.createElement('div'));
        overlay.setAttribute('id', 'lightwindow_overlay');
        // FF Mac has a problem with putting Flash above a layer without a 100% opacity background, so we need to use a pre-made
        if (Prototype.Browser.Gecko) {
            overlay.setStyle({
                backgroundImage: 'url(' + this.options.overlay.presetImage + ')',
                backgroundRepeat: 'repeat',
                height: this.pageDimensions.height + 'px'
            });
        } else {
            overlay.setStyle({
                opacity: this.options.overlay.opacity,
                backgroundImage: 'url(' + this.options.overlay.image + ')',
                backgroundRepeat: 'repeat',
                height: this.pageDimensions.height + 'px'
            });
        }

        var lw = document.createElement('div');
        lw.setAttribute('id', 'lightwindow');
        lw.innerHTML = this.options.skin.main;

        var body = document.getElementsByTagName('body')[0];
        body.appendChild(overlay);
        body.appendChild(lw);

        if ($('lightwindow_title_bar_close_link')) {
            Event.observe('lightwindow_title_bar_close_link', 'click', this.deactivate.bindAsEventListener(this));
            $('lightwindow_title_bar_close_link').onclick = function() { return false; };
        }

        Event.observe($('lightwindow_previous'), 'click', this.navigateWindow.bind(this, 'previous'), false);
        $('lightwindow_previous').onclick = function() { return false; };
        Event.observe($('lightwindow_next'), 'click', this.navigateWindow.bind(this, 'next'), false);
        $('lightwindow_next').onclick = function() { return false; };

        if (!this.options.hideGalleryTab) {
            Event.observe($('lightwindow_galleries_tab'), 'click', this._handleGalleryAnimation.bind(this, true), false);
            $('lightwindow_galleries_tab').onclick = function() { return false; };
        }

        // Because we use position absolute, kill the scroll Wheel on animations
        if (Prototype.Browser.IE) {
            Event.observe(document, 'mousewheel', this._stopScrolling.bindAsEventListener(this), false);
        } else {
            Event.observe(window, 'DOMMouseScroll', this._stopScrolling.bindAsEventListener(this), false);
        }

        Event.observe(overlay, 'click', this.deactivate.bindAsEventListener(this), false);
        overlay.onclick = function() { return false; };
    },
    //
    //  Add loading window markup
    //
    _addLoadingWindowMarkup: function() {
        $('lightwindow_contents').innerHTML += this.options.skin.loading;
    },
    //
    //  Setup the window elements
    //
    _setupWindowElements: function(link) {
        this.element = link;
        //  Replacing title with caption (adhere to XHTML)
        //this.element.title = null ? '' : link.getAttribute('title');
        //this.element.caption = null ? '' : link.getAttribute('caption');
        //this.element.author = null ? '' : link.getAttribute('author');
        this.element.author = '';
        this.element.title = null ? '' : link.getAttribute('title');
        this.element.caption = '';
        //  NR:  12/29/2008
        //  Fixing options
        //this.element.rel = null ? '' : link.getAttribute('rel');
        //  Temporary fix?
        //this.element.params = null ? '' : link.getAttribute('params');
        //  For backward compatibility
        this.element.params = '';
        if (this.element.params == '' && link.getAttribute('params')) this.element.params = link.getAttribute('params');
        if (this.element.params == '' && link.getAttribute('rel')) this.element.params = link.getAttribute('rel').replace('lightwindow ', '');
        this.element.rev = null ? '' : link.getAttribute('rev');

        // Set the window type
        this.contentToFetch = this.element.href;
        this.windowType = this._getParameter('lightwindow_type') ? this._getParameter('lightwindow_type') : this._fileType(this.contentToFetch);
    },
    //
    //  Clear the window contents out
    //
    _clearWindowContents: function(contents) {
        // If there is an iframe, its got to go
        if ($('lightwindow_iframe')) {
            Element.remove($('lightwindow_iframe'));
        }

        // Stop playing an object if its still around
        if ($('lightwindow_media_primary')) {
            try {
                $('lightwindow_media_primary').Stop();
            } catch (e) { }
            Element.remove($('lightwindow_media_primary'));
        }

        // Stop playing an object if its still around		
        if ($('lightwindow_media_secondary')) {
            try {
                $('lightwindow_media_secondary').Stop();
            } catch (e) { }
            Element.remove($('lightwindow_media_secondary'));
        }

        this.activeGallery = false;
        this._handleNavigation(this.activeGallery);

        if (contents) {
            // Empty the contents
            $('lightwindow_contents').innerHTML = '';

            // Reset the scroll bars
            $('lightwindow_contents').setStyle({
                overflow: 'hidden'
            });

            if (!this.windowActive) {
                $('lightwindow_data_slide_inner').setStyle({
                    display: 'none'
                });

                $('lightwindow_title_bar_title').innerHTML = '';
            }

            // Because of browser differences and to maintain flexible captions we need to reset this height at close
            $('lightwindow_data_slide').setStyle({
                height: 'auto'
            });
        }

        this.resizeTo.height = null;
        this.resizeTo.width = null;
    },
    //
    //	Set the status of our animation to keep things from getting clunky
    //
    _setStatus: function(status) {
        this.animating = status;
        if (status) {
            Element.show('lightwindow_loading');
        }
        if (!(/MSIE 6./i.test(navigator.userAgent))) {
            this._fixedWindow(status);
        }
    },
    //
    //  Make this window Fixed
    //
    _fixedWindow: function(status) {
        if (status) {
            if (this.windowActive) {
                this._getScroll();
                $('lightwindow').setStyle({
                    position: 'absolute',
                    top: parseFloat($('lightwindow').getStyle('top')) + this.pagePosition.y + 'px',
                    left: parseFloat($('lightwindow').getStyle('left')) + this.pagePosition.x + 'px'
                });
            } else {
                $('lightwindow').setStyle({
                    position: 'absolute'
                });
            }
        } else {
            if (this.windowActive) {
                this._getScroll();
                $('lightwindow').setStyle({
                    position: 'fixed',
                    top: parseFloat($('lightwindow').getStyle('top')) - this.pagePosition.y + 'px',
                    left: parseFloat($('lightwindow').getStyle('left')) - this.pagePosition.x + 'px'
                });
            } else {
                if ($('lightwindow_iframe')) {
                    // 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
                    this._browserDimensions();
                }
                $('lightwindow').setStyle({
                    position: 'fixed',
                    top: (parseFloat(this._getParameter('lightwindow_top')) ? parseFloat(this._getParameter('lightwindow_top')) + 'px' : this.dimensions.viewport.height / 2 + 'px'),
                    left: (parseFloat(this._getParameter('lightwindow_left')) ? parseFloat(this._getParameter('lightwindow_left')) + 'px' : this.dimensions.viewport.width / 2 + 'px')
                });
            }
        }
    },
    //
    //	Prepare the window for IE.
    //
    _prepareIE: function(setup) {
        if (Prototype.Browser.IE) {
            var height, overflowX, overflowY;
            if (setup) {
                var height = '100%';
            } else {
                var height = 'auto';
            }
            var body = document.getElementsByTagName('body')[0];
            var html = document.getElementsByTagName('html')[0];
            html.style.height = body.style.height = height;
        }
    },
    _stopScrolling: function(e) {
        if (this.animating) {
            if (e.preventDefault) {
                e.preventDefault();
            }
            e.returnValue = false;
        }
    },
    //
    //	Get the scroll for the page.
    //
    _getScroll: function() {
        if (typeof (window.pageYOffset) == 'number') {
            this.pagePosition.x = window.pageXOffset;
            this.pagePosition.y = window.pageYOffset;
        } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
            this.pagePosition.x = document.body.scrollLeft;
            this.pagePosition.y = document.body.scrollTop;
        } else if (document.documentElement) {
            this.pagePosition.x = document.documentElement.scrollLeft;
            this.pagePosition.y = document.documentElement.scrollTop;
        }
    },
    //
    //	Reset the scroll.
    //
    _setScroll: function(x, y) {
        document.documentElement.scrollLeft = x;
        document.documentElement.scrollTop = y;
    },
    //
    //	Hide Selects from the page because of IE.
    //     We could use iframe shims instead here but why add all the extra markup for one browser when this is much easier and cleaner
    //
    _toggleTroubleElements: function(visibility, content) {

        if (content) {
            var selects = $('lightwindow_contents').getElementsByTagName('select');
        } else {
            var selects = document.getElementsByTagName('select');
        }

        for (var i = 0; i < selects.length; i++) {
            selects[i].style.visibility = visibility;
        }

        if (!content) {
            if (this.options.hideFlash) {
                var objects = document.getElementsByTagName('object');
                for (i = 0; i != objects.length; i++) {
                    objects[i].style.visibility = visibility;
                }
                var embeds = document.getElementsByTagName('embed');
                for (i = 0; i != embeds.length; i++) {
                    embeds[i].style.visibility = visibility;
                }
            }
            var iframes = document.getElementsByTagName('iframe');
            for (i = 0; i != iframes.length; i++) {
                iframes[i].style.visibility = visibility;
            }
        }
    },
    // 
    //  Get the actual page size
    //
    _getPageDimensions: function() {
        var xScroll, yScroll;
        if (window.innerHeight && window.scrollMaxY) {
            xScroll = document.body.scrollWidth;
            yScroll = window.innerHeight + window.scrollMaxY;
        } else if (document.body.scrollHeight > document.body.offsetHeight) {
            xScroll = document.body.scrollWidth;
            yScroll = document.body.scrollHeight;
        } else {
            xScroll = document.body.offsetWidth;
            yScroll = document.body.offsetHeight;
        }

        var windowWidth, windowHeight;
        if (self.innerHeight) {
            windowWidth = self.innerWidth;
            windowHeight = self.innerHeight;
        } else if (document.documentElement && document.documentElement.clientHeight) {
            windowWidth = document.documentElement.clientWidth;
            windowHeight = document.documentElement.clientHeight;
        } else if (document.body) {
            windowWidth = document.body.clientWidth;
            windowHeight = document.body.clientHeight;
        }

        if (yScroll < windowHeight) {
            this.pageDimensions.height = windowHeight;
        } else {
            this.pageDimensions.height = yScroll;
        }

        if (xScroll < windowWidth) {
            this.pageDimensions.width = windowWidth;
        } else {
            this.pageDimensions.width = xScroll;
        }
    },
    //
    //	Display the lightWindow.
    //
    _displayLightWindow: function(display, visibility) {
        $('lightwindow_overlay').style.display = $('lightwindow').style.display = $('lightwindow_container').style.display = display;
        $('lightwindow_overlay').style.visibility = $('lightwindow').style.visibility = $('lightwindow_container').style.visibility = visibility;
    },
    //
    //	Setup Dimensions of lightwindow.

    //
    _setupDimensions: function() {

        var originalHeight, originalWidth;
        switch (this.windowType) {
            case 'page':
                originalHeight = this.options.dimensions.page.height;
                originalWidth = this.options.dimensions.page.width;
                break;

            case 'image':
                originalHeight = this.options.dimensions.image.height;
                originalWidth = this.options.dimensions.image.width;
                break;

            case 'media':
                originalHeight = this.options.dimensions.media.height;
                originalWidth = this.options.dimensions.media.width;
                break;

            case 'external':
                originalHeight = this.options.dimensions.external.height;
                originalWidth = this.options.dimensions.external.width;
                break;

            case 'inline':
                originalHeight = this.options.dimensions.inline.height;
                originalWidth = this.options.dimensions.inline.width;
                break;

            default:
                originalHeight = this.options.dimensions.page.height;
                originalWidth = this.options.dimensions.page.width;
                break;

        }

        var offsetHeight = this._getParameter('lightwindow_top') ? parseFloat(this._getParameter('lightwindow_top')) + this.pagePosition.y : this.dimensions.viewport.height / 2 + this.pagePosition.y;
        var offsetWidth = this._getParameter('lightwindow_left') ? parseFloat(this._getParameter('lightwindow_left')) + this.pagePosition.x : this.dimensions.viewport.width / 2 + this.pagePosition.x;

        // So if a theme has say shadowed edges, they should be consistant and take care of in the contentOffset
        $('lightwindow').setStyle({
            top: offsetHeight + 'px',
            left: offsetWidth + 'px'
        });

        $('lightwindow_container').setStyle({
            height: originalHeight + 'px',
            width: originalWidth + 'px',
            left: -(originalWidth / 2) + 'px',
            top: -(originalHeight / 2) + 'px'
        });

        $('lightwindow_contents').setStyle({
            height: originalHeight + 'px',
            width: originalWidth + 'px'
        });
    },
    //
    //	Get the type of file.
    //
    _fileType: function(url) {
        var image = new RegExp("[^\.]\.(" + this.options.fileTypes.image.join('|') + ")\s*$", "i");
        if (image.test(url)) return 'image';
        if (url.indexOf('#') > -1 && (document.domain == this._getDomain(url))) return 'inline';
        if (url.indexOf('?') > -1) url = url.substring(0, url.indexOf('?'));
        var type = 'unknown';
        var page = new RegExp("[^\.]\.(" + this.options.fileTypes.page.join('|') + ")\s*$", "i");
        var media = new RegExp("[^\.]\.(" + this.options.fileTypes.media.join('|') + ")\s*$", "i");
        if (document.domain != this._getDomain(url)) type = 'external';
        if (media.test(url)) type = 'media';
        if (type == 'external' || type == 'media') return type;
        if (page.test(url) || url.substr((url.length - 1), url.length) == '/') type = 'page';
        return type;
    },
    //
    //  Get file Extension
    //
    _fileExtension: function(url) {
        if (url.indexOf('?') > -1) {
            url = url.substring(0, url.indexOf('?'));
        }
        var extenstion = '';
        for (var x = (url.length - 1); x > -1; x--) {
            if (url.charAt(x) == '.') {
                return extenstion;
            }
            extenstion = url.charAt(x) + extenstion;
        }
    },
    //
    //	Monitor the keyboard while this lightwindow is up
    //
    _monitorKeyboard: function(status) {
        if (status) document.onkeydown = this._eventKeypress.bind(this);
        else document.onkeydown = '';
    },
    //
    //  Perform keyboard actions
    //
    _eventKeypress: function(e) {
        if (e == null) {
            var keycode = event.keyCode;
        } else {
            var keycode = e.which;
        }

        switch (keycode) {
            case 27:
                this.deactivate();
                break;

            case 13:
                return;

            default:
                break;
        }

        // Gotta stop those quick fingers
        if (this.animating) {
            return false;
        }

        switch (String.fromCharCode(keycode).toLowerCase()) {
            case 'p':
                if (this.navigationObservers.previous) {
                    this.navigateWindow('previous');
                }
                break;

            case 'n':
                if (this.navigationObservers.next) {
                    this.navigateWindow('next');
                }
                break;

            default:
                break;
        }
    },
    //
    //	Get Gallery Information
    //
    //  NR:  12/29/2008
    //  Changed rel to rev to make it more consistent
    _getGalleryInfo: function(rev) {
        if (!rev) return false;
        if (rev.indexOf('[') > -1) {
            return new Array(escape(rev.substring(0, rev.indexOf('['))), escape(rev.substring(rev.indexOf('[') + 1, rev.indexOf(']'))));
        } else {
            return false;
        }
    },
    //
    //	Get the domain from a string.
    //
    _getDomain: function(url) {
        var leadSlashes = url.indexOf('//');
        var domainStart = leadSlashes + 2;
        var withoutResource = url.substring(domainStart, url.length);
        var nextSlash = withoutResource.indexOf('/');
        var domain = withoutResource.substring(0, nextSlash);
        if (domain.indexOf(':') > -1) {
            var portColon = domain.indexOf(':');
            domain = domain.substring(0, portColon);
        }
        return domain;
    },
    //
    //	Get the value from the params attribute string.
    //
    _getParameter: function(parameter, parameters) {
        if (!this.element) return false;
        if (parameter == 'lightwindow_top' && this.element.top) {
            return unescape(this.element.top);
        } else if (parameter == 'lightwindow_left' && this.element.left) {
            return unescape(this.element.left);
        } else if (parameter == 'lightwindow_type' && this.element.type) {
            return unescape(this.element.type);
        } else if (parameter == 'lightwindow_show_images' && this.element.showImages) {
            return unescape(this.element.showImages);
        } else if (parameter == 'lightwindow_height' && this.element.height) {
            return unescape(this.element.height);
        } else if (parameter == 'lightwindow_width' && this.element.width) {
            return unescape(this.element.width);
        } else if (parameter == 'lightwindow_loading_animation' && this.element.loadingAnimation) {
            return unescape(this.element.loadingAnimation);
        } else if (parameter == 'lightwindow_iframe_embed' && this.element.iframeEmbed) {
            return unescape(this.element.iframeEmbed);
        } else if (parameter == 'lightwindow_form' && this.element.form) {
            return unescape(this.element.form);
        } else {
            if (!parameters) {
                if (this.element.params) parameters = this.element.params;
                else return;
            }
            var value;
            var parameterArray = parameters.split(',');
            var compareString = parameter + '=';
            var compareLength = compareString.length;
            for (var i = 0; i < parameterArray.length; i++) {
                if (parameterArray[i].substr(0, compareLength) == compareString) {
                    var currentParameter = parameterArray[i].split('=');
                    value = currentParameter[1];
                    break;
                }
            }
            if (!value) return false;
            else return unescape(value);
        }
    },
    //
    //  Get the Browser Viewport Dimensions
    //
    _browserDimensions: function() {
        if (Prototype.Browser.IE) {
            this.dimensions.viewport.height = document.documentElement.clientHeight;
            this.dimensions.viewport.width = document.documentElement.clientWidth;
        } else {
            this.dimensions.viewport.height = window.innerHeight;
            this.dimensions.viewport.width = document.width || document.body.offsetWidth;
        }
    },
    //
    //  Get the scrollbar offset, I don't like this method but there is really no other way I can find.
    //
    _getScrollerWidth: function() {
        var scrollDiv = Element.extend(document.createElement('div'));
        scrollDiv.setAttribute('id', 'lightwindow_scroll_div');
        scrollDiv.setStyle({
            position: 'absolute',
            top: '-10000px',
            left: '-10000px',
            width: '100px',
            height: '100px',
            overflow: 'hidden'
        });



        var contentDiv = Element.extend(document.createElement('div'));
        contentDiv.setAttribute('id', 'lightwindow_content_scroll_div');
        contentDiv.setStyle({
            width: '100%',
            height: '200px'
        });

        scrollDiv.appendChild(contentDiv);

        var body = document.getElementsByTagName('body')[0];
        body.appendChild(scrollDiv);

        var noScroll = $('lightwindow_content_scroll_div').offsetWidth;
        scrollDiv.style.overflow = 'auto';
        var withScroll = $('lightwindow_content_scroll_div').offsetWidth;

        Element.remove($('lightwindow_scroll_div'));

        this.scrollbarOffset = noScroll - withScroll;
    },


    //
    //  Add a param to an object dynamically created
    //
    _addParamToObject: function(name, value, object, id) {
        var param = document.createElement('param');
        param.setAttribute('value', value);
        param.setAttribute('name', name);
        if (id) {
            param.setAttribute('id', id);
        }
        object.appendChild(param);
        return object;
    },
    //
    //  Get the outer HTML of an object CROSS BROWSER
    //
    _outerHTML: function(object) {
        if (Prototype.Browser.IE) {
            return object.outerHTML;
        } else {
            var clone = object.cloneNode(true);
            var cloneDiv = document.createElement('div');
            cloneDiv.appendChild(clone);
            return cloneDiv.innerHTML;
        }
    },
    //
    //  Convert an object to markup
    //
    _convertToMarkup: function(object, closeTag) {
        var markup = this._outerHTML(object).replace('</' + closeTag + '>', '');
        if (Prototype.Browser.IE) {
            for (var i = 0; i < object.childNodes.length; i++) {
                markup += this._outerHTML(object.childNodes[i]);
            }
            markup += '</' + closeTag + '>';
        }
        return markup;
    },
    //
    //  Depending what type of browser it is we have to append the object differently... DAMN YOU IE!!
    //
    _appendObject: function(object, closeTag, appendTo) {
        if (Prototype.Browser.IE) {
            appendTo.innerHTML += this._convertToMarkup(object, closeTag);

            // Fix the Eolas activate thing but only for specified media, for example doing this to a quicktime film breaks it.
            if (this.options.EOLASFix.indexOf(this._fileType(this.element.href)) > -1) {
                var objectElements = document.getElementsByTagName('object');
                for (var i = 0; i < objectElements.length; i++) {
                    if (objectElements[i].getAttribute("data")) objectElements[i].removeAttribute('data');
                    objectElements[i].outerHTML = objectElements[i].outerHTML;
                    objectElements[i].style.visibility = "visible";
                }
            }
        } else {
            appendTo.appendChild(object);
        }
    },
    //
    //  Add in iframe
    //
    _appendIframe: function(scroll) {
        var iframe = document.createElement('iframe');
        iframe.setAttribute('id', 'lightwindow_iframe');
        iframe.setAttribute('name', 'lightwindow_iframe');
        iframe.setAttribute('src', 'about:blank');
        iframe.setAttribute('height', '100%');
        iframe.setAttribute('width', '100%');
        iframe.setAttribute('frameborder', '0');
        iframe.setAttribute('marginwidth', '0');
        iframe.setAttribute('marginheight', '0');
        iframe.setAttribute('scrolling', scroll);

        this._appendObject(iframe, 'iframe', $('lightwindow_contents'));
    },
    //
    //  Write Content to the iframe using the skin
    //
    _writeToIframe: function(content) {
        var template = this.options.skin.iframe;
        template = template.replace('{body_replace}', content);
        if ($('lightwindow_iframe').contentWindow) {
            $('lightwindow_iframe').contentWindow.document.open();
            $('lightwindow_iframe').contentWindow.document.write(template);
            $('lightwindow_iframe').contentWindow.document.close();
        } else {
            $('lightwindow_iframe').contentDocument.open();
            $('lightwindow_iframe').contentDocument.write(template);
            $('lightwindow_iframe').contentDocument.close();
        }
    },
    //
    //  Load the window Information
    //  
    _loadWindow: function() {
        switch (this.windowType) {
            case 'image':

                var current = 0;
                var images = [];
                this.checkImage = [];
                this.resizeTo.height = this.resizeTo.width = 0;
                this.imageCount = this._getParameter('lightwindow_show_images') ? parseInt(this._getParameter('lightwindow_show_images')) : 1;

                // If there is a gallery get it
                //  NR:  12/29/2008
                //  Fixing galleries (rel vs. rev)
                //if (gallery = this._getGalleryInfo(this.element.rel)) {
                if (gallery = this._getGalleryInfo(this.element.rev)) {
                    for (current = 0; current < this.galleries[gallery[0]][gallery[1]].length; current++) {
                        if (this.contentToFetch.indexOf(this.galleries[gallery[0]][gallery[1]][current].href) > -1) {
                            break;
                        }
                    }
                    if (this.galleries[gallery[0]][gallery[1]][current - this.imageCount]) {
                        this.navigationObservers.previous = this.galleries[gallery[0]][gallery[1]][current - this.imageCount];
                    } else {
                        this.navigationObservers.previous = false;
                    }
                    if (this.galleries[gallery[0]][gallery[1]][current + this.imageCount]) {
                        this.navigationObservers.next = this.galleries[gallery[0]][gallery[1]][current + this.imageCount];
                    } else {
                        this.navigationObservers.next = false;
                    }

                    this.activeGallery = true;
                } else {
                    this.navigationObservers.previous = false;
                    this.navigationObservers.next = false;

                    this.activeGallery = false;
                }

                for (var i = current; i < (current + this.imageCount); i++) {

                    if (gallery && this.galleries[gallery[0]][gallery[1]][i]) {
                        this.contentToFetch = this.galleries[gallery[0]][gallery[1]][i].href;

                        this.galleryLocation = { current: (i + 1) / this.imageCount, total: (this.galleries[gallery[0]][gallery[1]].length) / this.imageCount };

                        if (!this.galleries[gallery[0]][gallery[1]][i + this.imageCount]) {
                            $('lightwindow_next').setStyle({
                                display: 'none'
                            });
                        } else {
                            $('lightwindow_next').setStyle({
                                display: 'block'
                            });
                            $('lightwindow_next_title').innerHTML = this.galleries[gallery[0]][gallery[1]][i + this.imageCount].title;
                        }

                        if (!this.galleries[gallery[0]][gallery[1]][i - this.imageCount]) {
                            $('lightwindow_previous').setStyle({
                                display: 'none'
                            });
                        } else {
                            $('lightwindow_previous').setStyle({
                                display: 'block'
                            });
                            $('lightwindow_previous_title').innerHTML = this.galleries[gallery[0]][gallery[1]][i - this.imageCount].title;
                        }
                    }

                    images[i] = document.createElement('img');
                    images[i].setAttribute('id', 'lightwindow_image_' + i);
                    images[i].setAttribute('border', '0');
                    images[i].setAttribute('src', this.contentToFetch);
                    $('lightwindow_contents').appendChild(images[i]);

                    // We have to do this instead of .onload 
                    this.checkImage[i] = new PeriodicalExecuter(function(i) {
                        if (!(typeof $('lightwindow_image_' + i).naturalWidth != "undefined" && $('lightwindow_image_' + i).naturalWidth == 0)) {

                            this.checkImage[i].stop();

                            var imageHeight = $('lightwindow_image_' + i).getHeight();
                            if (imageHeight > this.resizeTo.height) {
                                this.resizeTo.height = imageHeight;
                            }
                            this.resizeTo.width += $('lightwindow_image_' + i).getWidth();
                            this.imageCount--;

                            $('lightwindow_image_' + i).setStyle({
                                height: '100%'
                            });

                            if (this.imageCount == 0) {
                                this._processWindow();
                            }
                        }

                    } .bind(this, i), 1);
                }


                break;

            case 'media':

                var current = 0;
                this.resizeTo.height = this.resizeTo.width = 0;

                // If there is a gallery get it
                //  NR:  12/29/2008
                //  Fixing galleries (rel vs. rev)
                //if (gallery = this._getGalleryInfo(this.element.rel)) {
                if (gallery = this._getGalleryInfo(this.element.rev)) {
                    for (current = 0; current < this.galleries[gallery[0]][gallery[1]].length; current++) {
                        if (this.contentToFetch.indexOf(this.galleries[gallery[0]][gallery[1]][current].href) > -1) {
                            break;
                        }
                    }

                    if (this.galleries[gallery[0]][gallery[1]][current - 1]) {
                        this.navigationObservers.previous = this.galleries[gallery[0]][gallery[1]][current - 1];
                    } else {
                        this.navigationObservers.previous = false;
                    }
                    if (this.galleries[gallery[0]][gallery[1]][current + 1]) {
                        this.navigationObservers.next = this.galleries[gallery[0]][gallery[1]][current + 1];
                    } else {
                        this.navigationObservers.next = false;
                    }

                    this.activeGallery = true;
                } else {
                    this.navigationObservers.previous = false;
                    this.navigationObservers.next = false;

                    this.activeGallery = false;
                }


                if (gallery && this.galleries[gallery[0]][gallery[1]][current]) {
                    this.contentToFetch = this.galleries[gallery[0]][gallery[1]][current].href;

                    this.galleryLocation = { current: current + 1, total: this.galleries[gallery[0]][gallery[1]].length };

                    if (!this.galleries[gallery[0]][gallery[1]][current + 1]) {
                        $('lightwindow_next').setStyle({
                            display: 'none'
                        });
                    } else {
                        $('lightwindow_next').setStyle({
                            display: 'block'
                        });
                        $('lightwindow_next_title').innerHTML = this.galleries[gallery[0]][gallery[1]][current + 1].title;
                    }

                    if (!this.galleries[gallery[0]][gallery[1]][current - 1]) {
                        $('lightwindow_previous').setStyle({
                            display: 'none'
                        });
                    } else {
                        $('lightwindow_previous').setStyle({
                            display: 'block'
                        });
                        $('lightwindow_previous_title').innerHTML = this.galleries[gallery[0]][gallery[1]][current - 1].title;
                    }
                }

                if (this._getParameter('lightwindow_iframe_embed')) {
                    this.resizeTo.height = this.dimensions.viewport.height;
                    this.resizeTo.width = this.dimensions.viewport.width;
                } else {
                    this.resizeTo.height = this._getParameter('lightwindow_height');
                    this.resizeTo.width = this._getParameter('lightwindow_width');
                }

                this._processWindow();

                break;

            case 'external':

                this._appendIframe('auto');

                this.resizeTo.height = this.dimensions.viewport.height;
                this.resizeTo.width = this.dimensions.viewport.width;

                this._processWindow();

                break;

            case 'page':

                var newAJAX = new Ajax.Request(
				this.contentToFetch, {
				    method: 'get',
				    parameters: '',
				    onComplete: function(response) {
				        $('lightwindow_contents').innerHTML += response.responseText;
				        this.resizeTo.height = $('lightwindow_contents').scrollHeight + (this.options.contentOffset.height);
				        this.resizeTo.width = $('lightwindow_contents').scrollWidth + (this.options.contentOffset.width);
				        this._processWindow();
				    } .bind(this)
				}
			);

                break;

            case 'inline':

                var content = this.contentToFetch;
                if (content.indexOf('?') > -1) {
                    content = content.substring(0, content.indexOf('?'));
                }
                content = content.substring(content.indexOf('#') + 1);

                new Insertion.Top($('lightwindow_contents'), $(content).innerHTML);

                this.resizeTo.height = $('lightwindow_contents').scrollHeight + (this.options.contentOffset.height);
                this.resizeTo.width = $('lightwindow_contents').scrollWidth + (this.options.contentOffset.width);

                this._toggleTroubleElements('hidden', true);
                this._processWindow();

                break;

            default:
                throw ("Page Type could not be determined, please amend this lightwindow URL " + this.contentToFetch);
                break;
        }
    },
    //
    //  Resize the Window to fit the viewport if necessary
    //
    _resizeWindowToFit: function() {
        if (this.resizeTo.height + this.dimensions.cruft.height > this.dimensions.viewport.height) {
            var heightRatio = this.resizeTo.height / this.resizeTo.width;
            this.resizeTo.height = this.dimensions.viewport.height - this.dimensions.cruft.height - (2 * this.options.viewportPadding);
            // We only care about ratio's with this window type			
            if (this.windowType == 'image' || this.windowType == 'page' || (this.windowType == 'media' && !this._getParameter('lightwindow_iframe_embed'))) {
                this.resizeTo.width = this.resizeTo.height / heightRatio;
                $('lightwindow_data_slide_inner').setStyle({
                    width: this.resizeTo.width + 'px'
                });
            }
        }
        if (this.resizeTo.width + this.dimensions.cruft.width > this.dimensions.viewport.width) {
            var widthRatio = this.resizeTo.width / this.resizeTo.height;
            this.resizeTo.width = this.dimensions.viewport.width - 2 * this.dimensions.cruft.width - (2 * this.options.viewportPadding);
            // We only care about ratio's with this window type
            if (this.windowType == 'image' || this.windowType == 'page' || (this.windowType == 'media' && !this._getParameter('lightwindow_iframe_embed'))) {
                this.resizeTo.height = this.resizeTo.width / widthRatio;
                $('lightwindow_data_slide_inner').setStyle({
                    height: this.resizeTo.height + 'px'
                });
            }
        }

    },
    //
    //  Set the Window to a preset size
    //
    _presetWindowSize: function() {
        if (this._getParameter('lightwindow_height')) {
            this.resizeTo.height = parseFloat(this._getParameter('lightwindow_height'));
        }
        if (this._getParameter('lightwindow_width')) {
            this.resizeTo.width = parseFloat(this._getParameter('lightwindow_width'));
        }
    },
    //
    //  Process the Window
    //
    _processWindow: function() {
        // Clean out our effects
        this.dimensions.dataEffects = [];

        //  NR:  12/29/2008
        //  Get rid of that annoying data details bar if nothing is in it
        if (!(this.element.author || (this.activeGallery && this.options.showGalleryCount))) {
            $('lightwindow_data_details').hide();
        }

        // Set up the data-slide if we have caption information
        //  NR:  12/29/2008
        //  Replaced caption with title
        if (this.element.title || this.element.author || (this.activeGallery && this.options.showGalleryCount)) {
            if (this.element.title) {
                $('lightwindow_data_caption').innerHTML = this.element.title;
                $('lightwindow_data_caption').setStyle({
                    display: 'block'
                });
            } else {
                $('lightwindow_data_caption').setStyle({
                    display: 'none'
                });
            }
            if (this.element.author) {
                $('lightwindow_data_author').innerHTML = this.element.author;
                $('lightwindow_data_author_container').setStyle({
                    display: 'block'
                });
            } else {
                $('lightwindow_data_author_container').setStyle({
                    display: 'none'
                });
            }
            if (this.activeGallery && this.options.showGalleryCount) {
                $('lightwindow_data_gallery_current').innerHTML = this.galleryLocation.current;
                $('lightwindow_data_gallery_total').innerHTML = this.galleryLocation.total;
                $('lightwindow_data_gallery_container').setStyle({
                    display: 'block'
                });
            } else {
                $('lightwindow_data_gallery_container').setStyle({
                    display: 'none'
                });
            }

            $('lightwindow_data_slide_inner').setStyle({
                width: this.resizeTo.width + 'px',
                height: 'auto',
                visibility: 'visible',
                display: 'block'
            });
            $('lightwindow_data_slide').setStyle({
                height: $('lightwindow_data_slide').getHeight() + 'px',
                width: '1px',
                overflow: 'hidden',
                display: 'block'
            });
        } else {
            $('lightwindow_data_slide').setStyle({
                display: 'none',
                width: 'auto'
            });
            $('lightwindow_data_slide_inner').setStyle({
                display: 'none',
                visibility: 'hidden',
                width: this.resizeTo.width + 'px',
                height: '0px'
            });
        }

        //        if (this.element.title != 'null') {
        //            $('lightwindow_title_bar_title').innerHTML = this.element.title;
        //        } else {
        //            $('lightwindow_title_bar_title').innerHTML = '';
        //        }

        var originalContainerDimensions = { height: $('lightwindow_container').getHeight(), width: $('lightwindow_container').getWidth() };
        // Position the window
        $('lightwindow_container').setStyle({
            height: 'auto',
            // We need to set the width to a px not auto as opera has problems with it
            width: $('lightwindow_container').getWidth() + this.options.contentOffset.width - (this.windowActive ? this.options.contentOffset.width : 0) + 'px'
        });
        var newContainerDimensions = { height: $('lightwindow_container').getHeight(), width: $('lightwindow_container').getWidth() };

        // We need to record the container dimension changes
        this.containerChange = { height: originalContainerDimensions.height - newContainerDimensions.height, width: originalContainerDimensions.width - newContainerDimensions.width };

        // Get out general dimensions
        this.dimensions.container = { height: $('lightwindow_container').getHeight(), width: $('lightwindow_container').getWidth() };
        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 };

        // Set Sizes if we need too
        this._presetWindowSize();
        this._resizeWindowToFit(); // Even if the window is preset we still don't want it to go outside of the viewport

        if (!this.windowActive) {
            // Position the window
            $('lightwindow_container').setStyle({
                left: -(this.dimensions.container.width / 2) + 'px',
                top: -(this.dimensions.container.height / 2) + 'px'
            });
        }
        $('lightwindow_container').setStyle({
            height: this.dimensions.container.height + 'px',
            width: this.dimensions.container.width + 'px'
        });

        // We are ready, lets show this puppy off!
        this._displayLightWindow('block', 'visible');
        this._animateLightWindow();
    },
    //
    //  Fire off our animation handler
    //
    _animateLightWindow: function() {
        if (this.options.animationHandler) {
            this.options.animationHandler().bind(this);
        } else {
            this._defaultAnimationHandler();
        }
    },
    //
    //  Fire off our transition handler
    //
    _handleNavigation: function(display) {
        if (this.options.navigationHandler) {
            this.options.navigationHandler().bind(this, display);
        } else {
            this._defaultDisplayNavigation(display);
        }
    },
    //
    //  Fire off our transition handler
    //
    _handleTransition: function() {
        if (this.options.transitionHandler) {
            this.options.transitionHandler().bind(this);
        } else {
            this._defaultTransitionHandler();
        }
    },
    //
    //  Handle the finish of the window animation
    // 
    _handleFinalWindowAnimation: function(delay) {
        if (this.options.finalAnimationHandler) {
            this.options.finalAnimationHandler().bind(this, delay);
        } else {
            this._defaultfinalWindowAnimationHandler(delay);
        }
    },
    //
    //  Handle the gallery Animation
    // 
    _handleGalleryAnimation: function(list) {
        if (this.options.galleryAnimationHandler) {
            this.options.galleryAnimationHandler().bind(this, list);
        } else {
            this._defaultGalleryAnimationHandler(list);
        }
    },
    //
    //  Display the navigation 
    //
    _defaultDisplayNavigation: function(display) {
        if (display) {
            $('lightwindow_navigation').setStyle({
                display: 'block',
                height: $('lightwindow_contents').getHeight() + 'px',
                width: '100%',
                marginTop: this.options.dimensions.titleHeight + 'px'
            });
        } else {
            $('lightwindow_navigation').setStyle({
                display: 'none',
                height: 'auto',
                width: 'auto'
            });
        }
    },
    //
    //  This is the default animation handler for LightWindow
    //
    _defaultAnimationHandler: function() {
        // Now that we have figures out the cruft lets make the caption go away and add its effects
        if (this.element.title || this.element.author || (this.activeGallery && this.options.showGalleryCount)) {
            $('lightwindow_data_slide').setStyle({
                display: 'none',
                width: 'auto'
            });
            this.dimensions.dataEffects.push(
				new Effect.SlideDown('lightwindow_data_slide', { sync: true }),
				new Effect.Appear('lightwindow_data_slide', { sync: true, from: 0.0, to: 1.0 })
			);
        }

        // Set up the Title if we have one
        $('lightwindow_title_bar_inner').setStyle({
            height: '0px',
            marginTop: this.options.dimensions.titleHeight + 'px'
        });

        // We always want the title bar as well
        this.dimensions.dataEffects.push(
			new Effect.Morph('lightwindow_title_bar_inner', { sync: true, style: { height: this.options.dimensions.titleHeight + 'px', marginTop: '0px'} }),
		 	new Effect.Appear('lightwindow_title_bar_inner', { sync: true, from: 0.0, to: 1.0 })
		);

        if (!this.options.hideGalleryTab) {
            this._handleGalleryAnimation(false);
            if ($('lightwindow_galleries_tab_container').getHeight() == 0) {
                this.dimensions.dataEffects.push(
					new Effect.Morph('lightwindow_galleries_tab_container', { sync: true, style: { height: '20px', marginTop: '0px'} })
				);
                $('lightwindow_galleries').setStyle({
                    width: '0px'
                });
            }
        }

        var resized = false;
        //        var ratio = this.dimensions.container.width - $('lightwindow_contents').getWidth() + this.resizeTo.width + this.options.contentOffset.width;
        //        if (ratio != $('lightwindow_container').getWidth()) {
        //            new Effect.Parallel([
        //					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 }),
        //					new Effect.Scale('lightwindow_container', 100 * (ratio / (this.dimensions.container.width)), { sync: true, scaleY: false, scaleFromCenter: true, scaleContent: false })
        //				], {
        //				    duration: this.duration,
        //				    delay: 0.25,
        //				    queue: { position: 'end', scope: 'lightwindowAnimation' }
        //				}
        //			);
        //        }

        var ratioWidth = this.dimensions.container.width - $('lightwindow_contents').getWidth() + this.resizeTo.width + this.options.contentOffset.width;
        var ratioHeight = this.dimensions.container.height - $('lightwindow_contents').getHeight() + this.resizeTo.height + this.options.contentOffset.height;
        if (ratioHeight != $('lightwindow_container').getHeight() || ratioWidth != $('lightwindow_container').getWidth()) {
            new Effect.Parallel([
            //new Effect.Appear('lightwindow_container', { sync: true }),
            		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 }),
					new Effect.Scale('lightwindow_container', 100 * (ratioWidth / (this.dimensions.container.width)), { sync: true, scaleY: false, scaleFromCenter: true, scaleContent: false }),
					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 }),
					new Effect.Scale('lightwindow_container', 100 * (ratioHeight / (this.dimensions.container.height)), { sync: true, scaleX: false, scaleFromCenter: true, scaleContent: false })
				], {
				    duration: this.duration * 1.25,
				    afterFinish: function() {
				        if (this.dimensions.dataEffects.length > 0) {
				            if (!this.options.hideGalleryTab) {
				                $('lightwindow_galleries').setStyle({
				                    width: this.resizeTo.width + 'px'
				                });
				            }
				            new Effect.Parallel(this.dimensions.dataEffects, {
				                duration: this.duration,
				                afterFinish: function() {
				                    this._finishWindow();
				                } .bind(this),
				                queue: { position: 'end', scope: 'lightwindowAnimation' }
				            }
							);
				        }
				    } .bind(this),
				    queue: { position: 'end', scope: 'lightwindowAnimation' }
				}
			);
            resized = true;
        }

        // We need to do our data effect since there was no resizing
        if (!resized && this.dimensions.dataEffects.length > 0) {
            new Effect.Parallel(this.dimensions.dataEffects, {
                duration: this.duration,
                beforeStart: function() {
                    if (!this.options.hideGalleryTab) {
                        $('lightwindow_galleries').setStyle({
                            width: this.resizeTo.width + 'px'
                        });
                    }
                    if (this.containerChange.height != 0 || this.containerChange.width != 0) {
                        new Effect.MoveBy('lightwindow_container', this.containerChange.height, this.containerChange.width, { transition: Effect.Transitions.sinoidal });
                    }
                } .bind(this),
                afterFinish: function() {
                    this._finishWindow();
                } .bind(this),
                queue: { position: 'end', scope: 'lightwindowAnimation' }
            }
			);
        }

    },
    //
    //  Finish up Window Animation
    //
    _defaultfinalWindowAnimationHandler: function(delay) {
        if (this.windowType == 'media' || this._getParameter('lightwindow_loading_animation')) {
            // Because of major flickering with the overlay we just hide it in this case
            Element.hide('lightwindow_loading');
            this._handleNavigation(this.activeGallery);
            this._setStatus(false);
        } else {
            Effect.Fade('lightwindow_loading', {
                duration: 0.75,
                delay: 1.0,
                afterFinish: function() {
                    // Just in case we need some scroll goodness (this also avoids the swiss cheese effect)
                    if (this.windowType != 'image' && this.windowType != 'media' && this.windowType != 'external') {
                        $('lightwindow_contents').setStyle({
                            overflow: 'auto'
                        });
                    }
                    this._handleNavigation(this.activeGallery);
                    this._defaultGalleryAnimationHandler();
                    this._setStatus(false);
                } .bind(this),
                queue: { position: 'end', scope: 'lightwindowAnimation' }
            });
        }
    },
    //
    //  Handle the gallery Animation
    //
    _defaultGalleryAnimationHandler: function(list) {
        if (this.activeGallery) {
            $('lightwindow_galleries').setStyle({
                display: 'block',
                marginBottom: $('lightwindow_data_slide').getHeight() + this.options.contentOffset.height / 2 + 'px'
            });
            $('lightwindow_navigation').setStyle({
                height: $('lightwindow_contents').getHeight() - 20 + 'px'
            });
        } else {
            $('lightwindow_galleries').setStyle({
                display: 'none'
            });
            $('lightwindow_galleries_tab_container').setStyle({
                height: '0px',
                marginTop: '20px'
            });
            $('lightwindow_galleries_list').setStyle({
                height: '0px'
            });
            return false;
        }

        if (list) {
            if ($('lightwindow_galleries_list').getHeight() == 0) {
                var height = $('lightwindow_contents').getHeight() * 0.80;
                $('lightwindow_galleries_tab_span').className = 'down';
            } else {
                var height = 0;
                $('lightwindow_galleries_tab_span').className = 'up';
            }

            new Effect.Morph('lightwindow_galleries_list', {
                duration: this.duration,
                transition: Effect.Transitions.sinoidal,
                style: { height: height + 'px' },
                beforeStart: function() {
                    $('lightwindow_galleries_list').setStyle({
                        overflow: 'hidden'
                    });
                },
                afterFinish: function() {
                    $('lightwindow_galleries_list').setStyle({
                        overflow: 'auto'
                    });
                },
                queue: { position: 'end', scope: 'lightwindowAnimation' }
            });
        }


    },
    //
    //  Default Transition Handler
    //
    _defaultTransitionHandler: function() {
        // Clean out our effects
        this.dimensions.dataEffects = [];

        // Now that we have figures out the cruft lets make the caption go away and add its effects
        if ($('lightwindow_data_slide').getStyle('display') != 'none') {
            this.dimensions.dataEffects.push(
				new Effect.SlideUp('lightwindow_data_slide', { sync: true }),
				new Effect.Fade('lightwindow_data_slide', { sync: true, from: 1.0, to: 0.0 })
			);
        }

        if (!this.options.hideGalleryTab) {
            if ($('lightwindow_galleries').getHeight() != 0 && !this.options.hideGalleryTab) {
                this.dimensions.dataEffects.push(
					new Effect.Morph('lightwindow_galleries_tab_container', { sync: true, style: { height: '0px', marginTop: '20px'} })
				);
            }

            if ($('lightwindow_galleries_list').getHeight() != 0) {
                $('lightwindow_galleries_tab_span').className = 'up';
                this.dimensions.dataEffects.push(
					new Effect.Morph('lightwindow_galleries_list', {
					    sync: true,
					    style: { height: '0px' },
					    transition: Effect.Transitions.sinoidal,
					    beforeStart: function() {
					        $('lightwindow_galleries_list').setStyle({
					            overflow: 'hidden'
					        });
					    },
					    afterFinish: function() {
					        $('lightwindow_galleries_list').setStyle({
					            overflow: 'auto'
					        });
					    }
					})
				);
            }
        }

        // We always want the title bar as well
        this.dimensions.dataEffects.push(
			new Effect.Morph('lightwindow_title_bar_inner', { sync: true, style: { height: '0px', marginTop: this.options.dimensions.titleHeight + 'px'} }),
		 	new Effect.Fade('lightwindow_title_bar_inner', { sync: true, from: 1.0, to: 0.0 })
		);

        new Effect.Parallel(this.dimensions.dataEffects, {
            duration: this.duration,
            afterFinish: function() {
                this._loadWindow();
            } .bind(this),
            queue: { position: 'end', scope: 'lightwindowAnimation' }
        }
		);
    },
    //
    //	Default Form handler for LightWindow
    //
    _defaultFormHandler: function(e) {
        var element = Event.element(e).parentNode;
        var parameterString = Form.serialize(this._getParameter('lightwindow_form', element.getAttribute('params')));
        if (this.options.formMethod == 'post') {
            var newAJAX = new Ajax.Request(element.href, {
                method: 'post',
                postBody: parameterString,
                onComplete: this.openWindow.bind(this, element)
            });
        } else if (this.options.formMethod == 'get') {
            var newAJAX = new Ajax.Request(element.href, {
                method: 'get',
                parameters: parameterString,
                onComplete: this.openWindow.bind(this, element)
            });
        }
    },
    // 
    //  Wrap everything up
    //
    _finishWindow: function() {
        if (this.windowType == 'external') {
            // We set the externals source here because it allows for a much smoother animation
            $('lightwindow_iframe').setAttribute('src', this.element.href);
            this._handleFinalWindowAnimation(1);
        } else if (this.windowType == 'media') {

            var outerObject = document.createElement('object');
            outerObject.setAttribute('classid', this.options.classids[this._fileExtension(this.contentToFetch)]);
            outerObject.setAttribute('codebase', this.options.codebases[this._fileExtension(this.contentToFetch)]);
            outerObject.setAttribute('id', 'lightwindow_media_primary');
            outerObject.setAttribute('name', 'lightwindow_media_primary');
            outerObject.setAttribute('width', this.resizeTo.width);
            outerObject.setAttribute('height', this.resizeTo.height);
            outerObject = this._addParamToObject('movie', this.contentToFetch, outerObject);
            outerObject = this._addParamToObject('src', this.contentToFetch, outerObject);
            outerObject = this._addParamToObject('controller', 'true', outerObject);
            outerObject = this._addParamToObject('wmode', 'transparent', outerObject);
            outerObject = this._addParamToObject('cache', 'false', outerObject);
            outerObject = this._addParamToObject('quality', 'high', outerObject);

            if (!Prototype.Browser.IE) {
                var innerObject = document.createElement('object');
                innerObject.setAttribute('type', this.options.mimeTypes[this._fileExtension(this.contentToFetch)]);
                innerObject.setAttribute('data', this.contentToFetch);
                innerObject.setAttribute('id', 'lightwindow_media_secondary');
                innerObject.setAttribute('name', 'lightwindow_media_secondary');
                innerObject.setAttribute('width', this.resizeTo.width);
                innerObject.setAttribute('height', this.resizeTo.height);
                innerObject = this._addParamToObject('controller', 'true', innerObject);
                innerObject = this._addParamToObject('wmode', 'transparent', innerObject);
                innerObject = this._addParamToObject('cache', 'false', innerObject);
                innerObject = this._addParamToObject('quality', 'high', innerObject);

                outerObject.appendChild(innerObject);
            }

            if (this._getParameter('lightwindow_iframe_embed')) {
                this._appendIframe('no');
                this._writeToIframe(this._convertToMarkup(outerObject, 'object'));
            } else {
                this._appendObject(outerObject, 'object', $('lightwindow_contents'));
            }

            this._handleFinalWindowAnimation(0);
        } else {
            this._handleFinalWindowAnimation(0);
        }

        // Initialize any actions
        this._setupActions();
    }
}

/*-----------------------------------------------------------------------------------------------*/



//
//	Set up all of our links
//
var myLightWindow = null;
function lightwindowInit() {
    myLightWindow = new lightwindow();
}






/**
Copyright (c) 2008 Victor Stanciu; contact [at] victorstanciu [dot] ro; http://www.victorstanciu.ro/

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

/** 
* @description		showcase plugin for prototype.js
* @author		Victor Stanciu; contact [at] victorstanciu [dot] ro; http://www.victorstanciu.ro/ 				
* @date		03/10/2008
* @requires		prototype.js 1.6, effects.js 1.8
*/

Showcase = Class.create(Abstract, {
    initialize: function(sections, controls, options) {

        this.allSections = this.sections = sections;
        this.controls = controls;

        this.options = Object.extend({
            ratio: 0.5,
            initialDelay: 1,
            duration: 0.5,
            size: this.sections.size()
        }, options || {});

        this.running = false;
        this.queue = new Array;

        this.computeMetrics();

        this.sections = this.allSections.slice(this.currentIndex - this.half, this.currentIndex + this.half + 1);

        this.allSections.each((function(section, index) {
            section.setStyle({ position: 'absolute', zIndex: Math.abs(index - this.sections.size()), left: '50%', top: '50%', marginLeft: -Math.round(section.getWidth() / 2) + 'px', marginTop: -Math.round(section.getHeight() / 2) + 'px' }).initialIndex = index;

            section.observe('click', this.jump.bind(this)).observe('mouseover', function(event) {
                section.setOpacity(1);
            }).observe('mouseout', function() {
                section.setOpacity(section.opacity);
            }).opacity = 1;

            if (!this.sections.member(section)) {
                this.queue.push(section.hide());
            }
        }).bind(this));

        for (i = 0; i <= this.half; i++) {
            this.sections.push(this.sections.shift());
        }

        this.controls.invoke('observe', 'click', this.click.bind(this));
        (this.animate.bind(this)).delay(this.options.initialDelay);
    },

    computeMetrics: function() {
        this.half = this.currentIndex = (this.options.size - 1) / 2;
        this.ratioStep = Math.round(((1 - this.options.ratio) / this.currentIndex) * 100) / 100;
        this.positionStep = Math.round(50 / this.half * 100) / 100;
        this.maxDimensions = this.sections.first().getDimensions();
    },

    click: function(event) {
        event.stop();
        var element = event.findElement('a');
        if (!this.running) {
            eval("this." + element.rel + "()");
        }
        this.animate(element.rel);
    },

    previous: function() {
        if (this.options.size < this.allSections.size()) {
            var sectionIn = this.queue.shift();
            var sectionOut = this.sections.pop();

            this.sections.unshift(sectionIn);
            this.queue.push(sectionOut.fade({ duration: this.options.duration }));
        } else {
            this.sections.unshift(this.sections.pop());
        }
    },

    next: function() {
        if (this.options.size < this.allSections.size()) {
            var sectionIn = this.queue.shift();
            var sectionOut = this.sections.shift();

            this.sections.push(sectionIn);
            this.queue.push(sectionOut.fade({ duration: this.options.duration }));
        } else {
            this.sections.push(this.sections.shift());
        }
    },

    jump: function(event) {
        event.stop();

        if (!this.running) {
            var section = this.sections[this.sections.indexOf(event.findElement('li'))];

            var direction = '';

            if (section.index < this.half) {
                (this.half - section.index).times((function() {
                    this.previous();
                }).bind(this));
                direction = 'previous';
            } else if (section.index == this.half) {
            } else {
                (section.index - this.half).times((function() {
                    this.next();
                }).bind(this));
                direction = 'next';
            }
        }

        this.animate(direction);
    },

    runEffects: function() {

        this.stackSections.bind(this).delay(this.options.duration / 2);

        this.running = new Effect.Parallel(
			this.effects.map(function(effect) {
			    return new Effect.Parallel([
					new Effect.Morph(effect.section, {
					    style: effect.style,
					    sync: true,
					    delay: 1,
					    transition: Effect.Transitions.linear
					}),
					new Effect.Appear(effect.section, {
					    to: Math.min(effect.section.ratio, 1),
					    sync: true
					})
					], {
					    sync: true,
					    beforeStart: function() {
					    }
					});
			}), {
			    duration: this.options.duration,
			    afterFinish: (function() {
			        this.running = false;
			    }).bind(this)
			});
    },

    stackSections: function() {
        this.sections.each(function(section) {
            section.setStyle({ zIndex: section.stackIndex });
        });
    },

    indexSections: function() {
        this.sections.each((function(section, index) {
            section.index = index;
            section.modifier = Math.abs(Math.abs((section.index - (this.sections.size() - 1) / 2)) - this.half);

            section.ratio = Math.round(((section.modifier * this.ratioStep) + this.options.ratio) * 100) / 100;

            section.width = Math.min(Math.round(this.maxDimensions.width * section.ratio), this.maxDimensions.width);
            section.height = Math.min(Math.round(this.maxDimensions.height * section.ratio), this.maxDimensions.height);

            section.positionIndex = (section.index - (this.sections.size() - 1) / 2);
            section.stackIndex = Math.abs(Math.abs((section.index - (this.sections.size() - 1) / 2)) - this.half) + 1;

            section.left = section.top = Math.round((this.half + section.positionIndex) * this.positionStep);
            section.opacity = Math.min(section.ratio, 1);
        }).bind(this));
    }
});

Showcase.Horizontal = Class.create(Showcase, {

    animate: function(direction) {
        this.indexSections();

        this.effects = new Array();
        this.sections.each((function(section) {
            var style = {
                left: section.left + '%',
                top: '50%',
                marginTop: -Math.abs(section.height / 2) + 'px',
                width: section.width + 'px',
                height: section.height + 'px'
            };

            if (section.left == 0) {
                style.marginLeft = '0px';
            } else if (section.left == 50) {
                style.marginLeft = -Math.round(section.width / 2) + 'px';
            } else if (section.left == 100) {
                style.marginLeft = -section.width + 'px';
            } else {
                style.marginLeft = -Math.round(section.width / 2) + 'px';
            }

            this.effects.push({ section: section, style: style });
        }).bind(this));

        this.currentIndex = this.sections[this.half].initialIndex;

        this.runEffects();
    }

});

Showcase.Vertical = Class.create(Showcase, {

    animate: function(direction) {
        this.indexSections();

        this.effects = new Array();
        this.sections.each((function(section) {
            var style = {
                top: section.top + '%',
                left: '50%',
                marginLeft: -Math.abs(section.width / 2) + 'px',
                width: section.width + 'px',
                height: section.height + 'px'
            };

            if (section.top == 0) {
                style.marginTop = '0px';
            } else if (section.top == 50) {
                style.marginTop = -Math.round(section.height / 2) + 'px';
            } else if (section.top == 100) {
                style.marginTop = -section.height + 'px';
            } else {
                style.marginTop = -Math.round(section.height / 2) + 'px';
            }

            this.effects.push({ section: section, style: style });
        }).bind(this));

        this.currentIndex = this.sections[this.half].initialIndex;

        this.runEffects();
    }
});

Showcase.Diagonal = Class.create(Showcase, {

    animate: function(direction) {
        this.indexSections();

        this.effects = new Array();
        this.sections.each((function(section) {
            var style = {
                left: section.left + '%',
                top: section.top + '%',
                width: section.width + 'px',
                height: section.height + 'px'
            };

            if (section.left == 0) {
                style.marginLeft = '0px';
            } else if (section.left == 50) {
                style.marginLeft = -Math.round(section.width / 2) + 'px';
            } else if (section.left == 100) {
                style.marginLeft = -section.width + 'px';
            } else {
                style.marginLeft = -Math.round(section.width / 2) + 'px';
            }

            if (section.top == 0) {
                style.marginTop = '0px';
            } else if (section.top == 50) {
                style.marginTop = -Math.round(section.height / 2) + 'px';
            } else if (section.top == 100) {
                style.marginTop = -section.height + 'px';
            } else {
                style.marginTop = -Math.round(section.height / 2) + 'px';
            }

            this.effects.push({ section: section, style: style });
        }).bind(this));

        this.currentIndex = this.sections[this.half].initialIndex;

        this.runEffects();
    }

});



/**
Copyright (c) 2008 Victor Stanciu; contact [at] victorstanciu [dot] ro; http://www.victorstanciu.ro/

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

/** 
* @description		carousel plugin for prototype.js
* @author		Victor Stanciu; contact [at] victorstanciu [dot] ro; http://www.victorstanciu.ro/ 
inspired by Glider.js by Bruno Bornsztein - http://missingmethod.com/projects/glider.html
* @date		30/03/08
* @requires		prototype.js 1.6, effects.js 1.8
*/

Carousel = Class.create(Abstract, {

    initialize: function(scroller, slides, controls, options) {

        this.scrolling = false;
        this.scroller = scroller;
        this.slides = slides;
        this.controls = controls;

        this.options = Object.extend({ duration: 1.0, frequency: 3, controlClassName: 'carousel-control', jumperClassName: 'carousel-jumper' }, options || {});

        this.slides.each(function(slide, index) {
            slide._index = index;
        });

        if (this.controls) {
            this.controls.invoke('observe', 'click', this.click.bind(this));
        }

        if (this.options.auto) {
            this.start();
            this.slides.invoke('observe', 'mouseover', this.pause.bind(this));
            this.slides.invoke('observe', 'mouseout', this.resume.bind(this));
        }

    },

    click: function(event) {

        this.stop();

        var element = event.findElement('a');

        if (!element.hasClassName('disabled')) {
            this.deactivateControls();
            if (element.hasClassName(this.options.controlClassName)) {
                eval("this." + element.rel + "()");
            } else if (element.hasClassName(this.options.jumperClassName)) {
                this.moveTo(element, element.rel);
            }
        }

        event.stop();

    },

    moveTo: function(trigger, element) {

        if (this.options.beforeMove && (typeof this.options.beforeMove == 'function')) {
            this.options.beforeMove();
        }

        if (this.controls && this.options.selectedClassName) {
            this.controls.each((function(elm) { elm.removeClassName(this.options.selectedClassName); }).bind(this));
            trigger.addClassName(this.options.selectedClassName);
        }

        this.previous = this.current ? this.current : this.slides[0];
        this.current = $(element);

        var scrollerOffset = this.scroller.cumulativeOffset();
        var elementOffset = this.current.cumulativeOffset();

        if (this.scrolling) {
            this.scrolling.cancel();
        }

        this.scrolling = new Effect.SmoothScroll(this.scroller, {
            duration: this.options.duration,
            x: (elementOffset[0] - scrollerOffset[0]),
            y: (elementOffset[1] - scrollerOffset[1]),
            queue: { position: 'end', limit: 1, scope: this.scroller.id },
            afterFinish: (function() {
                if (this.controls) {
                    this.activateControls();
                }
            }).bind(this)
        });

        if (this.options.afterMove && (typeof this.options.afterMove == 'function')) {
            this.options.afterMove();
        }

        return false;

    },

    prev: function() {
        if (this.current) {
            var currentIndex = this.current._index;
            var prevIndex = (currentIndex == 0) ? this.slides.length - 1 : currentIndex - 1;
        } else {
            var prevIndex = this.slides.length - 1;
        }

        this.moveTo(this.controls ? this.controls[prevIndex] : false, this.slides[prevIndex]);
    },

    next: function() {
        if (this.current) {
            var currentIndex = this.current._index;
            var nextIndex = (this.slides.length - 1 == currentIndex) ? 0 : currentIndex + 1;
        } else {
            var nextIndex = 1;
        }

        this.moveTo(this.controls ? this.controls[nextIndex] : false, this.slides[nextIndex]);
    },

    first: function() {
        var firstIndex = 0;
        if (this.current) {
            var currentIndex = this.current._index;
        }

        this.moveTo(this.controls[firstIndex], this.slides[firstIndex]);
    },

    last: function() {
        var lastIndex = (this.slides.length - 1);
        if (this.current) {
            var currentIndex = this.current._index;
        }

        this.moveTo(this.controls[lastIndex], this.slides[lastIndex]);
    },

    toggle: function() {
        if (this.previous) {
            this.moveTo(this.controls[this.previous._index], this.slides[this.previous._index]);
        } else {
            return false;
        }
    },

    stop: function() { clearTimeout(this.timer); },

    start: function() { this.periodicallyUpdate(); },

    pause: function(event) {
        this.stop();
        this.activateControls();
    },

    resume: function(event) {
        if (event) {
            var related = event.relatedTarget || event.toElement;
            if (!related || (!this.slides.include(related) && !this.slides.any(function(slide) { return related.descendantOf(slide); }))) {
                this.start();
            }
        } else {
            this.start();
        }
    },

    periodicallyUpdate: function() {
        if (this.timer != null) {
            clearTimeout(this.timer);
            this.next();
        }
        this.timer = setTimeout(this.periodicallyUpdate.bind(this), this.options.frequency * 1000);
    },

    deactivateControls: function() {
        this.controls.invoke('addClassName', 'disabled');
    },

    activateControls: function() {
        this.controls.invoke('removeClassName', 'disabled');
    }

});

Effect.SmoothScroll = Class.create();

Object.extend(Object.extend(Effect.SmoothScroll.prototype, Effect.Base.prototype), {

    initialize: function(element) {
        this.element = $(element);
        var options = Object.extend({ x: 0, y: 0, mode: 'absolute' }, arguments[1] || {});
        this.start(options);
    },

    setup: function() {
        if (this.options.continuous && !this.element._ext) {
            this.element.cleanWhitespace();
            this.element._ext = true;
            this.element.appendChild(this.element.firstChild);
        }

        this.originalLeft = this.element.scrollLeft;
        this.originalTop = this.element.scrollTop;

        if (this.options.mode == 'absolute') {
            this.options.x -= this.originalLeft;
            this.options.y -= this.originalTop;
        }
    },

    update: function(position) {
        this.element.scrollLeft = this.options.x * position + this.originalLeft;
        this.element.scrollTop = this.options.y * position + this.originalTop;
    }

});





//  Custom Initialization
//  This is proprietary to all SV clients

Event.observe(window, 'load', function() {
    if (lightwindowInit) lightwindowInit();

    //  Set each watermark
    $$('.watermark').each(function(element) {
        new Watermark(element, 'watermark');
    });

    //  Set each tooltip
    $$('.tip').each(function(element) {
        new Tips(element, 'tip');
    });

    //  Test for autocompleter search textbox
    if ($('tSearch')) {
        var searchAutocompleter = new Ajax.Autocompleter('tSearch', 'tSearchUpdate', '/User-Search-Parameters.aspx', { paramName: 'tSearch', minChars: 3, parameters: 'max=6', afterUpdateElement: function(e) { document.location = '/SearchResults.aspx?tSearch=' + $('tSearch').value; } });
    }

    //  This would be a good place to preload images for the Loading object extensions
    var loadingSmall = new Image();
    loadingSmall.src = '/images/design/loadingSmall.gif';

    var loadingMedium = new Image();
    loadingMedium.src = '/images/design/loadingMedium.gif';

    var loadingLarge = new Image();
    loadingLarge.src = '/images/design/loadingLarge.gif';
});