


$(function () {
  
  
  $('#subdomain')
    .focus(function () {
      var $this = $(this);
      if ($this.val()=='Set your subdomain') {
        $this.val('');
      }
    
    })
    .blur(function () {
      if ( $(this).val() ) {
        $.detonate('/seoify/this', [ $(this), $(this).val() ] );
      }        
    });

  $('div#editor-new-page')
    .click(function () {
      location.href= '/editor/';
    });


  $('div#editor-open-page')
    .click(function () {
      var $this = $('#editor-page-selector');
      
      if ( $this.val() != $('#editor-page-selector :first').val() ) {
        
        location.href = '/editor/#' + $this.val();
        
      }
    });
  
  
  $('div#editor-save-domain')
    .click(function () {
      $('div#editor-confirm-save-domain')
        .dialog('open');
    });



  $('#editor-confirm-save-domain').dialog({
    autoOpen: false,
    width: 400,
    buttons: {
      "YES! I love my domain name, save it!": function() {
          
        var $this = $(this), $subdomain  = $('#subdomain').val();
        
        $.post(
          '/xhr/xhr_save_domain.php', 
          { 'subdomain' : $subdomain },
          function (data) {
            
            if (data.domain_id) {
              $('#user-domain-full')
                .html('http://' + $subdomain + '.signed-on.com/');

              $('.select-page')
                .css({
                  display: ''
                });      
                
              $this.dialog("close");                
            }

          }
        );
      },
      "Go back and change it": function() {
        $(this).dialog("close");
      }      
    },
    modal: true
  });  
  
  
  if ( $('#subdomain').length > 0 ) {
    $('.select-page')
      .css({
        display: 'none'
      });
  }
  
});
