/********************************
jQuery Do when dom is ready!
Rob 2009
********************************/
$(document).ready(function() {
	// Hide All FAQ Cats
//	$("#tl_faqs").children("div").children("dl:visible").hide();
	
	// Have Hash?  Show that one
	var url = document.location.toString();
	if (url.match('#'))	{
		$("#tl_faqs div"+strstr(window.location.href, '#')).addClass("tl_expanded").children("dl:hidden").slideDown();
	}
	
	$("#tl_faqs div h4 a").toggle(
		function() {
			$(this).parent("h4").parent("div").addClass("tl_expanded").children("dl:hidden").slideDown();
			// Add Hash
			var location = strstr(window.location.href, '#', true);
			if (location) {
				window.location.href = location + $(this).attr("href");
			}else{
				window.location.href = window.location.href + $(this).attr("href");
			}
			return false;
		},
		function() {
			$(this).parent("h4").parent("div").removeClass("tl_expanded").children("dl:visible").slideUp();
			// Remove Hash
			window.location.href = strstr(window.location.href, '#', true);
			return false;
		}
	);
});

function strstr (haystack, needle, bool) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Onno Marsman
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: strstr('Kevin van Zonneveld', 'van');
    // *     returns 1: 'van Zonneveld'
    // *     example 2: strstr('Kevin van Zonneveld', 'van', true);
    // *     returns 2: 'Kevin '
    // *     example 3: strstr('name@example.com', '@');
    // *     returns 3: '@example.com'
    // *     example 4: strstr('name@example.com', '@', true);
    // *     returns 4: 'name'
 
    var pos = 0;
    
    haystack += '';
    pos = haystack.indexOf( needle );
    if (pos == -1) {
        return false;
    } else{
        if (bool){
            return haystack.substr( 0, pos );
        } else{
            return haystack.slice( pos );
        }
    }
}
