/*
*	UIManage v0.1
*	by Dario Cancelliere
*
*	27/06/11
*/

$(document).ready(function()
{
	//Tabs
	$(".tabs ul.navigator li a").click(function()
	{
		var index = $(".tabs ul li a").index(this);

		$(".tabs ul li").removeClass("active");
		$(".tabs ul li").eq(index).addClass("active");

		/* IE BUG FIX */
		$(".tabs .tab").removeClass("active");
		$(".tabs .tab").eq(index).addClass("active");
		/* IE BUG FIX */

		//$(".tabs .tab").hide();
		//$(".tabs .tab").eq(index).show();

		return false;
	});

	//Accordions
	$(".accordion .item .title a").click(function()
	{
		var Height = new Array();
		var index = $(".accordion .item .title a").index(this);

		if (!$(".accordion .item").eq(index).hasClass("active"))
		{
			$(".accordion .item .inside").each(function(i)
			{
				if (typeof(Height[i]) == "undefined")
				{
					Height[i] = 0;
				}

				$(".accordion .item").eq(i).addClass("active");

				if ($(this).height() && (!Height[i]))
				{
					Height[i] = $(this).height();
				}

				if (index != i)
				{
					$(this).stop(false, true).animate({height: 0}, 400, function()
					{
						$(".accordion .item").eq(i).removeClass("active");

						$(this).height(Height[i]);
					});
				}

				else
				{
					$(".accordion .item").eq(i).removeClass("active");
				}
			});

			$(".accordion .item").eq(index).addClass("active");

			$(".inside", $(".accordion .item").eq(index)).height(0);

			$(".inside", $(".accordion .item").eq(index)).stop(false, true).animate({height: Height[index]}, 400);
		}

		return false;
	});
});
