$(document).ready(
	function()
	{
	
		var categories = 0;
		var activated = 0;

		
		$(".inactive").each(
			function (i)
			{			
				categories++;
				//$(this).attr("href", "#" + $(this).attr("href"));
			}
		);
		
		
		var width = ((categories+1) * 123)+((categories)*7);
		var margin = Math.round(width/2);
		$("#menu").animate( { width: width+"px", marginLeft: "-"+margin+"px" }, { queue:false, duration:1000 } );	
		
		//$("#menu").css("overflow","visible");
		
		$(document).mouseover(
			function(e)
			{

				//$('#toolmenu').css({left: $("#goo1").pageX, top: $("#menu").pageY });
				
				
				//Append the tooltip template and its value
				//$('#toolmenu').text('LOL');	

				//Show the tooltip with faceIn effect
				//$('#toolmenu').fadeIn(300);		
			}
		);
		
		$(document).click(
			function(e)
			{
				e.preventDefault();
				if (e.target && (e.target.id.substr(0,2) == "go" || e.target.id.substr(0,4) == "item"))
				{

					var curact = $(".active").attr("id");

					if ($("#"+e.target.id).attr("class") == "active")
					{
						$("#middle").animate({top: "30%"}, 500);

						$(".active").css("color","pink");
						$("#"+curact).attr("class","inactive");
					} 
					else if ($("#"+e.target.id).attr("class") == "inactive")
					{
						$("#middle").animate({top: "20px"}, 500);

						$(".active").css("color","pink");
						$("#"+curact).attr("class","inactive");
						$("#"+e.target.id).attr("class","active");
						$("#"+e.target.id).css("color","yellow");
						activated = e.target.id.substr(2);
						if ($(e.target).attr('href')=='/forums')
						{
							$(e.target).css("color","yellow");
							$(".goo").hide(1000);
							$("#menu").animate( { width:"125px", marginLeft: "-63px" }, { queue:false, duration:1000 } );
							$('#goo'+e.target.id.substr(2)).show(100);
							//Show the tooltip with fadeIn effect
							//$('#fader').fadeIn('1000');
							$('#fader').fadeTo('1000',0.7);
							setTimeout("window.location.href='http://forums.graal.in/forums';",3000);
						}
						else if ($(e.target).attr('href')=='/chat')
						{
							$(e.target).css("color","yellow");
							$(".goo").hide(1000);
							$("#menu").animate( { width:"125px", marginLeft: "-63px" }, { queue:false, duration:1000 } );
							$('#goo'+e.target.id.substr(2)).show(100);

							//Append the tooltip template and its value
							$(".tipBody").html('<iframe width="780" height="554" scrolling="no" style="border:0" src="http://embed.mibbit.com/?server=irc.graal.in&amp;channel=%23graal&amp;settings=06bdb861d965804df4f153a5484ca538&amp;nick=OpenGraal"></iframe>');

							//Show the tooltip with fadeIn effect
							$('#tooltip').fadeIn('4000');
							$('#tooltip').fadeTo('10',0.8);
						}
                                                else if ($(e.target).attr('href')=='/playerworlds'||$(e.target).attr('href')=='/pages/servers/servercp-list.php')
                                                {
							var time = new Date()
                                                        $(e.target).css("color","yellow");
                                                        $(".goo").hide(1000);
                                                        $("#menu").animate( { width:"125px", marginLeft: "-63px" }, { queue:false, duration:1000 } );
                                                        $('#goo'+e.target.id.substr(2)).show(100);

                                                        //Append the tooltip template and its value
							$.post(
								'/pages/servers/servercp-list.php',
								{'time': time.getTime()},
								function(data)
								{
									$(".tipBody").html(data);
								}
							);
							$('#tooltip').css({'height':'auto'});
							$('.tipBody').css({'height':'auto'});

                                                        //Show the tooltip with fadeIn effect
                                                        $('#tooltip').fadeIn('4000');
                                                        $('#tooltip').fadeTo('10',1);
                                                }

					}					
				}
			}
		);
		
		
    	/*
		$("#go1").click(
			function()
			{
				$("#middle").animate({top: "20px"}, "slow");

				$("#go1").css("color","yellow");

				$(".goo").hide(1000);

				$("#menu").animate( { width:"125px", marginLeft: "-63px" }, { queue:false, duration:1000 } );

				$("#goo1").show(100);
				setTimeout("window.location.href='http://www.graalreborn.org/';",3000);

			}
		);

		$("#go2").click(
			function()
			{
				$("#middle").animate({top: "20px"}, "slow");

				$("#go2").css("color","yellow");

				$(".goo").hide(1000);

				$("#menu").animate( { width:"125px", marginLeft: "-63px" }, { queue:false, duration:1000 } );

				$("#goo2").show(100);
				setTimeout("window.location.href='http://www.graal.net/';",3000);
	
	    		}
		);

		$("#go3").click(
			function()
			{
				$("#middle").animate({top: "20px"}, "slow");

				$("#go3").css("color","yellow");

				$(".goo").hide(1000);

				$("#menu").animate( { width:"125px", marginLeft: "-63px" }, { queue:false, duration:1000 } );

				$("#goo3").show(100);
				setTimeout("window.location.href='http://www.graalonline.com/';",3000);
	
			}
		);

		$("#go4").click(
			function()
			{
				$("#middle").animate({top: "20px"}, "slow");

				$("#go4").css("color","yellow");

				$(".goo").hide(1000);

				$("#menu").animate( { width:"125px", marginLeft: "-63px" }, { queue:false, duration:1000 } );

				$("#goo4").show(100);
				setTimeout("window.location.href='http://statistics.graal.us/';",3000);
		
			}	
		);

		$("#go5").click(
			function()
			{
				$("#middle").animate({top: "20px"}, "slow");

				$("#go5").css("color","yellow");

				$(".goo").hide(1000);

				$("#menu").animate( { width:"125px", marginLeft: "-63px" }, { queue:false, duration:1000 } );

				$("#goo5").show(100);
				setTimeout("window.location.href='http://www.theugcc.com/';",3000);
	
			}
		);

		$("#go6").click(
			function()
			{
				$("#middle").animate({top: "20px"}, "slow");

				$("#go6").css("color","yellow");

				$(".goo").hide(1000);

				$("#menu").animate( { width:"125px", marginLeft: "-63px" }, { queue:false, duration:1000 } );

				$("#goo6").show(100);

				//Append the tooltip template and its value
				$(".tipBody").html('<iframe width="780" height="554" scrolling="no" style="border:0" src="http://embed.mibbit.com/?server=irc.graal.in&amp;channel=%23graal&amp;settings=06bdb861d965804df4f153a5484ca538&amp;nick=OpenGraal"></iframe>');

				//Show the tooltip with faceIn effect
				$('#tooltip').fadeIn('4000');
				$('#tooltip').fadeTo('10',0.7);
	
			}
		);

		$("#go7").click(
			function()
			{
				$("#middle").animate({top: "20px"}, "slow",
					function ()
					{
						$("#go7").css("color","yellow");

						$(".goo").hide(1000,
							function ()
							{
								$("#menu").animate( { width:"125px", marginLeft: "-63px" }, { queue:false, duration:1000 });
								$("#goo7").show(100,
									function ()
									{
										//Append the tooltip template and its value
										$(".tipBody").html('<iframe src="http://webchat.freenode.net/?randomnick=1&channels=graaldt&prompt=1" width="780" height="554"></iframe>');	

										//Show the tooltip with faceIn effect
										$('#tooltip').fadeIn(300,
											function ()
											{
												$('#tooltip').fadeTo(10,0.7);
											}
										);								
									}
								);	
							}
						);
					}
				);	
			}
		);
		*/
		$(".remchat").live('click',
			function()
			{

				$("#middle").animate({top: "30%"}, "slow",
					function()
					{
						//Remove the appended tooltip template

						$(".tipBody").html('Closing...');

						$('#tooltip').hide(300);
				
						$("#goo"+activated).hide(1000,
							function()
							{
								$("#menu").animate( { width: width+"px", marginLeft: "-"+margin+"px" }, { queue:false, duration:1000 } );
								$(".active").css("color","pink");
								//$("#"+curact).attr("class","inactive");	
								$(".goo").show(1000);
							}
						);
					}
				);
			}
		);
	}
);
  

