  window.close_shadow = Shadowbox.close;

  function isFamilyAndFriends() {
    return (Dom.get("ffAgencyId") != null);
  }

  function shadowbox_link() {
    return Dom.get('modal_link');
  }

  function ensure_modal_link(type, link) {
    if (shadowbox_link()) {
      shadowbox_link().parentNode.removeChild(shadowbox_link());
    }
    return ce('a', {
        'id': 'modal_link',
        'rel': 'shadowbox;width=710;height=481;',
        'href': link,
	    'title': "<div id='modal_close_container'><span>&nbsp;</span></div>",
	    'style': 'visibility:hidden'
    }, type, document.body);
  }

  function create_shadowbox() {
    if(isFamilyAndFriends()){return;}
    if (!shadowbox_link()) {return;}

    Shadowbox.init({
      initialHeight: 481,
      initialWidth: 710,
      staticSize: true,
      overlayOpacity: 0.65,
      noTroubleshooting: true,
      viewportPadding: 0,
      assetURL: get_callback_endpoint(),
      text: {
  	  title: "this is the title",
        cancel: 'Cancel',
        loading: 'Loading',
        close: '',
        next: '<span class="shortcut">N</span>ext',
        prev: '<span class="shortcut">P</span>revious',
        errors: {
          single: 'You must install the <a href="{0}">{1}</a> browser plugin to view this content.',
          shared: 'You must install both the <a href="{0}">{1}</a> and <a href="{2}">{3}</a> browser plugins to view this content.',
          either: 'You must install either the <a href="{0}">{1}</a> or the <a href="{2}">{3}</a> browser plugin to view this content.'
        }
      }
    });

    Shadowbox.open(Dom.get('modal_link'));
    Evt.onAvailable("shadowbox_title_inner", function(){
	    Evt.on(Dom.get("shadowbox_title_inner"), "click", function(){
	    	//App.log("Hiding the cta iframe....");
	    	App.hide("cta_frame");
		    Shadowbox.close();
	    });
    });

    Evt.onAvailable("shadowbox_content", function(){
		document.domain="ncl.com";
    	window.close_shadow = Shadowbox.close;
    });
  }

  function get_signup_endpoint() {
		return App.r2.base_url() + '/ncl_inside_scoop?nclweb_refer=YES';
  }

  function get_callback_endpoint() {
		return App.r2.base_url() + '/help/leads?nclweb_refer=YES';
  }

  function form_url_for(form_type) {
    if ('signup' === form_type) { 
		return get_signup_endpoint();
    }
	return  get_callback_endpoint();
  }

 function open_callback_window(e) {
	if (e) {Evt.stopEvent(e);}
	ensure_modal_link('Callback', form_url_for('callback'));
	//App.log("Showing the cta_frame....");
	App.show("cta_frame");
    create_shadowbox();
  }
  
  function open_signup_window(e) {
    if (e) {Evt.stopEvent(e);}
	ensure_modal_link('Signup', form_url_for('signup'));
    create_shadowbox();
  }
  
 function open_legacy_window(e) {
	if (e) {Evt.stopEvent(e);}
    var link = Evt.getTarget(e);
	ensure_modal_link('Callback', link.href);
	App.show("cta_frame");
    create_shadowbox();
  }
  
Evt.onDOMReady(function () {
    var phone_img = Dom.get("toll_free_image_btn");
    if (phone_img)
    {
        Evt.on(phone_img, 'click', open_callback_window);
    }
});

Evt.onContentReady('signup_button', function () {
  Evt.on(Dom.get("signup_button"), 'click', open_signup_window);
});

