$(document).ready(function() {

  var inittab = getUrlVars()["inittab"];

  if ( inittab == 'tcu' ) {
      $("#tcg_box").hide();
      $("#tc_box").hide();
      $("#ap_box").hide();
      $("#c_box").hide();
      $("#tcm_box").hide();
  }
  else {
      $("#tc_box").hide();
      $("#ap_box").hide();
      $("#c_box").hide();
      $("#tcm_box").hide();
      $("#tcu_box").hide();
  }

  var imgDir = "common/images";
  var i;
  var tabIndex = $("#center_box > div");
  var tabNum = $(tabIndex).length-1;
  var naviIndex = $("#menu > li > a");


  var arr = [ 0, "#tcg_box", "#tc_box", "#ap_box", "#c_box", "#tcm_box", "#tcu_box" ];


  // profile tab
  $("#menu > li > a").click(function() {
	    var targetID = $(this).attr("href");
	    if (targetID.substr(0,1) != "_") {
	    	return true;
	    }
	    targetID = "#" + targetID.substr(1);
	    $("#tcg_box").hide();
	    $("#tc_box").hide();
	    $("#ap_box").hide();
	    $("#c_box").hide();
	    $("#tcm_box").hide();
	    $("#tcu_box").hide();
	    for (i=0; i<=tabNum; i++) {
	      $("img", naviIndex[i]).attr("src", imgDir + "/clear.png");
	    }
	    $("img", $(this)).attr("src", imgDir + "/cbtn0" + jQuery.inArray(targetID, arr) + "_m.jpg");
	    $(targetID).show();
	    return false;
  });

  // tcg tab
  $("#tcg_stepcarousel-pagemaker > a").click(function() {
	var tcgImage = "images/tcg";
    var tcgIndex = $("#tcg_stepcarousel-pagemaker > a");
    var tcgNum = $(tcgIndex).length -1;
	var targetID = $(this).attr("href");
	    for (i=0; i<=tcgNum; i++) {
	      $("img", tcgIndex[i]).attr("src", imgDir + "/clear.png");
	    }
	    $("img", $(this)).attr("src", tcgImage + "/cbtn_on.gif");
	    stepcarousel.stepTo('tcg_stepcarousel', targetID.substr(1));
	    return false;
  });

  // tc tab
  $("#tc_stepcarousel-pagemaker > a").click(function() {
	var tcgImage = "images/tc";
    var tcgIndex = $("#tc_stepcarousel-pagemaker > a");
    var tcgNum = $(tcgIndex).length -1;
	var targetID = $(this).attr("href");
	    for (i=0; i<=tcgNum; i++) {
	      $("img", tcgIndex[i]).attr("src", imgDir + "/clear.png");
	    }
	    $("img", $(this)).attr("src", tcgImage + "/cbtn_on.gif");
	    stepcarousel.stepTo('tc_stepcarousel', targetID.substr(1));
	    return false;
  });



});




stepcarousel.setup({
	galleryid: 'tcg_stepcarousel', //id of carousel DIV
	beltclass: 'belt', //class of inner "belt" DIV containing all the panel DIVs
	panelclass: 'panel', //class of panel DIVs each holding content
	autostep: {enable:false, moveby:1, pause:3000},
	panelbehavior: {speed:500, wraparound:true, persist:true},
	defaultbuttons: {enable: false, moveby: 1, leftnav: ['', -5, 80], rightnav: ['', -20, 80]},
	statusvars: ['reportA', 'reportB', 'reportC'], //register 3 variables that contain current panel (start), current panel (last), and total panels
	contenttype: ['inline'] //content setting ['inline'] or ['ajax', 'path_to_external_file']
});

stepcarousel.setup({
	galleryid: 'tc_stepcarousel', //id of carousel DIV
	beltclass: 'belt', //class of inner "belt" DIV containing all the panel DIVs
	panelclass: 'panel', //class of panel DIVs each holding content
	autostep: {enable:false, moveby:1, pause:3000},
	panelbehavior: {speed:500, wraparound:true, persist:true},
	defaultbuttons: {enable: false, moveby: 1, leftnav: ['', -5, 80], rightnav: ['', -20, 80]},
	statusvars: ['reportA', 'reportB', 'reportC'], //register 3 variables that contain current panel (start), current panel (last), and total panels
	contenttype: ['inline'] //content setting ['inline'] or ['ajax', 'path_to_external_file']
});


function getUrlVars(){
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}
