
$(document).ready(function(){
    
    //$('#page').hide();
    $('#widecolumn').css('width','0px');
    /*$('#page').animate({opacity:1 },0).fadeIn(750);    
    
    $("#page a:not([href*=mailto])[target!=_blank]").click(function(){
        $("#page").fadeOut();
        setTimeout("nav('"+this.href+"')",800);
        return false;
    });
    */

    $('.reference_form textarea, .statements textarea').counter({ goal: 1000 });    
    $('#SendReference_message, .courseresults textarea').counter({ goal: 600 });
    $('#CancelApplication_reason, #reapply_reason').counter({ goal: 300 });
    
    $('#widecolumn').animate({
        'width':'610px'},500,null,function(){
            $('#widecolumn .inner').fadeIn();
    });

    
    //Homepage slideshow
    if ($('.slideshow').length){
        $('.slideshow').cycle({
    		timeout: 5000
    	});
    }
    
    //How it works circles
    $('#circles .circle').click(function(){
        if( $('#circleinfo div').is(':visible') ){
            $('#circleinfo div').hide();    
        }
        var circleClass = $(this).children('img').attr('class');
         $('#circleinfo .'+circleClass).show(); 
        
        $('.active').removeClass('active');
        
        $(this).addClass('active');   
    });
    
    //Dialog box open and closer
    $('.dialoglink').click(function(){
        $('.dialog').fadeIn('fast'); 
    });
    $('.dialog .close').click(function(){
        $(this).parent().fadeOut(('fast'));
    })
    
    
    $('#contactformlink').click( function(){
        $('#contactdetails').slideUp('normal',function(){
            $('#contactform').fadeIn();
        })
    } )
    
    //FAQ back to top scroller
    $('.top').click(function(){
      var targetOffset = $('html,body').offset().top;
      $('html,body').animate({scrollTop: targetOffset}, 1000);
    });
    
    //FAQ question scroller
    $('#questions a[href*=#]').click(function() {
        if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
        && location.hostname == this.hostname) {
          var $target = $(this.hash);
          $target = $target.length && $target
          || $('[name=' + this.hash.slice(1) +']');
          if ($target.length) {
            var targetOffset = $target.offset().top;
            $('html,body')
           .animate({scrollTop: targetOffset}, 1000);
           return false;
          }
        }
    });

 
$("input[name=applied_before]").each(function(i) {
    
    $(this).change(function(){
      
      if( $('#applied_before_no_output').is(':visible') ){
            $('#applied_before_no_output').fadeOut(250,
                function(){
                    $('#applied_before_yes_output').fadeIn(250);      
                });  
        } else if ( $('#applied_before_yes_output').is(':visible') ){
            $('#applied_before_yes_output').fadeOut(250,
                function(){
                    $('#applied_before_no_output').fadeIn(250);      
                });
        } else {
            $('#applied_before_'+$(this).val()+'_output').fadeIn();
        }
    });

  });

    $('#applicants_fd_funding_elsewhere_1').click( function(){
        $('.specify').slideDown('slow');       
    });
    $('#applicants_fd_funding_elsewhere_0').click( function(){
        $('.specify').slideUp('slow');       
    });
     
    $('#applicants_scholarship_attend_only_1').click( function(){
        $('.specify').slideDown('slow');       
    });
    $('#applicants_scholarship_attend_only_0').click( function(){
        $('.specify').slideUp('slow');       
    });
    
    // display of add supporting docs
    $('input#nzqa_number').blur(function() {
        $('div.supporting_docs_container').slideDown('slow');
    });
    $(window).load(function() {
        if ($('input#nzqa_number').val()) {
           $('div.supporting_docs_container').show();
        }
        else {
            $('div.supporting_docs_container').hide();
        }
    });
    
    $('#SubmitReference_award_scholarship_y').click( function(){
        $('#qualities_potential').slideDown('slow');       
    });
    $('#SubmitReference_award_scholarship_n').click( function(){
        $('#qualities_potential').slideUp('slow');       
    });    
    
    $('.help_link').toggle( 
        function(){
            $('.help').slideDown('slow');    
        },
        function(){
            $('.help').slideUp('slow');    
        }
    );
    $('#CourseResults_awarded_no').click( function(){
        $('#awarded_fields').fadeOut('normal',function(){
            $('#not_awarded_fields').fadeIn('normal');    
        });
            
    });
    $('#CourseResults_awarded_yes').click( function(){
        $('#not_awarded_fields').fadeOut('normal',function(){
            $('#awarded_fields').fadeIn('normal');    
        });
    });
});

function nav(href){
    location.href=href;
}
