var newZIndex = 99998;

function GetIFrameHeight()
{
try{
    var myIFrame = $('#iFrameContent' + newZIndex);
    var innerDoc = (myIFrame.get(0).contentDocument) ? myIFrame.get(0).contentDocument : myIFrame.get(0).contentWindow.document;

    
    if (innerDoc.body.scrollHeight + $(".editbartop").height() + $(".editbarbottom").height() > $(window).height() - 100) {
        var windowHeight = $(window).height() - 100;
        var windowTop = 50;
        $('#popup_container' + newZIndex).animate({ height: windowHeight, top: windowTop, opacity: 1 }, 800);
        $('#popup_contentpreview' + newZIndex).animate({ height: windowHeight }, 800);
        $('#editbarmiddle' + newZIndex).animate({ height: windowHeight - $(".editbartop").height() - $(".editbarbottom").height() }, 800);
        myIFrame.height(windowHeight - $(".editbartop").height() - $(".editbarbottom").height());

        $('.loadingContainer').animate({ opacity: 0 }, 2000, function() { $('#loadingContainer' + newZIndex).remove() });
        
        $('.png').ifixpng();
    }
    else
    {
        var windowHeight = innerDoc.body.scrollHeight + $(".editbartop").height() + $(".editbarbottom").height();
        var windowTop = ($(window).height() / 2) - (windowHeight / 2);

        $('#popup_container' + newZIndex).animate({ height: windowHeight, top: windowTop, opacity: 1 }, 800);
        $('#popup_contentpreview' + newZIndex).animate({ height: windowHeight }, 800);
        $('#editbarmiddle' + newZIndex).animate({ height: innerDoc.body.scrollHeight }, 0);
        myIFrame.height(innerDoc.body.scrollHeight);
        $('.loadingContainer').animate({ opacity: 0 }, 2000, function(){ $('#loadingContainer' + newZIndex).remove() });
        
        $('.png').ifixpng();
                
    }
    } catch (ex)
{

}
}





