﻿/*
 *  doTabs will inistialize tabs functionality
 */
function doTabs(tbid)
	{
		var lastIdx = 0;
			
		/*Get First Child Div [Tabs]*/
		var tabD = $('#' + tbid + '> div:first-child');
		/*Get Second Child Div [Datas]*/
		var dataD = $('#' + tbid + '> div:last-child');
		
		/* Get All Tabs */
		var tabs = tabD.children();
		/* Get All Datas */
		var datas = dataD.children();
		/* hide all datas */
		datas.hide();
	
		/*alert('tabs.length = ' + tabs.length);
		alert('datas.length = ' + datas.length);*/
		
		for(var t = 0 ; t < tabs.length; t++ )
			{
				/* initialization */
				if(t == 0)
					{
					$(tabs[t]).addClass('active');
					$(datas[t]).show();
					}
				/*alert('t = ' + t + ' : ' + tabs[t]);*/
				/*$(tabs[t]).attr('onclick','alert(' + t + ')');*/
				$(tabs[t]).bind
					('click', function () 
						{
							var currElm = $(this);
							var currIdx = currElm.index();
							/* hide all datas */
							datas.hide();
							/*alert($(this).index()); */
							/* remove curr class from last Tab */
							$(tabs[lastIdx]).removeClass('active');
							/* add curr class to the current Tab */
							currElm.addClass('active');
							/* show corrosponding data */
							$(datas[currIdx]).show();
							/* change lastIdx */
							lastIdx = currIdx;
						} 
					);
				
			}
		
		
	}

