function toggle(elementID){
    $('#' + elementID).slideToggle();
}

function arrow(elementID){
    var item = document.getElementById(elementID)
    if (item.className == '') {
        item.className = 'active'
    } else {
        item.className = ''
    }
}

/*---- clear inputs function ---*/
function clearInputs(){
	$('input:text, input:password, textarea').each(function(){
		if(!this.val) this.val = this.value;
		this.onfocus = function(){
			if(this.value == this.val) this.value = '';
		}
		this.onblur = function(){
			if(this.value == '') this.value = this.val;
		}
	});
}
/*--- navigation function ---*/
function initNav(){
	var nav_h = $('#side-nav');
	if(nav_h.length){
		var t_url = window.location.href;
		t_url = t_url.split('#')[1];
		var _a = nav_h.children().index(nav_h.children().filter('.active:eq(0)'));
		if(_a != -1) nav_h.children().removeClass('active').eq(_a).addClass('active');
		nav_h.find('a').each(function(_i){
			var _btn = $(this);
			var _box = false;
			if(_btn.attr('rel')) _box = $('#'+_btn.attr('rel'));
			if(_box && _box.length){
				if(t_url && _btn.attr('rel') == t_url){
					_a = _i;
					nav_h.children().removeClass('active').eq(_a).addClass('active');
				} 
				_btn.click(function(){
					nav_h.children().removeClass('active');
					$(this).parent().addClass('active');
					_a = nav_h.children().index($(this).parent());
					windowMove(_box);
					return false;
				});
			}
		});
		var _t1;
		var t_t1 = $(window).scrollTop();
		t_t1 -= 200;
		if(t_t1 < 0) t_t1 = 0;
		nav_h.css('top', t_t1);
		$(window).scroll(function(){
			if(_t1) clearTimeout(_t1);
			_t1 = setTimeout(function(){
				var t_t = $(window).scrollTop();
				t_t -= 200;
				if(t_t < 0) t_t = 0;
				nav_h.stop().animate({top: t_t}, Math.abs(nav_h.offset().top - t_t)/3);
			}, 100);
		});
	}
	var t_move;
	function windowMove(_box){
		if(t_move) clearInterval(t_move);
		var t_t = $(window).scrollTop();
		var n_t = _box.offset().top + 50;
		if(_a == 0 || n_t < 0) n_t = 0;
		var _step = (n_t - t_t)/50;
		if(Math.abs(t_t - n_t) > 20){
			if(t_t > n_t){
				if(-_step < 20) _step = -20;
				t_move = setInterval(function(){
					t_t = parseInt(t_t + _step);
					$(window).scrollTop(t_t);
					if(t_t <= n_t) clearInterval(t_move);
				}, 10);
			}
			else{
				if(_step < 20) _step = 20;
				t_move = setInterval(function(){
					t_t = parseInt(t_t + _step);
					$(window).scrollTop(t_t);
					if(t_t >= n_t) clearInterval(t_move);
				}, 10);
			}
		}
	}
}
$(document).ready(function(){
	clearInputs();
	initNav();
});
function initInputs()
{
	var inputs = document.getElementsByTagName("input");
	for (var i=0; i<inputs.length; i++)
	{
		if (inputs[i].type == "text" && (inputs[i].name == "search"))
		{
			inputs[i].onfocus = function ()
			{
				if (this.value == "Find more resources")
					this.value = "";
			}
			inputs[i].onblur = function ()
			{
				if (this.value == "" && this.name == "search") this.value = "Find more resources";
			}
		}
	}
}
if (window.addEventListener)
{
	window.addEventListener("load", initInputs, false);
}
else if (window.attachEvent){
	window.attachEvent("onload", initInputs);
}