//@TODO docs


(function(){

    var hash = 'install_package';
    
    if(window.localStorage) {

        if(!localStorage['installer.type']) {
            localStorage['installer.type'] = location.hash 
                                           ? location.hash.replace(/^\#/, '')
                                           : hash;
        } else {
            if(localStorage['installer.type'].match(/^install_/)) {
                hash = localStorage['installer.type'];
            }
        }

        window.addEventListener('hashchange', function(){
            if(location.hash) {
                var hash = location.hash.replace(/^\#/, '');
                if(hash.match(/^install_/)) {
                    localStorage['installer.type'] = hash;
                }
            }
        });

    }
    
    //Needs a hash by default
    if(!location.hash) location.hash = hash;
    
    window.addEvent('domready', function(){
        var buttons = $$('.-installer-form ul a');
    
        buttons.addEvent('click', function(){
            buttons.removeClass('active');
            this.addClass('active');
            
            var hash = this.hash.replace(/^\#/, '');
            switch (hash) {
                case 'install_directory':
                    var input = document.id(hash).getElement('input[type=text]');
                    if(input.setSelectionRange) {
                        setTimeout(function(){
                            var root = input.getProperty('data-root');
                            if(input.value.search(root) === 0) {
                                input.focus();
                                input.setSelectionRange(root.length+1, input.value.length);
                            } else {
                                input.select();
                            }
                        }, 1);
                    }
                    break;
                case 'install_url':
                    var input = document.id(hash).getElement('input[type=text]');
                    setTimeout(function(){
                        if(input.setSelectionRange && input.value.match(/^http\:\/\//)) {
                            input.focus();
                            input.setSelectionRange(7, input.value.length);
                        } else {
                            input.select();
                        }
                    }, 1);
                    break;
            }
        });
        
        buttons.each(function(button){
            if(button.hash == location.hash) button.fireEvent('click');
        });
        
        var package = document.id('install_package');
        package.getElement('input[type=file]').addEvent('change', function(){
            package.addClass('selected');
        });
        package.getParent('form').addEvent('reset', function(){
            package.removeClass('selected');
        });
        package.getParent('form').getElements('input[type=text]').addEvent('keypress', function(event){
            if(event.key == 'enter') this.form.submit();
        });
    });
})();
@@ -38,23 +38,19 @@
 hash = '
-install
+tab
 _package
@@ -271,16 +271,44 @@
 %5C#/, '')
+.replace('tab_', 'install_')
 %0A       
@@ -414,39 +414,35 @@
 .type'%5D.match(/%5E
-install
+tab
 _/)) %7B%0A         
@@ -695,23 +695,19 @@
 match(/%5E
-install
+tab
 _/)) %7B%0A 
@@ -1035,34 +1035,86 @@
 lick', function(
-)%7B
+event)%7B%0A            if(event) event.preventDefault();%0A
 %0A            but
@@ -1234,32 +1234,169 @@
 place(/%5E%5C#/, '')
+.replace('tab_', 'install_');%0A            $$('.install-by').setStyle('display', 'none');%0A            $(hash).setStyle('display', 'block')
 ;%0A            sw
@@ -2633,32 +2633,201 @@
 ;%0A            %7D%0A
+            hash = hash.replace('install_', 'tab_');%0A            window.location.hash = hash;%0A            if(window.localStorage) localStorage%5B'installer.type'%5D = hash;%0A
         %7D);%0A    
@@ -2913,16 +2913,44 @@
 ion.hash
+.replace('tab_', 'install_')
 ) button
@@ -2967,16 +2967,27 @@
 ('click'
+, new Event
 );%0A     

test #178 ready for testing