/*----------------------------------------------------

	JSONLOAD.JS

----------------------------------------------------*/

$(document).ready(function(){

	var bodyid = $('body').attr('id');
	
	// A. Close Response Messages
	//------------------------------------------------------------------------------------------

	$('#msg-response').bind("click", function(){
		if($('#msg-response').is(':visible')){
			$("#msg-response").slideUp();
		}
	});
	
	// B. Input Hints
	//------------------------------------------------------------------------------------------	

	/*$('input[type="text"]').each(function(){
		this.value = $(this).attr('title');
		$(this).focus(function(){
			if(this.value == $(this).attr('title')) {
				this.value = '';
			}
		});
		$(this).blur(function(){
			if(this.value == '') {
				this.value = $(this).attr('title');
			}
		});
	});*/

	// C. In Page Links
	//------------------------------------------------------------------------------------------
		
	/*$('a.in-link').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}, 900);
				return false;
			}
		}  
  	});*/
	
	// D. Logo Bio
	//------------------------------------------------------------------------------------------	
	
	$('#logo').append('<span>+</span>');
	$('#hdr-bio').hide();
	$('#hdr-bio').addClass('logo-bio');
	$('#logo span').click(function(event){
		if($('.logo-bio').is(':visible')){
			$('.logo-bio').hide();
			$('#logo span').removeClass('showing');
		}else{
			$('.logo-bio').show();
			$('#logo span').addClass('showing');
		}
		$(document).one('click',function() {
			$('.logo-bio').hide();
			$('#logo span').removeClass('showing');
		});
		event.stopPropagation();
	});
	$('#header').addClass('header-height');
	
	// F. Sidebar
	//------------------------------------------------------------------------------------------
	$('#ftr-sidebar').show();	
	$('#ftr-sidebar > li').hide();
	$('#ftr-sidebar h6').hide();
	$('#ftr-sidebar').wrap('<div id="ftr-sidebar-container"><div id="ftr-sidebar-inner-container">');
	$('#ftr-sidebar').before('<ul id="ftr-sidebar-nav"></ul>');
	$('#ftr-sidebar h6').each(function(){
		var tabid = $(this).html();
		tabid = tabid.toLowerCase();
		tabid = tabid.replace(" ","");
		$(this).attr('id',tabid);
		$(this).siblings('ul').attr('id',tabid);
		$('#ftr-sidebar-nav').append('<li><a id="nav-'+ $(this).attr('id') +'">'+ $(this).html() +'</a></li>');
	});
	$('#ftr-sidebar-nav a').click(function(event){
		var navitem = $(this).attr('id');
		if($('#'+navitem.replace("nav-","")).parent().is(':visible')){
			$('#'+navitem.replace("nav-","")).parent().slideUp();
			$(this).parent().removeClass('current');
		}else{
			$('#ftr-sidebar > li').slideUp();
			$('#'+navitem.replace("nav-","")).parent().slideDown();
			$('#ftr-sidebar-nav .current').removeClass('current');
			$(this).parent().addClass('current');
		}
			$(document).one('click',function() {
				$('#ftr-sidebar li').slideUp();
				$('#ftr-sidebar-nav .current').removeClass('current');
			});
			event.stopPropagation();

	});
	
});


// 01. trim
//------------------------------------------------------------------------------------------

function trim(str) {
	str = str.replace(/^\s+/, '');
	for (var i = str.length - 1; i >= 0; i--) {
		if (/\S/.test(str.charAt(i))) {
			str = str.substring(0, i + 1);
			break;
		}
	}
	return str;
}
