//used in functions below
var oInfoMngr = new Object();
var oNameTrns = new Object();



var clipTop = 0;
var clipWidth = 215;
var clipBottom = 206;
var topper = 0;
var lyrheight = 0;
var lyrname = "scollerLinks";
var oScrollDiv, time, amount, theTime, theHeight;

var DHTML = (document.getElementById || document.all);

function scrollayer(layername,amt,tim)
{
	if (!DHTML) return;
	thelayer = new getObj(layername);
	if (!thelayer) return;
	amount = amt;
	theTime = tim;
	realscroll();
}

function stopScroll()
{
	if (time) clearTimeout(time);
}

function realscroll()
{
	if (!DHTML) return;
	clipTop += amount;
	clipBottom += amount;
	topper -= amount;
	if (clipTop < 0 || clipBottom > lyrheight)
	{
		clipTop -= amount;
		clipBottom -= amount;
		topper += amount;
		return;
	}
	if (document.getElementById || document.all)
	{
		clipstring = 'rect('+clipTop+'px,'+clipWidth+'px,'+clipBottom+'px,0)'
		thelayer.style.clip = clipstring;
		thelayer.style.top = topper + 'px';
	}
	time = setTimeout('realscroll()',theTime);
}

function vis(divname,val)
{
	if (!DHTML) return;
	var f = new getObj(divname);
	f.style.visibility = val;
}

function getObj(name)
{
	if (document.getElementById)
	{
		this.obj = document.getElementById(name);
	}
	else if (document.all)
	{
		this.obj = document.all[name];
	}
	if ( this.obj )
	{
		this.style = this.obj.style;
		if (lyrheight == 0 )
		{
			lyrheight = this.obj.offsetHeight;
		}
	}
}

function scrollTabDefault(tagname, questid)
{
	
	showTabHidePrev(tagname);
	
    showDivHidePrev("tabQ" + tagname, "tab");
    
    showInitialQuestion(tagname, questid);
    
    changeDYK(tagname);
    
    resetScroller();
	
	return false;
}

function resetScroller()
{
	clipTop = 0;
	clipWidth = 215;
	clipBottom = 206;
	topper = 0;
	lyrheight = 0;
	clipstring = 'rect('+clipTop+'px,'+clipWidth+'px,'+clipBottom+'px,0)'
	
	if (! oScrollDiv )
	{
		oScrollDiv = new getObj(lyrname);
	}
	oScrollDiv.style.clip = clipstring;
	oScrollDiv.style.top = topper + 'px';
}

function changeDYK(category)
{
  var dykCategory = oInfoMngr.dykTags[category];
  if (dykCategory)
  {
	  var rand_number = Math.floor(Math.random()*dykCategory.length);
	  showDivHidePrev(dykCategory[rand_number], "dyk");
  }
}


oNameTrns["hydration"] = "tabHydration";
oNameTrns["fitness"] = "tabFitness";
oNameTrns["wellbeing"] = "tabWellBeing";
oNameTrns["children"] = "tabChildren";
oNameTrns["beverages"] = "tabBeverages";
oNameTrns["sweeteners"] = "tabSweet";
oNameTrns["caffeine"] = "tabCaffeine";
oNameTrns["nutrients"] = "tabNutrients";

function showTabHidePrev(tagname)
{
	//trace("tagname " + tagname)
	displayTab = oNameTrns[tagname]  + "Experts";
	
	if ( displayTab )
	{
		prevKey = "disptabPrev";
		prevTab = oInfoMngr[prevKey];
		
		if ( prevTab )
		{
			setTabButtonOff(prevTab);
			swapImage(oNameTrns[tagname], oNameTrns[tagname] + 'Off');
		}
		
		setTabButtonOn(displayTab);
		oInfoMngr[prevKey] = displayTab;
	}	
}


function showQA(qaid)
{
	showDivHidePrev(qaid, "answer")
}

function showDivHidePrev(divid, divtype)
{
	prevKey = divtype + "Prev";
	prevObj = oInfoMngr[prevKey];
	if ( prevObj && prevObj.style )
	{
		prevObj.style.display = "none";
	}
	
	var oDiv = document.getElementById(divid);
	if ( oDiv && oDiv.style )
	{
		oDiv.style.display = "block";
		oInfoMngr[prevKey] = oDiv;
	}
}

function showInitialQuestion(tagname, qid)
{
	if ( ! qid )
	{
		var qaIdsForTag = oInfoMngr.qaTags[tagname];
		if ( qaIdsForTag )
		{
			qid = qaIdsForTag[0];
		}
	}
	showDivHidePrev(qid, "answer");
}
