(function($) {
    
    //An array of input objects, id is the unique id, len is the allowed length of the input
    var inputs = [{id: '#sro1', len: 1}, {id: '#sro2', len: 3}, {id: '#sro3', len: 3}, {id: '#zip', len: 5}];
    
    //takes an object literal and binds keyup events for each input
    //could use error handling (like checking that we are indeed working with text-ish inputs)
    function makeNextInputActive(inputsmap) {
        $.each(inputsmap, function(i, elem){
            $(elem.id).keyup(function(){            
                if($(elem.id).val().length >= elem.len && inputsmap[i+1] !== undefined){
                    $(inputsmap[i+1].id).focus();
                }
            });
        });
    }
    
    function closeFacebox() {
        $.facebox.close();
    }
    
    $(document).ready(function() {
        
        makeNextInputActive(inputs);
        
        $("#status_content img, #status_content input[type='image']").hover(
            function() { $(this).attr("src",$(this).attr('src').replace("BUTTON","RolloverBUTTON")); },
            function() { $(this).attr("src",$(this).attr('src').replace("RolloverBUTTON","BUTTON")); }
        );
        
        $("#feedback").hide();
        
        $("#no_feedback").show().bind('click.tek-service', function(){
            $("#no_feedback").hide();
            $("#feedback").slideDown(function() { $("#feedback textarea").focus(); });
        });

        //init facebox (popups for stock/contact us)
        $('a[rel*=facebox]').facebox();
        
    });

})(jQuery);
