jQuery(document).ready(function() {
	// easy toggle for categories
	jQuery('#triggerCatID').click(function() {
		jQuery(this).toggleClass('focus');
		jQuery('#headerStrip').animate({ height: 'toggle', opacity: '100'}, 100);
		return false;
	});
	jQuery('#triggerCatID2').click(function() {
		jQuery(this).toggleClass('focus');
		jQuery('#footerStrip').animate({ height: 'toggle', opacity: '100'}, 100);
		return false;
	});
	jQuery('nav#nav a').click(function() { 
   var targ = jQuery(this).attr('href'), pos = jQuery('section'+targ).position().top - 15;
   jQuery('html,body').animate({scrollTop: pos}, 750);return false;
	});
	jQuery('div#controller a.backTop').click(function() { 
	jQuery('html,body').animate({scrollTop: 0}, 750);return false; 
	});
	jQuery('a.upOne').click(function() { return nav('up'); });
   	jQuery('a.downOne').click(function() { return nav('dn'); });
   	jQuery('a.backTop').click(function() {
    jQuery('html,body').animate({ scrollTop: 0 }, 750); return false;
   });
	
});

var navworking = false;
function nav(direction) {
   	if (! navworking) {
   		navworking = true;
   	var positions = []; var offset = 15;
  	var targ_pos = 0, last_section_pos = 0, current_pos = Math.round(jQuery(window).scrollTop());
   	jQuery('section').each(function() { positions.push( Math.round(jQuery(this).position().top) ); });
    for (i = 0; i < positions.length; i++) {
       var pos = positions[i];
       if ('up' == direction) {
           if (pos <= current_pos) { last_section_pos = pos; }
           else if (pos > current_pos) { targ_pos = last_section_pos; }
           if (pos <= current_pos && positions.length - 1 == i) { targ_pos = pos; }
       }
        else if ('dn' == direction) {
           if (current_pos + offset < pos) { targ_pos = pos; break; }
       }
   }
   
   jQuery('html,body').animate({ scrollTop: targ_pos - offset}, 750,function() { navworking = false; });
  }
  return false;
}

 