$.charge('/seoify/this', function ($this, str) {
  $this.val(str.replace(/\s+/g,'-').replace(/[^a-zA-Z0-9-]+/g,'').toLowerCase());
});


$.charge("/toggle/save/page", function () {
  if ( $('.save-page').css('opacity') > 0 ) {

    $('.save-page')
      .animate({
        opacity: 0
      },'fast', function () {
        $(this).hide();
      });

    return;
  }        
  $('.save-page')
    .show()
    .animate({
      opacity: 100
    },'med');
});

$.charge("/toggle/save/layout", function () {
  if ( $('.save-layout').css('opacity') > 0 ) {

    $('.save-layout')
      .animate({
        opacity: 0
      },'fast', function () {
        $(this).hide();
      });
    return;
  }        
  $('.save-layout')
    .show()
    .animate({
      opacity: 100
    },'med', function () {
    
    });
});

$.charge("/canvas/resize", function(){ 
  $('div#editor-canvas')
    .css({
      height: function () {
        return ( $(document).height() - this.offsetTop / 3 );
      }
    });  
});

$.charge("/layout/resize", function(){ 
  $('.panel')
    .css({
      height: function () {
        return $('div#editor-canvas').height();
      }
    });  
});

$.charge('/open/page', function () {
  location.href = '/editor/#' + $('#editor-page-selector').val();
});


//  APPLICATION 
$(function () {
  $('.button').button();    
  
  $('#editor-open-page')
    .click(function () {
      $.detonate('/open/page');
    });
  
  $('.so-logo').click(function () {
    location.href='/';
  });
});

