
var AdBuilder = {
  displayPriceSelect: function() {
    $j("#enterPrice").fadeOut("fast", function() {
      $j("#ad_price").val("");
      $j("#price_choose").val("free");
      $j("#priceSelect").fadeIn("fast");
    });
  },
  
  togglePrice: function() {
    if($j("#price_choose").val() == "notfree") {
      $j("#priceSelect").fadeOut("fast", function() {
        $j("#enterPrice").fadeIn("fast");
      });
    } else {
      $j("#price_choose").val("free");
      $j("#ad_price").val("0");
    }
  },
  
  displayAppropriatePriceInput: function(priceVal) {
    if(priceVal){
      $j("#enterPrice").show();
    } else {
      $j("#enterPrice").hide();
      $j("#price_choose").val("free");
    }
  },
  
  updatePrice: function(newValue) {
    $j("#ad_price").val($j("#ad_price_input").val());
  },
  
  addNew: function() {
    $j("#newPostPlaceholder").show(800, function() {
      // display popup
      AdBuilder.displayAdNewPopup();
    });
  },
  
  displayImagePopup: function() {
    var viewPhotoLinkOffset = $j("#viewPhotoLink").offset();
    $j("#adImageSmall").dialog( { modal:     false,
	                                resizable: false,
                                  width:     240,
                                  position: [viewPhotoLinkOffset.left, viewPhotoLinkOffset.top + 20] });
  },
  
  displayAdNewPopup: function() {
    var popup = $j("#addNewPopup");
    var popupArrow = $j("#addNewPopupArrow");
		var placeholderOffset = $j("#newPostPlaceholder").offset();
    popup.css( { 'position': 'absolute',
		              'top': placeholderOffset.top - 10,
                  'left': placeholderOffset.left + $j("#newPostPlaceholder").width() + 16
								})
	  popupArrow.css( { 'position': 'absolute',
    		              'top': placeholderOffset.top + 20,
                      'left': placeholderOffset.left + $j("#newPostPlaceholder").width()
    								})
    popup.show("fast", function() {
      popupArrow.show();
    });
  },
  
  deletePhoto: function() {
    // so the content doesnt bounce up and down as the elements
    // are hidden and then displayed
    $j("#managePhoto").css( { 'height': $j("#managePhoto").height() } );
    $j("#viewPhotoLink").hide("fast");
    $j("#deletePhotoLink").hide("fast", function() {
      $j("#deletePhotoUndoLink").show("fast");
    });
    
    $j("#deletePhoto").val("1");
  },
  
  undoDeletePhoto: function() {
    $j("#deletePhotoUndoLink").hide("fast", function() {
      $j("#deletePhotoLink").show("fast");
      $j("#viewPhotoLink").show("fast");
    });
    
    $j("#deletePhoto").val("0");
  },
  
  init: function() {
  }
}