
//Cookie save/get functions
function set_cookie ( name, value, exp_y, exp_m, exp_d, path, domain, secure ){
  var cookie_string = name + "=" + escape ( value );

  if ( exp_y ){
    var expires = new Date ( exp_y, exp_m, exp_d );
    cookie_string += "; expires=" + expires.toGMTString();
  }

  if ( path ){cookie_string += "; path=" + escape ( path );}
  if ( domain ){cookie_string += "; domain=" + escape ( domain );}
  if ( secure ){cookie_string += "; secure";}
  document.cookie = cookie_string;
}
function get_cookie ( cookie_name ){
  var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );
  if ( results ){
    return ( unescape ( results[2] ) );
  }else{
    return null;
	}
}


//When user clicks on a search form this code removes the 'search' text inside, and when user focuses out it returns it
var last_page = 0;
var def_search = 'as';
$(document).ready(function() {
	def_search = $('#search_input').val();
	$('#search_input').focus(function(){
		if($(this).val() == def_search){
			$(this).val('');
		};
	});
	$('#search_input').blur(function(){
		if($(this).val() == '' || $(this).val() == ' '){
			$(this).val(def_search);
		};
	});
	
})


//This code stores the Font size in cookie
var base_value = 62.5;
var current_value = base_value;
var step = 10;
function setFontSize(v){
	if(v == 0){
		$('body').css('font-size', base_value+'%')
		current_value = base_value;
	}else{
		current_value += v*step;
		$('body').css('font-size', current_value+'%')
	}
	set_cookie('fontsize', current_value);	
}
$(document).ready(function() {
	var value = get_cookie('fontsize');
	if(value !== null){
		current_value = value 
		$('body').css('font-size', current_value+'%')
	}
})



//TOC highlight
var currently_highlighted = null;
var currently_highlighted2 = null;
$(document).ready(function(){
    $('.toc a').click(function(){
        if(currently_highlighted !== null){
            $(currently_highlighted).removeClass('highlight');
        }
        if(currently_highlighted2 !== null){
            $(currently_highlighted2).removeClass('highlight');
        }
        
        //Hightlight bullet
        $(this).parent().addClass('highlight')
        currently_highlighted = $(this).parent();
        
        //Hightlight header
        var anchor = $(this).attr('href').substr(1);
        currently_highlighted2 = $('a[name='+anchor+']').addClass('highlight');
    })
});