(function($) {

    $.alerts = {

        // These properties can be read/written by accessing $.alerts.propertyName from your scripts at any time

        repositionOnResize: true,           // re-centers the dialog on window resize
        overlayOpacity: 0.85,                // transparency level of overlay
        overlayColor: '#000',               // base color of overlay
        className: 'information',

               

        _edit: function(myurl, title, callback) {
            $.alerts._overlay('show', newZIndex);
            
            
            
            
            $("body").append(
                '<div id="loadingContainer' + (newZIndex + 1) + '" class="loadingContainer png"></div>' +
			  '<div id="popup_container' + newZIndex + '" class="popup_container png" style="display:block;opacity:0">' +
			   '<div id="popup_contentpreview' + newZIndex + '" class="popup_contentpreview">' +
			      '<div class="editbartop png" id="editbartop' + newZIndex + '"></div><div class="editbarmiddle png" id="editbarmiddle'  + newZIndex + '">' +
			          '<div id="popup_preview' + newZIndex + '" class="popup_preview png"><p>' +
			          '<iframe id="iFrameContent' + newZIndex + '" onload="GetIFrameHeight(this)" allowtransparency="true" height="1px" width="100%" marginheight="0px" marginwidth="0px" style="background-color:transparent;margin:0;padding:0;margin-left:0px;overflow:visible;" scrolling="auto" frameborder="0" src="' + myurl + '"></iframe>' +
			          '</p><div style="clear:both;"></div></div>' +
			      '</div><div class="editbarbottom png"></div>' +
				'</div>' +
			  '</div>');

            // IE6 Fix
            var pos = ($.browser.msie && parseInt($.browser.version) <= 6) ? 'absolute' : 'fixed';
            $(".loadingContainer").css({
                zIndex: newZIndex + 1
            });
            
            $("#popup_container" + newZIndex).css({
                position: pos,
                overflow: 'visible',
                zIndex: newZIndex,
                padding: 0,
                left: '50%',
                marginLeft: '-384px',
                top: ($(window).height() / 2) - 35 + 'px',
                width: '768px',
                minWidth: '768px',
                maxWidth: '768px',
                opacity: 0

            });

            $("#editbartop" + newZIndex).html('\<img src="images\/headers\/LargeHeader\/' + decodeURI(title) + '.aspx" /><input type="button" id="popup_ok' + newZIndex + '" value="" onclick="$.alerts._hide(\'' + newZIndex + '\');" class="btnclosenotifybar" />')

            $.alerts._maintainPosition(true);

//            $("#popup_ok" + newZIndex).click(function() {
//                $('#popup_container' + newZIndex + ',#popup_overlay' + newZIndex).animate({ opacity: 0 }, 500, function() {
//                    $.alerts._hide();
//                    if (callback) callback(false);
//                });
//            });
            //if (callback) callback(false);
        },



        _notify: function(message, className, callback) {
            $.alerts._overlay('show', newZIndex);
            $("body").append(
			  '<div id="popup_containern' + newZIndex + '" style="display:block;opacity:0">' +
			   '<div id="popup_contentpreviewn' + newZIndex + '">' +
			      '<div class="editbartop notifybartop png" id="editbartop' + newZIndex + '"></div><div class="editbarmiddle notifybarmiddle png" id="editbarmiddle' + newZIndex + '">' +
			          '<div id="popup_previewn' + newZIndex + '" align="center">' +
			          '<p>' + message + '</p>' +
			          '</div>' +
			      '</div><div class="editbarbottom notifybarbottom png" id="editbarbottom' + newZIndex + '"></div>' +
				'</div>' +
			  '</div>');

            // IE6 Fix
            var pos = ($.browser.msie && parseInt($.browser.version) <= 6) ? 'absolute' : 'fixed';

            $("#popup_containern" + newZIndex).css({
                position: pos,
                overflow: 'hidden',
                zIndex: newZIndex,
                padding: 0,
                left: '50%',
                marginLeft: '-148px',
                top: 0, //($(window).height() / 2) - 35 + 'px',
                width: '297px',
                minWidth: '297px',
                maxWidth: '297px',
                opacity: 0

            });

            $("#editbartop" + newZIndex).html('<div class="' + className + '"></div><input type="button" id="popup_ok1' + newZIndex + '" value="" onclick="$.alerts._hide(\'' + newZIndex + '\');" class="btnclosenotifybar" />')

            $.alerts._repositionNotify();
            $.alerts._maintainPositionNotify(true);

            setTimeout("$('#popup_containern" + newZIndex + ",#popup_overlay" + newZIndex + "').animate({ opacity: 0 }, 500, function() {  $.alerts._hide('" + newZIndex + "');});", 6000);
        },


      
        _hide: function(zInd) {
            $('#popup_container' + zInd + ',#popup_containern' + zInd + ',#popup_overlay' + zInd).animate({ opacity: 0 }, 500, function() {
                $("#popup_container" + zInd).remove();
                $("#popup_containern" + zInd).remove();
                $.alerts._overlay('hide', zInd);
                //$.alerts._maintainPosition(false);
                //if (callback) callback(false);
            });
            
        },

        _overlay: function(status, zInd) {
            switch (status) {
                case 'show':

                    //$.alerts._overlay('hide');
                    $("body").append('<div id="popup_overlay' + zInd + '"  class="bgFramer"></div>');
                    $("#popup_overlay" + zInd).css({
                        position: 'fixed',
                        zIndex: zInd,
                        top: '0px',
                        left: '0px',
                        right: '0px',
                        bottom: '0px',
                        background: $.alerts.overlayColor,
                        opacity: 0
                    });
                    $("#popup_overlay" + zInd).animate({
                        opacity: $.alerts.overlayOpacity
                    }, 400);
                    break;
                case 'hide':
                    try {
                        $("#popup_overlay" + zInd).remove();
                    }
                    catch (ex) {

                    }
                    break;
            }
        },

        _reposition: function() {


            var myIFrame = $('#iFrameContent' + newZIndex, top.document);
            var innerDoc = (myIFrame.get(0).contentDocument) ? myIFrame.get(0).contentDocument : myIFrame.get(0).contentWindow.document;
            if (innerDoc.body.scrollHeight + $(".editbartop").height() + $(".editbarbottom").height() > $(window).height() - 100) {
                var windowHeight = $(window).height() - 100;
                var windowTop = 50;
                $('#popup_container' + newZIndex).animate({ height: windowHeight, top: windowTop }, 0);
                $('#popup_contentpreview' + newZIndex).animate({ height: windowHeight }, 0);
                $("#popup_container" + newZIndex).animate({ opacity: 1 }, 0);
                $('#editbarmiddle' + newZIndex).animate({ height: windowHeight - $(".editbartop").height() - $(".editbarbottom").height() }, 0);
                myIFrame.height(windowHeight - $(".editbartop").height() - $(".editbarbottom").height());
            }
            else {
                var windowHeight = innerDoc.body.scrollHeight + $(".editbartop").height() + $(".editbarbottom").height();
                var windowTop = ($(window).height() / 2) - (windowHeight / 2);
                $('#popup_container' + newZIndex).animate({ height: windowHeight, top: windowTop }, 0);
                $('#popup_contentpreview' + newZIndex).animate({ height: windowHeight }, 0);
                $("#popup_container" + newZIndex).animate({ opacity: 1 }, 0);
                $('#editbarmiddle' + newZIndex).animate({ height: innerDoc.body.scrollHeight }, 0);
                myIFrame.height(innerDoc.body.scrollHeight);
            }
        },
        
       
        _repositionNotify: function() {

            if ($("#editbarmiddle" + newZIndex).height() + $("#editbartop" + newZIndex).height() + $("#editbarbottom" + newZIndex).height() > $(window).height() - 100) {
                var windowHeight = $(window).height() - 100;
                var windowTop = 50;
                $('#popup_containern' + newZIndex).animate({ height: windowHeight, top: windowTop }, 0);
                $('#popup_contentpreviewn' + newZIndex).animate({ height: windowHeight }, 0);
                $("#popup_containern" + newZIndex).animate({ opacity: 1 }, 0);
            }
            else {
                var windowHeight = $("#editbarmiddle" + newZIndex).height() + $("#editbartop" + newZIndex).height() + $("#editbarbottom" + newZIndex).height();
                var windowTop = ($(window).height() / 2) - (windowHeight / 2);
                $('#popup_containern' + newZIndex).animate({ height: windowHeight, top: windowTop }, 0);
                $('#popup_contentpreviewn' + newZIndex).animate({ height: windowHeight }, 0);
                $("#popup_containern" + newZIndex).animate({ opacity: 1 }, 0);
            }


        },
        
        
        

        _maintainPosition: function(status) {
            if ($.alerts.repositionOnResize) {
                switch (status) {
                    case true:
                        $(window).bind('resize', function() {
                            $.alerts._reposition();
                            
                        });
                        break;
                    case false:
                        $(window).unbind('resize');
                        break;
                }
            }
        },
        
        _maintainPositionNotify: function(status) {
            if ($.alerts.repositionOnResize) {
                switch (status) {
                    case true:
                        $(window).bind('resize', function() {
                            $.alerts._repositionNotify();
                        });
                        break;
                    case false:
                        $(window).unbind('resize');
                        break;
                }
            }
        },
        
        
        
        edit: function(url, title, callback) {

            $.alerts._edit(url, title, function(result) {
                if (callback) callback(result);
            });

        },

        notify: function(message, className, callback) {

            $.alerts._notify(message, className, function(result) {
                if (callback) callback(result);
            });

        },

        confirm: function(message, className, callback) {

            $.alerts._notify(message, className, function(result) {
                if (callback) callback(result);
            });

        }

    }


    jEdit = function(url, title, callback) {
        newZIndex = newZIndex + 1;
        $.alerts.edit(url, title, callback);

    };

    jEvents = function(URL, title, callback) {
        newZIndex = newZIndex + 1;
        $.alerts.edit(URL, title, callback);
    };

    jNotify = function(message, notificationType, callback) {
        newZIndex = newZIndex + 1;
        if (notificationType == 'question') {
            $.alerts.confirm(message, notificationType, callback);
        } else {
            $.alerts.notify(message, notificationType, callback);
        }
    }

})(jQuery);




