

$(document).ready(function(){

	

		function linkify(containerName, jTipID, bonus) {
			// For each <a>, append data/linkText, plus an incremental id; assign the class jTip
			$('"' + containerName + '" a').each(function(i){
				var mytitle = this.title;
				
				// Check to see if there's a title. If so, use that as the file reference. If not, use the text inside the link.
				if (mytitle != null && mytitle != '')
					{ this.href = "../data/" + mytitle + "?width=550";
					}
				else
					{ this.href = "../data/" + escape(this.innerHTML) + "?width=550";
					}
					
				this.name = this.innerHTML;
				$(this).addClass('"' + jTipID + '"');
				this.id = i + bonus;
			});
		}

	

		// If you click something with the .lead class, replace the contents of the ajaxFrame with the referenced lifepath file

		$(".lead").live("click", function(){

			//Load contents of html file into the document, and initialize the tooltip functions/drag n drop functions

			$("#ajaxFrame").load(("settings/" + this.id + ".html"), function(){

				linkify("#ajaxFrame", "jTip", 0);		

			});

		});	

		

		// If you click a lifepath name, clone the current lpContainer and append it to the #container div //

		$("#ajaxFrame .lpName").live("click", function(){

			$(this).parent(".lpHead").parent(".lpContainer").clone(true).appendTo("#container");

			linkify("#container", "jTip2", 1000);

		});

		

		// If you click a lifepath name, clone the current lpContainer and append it to the #container div //

		$("#container .lpContainer").live("click", function(){

			$(this).remove();

		});

		

		// Toggle Character Pane

		$("#toggleCharacter").click(function(){

			$("#leftColumn").toggle("slow");

			$("#changelog").toggle("slow");

		});

	});
