//Prevent selection of tab-text
var tabs = document.getElementById('tabs').getElementsByTagName('div');
for(var i = 0; i<tabs.length; i++) {
    tabs[i].onselectstart = function() { return(false); };
}

//Twitter
var twitreq = new Request.JSONP({
    method: 'get',
    url: 'http://twitter.com/statuses/user_timeline/pegeenwright.json',
    onSuccess: function(response) {
        var tweet = response[0];
        var date = tweet.created_at.substring(4,10) + ", " +tweet.created_at.substring(26,30);
        var text = tweet.text;
        document.id('twitterstat').set('html', '<div style="text-align: right">'+date+'</div><div>'+text+'</div>');
    },
    onFailure: function(){
        console.log('failed');
    }
}).send();

//Newsletter
var subscribe_box = new function() {
    this.box = document.getElementById('subscribeform');
    this.form = document.subscribe;
    this.show = function() {
        this.form.reset();
        this.box.style.display = 'block';
    }
    this.hide = function() {
        this.box.style.display = 'none';
    }
    this.toggle = function() {
        if(this.box.style.display == 'none') {
            this.show();
        } else {
            this.hide();
        }
    }
    this.submit = function() {
        var req = new Request({
            method: 'post',
            url: '/subscribe/',
            data: this.form,
            onComplete: function(response) {
                if(response == "saved") {
                    alert('Your information has been saved.  Thank you!');
                    subscribe_box.hide();
                } else {
                    alert(response);
                }
            }
        }).send();
    }
}
document.getElementById('subscribe_submit').onclick = function() {subscribe_box.submit();};
document.getElementById('subscribe_nothanks').onclick = function() {subscribe_box.hide();};
document.getElementById('subscribe_x').onclick = function() {subscribe_box.hide();};

//Consult
var consult_box = new function() {
    this.box = document.getElementById('consultform');
    this.form = document.consult;
    this.show = function() {
        this.form.reset();
        this.box.style.display = 'block';
    }
    this.hide = function() {
        this.box.style.display = 'none';
    }
    this.toggle = function() {
        if(this.box.style.display == 'none') {
            this.show();
        } else {
            this.hide();
        }
    }
    this.submit = function() {
        var req = new Request({
            method: 'post',
            url: '/consult/',
            data: this.form,
            onComplete: function(response) {
                if(response == "saved") {
                    alert('Your request has been submitted.  Thank you!');
                    consult_box.hide();
                } else {
                    alert(response);
                }
            }
        }).send();
    }
}
document.getElementById('consult_submit').onclick = function() {consult_box.submit();};
document.getElementById('consult_nothanks').onclick = function() {consult_box.hide();};
document.getElementById('consult_x').onclick = function() {consult_box.hide();};

