$(document).ready(
	function ()
	{	
		// if there's any tab-navigation
		if ( $("#main-content .tab-navigation").length > 0 )
		{
			// first hide all tab-content-container
			$("#main-content .inner-tab-content").hide();
			
			// then make first tab active
			$("#main-content .tab-navigation li:first").addClass("active");
			// and show its content
			$("#main-content .inner-tab-content:first").show();
			
			// link tabs
			$("#main-content .tab-navigation li a").click(
				function ()
				{
					// if clicked element is not the current tab
					if ( !$(this).parent().hasClass("active") && !$(this).parent().hasClass("last-active") )
					{
						// reset current active tab
						$(this).parent().parent().children("li.active").removeClass("active");
						$(this).parent().parent().children("li.last-active").removeClass("last-active").addClass("last");
						$(this).parent().parent().children("li.before-active").removeClass("before-active");
						
						// make this tab active
						!$(this).parent().hasClass("last") ? $(this).parent().addClass("active") : $(this).parent().addClass("last-active");
						
						// if there's a tab before the current active, change its class (needed for bg-image)
						if ( $(this).parent() != $(this).parent().parent().children("li:first") )
						{
							$(this).parent().prev().addClass("before-active");
						}
						
						// get the id of the next tab-content
						var cHref = $(this).attr("href");
						
						// hide all tabs
						$("#main-content .inner-tab-content").hide();
						
						// hide eventually opened detailpanel
						if(typeof fVc != "undefined")
						{
							if (fVc.detailpanel!=false && fVc.detailpanel != undefined)
							{
								hideDetailPanel(fVc.detailpanel);
								fVc.detailpanel=false;
							}
						}
						
						// show next tab
						$(cHref).show();
						
						switch ( cHref )
						{
							case "#current-arrivals":
								fVc.switch2Arrivals();
							break;
							
							case "#current-departures":
								fVc.switch2Departures();
							break;
						}

					}
					return false;
				}
			);
			
			// if there's an id in the url parameter, activate that tab
			var cUrl = window.location.href;
			if ( cUrl.indexOf("#") != -1 )
			{
				var tabID = cUrl.substr(cUrl.indexOf("#"));
				if ( $("#main-content .tab-navigation li a[href=" + tabID + "]") )
				{
					$("#main-content .tab-navigation li a[href=" + tabID + "]").click();
				}
			}
		}

	}
);
