/*-----------------------------------------------------------
 Original
 http://archiva.jp/web/javascript/tab-menu.html

 Customized by WWW WATCH
 http://hyper-text.org/archives/2007/09/javascript_tab.shtml
------------------------------------------------------------*/

/*--setup--*/


jQuery(function(){
	var arrPages = arrTabLI = new Array();
	//there could be maximum 6 tabs in the news tab section in top page, so pushing those tabs into the array, 
	//otherwise js error occurs if no tab is created by the smarty template in case of no news under that tab is found
	for(var i=1; i<=6; i++){
		if(i.toString().length == 1) i='0'+i; 
		if( document.getElementById('tab_'+i) ) arrPages.push(document.getElementById('tab_'+i)); 	
	}
	
	if(document.getElementById('tab')){
		arrTabLI = ( document.getElementById('tab').getElementsByTagName('li') ) ? document.getElementById('tab').getElementsByTagName('li') : new Array();
	}
	
	tab.setup = {
	   tabs: arrTabLI,	   
	   pages: arrPages
	}	
	tab.init();
});
/*--setup end--*/

var tab = {
   init: function(){
      var tabs = this.setup.tabs;
      var pages = this.setup.pages;
      
      for(i=0; i<pages.length; i++) {
         if(i !== 0) pages[i].style.display = 'none';
         tabs[i].onclick = function(){ tab.showpage(this); return false; };
      }
   },
   
   showpage: function(obj){
      var tabs = this.setup.tabs;
      var pages = this.setup.pages;
      var num;
      
      for(num=0; num<tabs.length; num++) {
         if(tabs[num] === obj) break;
      }
      
      for(var i=0; i<pages.length; i++) {
         if(i == num) {
            pages[num].style.display = 'block';
            tabs[num].className = 'selected';
         }
         else{
            pages[i].style.display = 'none';
            tabs[i].className = null;
         }
      }
   }
}
