function toogleTab(parThis,classNamePrefix){
	
	// Get id
	var currentId = parThis.id;
	
	// Loop through all tabs and reset
	for (var i=0;i<=10;i++){
		if(document.getElementById('tab'+i)){
			document.getElementById('tab'+i).className = '';
			document.getElementById('tab'+i+'content').style.display = 'none';
		}
	}

	// Set selected tab
	if(classNamePrefix==''){ // Prefixes: first, other, last
		classNamePrefix='other';
	}
	
	// set current tab to selected
	document.getElementById(currentId).className = classNamePrefix+'Sel';
	document.getElementById(currentId+'content').style.display = 'block';
	
	// Blur selected tab
	document.getElementById(currentId).blur();


}

function resizeTabs(parTabs,parSize){
        var tabs = 0;

        for (var i=0;i<=10;i++)
        {
	  if(document.getElementById('tab'+i))
          {
            if (document.getElementById('tab'+i).style.display != 'none') tabs++;
          }
	}

	var totalwidth = parseInt(parSize) - 8; // Tabbar width - inner padding (due to the shadow)
//	var tabs = parseInt(parTabs);
	var devidetabs = totalwidth / tabs;
	var tabsrounded = Math.round(devidetabs);
	var tabsroundedtotal = tabsrounded * tabs;
	var countdifference = (tabsrounded * tabs) - totalwidth;
	var firsttab;
        var first = true;


	
	// Update tabbar width
	document.getElementById('tabbar').style.width = parSize + 'px';
	
	if(countdifference>0){
		firsttab = tabsrounded-countdifference;
	}else if(countdifference<0){
		firsttab = tabsrounded + (countdifference * -1);
	}else{
		firsttab = tabsrounded;
	}

	// Loop through the tabs
	for(var i=1;i<=5;i+=1)
        {

          if(document.getElementById('tab'+i))
          {          
            if(document.getElementById('tab'+i).style.display != 'none')
            {
              if(first)
              {
                document.getElementById('tab'+i).style.width = firsttab + 'px';
                document.getElementById('tab'+i).className = 'firstSel';
                document.getElementById('tab'+i+'content').style.display = 'block';
                first = false;
              }
              else
              {
                document.getElementById('tab'+i).style.width = tabsrounded + 'px';
	      }
//                if (document.getElementById('tab'+i).className == 'firstSel')
//                    document.getElementById('tab'+i+'content').style.display = 'block';
            }
          }  
	}
}


/* Tabs
---------------------------------------------------------------- */

var tabs = function(){
	return {
		initialize:function(){
			var elm   = document.getElementById('ntabs');
		      if (elm != null)
                      {
			var front = document.getElementById('FrontpageContent');
			var items = elm.getElementsByTagName('a');
			var count = items.length;
			var fix = count;

			if(!front){if(count<4){fix=4;}}
			var _itm = elm.offsetWidth / fix;
			_itm = Math.floor(_itm);
			var _add = (fix - 1);
			var _all = fix * _itm;
			var _diff = elm.offsetWidth - _all;
			var _last = _itm + _diff;
			for(var t=0;t<count;t+=1){
				if(t==0){items[t].style.width = _last + 'px';}else{items[t].style.width = _itm + 'px';}
			}
                       }

		},
		click:function(f){
			var obj = document.getElementById(f.id + '_child');
			tabs.reset();
			f.className = 'selected';
			f.blur();
			if(obj){obj.style.display = 'block';}
		},
		reset:function(){
			var elm = document.getElementById('ntabs');
			var items = elm.getElementsByTagName('a');
			var count = items.length;
			for(var t=0;t<count;t+=1){
				items[t].className = '';
				var elm = document.getElementById(items[t].id + '_child');
				if(elm){elm.style.display = 'none';}
			}
		}
	};
}();


/* Window handler // eg. windows.load or myfunction (windows.load(alert('test')))
---------------------------------------------------------------- */

var windows = function(){
	return {
		load:function(functions){
			if(functions){
				if(window.addEventListener){
					window.addEventListener("load", functions, false);
				}else if(window.attachEvent){
					window.attachEvent("onload", functions);
				}else if(document.getElementById){
					window.onload = functions;
				}
			}
		}
	};
}();

// Add onload events
windows.load(tabs.initialize);
