var gNewImageProcess = {

  _confirmPanel: null,
  _overlapPanel: null,
  _outOfBoundsPanel: null,
  _zoomInAlertPanel: null,
  _soldPanel: null,

	showLoadingPanel: function() {
		var elPanel = $("loadingPanel");
		this.centerPanel( elPanel );
		elPanel.style.visibility = "visible";
	},

	hideLoadingPanel: function() {
		$("loadingPanel").style.visibility = "hidden";
	},

  showStartScreen: function() {
    this.hideAllScreens();
    $("startScreen").style.display = "block";
    gApp.enableFileUpload();
  },

  hideStartScreen: function() {
    $("startScreen").style.display = "none";
  },
  
  showPlacementScreen: function() {

		this.hideLoadingPanel();

		// if the zoom is not at level 0, zoom in
		var curZoomLevel = gMap.getZoomLevel();
		if( curZoomLevel > 0 ){
      this.showZoomInAlert( 400 );
		} else {

			// hack: zoom is locked to prevent the history manager from taking action when the upload iframe changes the history state.
			gMap.unlockMap();

      this.hideAllScreens();
      $("placementScreen").style.display = "block";
      gNewImage.displayTempImage();
    }

  },

  afterZoomInAlert: function() {
    // called by the alert dialog that appears before the user is zoomed into level 0 after uploading an image.

		// hack: zoom is locked to prevent the history manager from taking action when the upload iframe changes the history state.
		gMap.unlockMap();

    this.hideZoomInAlertPanel();
    gMap.setZoomLevel( 0, true );
    this.hideAllScreens();
    $("placementScreen").style.display = "block";
    gNewImage.displayTempImage();
  },


  hidePlacementScreen: function() {
    $("placementScreen").style.display = "none";
  },




  showErrorScreen: function( errorReason ) {
    this.hideAllScreens();

    $("errorScreen").style.display = "block";

    // if a reason was given for the error, display it
    var elReasonContainer = $("errorReasonContainer");
    if( errorReason ){
      elReasonContainer.style.display = "block";
       _proxy_jslib_assign('', $("errorReason"), 'innerHTML', '=', ( errorReason));
    } else {
      elReasonContainer.style.display = "none";
    }

  },

  hideErrorScreen: function() {
    $("errorScreen").style.display = "none";
  },


  showLoginScreen: function() {
    this.hideAllScreens();
    $("loginScreen").style.display = "block";
  },

  hideLoginScreen: function() {
    $("loginScreen").style.display = "none";
  },


  showZoomInAlert: function( width ) {

    if( !this._zoomInAlertPanel ){
      var options = {
        width: width + "px",
        height: "90px",
        fixedcenter: true,
        underlay: "shadow",
        close: false,
        modal: true,
        draggable: true,
        visible: true
 };

      this._zoomInAlertPanel = new (YAHOO.widget.SimpleDialog)("zoomInAlertPanel", options);
      this._zoomInAlertPanel.render(  _proxy_jslib_handle(document, 'body', '', 0, 0) );
    }
    this._zoomInAlertPanel.show();

    $("zoomInOkBtn").focus();
    
    this.centerPanel( $("zoomInAlertPanel"), this._zoomInAlertPanel );
  },


  hideZoomInAlertPanel: function() {
    if( this._zoomInAlertPanel ){
      this._zoomInAlertPanel.hide();
    }
  },
  
  showSoldPanel: function() {
    var elPanel = $("soldPanel");

    if( !this._soldPanel ){
      var options = {
        width: "400px",
        height: "135px",
        fixedcenter: true,
        underlay: "shadow",
        close: false,
        modal: true,
        draggable: true,
        visible: true
 };
      
      this._soldPanel = new (YAHOO.widget.SimpleDialog)(elPanel, options);
      this._soldPanel.render(  _proxy_jslib_handle(document, 'body', '', 0, 0) );
    }
    this._soldPanel.show();
    
    $("soldOkBtn").focus();

    this.centerPanel( elPanel, this._soldPanel );
  },

  hideSoldPanel: function() {
    if( this._soldPanel ){
      this._soldPanel.hide();
    }
  },




  showOutOfBoundsPanel: function() {
    var elPanel = $("outOfBoundsPanel");

    if( !this._outOfBoundsPanel ){

      var options = {
         width: "430px",
//         height: "90px",
        fixedcenter: true,
        underlay: "shadow",
        close: false,
        modal: true,
        draggable: true,
        visible: true
 };

      this._outOfBoundsPanel = new (YAHOO.widget.SimpleDialog)(elPanel, options);
      this._outOfBoundsPanel.render(  _proxy_jslib_handle(document, 'body', '', 0, 0) );
    }

    //this._outOfBoundsPanel.center();  // doesnt work
    this._outOfBoundsPanel.show();

    this.centerPanel( elPanel, this._outOfBoundsPanel );
  },

  hideOutOfBoundsPanel: function() {
    if( this._outOfBoundsPanel ) {
      this._outOfBoundsPanel.hide();
    }
  },


  showOverlapPanel: function() {

    var elPanel = $("overlapPanel");

    if( !this._overlapPanel ){

      var options = {
        width: "360px",
        height: "120px",
        fixedcenter: true,
        underlay: "shadow",
        close: false,
        modal: true,
        draggable: true,
        visible: true
 };

      this._overlapPanel = new (YAHOO.widget.SimpleDialog)(elPanel, options);
       _proxy_jslib_handle(this._overlapPanel.cfg, 'setProperty', '', 1, 0)("icon", YAHOO.widget.SimpleDialog.ICON_ERROR);

      this._overlapPanel.render(  _proxy_jslib_handle(document, 'body', '', 0, 0) );
    }

    //    this._overlapPanel.center();  // doesnt work
    this._overlapPanel.show();
    
    this.centerPanel( elPanel, this._overlapPanel );

  },

  hideOverlapPanel: function() {
    if( this._overlapPanel ) {
      this._overlapPanel.hide();
    }
  },


  showConfirmPanel: function( sizeStr, locationStr, priceStr ) {

    var elPanel = $("confirmOrderPanel");

     _proxy_jslib_assign('', $("confirmSize"), 'innerHTML', '=', ( sizeStr));
     _proxy_jslib_assign('', $("confirmPrice"), 'innerHTML', '=', ( priceStr));

    var options = {
			width: "400px",
      height: "180px",
      fixedcenter: true,
      underlay: "shadow",
      close: false,
      modal: true,
      draggable: true,
      visible: true
 };

    if( !this._confirmPanel) {
      this._confirmPanel = new (YAHOO.widget.Panel)(elPanel, options);
      this._confirmPanel.render( _proxy_jslib_handle(document, 'body', '', 0, 0));
    }
    
    
    // put the image in there
    var elImg = $("confirmImage");
     _proxy_jslib_assign('', elImg, 'src', '=', ( gMapSelect.getImageUrl()));
    
    //     this._confirmPanel.center();  // doenst work
    this._confirmPanel.show();
    
    this.centerPanel( elPanel, this._confirmPanel );

  },


  centerPanel: function( elPanel, oPanel ) {

    // need to position the element myself because the YUI Panel code has a bug
    //  that makes it compute the center posistion based on the dialog having 0 width and height.
    var scrollX = document.documentElement.scrollLeft ||  _proxy_jslib_handle(document, 'body', '', 0, 0).scrollLeft;
    var scrollY = document.documentElement.scrollTop ||  _proxy_jslib_handle(document, 'body', '', 0, 0).scrollTop;
    var viewPortWidth = YUD.getViewportWidth();
    var viewPortHeight = YUD.getViewportHeight();
    var elementWidth = parseInt(elPanel.clientWidth);
    var elementHeight = parseInt(elPanel.clientHeight);
    var x = (viewPortWidth / 2) - (elementWidth / 2) + scrollX;
    var y = (viewPortHeight / 2) - (elementHeight / 2) + scrollY;

		if( oPanel ){
			 _proxy_jslib_handle(oPanel.cfg, 'setProperty', '', 1, 0)("xy", [parseInt(x, 10), parseInt(y, 10)]);   // not sure why the parseInt is there
		} else {
			elPanel.style.left = x + "px";

			// $$$$$ top 0 is right below the header in this context.  i'm subtracting 80 to account for the header height of 81 pixels.
			 _proxy_jslib_assign('', elPanel.style, 'top', '=', ( (y-80) + "px"));   
		}
	},


  



  hideConfirmPanel: function() {
    if( this._confirmPanel ){
      this._confirmPanel.hide();
    }
  },

  hideAllScreens: function() {
    this.hideConfirmPanel();
    this.hideErrorScreen();
    this.hideStartScreen();
    this.hidePlacementScreen();
    this.hideLoginScreen();
  }

}
