//var prevSearch = "";
$(document).ready(function () 
{
	
	
	/*$("#search").keyup(function ()
	{
		if(prevSearch!="")
		{
			for (var i = 0; i < prevSearch.length; ++i) 
			{
				$(prevSearch[i]).removeClass("yellow");
				
			}
		}
		find($(this).val());
	});
	
	$("#searchForm").submit(function ()
	{
		return false;
	});
	
	$("#search").click(function ()
	{
		$(this).val("");
	});*/
	
	$("h3.down").prepend("<img class=\"d\" src=\"images/down.png\"/> ");
	$("h3.down").prepend("<img class=\"r\" src=\"images/right.png\"/> ").children("img.d").toggle();
	$("h3.down").next().next("ul").toggleClass("hidden");
	
	$("h3.down").click(function ()
	{
		$(this).next().next("ul").toggle("fold", {direction: "up"}, 500, function ()
		{
			$(this).removeAttr("style");
			$(this).toggleClass("hidden");
		});
		$(this).children().toggle();
		$(this).next().next().next("a.readMore").toggle();
	});
	
	$("a.readMore").click(function ()
	{
		$(this).toggle();
		$(this).prev("ul").toggle("fold", {direction: "up"}, 500, function ()
		{
			$(this).removeAttr("style");
			$(this).toggleClass("hidden");
		});
		$(this).prev().prev().prev("h3.down").children().toggle();
	});
	
	var hashval = window.location.hash;
	if(hashval != "")
	{
		$(hashval).next().next("ul").toggle("fold", {direction: "up"}, 500, function ()
		{
			$(this).removeAttr("style");
			$(this).toggleClass("hidden");
		});
		$(hashval).children().toggle();
		$(hashval).next().next().next("a.readMore").toggle();
		window.location.hash = hashval;
	}
});
/*
function find(searchVal)
{
	var findCount = 0;
	if(searchVal!="" && searchVal.length>2)
	{
		var values = searchVal.split(' ');
		
		
		if(searchVal.charAt(0)==' ')
			searchVal = searchVal.slice(1);
		
		if(searchVal.charAt(searchVal.length-1)==' ')
			searchVal = searchVal.slice(0,searchVal.length-1);
		
		var regex = new RegExp(searchVal.replace(' ',"|"),"i");
		var n = $(".content").egrep(regex);
		for (var i = 0; i < n.length; ++i) 
		{
			void($(n[i]).addClass("yellow").parent("ul").slideDown());
			void($(n[i]).parent().next().hide());
			void($(n[i]).parent().prev().prev().children("img.d").show());
			void($(n[i]).parent().prev().prev().children("img.r").hide());
		}
		findCount = n.length;
		var matches = " match";
		if(findCount>1)
		{
			matches = " matches";
		}
		$("#resultNum").text(" ( "+findCount+matches+" found)");
		prevSearch = n;
	}
	else
		$("#resultNum").text("");
}


$.fn.egrep = function(pat) {
	var out = [];
	var textNodes = function(n) {
		if (n.nodeType == 3) {
			var t = typeof pat == 'string' ? n.nodeValue.indexOf(pat) != -1 : pat.test(n.nodeValue);
			if (t) {
				out.push(n.parentNode);
			}
		}
		else {
			$.each(n.childNodes, function(a, b) {
				textNodes(b);
			});
		}
	};
	this.each(function() {
		textNodes(this);
	});
	return out;
};*/

