

// lightwindow.js v2.0, Copyright (c) 2007 stickmanlabs, Author: Kevin P Miller | http://www.stickmanlabs.com
var myLightWindow = null;
var barcodes_1 = {};
var qty_1 = {};
var limit_1 = {};
var backordered_message_1 = {};
var notify_me_popup_1 = {};

try { // This will stop image flickering in IE6 when elements with images are moved
    document.execCommand("BackgroundImageCache", false, true);
} catch(e) {}

var Lightwindow = Class.create();
Lightwindow.prototype = {
    _onCompleteActions: new Array(),
    _onDeactivateWindowActions: new Array(),
    element: null,
    contentToFetch: null,
    windowActive: false,
    clickFreshpairButton: 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
    },
    resizeTo: {
        height: null,
        heightPercent: null,
        width: null,
        widthPercent: null,
        fixedTop: null,
        fixedLeft: null
    },
    scrollbarOffset: 18,
    containerChange: {
        height: 0,
        width: 0
    },
    initialize: function(options) {
        this.options = Object.extend({
            resizeSpeed: 10,
            contentOffset: {
                height: 20,
                width: 3
            },
            dimensions: {
                page: {
                    height: 250,
                    width: 250
                },
                inline: {
                    height: 250,
                    width: 250
                },
                titleHeight: 25
            },
            classNames: {
                standard: 'lightwindow',
                action: 'lightwindow_action'
            },
            viewportPadding: 10,
            overlay: {
                opacity: 0.7,
                image: 'http://c0210251.cdn.cloudfiles.rackspacecloud.com/grey-40_001.png',
                presetImage: 'http://c0210251.cdn.cloudfiles.rackspacecloud.com/grey-40_001.png'
            },
            skin: {
                main: '<div id="lightwindow_container" >' + '<div class="rounded-corners"><div class="top1"></div><div class="top2"></div><div class="top3"></div></div>' + '<div id="lightwindow_stage" >' + '<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" >&nbsp;</a>' + '</div>' + '</div>' + '<div id="lightwindow_contents" >' + '</div>' + '</div>' + '<div class="rounded-corners"><div class="bottom1"></div><div class="bottom2"></div><div class="bottom3"></div></div>' + '</div>',
                loading: '<div id="lightwindow_loading" >' + '<img src="http://c0210251.cdn.cloudfiles.rackspacecloud.com/ajax-loader_001.gif" alt="loading" /><br /></div>'
            },
            hideFlash: false,
            showTitleBar: false,
            animationHandler: false,
            finalAnimationHandler: false
        },
				     options || {});
        this.duration = ((11 - this.options.resizeSpeed) * 0.15);
        this._getScroll();
        this._getPageDimensions();
        this._browserDimensions();
        this._addLightWindowMarkup(false);
        this._setupDimensions();
    },
    deactivate: function() {
        this.clickFreshpairButton = false;
        this.windowActive = false;
        // Kill the animation
        this.animating = false;
        // Clear our element
        this.element = null;
        this._displayLightWindow('none', 'visible');
        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);
	this.onDeactivateWindowActions();
    },
    //  Open a Window from a hash of attribute
    activateWindow: function(options) {
        //    this.windowActive = true; //FP added here to block button before multiple click as quick as it's possible, !!!! it akes problems with window position under firefox, so this is wrong place
        this.clickFreshpairButton = true;
        this.element = Object.extend({
            itemid: null,
            href: null,
            title: null,
            titleHeight: 25,
            author: null,
            rel: null,
            top: null,
            left: null,
            type: null,
            height: null,
            width: null
        },
				     options || {});
        // Set the window type
        this.contentToFetch = this.element.href;
        this.windowType = this.element.type; //? this.element.type : this._fileType(this.element.href);
        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();
    },
    _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() {
                //creteReacapthaImage('');
                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;
        };
    },
    _addLoadingWindowMarkup: function() {
        $('lightwindow_contents').innerHTML += this.options.skin.loading;
    },
    _clearWindowContents: function(contents) {
        if (contents) {
            // Empty the contents
            $('lightwindow_contents').innerHTML = '';

            // Reset the scroll bars
            $('lightwindow_contents').setStyle({
                overflow: 'hidden'
            });

            if (!this.windowActive) {
                $('lightwindow_title_bar_title').innerHTML = '';
            }
        }

        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 {
                $('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 = setup ? '100%' : 'auto';
            document.getElementsByTagName('html')[0].style.height = document.getElementsByTagName('body')[0].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) {
	var selects = (content ? $('lightwindow_contents') : document).getElementsByTagName('select');
        for (var i = 0; i < selects.length; i++) {
            selects[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;
        }
    },
    _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;
    },
    _setupDimensions: function() {

        var originalHeight, originalWidth;
        switch (this.windowType) {
        case 'page':
            originalHeight = this.options.dimensions.page.height;
            originalWidth = this.options.dimensions.page.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'
        });
    },
    //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) {
        var keycode = (e === null) ? event.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;
        }

    },
    //Get the value from the params attribute string.
    _getParameter: function(parameter) {
        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_height' && this.element.height) {
            return unescape(this.element.height);
        } else if (parameter == 'lightwindow_width' && this.element.width) {
            return unescape(this.element.width);
        }
    },
    //  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;
        }
    },

    addOnCompleteAction: function(action) {
	this._onCompleteActions.push(action);
    },	

    onCompleteActions: function() {
    	this._onCompleteActions.each(function(fun) {fun.call(); });
	this._onCompleteActions.clear();
    },

    addOnDeactivateWindowAction: function(action) {
	this._onDeactivateWindowActions.push(action);
    },	

    onDeactivateWindowActions: function() {
    	this._onDeactivateWindowActions.each(function(fun) {fun.call(); });
	this._onDeactivateWindowActions.clear();
    },

    _loadWindow: function() {
	var ajaxRequest;
        switch (this.windowType) {
        case 'page':
            ajaxRequest = 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();
		    this.onCompleteActions();
                }.bind(this)
            });
            break;

        case 'pageAjaxCart':
            $('lightwindow_title_bar_inner').className = 'ajaxCartTitleBar';
            ajaxRequest = new Ajax.Request(this.contentToFetch, {
                method: 'get',
                parameters: '',
                onComplete: function(response) {
                    var lwindow = this._setUpProcessWindow(response.responseText);
                    this._processWindow();
                    window.setTimeout(function() {
                        myLightWindow._setWindowScroll(lwindow); //we need to use myLightWindow object because within anynomous function "this" means something else that we expect - it's probably anonymous function object in this case
                        
                        AjaxPopup.resizeAjaxPopup(lwindow, AjaxPopup.getAjaxCartCrossBrowserHeight(), AJAX_CART_WIDTH);
                        //AjaxPopup.resizeAjaxPopup(lwindow, AJAX_CART_HEIGTH, AJAX_CART_WIDTH);
                        AjaxPopup.onCompleteCartPopupActions(lwindow);
		    },
		      		      1000);
		    this.onCompleteActions();
		    
                }.bind(this)
            });
            break;
	    
        case 'pageQuickLook':
            $('lightwindow_title_bar_inner').className = '';
            ajaxRequest = new Ajax.Request(this.contentToFetch, {
                method: 'get',
                parameters: '',
                onComplete: function(response) {
                    var lwindow = this._setUpProcessWindow(response.responseText);
                    this._processWindow();
                    window.setTimeout(function() {
			 AjaxPopup.prepareItemPopupContent();
			 myLightWindow._setWindowScroll(lwindow); 
		     },
				       1000);
		     AjaxPopup.getLiveInventory(this.element.itemid);
		    this.onCompleteActions();
		 }.bind(this)
	     });
	     break;
	     
	case 'simple':
            ajaxRequest = new Ajax.Request(this.contentToFetch, {
                method: 'get',
                parameters: '',
                onComplete: function(response) {
                    this.resizeTo.height = $('lightwindow_contents').scrollHeight + this.options.contentOffset.height;
                    this.resizeTo.width = $('lightwindow_contents').scrollWidth + this.options.contentOffset.width;
                    this._processWindow();
		    var lwindow = this._setUpProcessWindow(response.responseText);
		    myLightWindow._setWindowScroll(lwindow);
		    var popup_body = $('popup_body');
		    if (this.element.autoresize && popup_body) {
			setTimeout(function() {
			    AjaxPopup.resizeSimpleAjaxPopup(lwindow, popup_body.getHeight(),
							    this.resizeTo.width,
							    this.element.resize_x,
							    this.element.resize_y);
			}.bind(this), 1000).bind(this);
		    }
		    this.onCompleteActions();
                }.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);
	    var insertionResult = 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);
	}
	
     },
     //--- FP function
    _setUpProcessWindow: function(responseText) {
	var lwindow = $('lightwindow_contents');
	lwindow.setStyle({
	     overflowX: 'hidden',
	     overflowY: 'hidden'
	}); //disable scroll under IE after second popup call
	lwindow.innerHTML += responseText;
	this.resizeTo.height = lwindow.scrollHeight; //FP+(this.options.contentOffset.height);
	this.resizeTo.width = lwindow.scrollWidth; //FP+(this.options.contentOffset.width);
	return lwindow;
    },
     //--- FP function
    _setWindowScroll: function(lwindow) {
//	 if ((lwindow.scrollHeight - lwindow.clientHeight) > 30) {
	lwindow.setStyle({
		 overflowX: 'hidden',
		 overflowY: 'auto'
	     });
//	 }
    },

    //  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);
        }
        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);
        }

    },
    //  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 = [];
        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();
        }
    },
    //  Handle the finish of the window animation
    _handleFinalWindowAnimation: function(delay) {
        if (this.options.finalAnimationHandler) {
            this.options.finalAnimationHandler().bind(this, delay);
        } else {
            this._defaultfinalWindowAnimationHandler(delay);
        }
    },
    _defaultAnimationHandler: function() {
        // Set up the Title if we have one
        $('lightwindow_title_bar_inner').setStyle({
            height: '0px',
            marginTop: this.element.titleHeight + 'px'
        });

        $('lightwindow_title_bar').setStyle({
            height: this.element.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.element.titleHeight + 'px',
                marginTop: '0px'
            }
        }), new Effect.Appear('lightwindow_title_bar_inner', {
            sync: true,
            from: 0.0,
            to: 1.0
        }));
        var resized = false;
	var effectResult;
        var ratio = this.dimensions.container.width - $('lightwindow_contents').getWidth() + this.resizeTo.width + this.options.contentOffset.width;
        if (ratio != $('lightwindow_container').getWidth()) {
            effectResult =  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'
                }
            });
        }

        ratio = this.dimensions.container.height - $('lightwindow_contents').getHeight() + this.resizeTo.height + this.options.contentOffset.height;
        if (ratio != $('lightwindow_container').getHeight()) {
            effectResult = new Effect.Parallel([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 * (ratio / this.dimensions.container.height), {
                sync: true,
                scaleX: false,
                scaleFromCenter: true,
                scaleContent: false
            })], {
                duration: this.duration,
                afterFinish: function() {
                    if (this.dimensions.dataEffects.length > 0) {
                        effectResult = 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) {
            effectResult = new Effect.Parallel(this.dimensions.dataEffects, {
                duration: this.duration,
                beforeStart: function() {
                    if (this.containerChange.height !== 0 || this.containerChange.width !== 0) {
                        effectResult = 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) {
        Effect.Fade('lightwindow_loading', {
            duration: 0.3,
            delay: 0.0,
            afterFinish: function() {
                this._setStatus(false);
            }.bind(this),
            queue: {
                position: 'end',
                scope: 'lightwindowAnimation'
            }
        });
    },
    _finishWindow: function() {
        this._handleFinalWindowAnimation(0);
        this._setupActions();
    }
};

//--- ligtwindow initialize
Event.observe(window, 'load',
	      function() {
		  myLightWindow = new Lightwindow();
	      },
	      false);
