/*
	mymodal v1.2.6 - a full featured, light-weight, customizable lightbox based on jQuery 1.3
	(c) 2009 Jack Moore - www.colorpowered.com - jack@colorpowered.com
	Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
*/
(function($) {

    var open, element, settings, callback, maxWidth, maxHeight, loadedWidth, loadedHeight, interfaceHeight, interfaceWidth, index, $related, ssTimeout, $slideshow, $window, $close, $next, $prev, $current, $title, $modal, $wrap, $loadingOverlay, $loadingGraphic, $overlay, $modalContent, $loaded, $borderTopCenter, $borderMiddleLeft, $borderMiddleRight, $borderBottomCenter, $modalActionButton;
    var $okBtn, $cancelBtn, $iconsContainer, modalContentContainer;
    /* Helper Functions */
    //function for IE6 to set the background overlay
    function IE6Overlay() {
        $overlay.css({ "position": "absolute", width: $window.width(), height: $window.height(), top: $window.scrollTop(), left: $window.scrollLeft() });
    }

    function slideshow() {
        var stop;
        function start() {

            $slideshow
			.text(settings.slideshowStop)
			.bind("cbox_complete", function() {
			    ssTimeout = setTimeout($.fn.mymodal.next, settings.slideshowSpeed);
			})
			.bind("cbox_load", function() {
			    clearTimeout(ssTimeout);
			}).one("click", function() {
			    stop();
			    $(this).removeClass('hover');
			});
            $modal.removeClass("cboxSlideshow_off").addClass("cboxSlideshow_on");

        }

        stop = function() {

            clearTimeout(ssTimeout);
            $slideshow
			.text(settings.slideshowStart)
			.unbind('cbox_complete cbox_load')
			.one("click", function() {
			    start();
			    ssTimeout = setTimeout($.fn.mymodal.next, settings.slideshowSpeed);
			    $(this).removeClass('hover');
			});
            $modal.removeClass("cboxSlideshow_on").addClass("cboxSlideshow_off");
        };

        if (settings.slideshow && $related.length > 1) {
            if (settings.slideshowAuto) {
                start();
            } else {
                stop();
            }
        }
    }

    function clearInline() {
        if ($("#cboxInlineTemp").length > 0) {
            $loaded.children().insertBefore("#cboxInlineTemp");
            $("#cboxInlineTemp").remove();
        }
    }

    function cbox_key(e) {
        if (e.keyCode == 37) {
            e.preventDefault();
            $prev.click();
        } else if (e.keyCode == 39) {
            e.preventDefault();
            $next.click();
        }
    }

    // Convert % values to pixels
    function setSize(size, dimension) {
        dimension = dimension == 'x' ? document.documentElement.clientWidth : document.documentElement.clientHeight;
        return (typeof size == 'string') ? (size.match(/%/) ? (dimension / 100) * parseInt(size, 10) : parseInt(size, 10)) : size;
    }

    function isImage(url) {
        return settings.photo ? true : url.match(/\.(gif|png|jpg|jpeg|bmp)(?:\?([^#]*))?(?:#(.*))?$/i);
    }

    /* Initializes mymodal when the DOM has loaded */
    $(function() {
        $.fn.mymodal.init();
    });

    $.fn.mymodal = function(options, custom_callback) {
        if (this.length) {
            this.each(function() {
                var data = $(this).data("mymodal") ? $.extend({},
					$(this).data("mymodal"), options) : $.extend({}, $.fn.mymodal.settings, options);
                $(this).data("mymodal", data).addClass("cboxelement");
            });
        } else {
            $(this).data("mymodal", $.extend({}, $.fn.mymodal.settings, options));
        }

        $(this).unbind("click.mymodal").bind("click.mymodal", function(event) {

            element = this;

            settings = $(element).data('mymodal');

            //remove the focus from the anchor to prevent accidentally calling
            //mymodal multiple times (by pressing the 'Enter' key
            //after mymodal has opened, but before the user has clicked on anything else)
            element.blur();


            callback = custom_callback ? custom_callback : false;

            var rel = settings.rel ? settings.rel : element.rel;

            if (rel && rel != 'nofollow') {
                $related = $('.cboxelement').filter(function() {
                    var relRelated = $(this).data("mymodal").rel ? $(this).data("mymodal").rel : this.rel;
                    return (relRelated == rel);
                });
                index = $related.index(element);

                if (index < 0) { //this checks direct calls to mymodal
                    $related = $related.add(element);
                    index = $related.length - 1;
                }

            } else {
                $related = $(element);
                index = 0;
            }


            if (!open) {
                $.event.trigger('cbox_open');
                //$close.html(settings.close);
                $overlay.css({ "opacity": settings.opacity }).show();
                open = true;
                $.fn.mymodal.position(setSize(settings.initialWidth, 'x'), setSize(settings.initialHeight, 'y'), 0);
                if ($.browser.msie && $.browser.version < 7) {
                    $window.bind("resize scroll", IE6Overlay);
                }
            }


            slideshow();
            $.fn.mymodal.load();

            if (settings.overlayClose === true) {
                $overlay.css({ "cursor": "pointer" }).click($.fn.mymodal.close);
            }
            event.preventDefault();
        });

        if (options && options.open) {
            $(this).triggerHandler('click.mymodal');
        }

        return this;
    };

    $.fn.mymodal.element = function() {
        return element;
    };

    /*
    Initialize the modal: store common calculations, preload the interface graphics, append the html.
    This preps mymodal for a speedy open when clicked, and lightens the burdon on the browser by only
    having to run once, instead of each time mymodal is opened.
    */
    $.fn.mymodal.init = function() {

        $window = $(window);

        $('body').prepend(
			$overlay = $('<div id="cboxOverlay" />').hide(),
			$modal = $('<div id="mymodal" />')
		);

        //$modal.center();


        $(window).bind("scroll", function(e) { $.fn.mymodal.center(); });

        $modal.attr("collapsed", "false");


        $borderMiddleLeft = $('<div id="cboxMiddleLeft" />');
        $modalContent = $('<div id="cboxContent" class="cboxContent" />').append();
        $borderMiddleRight = $('<div id="cboxMiddleRight" />');

        $modalContentContainer = $('<div class="modalContentContainer">');
        $modalContentContainer.append($borderMiddleLeft);
        $modalContentContainer.append($modalContent);
        $modalContentContainer.append($borderMiddleRight);
        $modalContentContainer.attr("collapsed", "false");

        $wrap = $('<div id="cboxWrapper" />').appendTo($modal).append(
			$('<div/>').append(
				$('<div id="cboxTopLeft"/>'),
				$borderTopCenter = $('<div id="cboxTopCenter"/>'),
				$('<div id="cboxTopRight"/>')
			),
			$modalContentContainer,
			$('<div/>').append(
				$('<div id="cboxBottomLeft"/>'),
				$borderBottomCenter = $('<div id="cboxBottomCenter"/>'),
				$('<div id="cboxBottomRight"/>')
			)





		);

        $buttonBar = $('<div class="buttonBar"/>');
        $buttonBar.append($collapse = $('<div class="collapsedContainer" src="/modal/colorbox/onlineapply/images/black/min.png" />').click($.fn.mymodal.containerCollapse));
        $buttonBar.append($close = $('<div class="close" src="/Ressources/Scripts/jquery/plugins/mymodal/css/images/blue/close.png" />').click($.fn.mymodal.close));
        $buttonBar.append('<div class="iconizeContainer" src="/modal/colorbox/onlineapply/images/black/iconize.png" />')


        var fadeOnClose = $.browser.mozilla || $.browser.safari;
        fadeOnClose = true;
        if (fadeOnClose && $.browser.mozilla) {
            $buttonBar.find("div")
              .css({ opacity: .5, cursor: "pointer", "mozUserSelect": "none", "khtmlUserSelect": "none" })
              .mouseover(function() { $(this).fadeTo(200, 1); })
              .mouseout(function() { if (fadeOnClose) $(this).fadeTo(200, .5); });
        } else {
            $buttonBar.find("div")
              .css({ cursor: "hand", "mozUserSelect": "none", "khtmlUserSelect": "none" });
        }

        $iconsContainer = $('<div class="icons"/>');
        $iconsContainer.css('display', 'none');

        $borderTopCenter.append($iconsContainer);
        $borderTopCenter.append($title = $('<div id="cboxTitle" />'));
        $borderTopCenter.append($buttonBar);

        $wrap.find("[id]").css({ 'float': 'left' });
        $buttonBar.css({ 'float': 'right' });

        $modalContent.append(
        //loaded is filled with temporary HTML to allow the CSS backgrounds for those elements to load before mymodal is actually called.
			$loaded = $('<div id="cboxLoadedContent" class="cboxLoadedContent" style="width:0; height:0;" />'),
			$loadingOverlay = $('<div id="cboxLoadingOverlay" />'),
			$loadingGraphic = $('<div id="cboxLoadingGraphic" />'),
			$current = $('<div id="cboxCurrent" />'),
			$slideshow = $('<div id="cboxSlideshow" />'),
			$next = $('<div id="cboxNext" />').click($.fn.mymodal.next),
			$prev = $('<div id="cboxPrevious" />').click($.fn.mymodal.prev)
		);


        $modalContent.children()
			.addClass("hover")
			.mouseover(function() { $(this).addClass("hover"); })
			.mouseout(function() { $(this).removeClass("hover"); })
			.hide();

        //precalculate sizes that will be needed multiple times.
        interfaceHeight = $borderTopCenter.height() + $borderBottomCenter.height() + $modalContent.outerHeight(true) - $modalContent.height(); //Subtraction needed for IE6
        interfaceWidth = $borderMiddleLeft.width() + $borderMiddleRight.width() + $modalContent.outerWidth(true) - $modalContent.width();
        loadedHeight = $loaded.outerHeight(true);
        loadedWidth = $loaded.outerWidth(true);

        interfaceWidth = interfaceWidth + 15;

        $modal.css({ "padding-bottom": interfaceHeight, "padding-right": interfaceWidth }).hide(); //the padding removes the need to do size conversions during the animation step.

        //Setup button & key events.
        $().bind("keydown.cbox_close", function(e) {
            if (e.keyCode == 27) {
                e.preventDefault();
                $close.click();
            }
        });

        $modalContent.children().removeClass("hover");
    };

    //navigates to the next page/image in a set.
    $.fn.mymodal.next = function() {
        index = index < $related.length - 1 ? index + 1 : 0;
        $.fn.mymodal.load();
    };

    $.fn.mymodal.prev = function() {
        index = index > 0 ? index - 1 : $related.length - 1;
        $.fn.mymodal.load();
    };

    $.fn.mymodal.position = function(mWidth, mHeight, speed, loadedCallback) {

        var winHeight = document.documentElement.clientHeight;
        var posTop = winHeight / 2 - mHeight / 2;
        var posLeft = document.documentElement.clientWidth / 2 - mWidth / 2;
        //keeps the box from expanding to an inaccessible area offscreen.
        if (mHeight > winHeight) { posTop -= (mHeight - winHeight); }
        if (posTop < 0) { posTop = 0; }
        if (posLeft < 0) { posLeft = 0; }

        posTop += $window.scrollTop();
        posLeft += $window.scrollLeft();

        mWidth = mWidth - interfaceWidth;
        mHeight = mHeight - interfaceHeight;


        //this gives the wrapper plenty of breathing room so it's floated contents can move around smoothly,
        //but it has to be shrank down around the size of div#mymodal when it's done.  If not,
        //it can invoke an obscure IE bug when using iframes.
        $wrap[0].style.width = $wrap[0].style.height = "9999px";

        function modalDimensions(that) {
            //loading overlay size has to be sure that IE6 uses the correct height.
            $borderTopCenter[0].style.width = $borderBottomCenter[0].style.width = $modalContent[0].style.width = that.style.width;
            $loadingGraphic[0].style.height = $loadingOverlay[0].style.height = $modalContent[0].style.height = $borderMiddleLeft[0].style.height = $borderMiddleRight[0].style.height = that.style.height;
        }

        //setting the speed to 0 to reduce the delay between same-sized content.
        var animate_speed = ($modal.width() === mWidth && $modal.height() === mHeight) ? 0 : speed;
        $modal.dequeue().animate({ height: mHeight, width: mWidth, top: posTop, left: posLeft }, { duration: animate_speed,
            complete: function() {
                modalDimensions(this);

                //shrink the wrapper down to exactly the size of mymodal to avoid a bug in IE's iframe implementation.
                $wrap[0].style.width = (mWidth + interfaceWidth) + "px";
                $wrap[0].style.height = (mHeight + interfaceHeight) + "px";

                if (loadedCallback) { loadedCallback(); }
                if ($.browser.msie && $.browser.version < 7) { IE6Overlay(); }
            },
            step: function() {
                modalDimensions(this);
            }
        });
    };

    $.fn.mymodal.dimensions = function(object) {

        if (!open) { return; }

        $window.unbind('resize.cbox_resize');

        var speed = settings.transition == "none" ? 0 : settings.speed;
        $loaded.remove();
        $loaded = $(object);

        var width;
        var height;

        function getWidth() {
            if (settings.width) {
                width = maxWidth;
            } else {
                width = maxWidth && maxWidth < $loaded.width() ? maxWidth : $loaded.width();
            }
            return width;
        }
        function getHeight() {
            if (settings.height) {
                height = maxHeight;
            } else {
                height = maxHeight && maxHeight < $loaded.height() ? maxHeight : $loaded.height();
            }

            if ($modalActionButton && settings.message != "")
                height = height + $modalActionButton.height() + 10;
            return height;
        }


        $loaded.hide().appendTo('body')
		.attr({ id: 'cboxLoadedContent' })
		.css({ width: getWidth() })
		.css({ height: getHeight() })//sets the height independently from the width in case the new width influences the value of height.
		.prependTo($modalContent);


        if ($.browser.msie && $.browser.version < 7) {
            $('select').not($('#mymodal select')).css({ 'visibility': 'hidden' });
        }

        if ($('#cboxPhoto').length > 0 && settings.height) {
            var topMargin = (height - parseInt($('#cboxPhoto')[0].style.height, 10)) / 2;
            $('#cboxPhoto').css({ marginTop: (topMargin > 0 ? topMargin : 0) });
        }

        function setPosition(s) {

            var mWidth = width + loadedWidth + interfaceWidth;
            var mHeight = height + loadedHeight + interfaceHeight;
            $.fn.mymodal.position(mWidth, mHeight, s, function() {
                if (!open) { return; }

                if ($.browser.msie) {
                    //This fadeIn helps the bicubic resampling to kick-in.
                    if ($('#cboxPhoto').length > 0) { $loaded.fadeIn(100); }
                    //IE adds a filter when mymodal fades in and out that can cause problems if the loaded content contains transparent pngs.
                    $modal.css('filter', '');
                }

                $modalContent.children().show();

                //Waited until the iframe is added to the DOM & it is visible before setting the src.
                //This increases compatability with pages using DOM dependent JavaScript.
                $('#cboxIframe').after("<iframe name='iframe_" + new Date().getTime() + "' frameborder=0 src='" + (settings.href ? settings.href : element.href) + "' />").remove();

                $loadingOverlay.hide();
                $loadingGraphic.hide();
                $slideshow.hide();

                if ($related.length > 1) {
                    $current.html(settings.current.replace(/\{current\}/, index + 1).replace(/\{total\}/, $related.length));
                    $next.html(settings.next);
                    $prev.html(settings.previous);

                    $().unbind('keydown', cbox_key).one('keydown', cbox_key);

                    if (settings.slideshow) {
                        $slideshow.show();
                    }
                } else {
                    $current.add($next).add($prev).hide();
                }

                $title.html(settings.title ? settings.title : element.title);


                $.event.trigger('cbox_complete');

                settings.onComplete();



                if (callback) {
                    callback.call(element);
                }

                if (settings.transition === 'fade') {
                    $modal.fadeTo(speed, 1, function() {
                        if ($.browser.msie) { $modal.css('filter', ''); }
                    });
                }

                $window.bind('resize.cbox_resize', function() {
                    $.fn.mymodal.position(mWidth, mHeight, 0);
                });
            });
        }
        if (settings.transition == 'fade') {
            $modal.fadeTo(speed, 0, function() { setPosition(0); });
        } else {
            setPosition(speed);
        }

        if (settings.preloading && $related.length > 1) {
            var prev = index > 0 ? $related[index - 1] : $related[$related.length - 1];
            var next = index < $related.length - 1 ? $related[index + 1] : $related[0];

            var nextSrc = $(next).data('mymodal').href ? $(next).data('mymodal').href : next.href;
            var prevSrc = $(prev).data('mymodal').href ? $(prev).data('mymodal').href : prev.href;

            if (isImage(nextSrc)) {
                $('<img />').attr('src', nextSrc);
            }
            if (isImage(prevSrc)) {
                $('<img />').attr('src', prevSrc);
            }
        }
    };

    $.fn.mymodal.load = function() {

        element = $related[index];

        settings = $(element).data('mymodal');



        $.event.trigger('cbox_load');

        if (settings.onLoading != false) {
            settings.onLoading();
        } else {
            $loadingOverlay.show();
            $loadingGraphic.show();
        }

        $close.show();
        clearInline(); //puts inline elements back if they are being used

        if ($iconsContainer && settings.icon != false) {
            $iconsContainer.addClass('icons-' + settings.icon).show();
        } else {
            $iconsContainer.hide();
        }



        switch (settings.type) {
            case 'alert':
                $.fn.mymodal.alertBox();
                break;
            case 'dialog':
                $.fn.mymodal.dialogBox();
                break;
            default:
                if ($modalActionButton)
                    $modalActionButton.hide();
        }

        if (settings.inline) {
            if ($modalActionButton)
                $modalActionButton.hide();
        }

        // Evaluate the height based on the optional height and width settings.
        var height = settings.height ? setSize(settings.height, 'y') - loadedHeight - interfaceHeight : false;
        var width = settings.width ? setSize(settings.width, 'x') - loadedWidth - interfaceWidth : false;

        //Re-evaluate the maximum dimensions based on the optional maxheight and maxwidth.
        if (settings.maxHeight) {
            maxHeight = settings.maxHeight ? setSize(settings.maxHeight, 'y') - loadedHeight - interfaceHeight : false;
            height = height && height < maxHeight ? height : maxHeight;
        }
        if (settings.maxWidth) {
            maxWidth = settings.maxWidth ? setSize(settings.maxWidth, 'x') - loadedWidth - interfaceWidth : false;
            width = width && width < maxWidth ? width : maxWidth;
        }

        maxHeight = height
        maxWidth = width;

        var href = settings.href ? settings.href : element.href;
        if (!settings.inline && settings.message != "" && (settings.type == 'alert' || settings.type == 'dialog' || settings.type == 'loading')) {
            $//message = $('<div class="message">' + settings.message + '<div>')
            $message = $('<div class="message"><div class="message-content">' + settings.message + '</div><div>');
            if ($modalActionButton)
                $message.append($modalActionButton);
            $('<div id="cboxInlineTemp" />').hide().insertBefore($message);
            $.fn.mymodal.dimensions($message.wrapAll('<div/>').parent());
        } else if (settings.inline) {
            if ($modalActionButton)
                $(href).append($modalActionButton);
            $('<div id="cboxInlineTemp" />').hide().insertBefore($(href)[0]);
            $.fn.mymodal.dimensions($(href).wrapAll('<div/>').parent());
        } else if (settings.iframe) {

            $.fn.mymodal.dimensions(
				$("<div><div id='cboxIframe' /></div>")
			); //timestamp to prevent caching.
        } else if (isImage(href)) {
            var loadingElement = new Image();
            loadingElement.onload = function() {
                loadingElement.onload = null;

                if ((maxHeight || maxWidth) && settings.resize) {
                    var width = this.width;
                    var height = this.height;
                    var percent = 0;
                    var that = this;


                    var setResize = function() {
                        height += height * percent;
                        width += width * percent;
                        that.height = height;
                        that.width = width;
                    };
                    if (maxWidth && width > maxWidth) {
                        percent = (maxWidth - width) / width;
                        setResize();
                    }
                    if (maxHeight && height > maxHeight) {
                        percent = (maxHeight - height) / height;
                        setResize();
                    }
                }
                $.fn.mymodal.dimensions($("<div />").css({ width: this.width, height: this.height }).append($(this).css({ width: this.width, height: this.height, display: "block", margin: "auto", border: 0 }).attr('id', 'cboxPhoto')));
                if ($related.length > 1) {
                    $(this).css({ cursor: 'pointer' }).click($.fn.mymodal.next);
                }
                if ($.browser.msie && $.browser.version == 7) {
                    this.style.msInterpolationMode = 'bicubic';
                }
            };
            loadingElement.src = href;
        } else {

            if (settings.postParameters != null) {

                $('<div />').load(href, settings.postParameters, function(data, textStatus, xhr) {
                    if (textStatus == "success") {
                        switch (xhr.status) {
                            case 410:
                                alert("iiiiiiiii");
                                $.fn.mymodal({ open: true, width: "400", inline: false, title: "Account", message: $('#message-session-expires').html(), type: 'alert', alertParameters: { okLabel: 'ok', onOkCallback: function() { window.location.href = '/Account/LogOff' } } });
                                break;
                            case 401:
                                $.fn.mymodal({ open: true, width: "400", inline: false, title: "Account", message: $('#message-session-expires').html(), type: 'alert', alertParameters: { okLabel: 'ok', onOkCallback: function() { window.location.href = '/Account/LogOff' } } });
                            default:
                                if ($modalActionButton)
                                    $(this).append($modalActionButton);
                                $.fn.mymodal.dimensions($(this));
                        }
                    } else {
                        switch (xhr.status) {
                            case 410:
                                $.fn.mymodal({ open: true, width: "400", inline: false, title: "Account", message: $('#message-session-expires').html(), type: 'alert', alertParameters: { okLabel: 'ok', onOkCallback: function() { window.location.href = '/Account/LogOff' } } });
                                break;
                            case 401:
                                $.fn.mymodal({ open: true, width: "400", inline: false, title: "Account", message: $('#message-session-expires').html(), type: 'alert', alertParameters: { okLabel: 'ok', onOkCallback: function() { window.location.href = '/Account/LogOff' } } });
                            default:
                                if ($modalActionButton)
                                    $(this).append($modalActionButton);
                                $.fn.mymodal.dimensions($(this));
                        }
                    }
                });

            } else {
                $('<div />').load(href, function(data, textStatus, xhr) {
                    if (textStatus == "success") {
                        switch (xhr.status) {
                            case 410:
                                alert("iiiiiiiii");
                                $.fn.mymodal({ open: true, width: "400", inline: false, title: "Account", message: $('#message-session-expires').html(), type: 'alert', alertParameters: { okLabel: 'ok', onOkCallback: function() { window.location.href = '/Account/LogOff' } } });
                                break;
                            case 401:
                                $.fn.mymodal({ open: true, width: "400", inline: false, title: "Account", message: $('#message-session-expires').html(), type: 'alert', alertParameters: { okLabel: 'ok', onOkCallback: function() { window.location.href = '/Account/LogOff' } } });
                            default:
                                if ($modalActionButton)
                                    $(this).append($modalActionButton);
                                $.fn.mymodal.dimensions($(this));
                        }
                    } else {
                        switch (xhr.status) {
                            case 410:
                                $.fn.mymodal({ open: true, width: "400", inline: false, title: "Account", message: $('#message-session-expires').html(), type: 'alert', alertParameters: { okLabel: 'ok', onOkCallback: function() { window.location.href = '/Account/LogOff' } } });
                                break;
                            case 401:
                                $.fn.mymodal({ open: true, width: "400", inline: false, title: "Account", message: $('#message-session-expires').html(), type: 'alert', alertParameters: { okLabel: 'ok', onOkCallback: function() { window.location.href = '/Account/LogOff' } } });
                            default:
                                if ($modalActionButton)
                                    $(this).append($modalActionButton);
                                $.fn.mymodal.dimensions($(this));
                        }
                    }
                });
            }


        }
    };

    $.fn.mymodal.alertBox = function() {

        element = $related[index];
        var settings = $(element).data('mymodal');

        if (!$modalActionButton)
            $modalActionButton = $('<div class="modalActionButton">');
        else
            $modalActionButton.html('');

        $okBtn = $('<span class="dialog-btn">' + settings.alertParameters.okLabel + '</span>');
        $modalActionButton.show();
        $okBtn.bind("click", function() {
            settings.alertParameters.onOkCallback();
            $.fn.mymodal.close();
        })
        $modalActionButton.append($okBtn);
        $modalActionButton.append('<div class="dialog-btn-clear"></div>');
        $modalActionButton.css("width", '110px');

    };

    $.fn.mymodal.dialogBox = function() {
        element = $related[index];
        var settings = $(element).data('mymodal');
        if (!$modalActionButton)
            $modalActionButton = $('<div class="modalActionButton">');
        else
            $modalActionButton.html('');

        $okBtn = $('<span class="dialog-btn">' + settings.dialogParameters.okLabel + '</span>');
        $cancelBtn = $('<span class="dialog-btn">' + settings.dialogParameters.cancelLabel + '</span>');

        $okBtn.bind("click", function() { settings.dialogParameters.onOkCallback(); });
        $cancelBtn.bind("click", function() { settings.dialogParameters.onCancelCallback(); $.fn.mymodal.close(); });


        $modalActionButton.show();
        $modalActionButton.append($okBtn);
        $modalActionButton.append($cancelBtn);
        $modalActionButton.append('<div class="dialog-btn-clear"></div>');
        $modalActionButton.css("width", '230px');

    };

    $.fn.mymodal.containerCollapse = function() {

        //alert($borderBottomCenter.outerHeight() + $borderTopCenter.outerHeight());
        if ($modalContentContainer.attr("collapsed") == "false") {
            $modalContentContainer.attr("w", $modal.outerWidth());
            $modalContentContainer.attr("h", $modal.outerHeight());
            $modal.animate({ height: 0 }, 300, function() { $modalContentContainer.hide(); });

            $modalContentContainer.attr("collapsed", "true");
        }
        else {
            $modalContentContainer.show();
            $modal.animate({ height: $modalContentContainer.attr("h") }, 300, function() { });
            $modalContentContainer.attr("collapsed", "false");
        }
    };


    $.fn.mymodal.getBrowserSize = function() {

        var browserDim = { top: 0, left: 0, width: 0, height: 0 };

        var scrOfX = 0, scrOfY = 0; //, myWidth = 0, myHeight = 0;
        // on rcupre le scroll
        if (typeof (window.pageYOffset) == 'number') {
            //Netscape compliant
            scrOfY = window.pageYOffset;
            scrOfX = window.pageXOffset;
        } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
            //DOM compliant
            scrOfY = document.body.scrollTop;
            scrOfX = document.body.scrollLeft;
        } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
            //IE6 standards compliant mode
            scrOfY = document.documentElement.scrollTop;
            scrOfX = document.documentElement.scrollLeft;
        }
        this.top = scrOfY;
        this.left = scrOfX;
        // on rcupre la taille de la fentre
        if (typeof (window.innerWidth) == 'number') {
            //Non-IE
            myWidth = window.innerWidth;
            myHeight = window.innerHeight;
        } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
            //IE 6+ in 'standards compliant mode'
            myWidth = document.documentElement.clientWidth;
            myHeight = document.documentElement.clientHeight;
        } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
            //IE 4 compatible
            myWidth = document.body.clientWidth;
            myHeight = document.body.clientHeight;
        }

        browserDim.top = scrOfY;
        browserDim.left = scrOfX;
        browserDim.width = myWidth;
        browserDim.height = myHeight;
        return browserDim;
    };

    $.fn.mymodal.center = function() {
        browserDim = $.fn.mymodal.getBrowserSize();

        mheight = $modal.height();
        mwidth = $modal.width();
        //left = browserDim.width - parseInt($modal.width());
        //top = browserDim.height - parseInt($modal.height());
        //alert(mheight)
        //alert(top)

        if ($modal.width() > 0) {

            var left = (browserDim.width - mwidth) / 2
            var top = ((browserDim.height - mheight) / 2) + browserDim.top;
            $modal.css('left', left);
            $modal.css('top', top - 200);
            $modal.animate({ top: top - 50 }, 200, 'linear', function() { });
        }
    };


    //public function for closing mymodal.  To use this within an iframe use the following format: parent.$.fn.mymodal.close();
    $.fn.mymodal.close = function() {

        settings.onClose();
        open = false;
        //alert(ssTimeout)
        clearTimeout(ssTimeout);
        $window.unbind('resize.cbox_resize');
        $slideshow.unbind('cbox_complete cbox_load click');
        clearInline();
        $overlay.css({ cursor: 'auto' }).fadeOut('fast').unbind('click', $.fn.mymodal.close);

        $().unbind('keydown', cbox_key);

        if ($.browser.msie && $.browser.version < 7) {
            $('select').css({ 'visibility': 'inherit' });
            $window.unbind('resize scroll', IE6Overlay);
        }
        $modalContentContainer.show();
        $modalContentContainer.attr("collapsed", "false");
        $modalContent.children().hide();
        if ($modalActionButton)
            $modalActionButton.html('');

        $title.html("");

        if ($.browser.msie) {
            $modal
		    .stop(true, false)
		    .removeClass();

            //$loaded.remove();
            //$modal.css({ 'opacity': 1 });
            $.event.trigger('cbox_closed');
            $modal.hide()

        } else {
            $modal
		    .stop(true, false)
		    .removeClass()
            .fadeOut('fast', function() {
                element.focus();
                $loaded.remove();
                $modal.css({ 'opacity': 1 });
                $.event.trigger('cbox_closed');
            });
        }

        settings.afterClose();


    };



    /*
    mymodal Default Settings.
		
		The mymodal() function takes one argument, an object of key/value pairs, that are used to initialize the modal.
		
		Please do not change these settings here, instead overwrite these settings when attaching the mymodal() event to your anchors.
    Example (Global)	: $.fn.mymodal.settings.transition = "fade"; //changes the transition to fade for all mymodal() events proceeding it's declaration.
    Example (Specific)	: $("a[href='http://www.google.com']").mymodal({width:"90%", height:"450px", iframe:true});
		
		See http://colorpowered.com/mymodal for details.
    */
    $.fn.mymodal.settings = {
        type: '', // alert,dialog, if not specified no callback button
        alertParameters: { okLabel: 'ok', onOkCallback: function(op) { } },
        dialogParameters: { okLabel: 'ok', onOkCallback: function(op) { }, cancelLabel: 'cancel', onCancelCallback: function(op) { alert('rien'); } },
        onComplete: function() { },
        onClose: function() { },
        afterClose: function() { },
        onLoading: false,
        message: '',
        icon: false,
        transition: "elastic",
        speed: 350,
        width: false,
        height: false,
        initialWidth: "400",
        initialHeight: "400",
        maxWidth: false,
        maxHeight: false,
        resize: true,
        inline: false,
        iframe: false,
        photo: false,
        href: false,
        title: false,
        rel: false,
        opacity: 0.0,
        preloading: true,
        current: "image {current} of {total}",
        previous: "previous",
        next: "next",
        close: "close",
        open: false,
        overlayClose: false,
        slideshow: false,
        slideshowAuto: true,
        slideshowSpeed: 2500,
        slideshowStart: "start slideshow",
        slideshowStop: "stop slideshow",
        postParameters: null
    };
})(jQuery);
	

