/*
 * SimpleModal 1.1.1 - jQuery Plugin
 * http://www.ericmmartin.com/projects/simplemodal/
 * http://plugins.jquery.com/project/SimpleModal
 * http://code.google.com/p/simplemodal/
 *
 * Copyright (c) 2007 Eric Martin - http://ericmmartin.com
 *
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 * Revision: jQueryId: jquery.simplemodal.js 93 2008-01-15 16:14:20Z emartin24 jQuery
 *
 */
function updateModal(dialog, content, contentUrl) {
	if (typeof contentUrl == "undefined") {
		contentUrl = true;
	}

	dialog.container.slideUp('fast', function () {
		dialog.container.hide('fast', function () {
			if (contentUrl) {
				var html = jQuery.ajax({ url: content, async: false }).responseText;
				jQuery('#basicModalContent').html(html);
			}
			else {
				jQuery('#basicModalContent').html(content);
			}
			
			dialog.data.hide();
			dialog.container.fadeIn('fast', function () {
				dialog.data.slideDown('fast');
			});
		});
	});
}

function modalClose (dialog, needRefresh) {
	if (typeof needRefresh == "undefined") {
		needRefresh = false;
	}
	
	dialog.container.slideUp('fast', function () {
		dialog.container.hide('fast', function () {
			dialog.overlay.fadeOut('slow', function () {
				jQuery.modal.close();
				
				if (needRefresh) {
					window.location.reload();
				}
			});
		});
	});
}

function modalOpen (dialog) {
	dialog.overlay.fadeIn('slow', function () {
		var html = jQuery.ajax({ url: myDialogContent, async: false }).responseText;
		jQuery('#basicModalContent').html(html);

		dialog.data.hide();
		dialog.container.fadeIn('fast', function () {
			dialog.data.slideDown('fast');
			
			myDialog = dialog;
		});
	});
}

(function(jQuery){jQuery.modal=function(data,options){return jQuery.modal.impl.init(data,options);};jQuery.modal.close=function(){jQuery.modal.impl.close(true);};jQuery.fn.modal=function(options){return jQuery.modal.impl.init(this,options);};jQuery.modal.defaults={overlay:50,overlayId:'modalOverlay',overlayCss:{},containerId:'modalContainer',containerCss:{},close:true,closeTitle:'Close',closeClass:'modalClose',persist:false,onOpen:null,onShow:null,onClose:null};jQuery.modal.impl={opts:null,dialog:{},init:function(data,options){if(this.dialog.data){return false;}this.opts=jQuery.extend({},jQuery.modal.defaults,options);if(typeof data=='object'){data=data instanceof jQuery?data:jQuery(data);if(data.parent().parent().size()>0){this.dialog.parentNode=data.parent();if(!this.opts.persist){this.dialog.original=data.clone(true);}}}else if(typeof data=='string'||typeof data=='number'){data=jQuery('<div>').html(data);}else{if(console){console.log('SimpleModal Error: Unsupported data type: '+typeof data);}return false;}this.dialog.data=data.addClass('modalData');data=null;this.create();this.open();if(jQuery.isFunction(this.opts.onShow)){this.opts.onShow.apply(this,[this.dialog]);}return this;},create:function(){this.dialog.overlay=jQuery('<div>').attr('id',this.opts.overlayId).addClass('modalOverlay').css(jQuery.extend(this.opts.overlayCss,{opacity:this.opts.overlay/100,height:'2000px',width:'100%',position:'absolute',left:0,top:0,zIndex:3000})).hide().appendTo('body');this.dialog.container=jQuery('<div>').attr('id',this.opts.containerId).addClass('modalContainer').css(jQuery.extend(this.opts.containerCss,{position:'absolute',zIndex:3100})).append(this.opts.close?'<a class="modalCloseImg '+this.opts.closeClass
+'" title="'+this.opts.closeTitle+'"></a>':'').hide().appendTo('body');if(jQuery.browser.msie&&(jQuery.browser.version<7)){this.fixIE();}this.dialog.container.append(this.dialog.data.hide());},bindEvents:function(){var modal=this;jQuery('.'+this.opts.closeClass).click(function(e){e.preventDefault();modal.close();});},unbindEvents:function(){jQuery('.'+this.opts.closeClass).unbind('click');},fixIE:function(){var wHeight=jQuery(document.body).height()+'px';var wWidth=jQuery(document.body).width()+'px';this.dialog.overlay.css({position:'absolute',height:wHeight,width:wWidth});this.dialog.container.css({position:'absolute'});this.dialog.iframe=jQuery('<iframe src="javascript:false;">').css(jQuery.extend(this.opts.iframeCss,{opacity:0,position:'absolute',height:wHeight,width:wWidth,zIndex:1000,width:'100%',top:0,left:0})).hide().appendTo('body');},open:function(){if(this.dialog.iframe){this.dialog.iframe.show();}if(jQuery.isFunction(this.opts.onOpen)){this.opts.onOpen.apply(this,[this.dialog]);}else{this.dialog.overlay.show();this.dialog.container.show();this.dialog.data.show();}this.bindEvents();},close:function(external){if(!this.dialog.data){return false;}if(jQuery.isFunction(this.opts.onClose)&&!external){this.opts.onClose.apply(this,[this.dialog]);}else{if(this.dialog.parentNode){if(this.opts.persist){this.dialog.data.hide().appendTo(this.dialog.parentNode);}else{this.dialog.data.remove();this.dialog.original.appendTo(this.dialog.parentNode);}}else{this.dialog.data.remove();}this.dialog.container.remove();this.dialog.overlay.remove();if(this.dialog.iframe){this.dialog.iframe.remove();}this.dialog={};}this.unbindEvents();}};})(jQuery);