$j( document ).ready( function() {
    var tabLoad = function() {
        $j( ".pagePic" ).fadeIn( 3000 );

        $j( "#salmonSeasonBox" ).fadeIn( 1000, function() {
            $j( "#troutSeasonBox" ).fadeIn( 1000, function() {
                $j( "#steelheadSeasonBox" ).fadeIn( 1000 );
            } );
        } );

        $j( '#contactEmailButton' ).click( function() {
            $j( '#contactEmail' ).show();
            $j( '#contactPhone' ).hide();
            $j( '#bookingPhone' ).val( '' );
        } );

        $j( '#contactPhoneButton' ).click( function() {
            $j( '#contactPhone' ).show();
            $j( '#contactEmail' ).hide();
            $j( '#bookingEmail' ).val( '' );
        } );

        $j( '#submitBooking' ).click( function() {
            $j( '#submitBooking' ).attr( "disabled",
                                         "disabled" );

            $j( '#book' ).ajaxSubmit( function() {
                $j( '#resetBooking' ).click();

                $j( "#bookingFormContainer" ).hide();
                $j( "#requestSent" ).fadeIn( 1700 );
            } );

            return false;
        } );

        $j( '#resetBooking' ).click( function() {
            $j( '#submitBooking' ).removeAttr( "disabled" );
            $j( '#book' ).resetForm();
            $j( '#contactEmailButton' ).click();

            return false;
        } );

        $j( "#contactEmailButton" ).click();
    };

    $j( ".tabSelector" ).click( function() {
        if ( ! $j( this ).is( ".tabSelected" ) ) {
            $j( ".tabSelected" ).removeClass( "tabSelected" );
            $j( this ).addClass( "tabSelected" );

            var target;
            var id = $j( this ).attr( "id" );
            if ( id == "infoSelector" ) {
                target = "bookingInfo";
            } else if ( id == "seasonsSelector" ) {
                target = "seasons";
            } else if ( id == "bringSelector" ) {
                target = "whatToBring";
            } else if ( id == "cancellationSelector" ) {
                target = "cancellation";
            } else if ( id == "bookTripSelector" ) {
                target = "bookATrip";
            }

            $j( "#bookingContent" ).load( "/tail/" + target,
                                          {},
                                          tabLoad );
        }
    } );

    $j( "#infoSelector" ).click();
} );
