(function($){
	$.fn.faq_target = function(){		
		
		this.find("a[name]").each(function(){
			this.href = "#"+this.name;
		});
		
		this.find("h4").bind("click",function(self){
			self = $(this);
			if (self.next().css("display") != "none") {
				self.css({backgroundPosition: "3px 1px"}).next().stop().css({
					opacity: 1
				}).slideUp(150).animate({
					opacity: 0
				}, 150);
				$.fn.faq_target.opened = null;				
			}
			else {
				self.css({backgroundPosition: "left -13px"}).next().stop().css({
					opacity: 0
				}).slideDown(150).animate({
					opacity: 1
				}, 150);
				
				if($.fn.faq_target.opened) $.fn.faq_target.opened.css({backgroundPosition: "3px 1px"}).next().stop().css({
					opacity: 1
				}).slideUp(150).animate({
					opacity: 0
				}, 150, function() { document.location = self.prev()[0].href; });
				$.fn.faq_target.opened = self;
			}
		});
		
		var name = false;
		if(document.URL.indexOf("#") != -1) name = document.URL.split("#")[1];
		if(name) this.find("a[name='"+name+"']").next().trigger("click");
		
		this.find("a[name]").each(function(){
			this.name = "";
		});
	};
	$.fn.faq_target.opened = null;
	$(function() {
		$('#contentfaq.content').faq_target();
	})
})(jQuery);

