// jQuery Alert Dialogs Plugin
//
// Version 1.1
//
// Cory S.N. LaViska
// A Beautiful Site (http://abeautifulsite.net/)
// 14 May 2009
//
// Visit http://abeautifulsite.net/notebook/87 for more information
//
// Usage:
//		jAlert( message, [title, callback] )
//		jConfirm( message, [title, callback] )
//		jPrompt( message, [value, title, callback] )
// 
// History:
//
//		1.00 - Released (29 December 2008)
//
//		1.01 - Fixed bug where unbinding would destroy all resize events
//
// License:
// 
// This plugin is dual-licensed under the GNU General Public License and the MIT License and
// is copyright 2008 A Beautiful Site, LLC. 
//



function GetIFrameHeight(ihelpFrame)
{
   
    var myIFrame = $('#iFrameContent');
    var innerDoc = (myIFrame.get(0).contentDocument) ? myIFrame.get(0).contentDocument : myIFrame.get(0).contentWindow.document;
        
    if (innerDoc.body.scrollHeight > $(window).height() - 100)
    {
        var windowHeight = $(window).height() - 100;
        var windowHeightNoH1 = windowHeight - 35;
        $('#popup_container').animate({height: windowHeight, opacity: 1}, 600);
        $('#popup_contentpreview').animate({height: windowHeightNoH1}, 600);
        $('#popup_preview').animate({height: windowHeightNoH1}, 600);
        var theFrame = $("#iFrameContent");
        theFrame.height(windowHeightNoH1);
        $(".bgFramer").bgIframe();
        
    }
    else
    {
        var windowHeight = innerDoc.body.scrollHeight;
        var windowHeightH1 = windowHeight + 35;
        $('#popup_container').animate({height: windowHeightH1, opacity: 1}, 600);
        $('#popup_contentpreview').animate({height: windowHeight}, 600);
        $('#popup_preview').animate({height: windowHeight}, 600);
        var theFrame = $("#iFrameContent");
        theFrame.height(windowHeight);
        $(".bgFramer").bgIframe();
        
    }
}



(function($) {
	
	$.alerts = {
		
		// These properties can be read/written by accessing $.alerts.propertyName from your scripts at any time
		
		verticalOffset: 0,                // vertical offset of the dialog from center screen, in pixels
		horizontalOffset: 0,                // horizontal offset of the dialog from center screen, in pixels/
		repositionOnResize: true,           // re-centers the dialog on window resize
		overlayOpacity: 0.95,                // transparency level of overlay
		overlayColor: '#000',               // base color of overlay
		draggable: true,                    // make the dialogs draggable (requires UI Draggables plugin)
		okButton: '&nbsp;OK&nbsp;',         // text for the OK button
		cancelButton: '&nbsp;Cancel&nbsp;', // text for the Cancel button
		dialogClass: null,                  // if specified, this class will be applied to all dialogs
		
		// Public methods
		
		edit: function(url, title, callback) {
		
			$.alerts._edit(url, title, function(result) {
				if( callback ) callback(result);
			});
			
		},
			
		_edit: function(myurl, title, callback) {
		   	
		    $.alerts._hide();
			$.alerts._overlay('show');
			
						
			$("BODY").append(
			  '<div id="popup_container" style="top: 0;width:748px;opacity: 0;">' +
			   '<h1 id="popup_title"></h1>' +
			   '<div id="popup_contentpreview">' +
			      '<div id="popup_preview">' +
			      '<iframe id="iFrameContent" onload="GetIFrameHeight(this)" width="748px" marginheight="0px" marginwidth="0px" style="margin:0;padding:0;margin-left:0px;overflow:auto;" scrolling="auto" frameborder="0" src="' + myurl + '"></iframe>' +
			      '</div>' +
				'</div>' +
			  '</div>');
			
			//if( $.alerts.dialogClass ) $("#popup_container").addClass($.alerts.dialogClass);
			
			// IE6 Fix
			var pos = ($.browser.msie && parseInt($.browser.version) <= 6 ) ? 'absolute' : 'fixed'; 
			
			$("#popup_container").css({
				position: pos,
				zIndex: 99999,
				padding: 0,
				margin: 0,
				width: '748px',
				minWidth: '748px',
				maxWidth: '748px',
				height: 'auto',
				top: 0
				
			});
			
			
								
    		$.alerts._reposition();
			$.alerts._maintainPosition(true);
			
			$("#popup_title").html('\<img src="..\/images\/headers\/LargeHeader\/' + decodeURI(title) + '.aspx" />')
	        $("#popup_title").after('<input type="button" id="popup_ok1" value="" class="btncloseedit" />');

			$("#popup_ok1").click( function() {
				
				$('#popup_container,#popup_overlay').animate({opacity: 0}, 400, function(){
				    $.alerts._hide();						
					if( callback ) callback(false);
				});
			});
					
		
			
			if( $.alerts.draggable ) {
				try {
					$("#popup_container").draggable({ handle: $("#popup_title") });
					$("#popup_title").css({ cursor: 'move' });
				} catch(e) {  }
			}
			
			
			
		},
		
		
		_hide: function() {
		    
			$("#popup_container").remove();
			$.alerts._overlay('hide');
			$.alerts._maintainPosition(false);
		},
		
		_overlay: function(status) {
			switch( status ) {
				case 'show':
					$.alerts._overlay('hide');
					$("BODY").append('<div id="popup_overlay" class="bgFramer"></div>');
					$("#popup_overlay").css({
						position: 'absolute',
						zIndex: 99998,
						top: '0px',
						left: '0px',
						right: '0px',
						bottom: '0px',
						background: $.alerts.overlayColor,
						opacity: 0
					});
					$("#popup_overlay").animate({
						opacity: $.alerts.overlayOpacity
					},400);
				break;
				case 'hide':
				    $("#popup_overlay").remove();
					
				break;
			}
		},
		
		_reposition: function() {
			var top = 20; //(($(window).height() / 2) - ($("#popup_container").outerHeight() / 2)) + $.alerts.verticalOffset;
			var left = (($(window).width() / 2) - ($("#popup_container").outerWidth() / 2)) + $.alerts.horizontalOffset;
			if( top < 0 ) top = 0;
			if( left < 0 ) left = 0;
			
			// IE6 fix
			if( $.browser.msie && parseInt($.browser.version) <= 6 ) top = top + $(window).scrollTop();
			
			$("#popup_container").animate({
				top: top + 'px',
				left: left + 'px'
			}, 400);
			$("#popup_overlay").height( $(document).height() );
		},
		
		_maintainPosition: function(status) {
			if( $.alerts.repositionOnResize ) {
				switch(status) {
					case true:
						$(window).bind('resize', function() {
							$.alerts._reposition();
						});
					break;
					case false:
						$(window).unbind('resize');
					break;
				}
			}
		}
		
	}
	
	
	jEdit = function(url, title, callback) {
	    
		$.alerts.edit(url, title, callback);
		
	};

	jEvents = function(URL, title, callback) {
	    $.alerts.edit(URL, title, callback);
	};
	
})(jQuery);



