Ext.ns('Tsf.site');
Ext.ns('Tsf.util');

if (!window.console) { 
    window.console = {
        print: function() {
            // do something for IE here?
        },
        log: function() {
            // do something for IE here?
        }
    };
}

// Tsf.util.prototype.slideTo

Ext.onReady(function()
{
    // Put external links to a new window
    Ext.select('a[href^="http://"]').set({"target": "_blank"});

    // Text field hints
    var HintInput = function HintInput(){};
    HintInput.prototype.onFocus = function(evt, target) {
        if (target.value != this.origHintValue) return;
        target.value = '';
    };
    HintInput.prototype.onBlur = function(evt, target) {
        if ('' != target.value) return;
        target.value = this.origHintValue;
    };
    // Text input hints
    var hintInput = new HintInput();
    Ext.select('form input[type=text].hint').each(function(el) {
        hintInput.origHintValue = el.getValue();
        el.on('focus', hintInput.onFocus, hintInput);
        el.on('blur', hintInput.onBlur, hintInput);
    });

    // Newsletter
    var newsletter = Ext.get('newsletter-subscribe');
    newsletter.child('label').on('click', function(evt, t) {
       newsletter.toggleClass('show-input');
    });
    // Really simple subscibe to newsletter
    newsletter.on('submit', function(evt, t) {
        evt.preventDefault();
        
        newsletter.child('label').update('Thanks!')
            .removeListener('on')
            .setStyle({cursor: 'default'});
        newsletter.toggleClass('show-input');
        
        Ext.Ajax.request({
            url: '/subscribe',
            form: 'newsletter-subscribe'
        });
    });
    
    
});
