var tabCurPos = 0;
var $gclTabLinks;
var $gclTabLinkCells;
var $gclTabPanels;
var $gclTabNext;
var myFile;
var myAnchor;
var tempTabCurPos = 0;

$(document).ready(function() {			 
	$("#tab_menu a").addClass("tab_link");
	$gclTabLinks     = $(".tab_link");
	$gclTabLinkCells = $("#tab_menu li");
	$gclTabPanels    = $(".tab_panel");
    $gclTabNext      = $(".tab_next");
	
	$gclTabPanels.hide();

	function toggleTab() {
		$gclTabLinkCells.removeClass("tab_selected");
		$gclTabLinkCells.eq(tabCurPos).addClass("tab_selected");
		$gclTabPanels.hide("fast");
		$gclTabPanels.eq(tabCurPos).show(500);
	}
	

	myFile = document.location.toString();
	if (myFile.match('#')) {
	  myAnchor = myFile.split("#")[1];
	  tempTabCurPos = 0;
	  $gclTabLinks.each(function() {
		if ( $(this).attr('href') == '#'+myAnchor ) { tabCurPos = tempTabCurPos; toggleTab(); }
		tempTabCurPos++;
	  });
	} else {
		// by default, first tab is selected
		tabCurPos = 0; 
		toggleTab();
	}
	$gclTabLinks.click(function () {
      if(tabCurPos != $gclTabLinks.index(this)) {
      	tabCurPos = $gclTabLinks.index(this);
		toggleTab();
		}
	});


    $gclTabNext.click(function () {
		myFile = $(this).attr("href");
		if (myFile.match('#')) {
		  myAnchor = myFile.split("#")[1];
		  tempTabCurPos = 0;
		  $gclTabLinks.each(function() {
			if ( $(this).attr('href') == '#'+myAnchor ) { tabCurPos = tempTabCurPos; toggleTab(); }
			tempTabCurPos++;
		  });
		}
	});


});