// Avoid conflict with prototype
var $j = jQuery.noConflict();

// jQuery onready function
$j(document).ready(function() {

    // Zebra tables
    $j('table.standard tr:even').addClass('even');
    $j('table.standard tr:odd').addClass('odd');
    
    // Camp details
    /*$j('#EventId').change(
        function() {
            
            var selected = this.options[this.selectedIndex];
            if (selected.value != '' && selected.value != 'NULL') {
                $j('.camper_details').show(0);
            } else {
                $j('.camper_details').hide(0);
            }
        }
    );*/
    
    
    
    
    
    
    
    // Navigation on all pages
    $j('#nav li.dropdown').hover(
        function() {
            $j(this).find('ul:first:hidden').css({visibility: "visible", display: "none"}).slideDown(400);
		},
        function() {
            $j(this).find('ul:first').css({visibility: "hidden"});
        }
    );
    
    // Creditcard processing pages
    $j('form.paymentform').submit(
        function() {
            var submit = $j('input[type=submit]');
            submit.attr("disabled", "disabled"); 
            setTimeout(
                function() { submit.removeAttr("disabled"); },
                10000
            );
        }
    );
    
    // Editorial board index
    $j('.country_list a').click(function(event) {
        event.preventDefault();
        $j('#countries').find('.country').slideUp();        
        var country = $j(this).attr('href').split('/').pop();
        $j('#' + country).slideDown();
    });
    
    // Add another author box during create paper
    $j('#add_author').click(function myAuthorBox (event) {
        event.preventDefault();
                
        // Add another author box
        inputHtml =   '<div class="author">'
                    + '    <div class="role">Additional Author #' + authorIndexCounter + '</div>'
                    + '    <div class="form">'
                    + '        <input type="hidden" name="data[Author][' + authorIndexCounter + '][weight]" value="' + (authorIndexCounter + 1) * 10 + '" id="Author0Weight" />'
                    + '        <div class="input text"><label for="Author' + authorIndexCounter + 'Firstname">First name</label><input name="data[Author][' + authorIndexCounter + '][firstname]" type="text" value="" id="Author' + authorIndexCounter + 'Firstname" /></div>'
                    + '        <div class="input text"><label for="Author' + authorIndexCounter + 'Surname">Family name</label><input name="data[Author][' + authorIndexCounter + '][surname]" type="text" value="" id="Author' + authorIndexCounter + 'Surname" /></div>'
                    + '        <div class="input text"><label for="Author' + authorIndexCounter + 'Email">Email</label><input name="data[Author][' + authorIndexCounter + '][email]" type="text" maxlength="200" value="" id="Author' + authorIndexCounter + 'Email" /></div>'
                    + '        <div class="input textarea"><label for="Author' + authorIndexCounter + 'Blurb">Blurb</label><textarea name="data[Author][' + authorIndexCounter + '][blurb]" cols="30" rows="6" id="Author' + authorIndexCounter + 'Blurb" ></textarea></div>'
                    + '    </div>'
                    + '</div>';
        
        // Append it
        $j('#authors_container').append(inputHtml);
        
        authorIndexCounter++;
        }
    );
    
    // Slide down the paper list for each volume
    $j('.volumes_year h3 a').click(function(event) {
        event.preventDefault();       
        var number = $j(this).attr('href').split('/').pop();
        $j('#volume' + number).toggle(400);
    });
    
});