The problem with $('.btn_close').click()
event is that the element doesn't exist the moment its declared so the event is not bound to the element since it will still receive the class.
A workaround is to make a function instead to be called:
//was changed so the animation wouldn't interfere in the
//scrollTop animation upon close
function open() {
$('body, html').animate({ //body & html to work in all browsers
scrollTop: $("#btn").offset().top
}, 800);
}
//changed to be able to be called
function close(){
$('body, html').animate({ //body & html to work in all browsers
scrollTop: $("#header").offset().top
}, 800);
}
replacing the last 2 click events, and change this block:
if($(this).hasClass("btn_close")){
$(this).text("close");
open(); //added line
}else{
$(this).text("open");
close(); //added line
}
FIDDLE: http://jsfiddle.net/wBkf9/10/
EDIT: The question edit has a similar problem, one way or another we need to check the current state of the section, either opened or closed, or the close event will never be fired and yes it will always animate to section offset if there's no check:
$("#btn_1").click(function() {
//check if its closed to fire close event
if($(this).hasClass('arrow_down'))
close();
else{
$('html, body').animate({
scrollTop: $("#section_1").offset().top
}, 800);
}
});
function close(){
$('html, body').animate({
scrollTop: $("#header").offset().top
}, 800);
}
FIDDLE 2: http://jsfiddle.net/ACH5L/2/