(function($){

//----------------------------------------------//
// Scripted together by Vandread, November 2010 //
//                                              //
//                                              //
// Do not forget to set the Hex Codes for the   //
// Zebra stripes colors in the script. You can  //
// find those easily using CTRL+F and locating  //
//               "COLOR HEX HERE"               //
//----------------------------------------------//

	function parseNav()
		{
			$dataObject = $("table:first");
	// Function is executed on:
	//	all pages
			indices = [0];
			$("table.tborder:first").children("tbody").children("tr").children("td.thead").each(function(){
				indices.push($(this).parent("tr").index());
				$(this).parent("tr").addClass("temp_counter");
				});
			$dataObject.data("nav_ids", indices);
			var nav_idsName = [];
			for (i = 0; i < indices.length; i++)
			{
				if (i == 0)
				{
					nav_idsName.push($("table.tborder:first").children("tbody").children("tr").eq($dataObject.data("nav_ids")[i]).children("td").children("a").html());
				}
				else
				{
				nav_idsName.push($("table.tborder:first").children("tbody").children("tr").eq($dataObject.data("nav_ids")[i]).children("td").html());
				}
			}
			$dataObject.data("nav_idsName", nav_idsName);
			for (i = 0; i < indices.length; i++)
			{
				tempSubNavNames = [];
				$("table.tborder:first").children("tbody").children("tr").eq(indices[i]).nextUntil("tr.temp_counter").each(function(){
					tempSubNavNames.push($(this).children("td").html());
				});
				$dataObject.data(indices[i] + "_nav_idsName", tempSubNavNames);
			}
			adminLinks = [];
			userLinks = [];
			for (i = 0; i < indices.length; i++)
			{
				tempCompare = $("table.tborder:first").children("tbody").children("tr").eq($dataObject.data("nav_ids")[i]).children("td");
				if (i == 0)
				{
					tempCompare = tempCompare.children("a").html();
				}
				else
				{
					tempCompare = tempCompare.html();
				}
				if ( tempCompare == "RF PoA" || tempCompare == "Account" || tempCompare == "Donations" || tempCompare == "Server" )
				{
					userLinks.push(indices[i]);
				}
				else
				{
					adminLinks.push(indices[i]);
				}
			}
			$("table.tborder:first").parent("td").parent("tr").before("<tr><td><table id='gameCPnav'></table></td></tr>");
			$("table.tborder:first").parent("td").next("td").remove();
			$("table.tborder:first").parent("td").remove();
			$("table#gameCPnav").html("<tr><td></td></tr>").children("tbody").children("tr").children("td").addClass("tcat").css("padding", "6px").html($dataObject.data("nav_idsName")[$dataObject.data("nav_ids").indexOf(userLinks[0])]);

			for (i = 1; i < userLinks.length; i++)
			{
				j = $dataObject.data("nav_ids").indexOf(userLinks[i]);
				$("table#gameCPnav")
					.children("tbody")
					.children("tr:last")
						.append("<td></td>")
						.children("td:last")
							.addClass("tcat")
							.css("padding", "6px")
							.html($dataObject.data("nav_idsName")[j]);
			}
			userSublinkLength = 0;
			for (i = 0; i < userLinks.length; i++)
			{
				j = $dataObject.data(userLinks[i] + "_nav_idsName").length;
				if (userSublinkLength < j)
					{
						userSublinkLength = j;
					}
			}
			for (i = 0; i < userSublinkLength; i++)
			{

				$("table#gameCPnav")
					.children("tbody")
						.append("<tr></tr>");
					for (j = 0; j < userLinks.length; j++)
					{
						$("table#gameCPnav")
							.children("tbody")
							.children("tr:last")
								.append("<td></td>")
								.children("td:last")
									.addClass("alt2")
									.attr("nowrap", "nowrap");
						if ($dataObject.data(userLinks[j] + "_nav_idsName")[i])
						{
							$("table#gameCPnav")
								.children("tbody")
									.children("tr:last")
									.children("td:last")
										.html($dataObject.data(userLinks[j] + "_nav_idsName")[i]);
						}
						else
						{
							$("table#gameCPnav")
								.children("tbody")
									.children("tr:last")
									.children("td:last")
										.html("&nbsp;");
						}
					}
			}


			if (adminLinks.length>0)
			{
				$("table#gameCPnav").parent("td").parent("tr").after("<tr><td><p class='subheader'>Administrative Tools</p></td></tr><tr><td><table id='gameCPadminNav'></table></td></tr>");
				$("table#gameCPadminNav").html("<tr><td></td></tr>").children("tbody").children("tr").children("td").addClass("tcat").css("padding", "6px").html($dataObject.data("nav_idsName")[$dataObject.data("nav_ids").indexOf(adminLinks[0])]);
				for (i = 1; i < adminLinks.length; i++)
				{
					j = $dataObject.data("nav_ids").indexOf(adminLinks[i]);
					$("table#gameCPadminNav")
						.children("tbody")
						.children("tr:last")
							.append("<td></td>")
							.children("td:last")
								.addClass("tcat")
								.css("padding", "6px")
								.html($dataObject.data("nav_idsName")[j]);
				}
				adminSublinkLength = 0;
				for (i = 0; i < adminLinks.length; i++)
				{
					j = $dataObject.data(adminLinks[i] + "_nav_idsName").length;
					if (adminSublinkLength < j)
						{
							adminSublinkLength = j;
						}
				}
				for (i = 0; i < adminSublinkLength; i++)
				{

					$("table#gameCPadminNav")
						.children("tbody")
							.append("<tr></tr>");
						for (j = 0; j < adminLinks.length; j++)
						{
							$("table#gameCPadminNav")
								.children("tbody")
									.children("tr:last")
									.append("<td></td>")
									.children("td:last")
										.addClass("alt2")
										.attr("nowrap", "nowrap");
							if ($dataObject.data(adminLinks[j] + "_nav_idsName")[i])
							{
								$("table#gameCPadminNav")
									.children("tbody")
										.children("tr:last")
										.children("td:last")
											.html($dataObject.data(adminLinks[j] + "_nav_idsName")[i]);
							}
							else
							{
								$("table#gameCPadminNav")
									.children("tbody")
										.children("tr:last")
										.children("td:last")
											.html("&nbsp;");
							}
						}
				}
			}
		}

	function playerList()
		{

	// Function is executed on:
	//	do=all_player_list

			$("div.panel")
				.children("table.tborder")
				.children("tbody")
				.children("tr")
					.each(function(index){
						var raceCell = $(this).children("td").eq(2).children("b").children("span");
						if ( raceCell.html() == "Acc" )
						{
							raceCell.css("color", "#8DFFED");	// SET Acc COLOR HEX HERE
						}
						else if ( raceCell.html() == "Bell" )
						{
							raceCell.css("color", "#AE361C"); // SET Bell COLOR HEX HERE
						}
						else if ( raceCell.html() == "Cora" )
						{
							raceCell.css("color", "#00FF00"); // SET Cora COLOR HEX HERE
						}


						// COMMENT THIS ENTIRE BLOCK OUT IF YOU DON'T WANT ZEBRA STRIPES
						var zebraCalc = index%2; // 0 if even, 1 if odd

						if (zebraCalc == 0)
						{
							//Have to iterate through each child TD to fix IE6 and 7
							$(this).children("td").each(function(){
								$(this).css("background-color", "#0D0D0D"); // SET even rows BG COLOR HEX HERE
							});
						}
						else
						{
							$(this).children("td").each(function(){
								$(this).css("background-color", "#0A0A0B"); // SET odd rows BG COLOR HEX HERE
							});
						}
						// END ZEBRA STRIPES
				});
		}

	function banList()
		{

	// Function is executed on:
	//	do=all_userbanlist

				// ZEBRA STRIPES
				$("div.panel")
					.children("table.tborder")
					.children("tbody")
					.children("tr")
						.each(function(){
							if ($(this).children("td:first").html() != "»" && $(this).children("td:first").html != "#")
								{
									var zebraCalc = parseFloat($(this).children("td:first").html())%2; // 0 if even, 1 if odd

									if (zebraCalc == 0)
									{
										$(this).children("td").each(function(){
											$(this).css({"background-color" : "#0D0D0D", "font-size" : "8pt"}); // SET even rows BG COLOR HEX HERE
										});
									}
									else if (zebraCalc == 1)
									{
										$(this).children("td").each(function(){
											$(this).css({"background-color" : "#0A0A0B", "font-size" : "8pt"}); // SET odd rows BG COLOR HEX HERE
										});
									}
								}
							else if ($(this).children("td:first").html() == "»")
							{
								$(this).children("td").each(function(){
									// Looping through the list, the characters need the same zebrastripe as their 'parent' entry
									// so we look at the previous' TR's first TD child-tag's background-color and use that throughout
									// the entire row.
									var cellBackground = $(this).parent("tr").prev("tr").children("td:first").css("background-color");
									$(this).css("background-color", cellBackground);
								});
							}
						});
		}

	function accountInfoList()
		{

	// Function is executed on:
	//	do=user_accountinfo

			$("div.panel")
				.children("table.tborder")
				.children("tbody")
				.children("tr")
					.each(function(index){
						if ($(this).children("td").length > 3)
						{
							var raceCell = $(this).children("td").eq(1).children("span");
							if ( raceCell.html() == "Acc" )
							{
								raceCell.css("color", "#8DFFED");	// SET Acc COLOR HEX HERE
							}
							else if ( raceCell.html() == "Bell" )
							{
								raceCell.css("color", "#AE361C"); // SET Bell COLOR HEX HERE
							}
							else if ( raceCell.html() == "Cora" )
							{
								raceCell.css("color", "#00FF00"); // SET Cora COLOR HEX HERE
							}
						}
					});
		}

	function adminList()
		{

	// Function is executed on:
	//	do=support_list_guilds
	//	do=support_items_list
	//	do=support_monsters_list
	//	do=admin_manage_redeem

			//ZEBRA STRIPES
			$("div.panel table.tborder:last")
				.children("tbody")
				.children("tr")
					.each(function(index){

						if ($("table.tborder").eq(1).children("tbody").children("tr:first").children("td:first").html().split("").reverse().slice(0,13).reverse().join("") == "- Redeem Logs")
						{
							var threshold = 0;
						}
						else
						{
							var threshold = 1;
						}

						if (index > threshold)
						{
							var zebraCalc = parseFloat($(this).children("td:first").html())%2; // 0 if even, 1 if odd

									if (zebraCalc == 0)
									{
										$(this).children("td").each(function(){
											$(this).css({"background-color" : "#0D0D0D", "font-size" : "8pt"}); // SET even rows BG COLOR HEX HERE
										});
									}
									else if (zebraCalc == 1)
									{
										$(this).children("td").each(function(){
											$(this).css({"background-color" : "#0A0A0B", "font-size" : "8pt"}); // SET odd rows BG COLOR HEX HERE
										});
									}
						}
					});
		}


	function footerFix()
		{

	// Function is executed on:
	//	all pages

		// Center that annoying footer
		// (Note: if you want to remove it entirely,
		//	comment out the first bit and uncomment the second)

				$("p.smallfont:last")
					.parent("div")
					.parent("td")
					.parent("tr")
					.parent("tbody")
					.parent("table")
						.css({"width" : "100%", "padding" : "0px"});

				/*
				$("p.smallfont:last")
					.parent("div")
					.parent("td")
					.parent("tr")
					.parent("tbody")
					.parent("table")
						.remove();
				*/
		}

	$(document).ready(function() {

		var page = $("table.tborder").eq(1).children("tbody").children("tr:first").children("td:first").html();

		if (page == "&nbsp;Top Players List")
		{
			playerList();
		}
		else if (page == "&nbsp;Latest Banned Users")
		{
			banList();
		}
		else if (page.split("").reverse().slice(0,34).reverse().join("") == "Account Information and Characters")
		{
			accountInfoList();
		}
		else if (page == "&nbsp;Guild List" || page == "&nbsp;Items List" || page == "&nbsp;Monster List" || page.split("").reverse().slice(0,13).reverse().join("") == "- Redeem Logs")
		{
			adminList();
		}
		footerFix();
		//parseNav();
	});
})(jQuery);
