var tabCurPos = 0;
var $gclTabLinks;
var $gclTabLinkCells;
var $gclTabPanels;

$(document).ready(function() {
						   
   	/**************************************************/
  	/*** [TAB FUNCTIONS] ******************************/
	
	$("#tab_menu a").addClass("tab_link");
	
  	$gclTabLinks     = $(".tab_link");
	$gclTabLinkCells = $("#tab_menu li");
	$gclTabPanels    = $(".tab_panel");
	
	$gclTabPanels.hide();

	function toggleTab() {
		$gclTabLinkCells.removeClass("tab_selected");
		$gclTabLinkCells.eq(tabCurPos).addClass("tab_selected");
		$gclTabPanels.hide("fast");
      	$gclTabPanels.eq(tabCurPos).show(500);
	}
	
	
	var myFile = document.location.toString();
	if (myFile.match('#')) {
	  var myAnchor = myFile.split("#")[1];
	  //$("a[href='#"+myAnchor+"']").text("demoooo");
	  tabCurPos = 0;
	  $gclTabLinks.each(function() {
		if ( $(this).attr('href') == '#'+myAnchor ) { toggleTab(); }
		tabCurPos++;
	  });
	} else {
		// by default, first tab is selected
		tabCurPos = 0; 
		var tryTabCurPos = $("#tab_menu").attr("tabpos");
		if ( (typeof(tryTabCurPos) != undefined) && (typeof (tryTabCurPos) != 'undefined') ) {
		  tabCurPos = tryTabCurPos;
		}
		toggleTab();
	}

	//$gclTabLinks.attr({'href': 'javascript:void(0)'});

	$gclTabLinks.click(function () {
      if(tabCurPos != $gclTabLinks.index(this)) {
      	tabCurPos = $gclTabLinks.index(this);
		toggleTab();
		}
	});
	

});