  function init_popup(thar,config) {      //thar is the button that will later spawn the popup
        config.containerID = ( config.containerID || 'pop-up-big' );
        if ( ! $(config.containerID) ) {  //try and make one using the default id
           $(document.body).insert(
              '<div id="pop-up-big" style="display: none; position: absolute; left: -100px; top: -100px;">' +
                '<div class="pop-up_body" style="position:relative">' +
                  '<a class="cancel close" href="#" onclick="return false;">&nbsp;</a>' +
                  '<div class="pop-up_content">' +
                      //'Loading...' +
                  '</div>' +
                '</div>' +
              '</div>'
           );
       }
       
       if ( ! $('pop-up_curtain') ) {
               $(document.body).insert( '<div id="pop-up_curtain" style="display: none; position: absolute; left: -100px; top: -100px; "> </div>' );
       }

		if ( thar ) {  //you'll be calling pop_dialog programatically and passing required args
	        $(config.containerID).popConfig = config;  //save it locally
	        Event.observe(thar,'click', pop_dialog.bindAsEventListener(pop_dialog, config));
		}


  }


  function pop_dialog(e,config) {  
	  
	  if ( config.disableClose ) {	
        $('pop-up_curtain').stopObserving();
        $(config.containerID).down('a.close').stopObserving();
      } else {
      	var closebuttons = [ $(config.containerID).down('a.close') ];
      
      	if ( config.customCloseButtons && Object.isArray(config.customCloseButtons) ) 
    		closebuttons.push( config.customCloseButtons.collect(function(f){ return $(f) }) );
      
        Event.observe( $('pop-up_curtain'), 'click', drop_dialog.bindAsEventListener(drop_dialog,config) );
        closebuttons.each(function(c) {
	        Event.observe( c, 'click', drop_dialog.bindAsEventListener(drop_dialog,config));
	    });
      }  

      if ( config.url ) {
          $w($(config.containerID).className).each(function(k){ $(config.containerID).removeClassName(k);  });

          if ( typeof config.onClick == 'function' ) 
            config.onClick();

          if ( config.optionClass )
              $(config.containerID).addClassName( config.optionClass );


          	  
          new Ajax.Updater( 	$(config.containerID).down('div.pop-up_content'), 
          						config.url, 
          						{ 
          							method:'GET', 
          							onComplete:function() {
       								       // any forms that get pulled into the popup should get auto ajaxified
       								       
									       if ( config.ajaxForms )
									       		ajaxy_form( $(config.containerID).down('div.pop-up_content') || $(config.containerID) );
									          
									       // any a-hrefs that get pulled in should also ajaxy load themselves into the modal popup
									       // iff they are className = 'pop-up-big_link'
									       register_links( null, ($(config.containerID).down('div.pop-up_content') || $(config.containerID)), config);

                         if ( typeof config.callback == 'function' )
                            config.callback(e,config);
          							},
        							  onException: function(req,e) {
        								  if ( typeof console != 'undefined' )
        									  console.log(e);
        								  else 
        									  alert( e.number+' : '+e.name+' :: '+ e.message );
        							  }          							
          						} 
          				);
      } else {
	       register_links( null, ($(config.containerID).down('div.pop-up_content') || $(config.containerID)), config);
         if ( typeof config.callback == 'function' )
             config.callback(e,config);
      }

      var zIndex = ( config.zIndex || '101010' );
      var curtain_zIndex = zIndex - 10;

/*     console.log( document.viewport.getWidth()+' - '+$(config.containerID).getWidth() ); */
      var voff = ( ( ! isNaN(config.yOffset) ? config.yOffset : 120 ) + ( config.absolute ? 0 : document.viewport.getScrollOffsets()[1] ) );
      $('pop-up_curtain').setStyle({ width:'100%', zIndex: curtain_zIndex, height:( 42 + $(document.body).getHeight() )+'px', top:0, left:0}).appear({duration:0.5,from:0.0, to:(config.finalOpacity || 0.7)});
        $(config.containerID).setStyle({
          'left':( ( document.viewport.getWidth() - $(config.containerID).getWidth() ) / 2 ) + 'px',
          'top':voff.toString()+'px', // 
          'zIndex':zIndex
            }).appear({duration:0.5});
  }

  function drop_dialog(e,config) {    //thar is the button closing the popup
        var thar;
        if ( e ) {
          thar = Event.element(e);
          if (thar) {
            $(thar).blur();
          }
        }

        $(config.containerID).fade({ 
          duration:0.5,
          afterFinish: function(){    
            $(config.containerID).setStyle({
              'left':'-1000px',
              'top':'-1000px'
            });
            if ( $(config.containerID).down('div.pop-up_content') )
            	$(config.containerID).down('div.pop-up_content').replace('<div class="pop-up_content">' + 'Loading...' + '</div>');
          }
        });
      
      $('pop-up_curtain').fade({duration:0.5,from:0.7, to:0.0, onFinish:function(){ $('pop-up_curtain').setStyle({ width:0, height:0, top:'-1000px', left:'-1000px'}); } });
  }
  
  //automatically make any forms within the popup submit ajaxy and update the popupcontainer
  function ajaxy_form(container) {
  		container = $(container);
  		var forms = container.select('form');
/*   		console.log(forms); */
 		forms.each(function(f){
 		
/*  		console.log(f); */
  			f.onsubmit = function() { return false };
 
  			Event.observe(f,'submit',function() {
  					new Ajax.Updater(container, f.action,
  						{
  							method:( f['method'] || 'GET' ),
  							parameters:f.serialize(true)	
  						});
 
  				});
  		});

  }

  function register_links(e,context,config) {
     (  
     	$(context) 
     		?
     	$(context).select('a.pop-up-big_link')	
     		:
     	$$('a.pop-up-big_link') // globally
     ).each( function(b) {
     		var cconfig = ( config ? Object.deepClone(config) : {} );
			if ( b.href )
				cconfig.url = b.href;

            b.onclick = function() { return false };  //null out click handler
            init_popup( b, cconfig );
            
            
      });

            //init admin editability
     $$('.admin_editable').each(function(spval) {
			new ADMIN_META_EDIT(spval);
     	});
     
  }
  

  Event.observe(document,'dom:loaded',register_links.bindAsEventListener(this,null,(typeof popupConfig == 'object' ? popupConfig : {})));
