//todo: clean up code create functions to replace duplicate/similar code

var giScreenVisibleX=0, giScreenVisibleY=0, giScreenScrollX=0, giScreenScrollY=0, giScreenVisibleXMax=0;

var giTimeOutStaff=null;
var giTimeOutMap=null;
var giTimeOutFAQ=null;
var giTimeOutNews=null;
var giTimeOutSpecial=null;
var giTimeOutInfo=null;
var giTimeOutEvents=null;
var giTimeOutProc=null;
var giTimeOutTrans=null;
var giTimeOutNutri=null;
var giTimeOutResearch=null;
var anim01Timeout=null;

var giTimeout=null;
var giLastScreenX=-1;
var giLastScreenY=-1;
var giFirstLoadMap=true;
var giCurrentMap=1;
var giCalLock=new Array(true,false,false,false);
var GI_MAX_DATES=1000;
var giDateType=new Array(GI_MAX_DATES);
var giDateHandle=new Array(GI_MAX_DATES);
var giDateMonth=new Array(GI_MAX_DATES);
var giDateDay=new Array(GI_MAX_DATES);
var giDateDay2=new Array(GI_MAX_DATES);
var giDateYear=new Array(GI_MAX_DATES);
var giDateIndex=0;

var GI_MAX_SUBCAT=300;
var GI_MAX_CAT=10;
var giItemSubCat=new Array(GI_MAX_CAT*GI_MAX_SUBCAT);
var giItemName=new Array(GI_MAX_CAT*GI_MAX_SUBCAT);
var giItemLink=new Array(GI_MAX_CAT*GI_MAX_SUBCAT);
var giItemIndex=new Array(GI_MAX_CAT);

for (var zzz=0;zzz<GI_MAX_CAT;zzz++) {
	giItemIndex[zzz]=0;
}

var giCurrentMonths=0;
var giDefaultText='';
var giFirstLoadVar=true;

var c1=null;
var c2=null;
var c3=null;
var c6=null;
var c7=null;
var c8=null;
var c9=null;
var c10=null;
var c10b=null;
var c11=null;
var c12=null;
var c13=null;
var c14=null;
var c50=null;
var c51=null;
var c52=null;
var c53=null;
var c54=null;
var c55=null;
var c56=null;
var c57=null;
var c58=null;
var c59=null;
var c60=null;
var c61=null;

var dd50=0;
var xx50=0;
var dd51=0;
var xx51=0;
var dd52=0;
var xx52=0;
var dd53=0;
var xx53=0;
var dd54=0;
var xx54=0;
var dd55=0;
var xx55=0;
var tt1=0;
var tt2=0;
var tt3=0;
var tt4=0;
var tt5=0;
var tt6=0;

var calcount=0;
var calcount2=0;
var calView=1;
var calYear=0;
var calMonth=0;

var anim01x=0;

function anim01() {
	document.getElementById('eventsmessageinner').style.left=anim01x+'px';
	var aa=document.getElementById('eventsmessageinner').offsetWidth;
	//giScreenVisibleXMax
	anim01x-=3;
	if (anim01x<=aa * -1)
		anim01x=giScreenVisibleXMax;
	anim01Timeout=setTimeout('anim01()',50);
}

function giUpdateCalInfo(a) {
	document.getElementById('gicalinfo').innerHTML=document.getElementById('gicalmark'+a).innerHTML+'<br /><br /><i>For a plain text list of all events and updates <a href="?a=Events&amp;b=Events Plain">click here</a>.</i>';
}

function giAddDateB(a,m,d,y,divid) {
	giAddDateC(a,m,d,d,y,divid);
}

function giAddItem(a,b,c,d) {
	giItemSubCat[a*GI_MAX_SUBCAT+giItemIndex[a]]=b;
	giItemName[a*GI_MAX_SUBCAT+giItemIndex[a]]=c;
	giItemLink[a*GI_MAX_SUBCAT+giItemIndex[a]]=d;
	giItemIndex[a]++;
}

function giAddItemB(a,b,d,c) {
	giAddItem(a,b,c,d);
}

function giDisplayItems(a,b) {
var s='';

	for (var aa=0; aa < giItemIndex[a]; aa++) {
		if (b==1 || giItemSubCat[a*GI_MAX_SUBCAT+aa]==b) {			
			s+='<a href="'+giItemLink[a*GI_MAX_SUBCAT+aa]+'">'+giItemName[a*GI_MAX_SUBCAT+aa]+'</a><br />';
		}
	}
	
	return s;
}

function giSearchItems(a,t) {
var s='', temp='';

	for (var aa=0; aa < giItemIndex[a]; aa++) {
		temp=giItemName[a*GI_MAX_SUBCAT+aa].substring(0,t.length).toUpperCase();
		if (temp==t.toUpperCase() || (giItemName[a*GI_MAX_SUBCAT+aa].toUpperCase().indexOf(' '+t.toUpperCase())>=0) || (giItemName[a*GI_MAX_SUBCAT+aa].toUpperCase().indexOf('('+t.toUpperCase())>=0) ) {			
			s+='<a href="'+giItemLink[a*GI_MAX_SUBCAT+aa]+'">'+giItemName[a*GI_MAX_SUBCAT+aa]+'</a><br />';
		}
	}
	
	document.getElementById('gisub'+a).innerHTML=s;
}

function giAddDateC(a,m,d,d2,y,divid) {
	giDateType[giDateIndex]=a;
	giDateMonth[giDateIndex]=m;
	giDateDay[giDateIndex]=d;
	giDateDay2[giDateIndex]=d2;
	giDateYear[giDateIndex]=y;
	giDateHandle[giDateIndex]=divid;
	giDateIndex++;
}

function setMonthYear(a,b) {
	calMonth=a;
	calYear=b;
}

function selectView(a) {
	if (a==1) {
		document.getElementById('view1').style.color='#417eaa';
		document.getElementById('view2').style.color='#b5b2b5';
		document.getElementById('view3').style.color='#b5b2b5';
		calView=1;
	} else if (a==2) {
		document.getElementById('view1').style.color='#b5b2b5';
		document.getElementById('view2').style.color='#a4aa41';
		document.getElementById('view3').style.color='#b5b2b5';
		calView=2;
	} else if (a==3) {
		document.getElementById('view1').style.color='#b5b2b5';
		document.getElementById('view2').style.color='#b5b2b5';
		document.getElementById('view3').style.color='#aa4141';
		calView=3;
	}
	
	document.getElementById('gicalbase').innerHTML=generateMonths((calYear-2009)*12+calMonth);
	document.getElementById('gicalbase2').innerHTML=generateMonths((calYear-2009)*12+calMonth+1);
	
	return false;
}

function selectCat(a,i) {
	for (b=1; b <= 100;b++) {
		if (document.getElementById('cat'+a+'x'+b)) {		
			if (i==b)
				document.getElementById('cat'+a+'x'+b).style.color='#417eaa';
			else
				document.getElementById('cat'+a+'x'+b).style.color='#b5b2b5';
		} else {
			break;
		}
	}
	
	document.getElementById('gisearch'+a).value='';
	document.getElementById('gisub'+a).innerHTML=giDisplayItems(a,i);
	
	return false;
}

function selectCatB(a,i) {
	for (b=1; b <= 100;b++) {
		if (document.getElementById('cat'+a+'x'+b)) {		
			if (i==b)
				document.getElementById('cat'+a+'x'+b).style.color='#417eaa';
			else
				document.getElementById('cat'+a+'x'+b).style.color='#b5b2b5';
		} else {
			break;
		}
	}
}

function selectYear(a) {
	
	for (b=2009; b <= 2012;b++) {
		if (a==b)
			document.getElementById('year'+b).style.color='#417eaa';
		else
			document.getElementById('year'+b).style.color='#b5b2b5';
	}
	
	calYear=a;
	
	document.getElementById('gicalbase').innerHTML=generateMonths((calYear-2009)*12+calMonth);
	document.getElementById('gicalbase2').innerHTML=generateMonths((calYear-2009)*12+calMonth+1);
	document.getElementById('gicalmonths').innerHTML=generateMonthsTitle();
	
	return false;
}

function selectMonth(a) {
	
	for (b=1; b <= 11;b+=2) {
		if (a==b)
			document.getElementById('month'+b).style.color='#417eaa';
		else
			document.getElementById('month'+b).style.color='#b5b2b5';
	}
	
	calMonth=a;

	document.getElementById('gicalbase').innerHTML=generateMonths((calYear-2009)*12+calMonth);
	document.getElementById('gicalbase2').innerHTML=generateMonths((calYear-2009)*12+calMonth+1);
	
	return false;
}

function countEvents(m,y) {
var cc=0;
	for (var aa=0; aa < giDateIndex; aa++) {
		if (giDateYear[aa]==y && giDateMonth[aa]==m) {
			cc++;
		}
	}
	
	return cc;
}

function generateMonthsTitle() {
var s1='', s3='', s5='', s7='', s9='', s11='';

	if (calMonth==1)
		s1=' style="color:#417eaa;"';
	else if (calMonth==3)
		s3=' style="color:#417eaa;"';	
	else if (calMonth==5)
		s5=' style="color:#417eaa;"';	
	else if (calMonth==7)
		s7=' style="color:#417eaa;"';	
	else if (calMonth==9)
		s9=' style="color:#417eaa;"';	
	else if (calMonth==11)
		s11=' style="color:#417eaa;"';	

	return '<b>Select Months:</b> <span id="month1" onmousedown="return selectMonth(1);"'+s1+'>Jan-Feb (<b>'+(countEvents(1,calYear)+countEvents(2,calYear))+'</b>)</span>, <span id="month3" onmousedown="return selectMonth(3);"'+s3+'>Mar-Apr (<b>'+(countEvents(3,calYear)+countEvents(4,calYear))+'</b>)</span>, <span id="month5" onmousedown="return selectMonth(5);"'+s5+'>May-Jun (<b>'+(countEvents(5,calYear)+countEvents(6,calYear))+'</b>)</span>, <span id="month7" onmousedown="return selectMonth(7);"'+s7+'>Jul-Aug (<b>'+(countEvents(7,calYear)+countEvents(8,calYear))+'</b>)</span>, <span id="month9" onmousedown="return selectMonth(9);"'+s9+'>Sep-Oct (<b>'+(countEvents(9,calYear)+countEvents(10,calYear))+'</b>)</span>, <span id="month11" onmousedown="return selectMonth(11);"'+s11+'>Nov-Dec (<b>'+(countEvents(11,calYear)+countEvents(12,calYear))+'</b>)</span>';
}

function generateMonths(a) {
var s='', d=32, d2=1, m=31, sAll='', b=Math.floor((a-1)/12);
	
	switch((a-1) % 12) {
	case 0:
		s='January';
		break;
	case 1:
		s='February';
		break;
	case 2:
		s='March';
		break;
	case 3:
		s='April';
		break;
	case 4:
		s='May';
		break;
	case 5:
		s='June';
		break;
	case 6:
		s='July';
		break;
	case 7:
		s='August';
		break;
	case 8:
		s='September';
		break;
	case 9:
		s='October';
		break;
	case 10:
		s='November';
		break;
	case 11:
		s='December';
		break;
	}
	
	switch (a) {
	case 1: d=5; m=31; break;
	case 2: d=1; m=28; break;
	case 3: d=1; m=31; break;
	case 4: d=4; m=30; break;
	case 5: d=6; m=31; break;
	case 6: d=2; m=30; break;
	case 7: d=4; m=31; break;
	case 8: d=7; m=31; break;
	case 9: d=3; m=30; break;
	case 10: d=5; m=31; break;
	case 11: d=1; m=30; break;
	case 12: d=3; m=31; break;
		
	case 13: d=6; m=31; break;
	case 14: d=2; m=28; break;
	case 15: d=2; m=31; break;
	case 16: d=5; m=30; break;
	case 17: d=7; m=31; break;
	case 18: d=3; m=30; break;
	case 19: d=5; m=31; break;
	case 20: d=1; m=31; break;
	case 21: d=4; m=30; break;
	case 22: d=6; m=31; break;
	case 23: d=2; m=30; break;
	case 24: d=4; m=31; break;
	case 25: d=7; m=31; break;
	case 26: d=3; m=28; break;
	case 27: d=3; m=31; break;
	case 28: d=6; m=30; break;
	case 29: d=1; m=31; break;
	case 30: d=4; m=30; break;
	case 31: d=6; m=31; break;
	case 32: d=2; m=31; break;
	case 33: d=5; m=30; break;
	case 34: d=7; m=31; break;
	case 35: d=3; m=30; break;
	case 36: d=5; m=31; break;
	case 37: d=1; m=31; break;
	case 38: d=4; m=29; break;
	case 39: d=5; m=31; break;
	case 40: d=1; m=30; break;
	case 41: d=3; m=31; break;
	case 42: d=6; m=30; break;
	case 43: d=1; m=31; break;
	case 44: d=4; m=31; break;
	case 45: d=7; m=30; break;
	case 46: d=2; m=31; break;
	case 47: d=5; m=30; break;
	case 48: d=7; m=31; break;
	}
	
	sAll='<div style="width:210px;height:160px;background-color:#b5b2b5;"><table style="width:210px;height:160px;border:1px solid #000000;" cellpadding="0" cellspacing="1"><tr style="height:20px;"><td colspan="7" align="center" valign="center" style="font-size:12px;background-color:#417eaa;color:#ffffff"><b>' + s + ', ' + (2009+b) + '</b></td></tr>';
	sAll+='<tr><td class="cday1" align="center" valign="center">Su</td><td class="cday1" align="center" valign="center">M</td><td class="cday1" align="center" valign="center">Tu</td><td class="cday1" align="center" valign="center">W</td><td class="cday1" align="center" valign="center">Th</td><td class="cday1" align="center" valign="center">F</td><td class="cday1" align="center" valign="center">Sa</td></tr>';
	
	calcount=0;
	calcount2=1;
	
	sAll+='<tr>'+generateDays(d,m,a)+'</tr>';
	sAll+='<tr>'+generateDays(d,m,a)+'</tr>';
	sAll+='<tr>'+generateDays(d,m,a)+'</tr>';
	sAll+='<tr>'+generateDays(d,m,a)+'</tr>';
	sAll+='<tr>'+generateDays(d,m,a)+'</tr>';
	sAll+='<tr>'+generateDays(d,m,a)+'</tr>';
	
	sAll+='</table></div>';
	
	return sAll;
}

function validateDay(d,m,y) {
	for (aa=0; aa < giDateIndex; aa++) {
		if (giDateYear[aa]==y && giDateMonth[aa]==m) {
			if (d >= giDateDay[aa] && d <= giDateDay2[aa]) {
				if (giDateType[aa]==1 && (calView==1 || calView==2))
					return '<td class="cday4" align="center" valign="center" onclick="giUpdateCalInfo('+giDateHandle[aa]+');">'+d+'</td>';
				else if (giDateType[aa]==2 && (calView==1 || calView==3))
					return '<td class="cday5" align="center" valign="center" onclick="giUpdateCalInfo('+giDateHandle[aa]+');">'+d+'</td>';
				else if (giDateType[aa]==3)
					return '<td class="cday6" align="center" valign="center" onclick="giUpdateCalInfo('+giDateHandle[aa]+');">'+d+'</td>';
			}
		}
	}
	
	return '<td class="cday2" align="center" valign="center">'+d+'</td>';
}

function generateDays(d,m,curM) {
	var s2='', c=0;
	d=d-1;
	
	for (c=0; c < 7;c++) {
		if (calcount < d || calcount2 > m) {
			s2+='<td class="cday3" align="center" valign="center">&nbsp;</td>';
		} else {
			s2+=validateDay(calcount2,((curM-1) % 12)+1,calYear);
			calcount2++;
		}
		calcount++;
	}
	
	return '<tr>'+s2+'</tr>';
}

function giShowMonths(a) {
	var m1=document.getElementById('gicalmonth1');
	var m2=document.getElementById('gicalmonth2');
	var m3=document.getElementById('gicalmonth3');
	
	if (a==0) {
		m1.style.backgroundPosition='0px 0px';
		m2.style.backgroundPosition='-113px 0px';
		m3.style.backgroundPosition='-226px 0px';
	} else if (a==1) {
		m1.style.backgroundPosition='-339px 0px';
		m2.style.backgroundPosition='-452px 0px';
		m3.style.backgroundPosition='-565px 0px';
	} else if (a==2) {
		m1.style.backgroundPosition='-678px 0px';
		m2.style.backgroundPosition='-791px 0px';
		m3.style.backgroundPosition='-904px 0px';
	} else if (a==3) {
		m1.style.backgroundPosition='-1017px 0px';
		m2.style.backgroundPosition='-1130px 0px';
		m3.style.backgroundPosition='-1243px 0px';
	}
	
	giCurrentMonths=a;
}

/*function f12(a,b,c,d) {
	var e=0;
	if (!giCalLock[d]) {
		giCalLock[d]=true;
		for (e=0;e<4;e++) {
			if (e!=d) {
				giCalLock[e]=false;
				document.getElementById('gicalcat'+(e+1)).onmouseout();
			}
		}
		a.style.backgroundPosition=(b*-1)+'px '+(c*-1)+'px';
		giShowMonths(d);
		giShowMarks();
	}
}*/

function giPrintPage(a,b) {
	if ((a.length > 0 || b.length > 0) && giFirstLoadMap)
		window.open ('print.php?a='+a+'&b='+b, 'giprintwin','scrollbars=1,location=0,toolbar=0,status=0,menubar=0,resizable=1,width=800,height=500');
	else
		alert('Sorry, you can not print this page using this button.');
}

function f00(a,b) {
	a.style.backgroundPosition='0px '+(b*-1)+'px';
}

function f04(a,b,c) {
	a.style.backgroundPosition=(b*-1)+'px '+(c*-1)+'px';
}

function f11(a,b,c,d) {
	if (!giCalLock[d])
		a.style.backgroundPosition=(b*-1)+'px '+(c*-1)+'px';
}

function f01(a,b) {
	if (a==1)
		s='gibutton'+b;
	else if (a==2)
		s='gidivide'+b;
	
	return document.getElementById(s);
}

function f02(a,b) {
	var s=IITSS_DEFAULT_TEXT;
	if (a.value==s) {
		a.value='';
	} else if (a.value.length==0 && b==1) {
		a.value=s;
	}
}

function f03(a) {
	document.getElementById('gistaffinfo').innerHTML=a;
}

function f05(a) {
	document.getElementById('gimapinfo').innerHTML=a;
}

function f06() {
	f08();
	document.getElementById('gimapinner').style.visibility='hidden';
	document.getElementById('gimapinner2').style.visibility='hidden';
	document.getElementById('gimapouter').style.visibility='hidden';
	giFirstLoadMap=true;
}

function f07() {
	document.getElementById('gimapinner').src='http://maps.google.ca/maps?f=q&hl=en&geocode=&q=2100+Clinch+Avenue,+Suite+510+Knoxville,+TN+37916&sll=35.954995,-83.938143&sspn=0.011846,0.018711&layer=c&ie=UTF8&cbll=35.95621,-83.93864&panoid=0Le6eYaeLryJHnUGY1Ob_w&s=AARTsJrzfoGKxnwdkNkbIoVv8qB9LkqNgg&ll=35.966614,-83.934431&spn=0.033345,0.054932&z=14&iwloc=addr&output=embed';
	document.getElementById('gimapinner2').src='http://maps.google.ca/maps?f=q&hl=en&geocode=&q=146+West+Park+Drive,+Suite+9D+Kingsport,+TN+37660&sll=35.959476,-83.938315&sspn=0.011845,0.018711&layer=c&ie=UTF8&s=AARTsJrhVZsuLv9cM4j3YifBmQZOY1wGNw&ll=36.562049,-82.547922&spn=0.033091,0.054932&z=14&iwloc=addr&output=embed';
}

function f08() {
	document.getElementById('gimapinner').src='about:blank';
	document.getElementById('gimapinner2').src='about:blank';
}

function f09(a,b,c) {
	a.style.backgroundColor='#'+b;
	a.style.color='#'+c;
}

function f10(a) {
	window.open ('images/maintheme/'+a, 'giimagewin','scrollbars=1,location=0,toolbar=0,status=0,menubar=0,resizable=1,width=930,height=700');
}

function f13(a) {
	if (giDefaultText.length==0)
		giDefaultText=document.getElementById('gicalinfo').innerHTML;
	
	document.getElementById('gicalinfo').innerHTML=a;
}

function f14() {
	if (giDefaultText.length!=0)
		document.getElementById('gicalinfo').innerHTML=giDefaultText;
}

function f15(s) {
	if (s.length==0)
		//document.getElementById('gistaffnames').innerHTML="<b><a href=\"images/maintheme/fp006.jpg\" target=\"_blank\">View larger image</a></b>";
		document.getElementById('gistaffnames').innerHTML="<b>&nbsp;</b>";
	else
		document.getElementById('gistaffnames').innerHTML="<b>"+s+"</b>";
}

function giSwithMap() {
	if (giCurrentMap==1)
		giCurrentMap=2;
	else if (giCurrentMap==2)
		giCurrentMap=1;
	
	giLoadMap(giCurrentMap);
}

function giLoadMap(a) {
	if (giFirstLoadMap) {
		f07();
		giFirstLoadMap=false;
	}
	
	if (a==1 || a==2) {
		document.getElementById('gimapouter').style.visibility='visible';
		giCurrentMap=a;
	}
	
	if (a==1) {
		document.getElementById('gimapinner').style.visibility='visible';
		document.getElementById('gimapinner2').style.visibility='hidden';
	} else if (a==2) {
		document.getElementById('gimapinner').style.visibility='hidden';
		document.getElementById('gimapinner2').style.visibility='visible';
	}
}

function giClearTimeoutResearch() {
	if (giTimeOutResearch!=null) {
			window.clearTimeout(giTimeOutResearch);
			giTimeOutResearch=null;
	}
}

function giShowResearch() {
	f00(document.getElementById('gibutton7'),30);
	giClearTimeoutResearch();
	giTimeOutResearch=window.setTimeout('giShowResearchTimer()', 250);
}

function giShowResearchTimer() {
	document.getElementById('giresearchpopup').style.visibility='visible';
	giTimeOutResearch=null;
}

function giHideResearch() {
	f00(document.getElementById('gibutton7'),0);
	giClearTimeoutResearch();
	giTimeOutResearch=window.setTimeout('giHideResearchTimer()', 250);
}

function giHideResearchTimer() {
	document.getElementById('giresearchpopup').style.visibility='hidden';
	giTimeOutResearch=null;
}

function giClearTimeoutNutri() {
	if (giTimeOutNutri!=null) {
			window.clearTimeout(giTimeOutNutri);
			giTimeOutNutri=null;
	}
}

function giShowNutri() {
	f00(document.getElementById('gibutton5'),30);
	giClearTimeoutNutri();
	giTimeOutNutri=window.setTimeout('giShowNutriTimer()', 250);
}

function giShowNutriTimer() {
	document.getElementById('ginutripopup').style.visibility='visible';
	giTimeOutNutri=null;
}

function giHideNutri() {
	f00(document.getElementById('gibutton5'),0);
	giClearTimeoutNutri();
	giTimeOutNutri=window.setTimeout('giHideNutriTimer()', 250);
}

function giHideNutriTimer() {
	document.getElementById('ginutripopup').style.visibility='hidden';
	giTimeOutNutri=null;
}

function giClearTimeoutTrans() {
	if (giTimeOutTrans!=null) {
			window.clearTimeout(giTimeOutTrans);
			giTimeOutTrans=null;
	}
}

function giShowTrans() {
	f00(document.getElementById('gibutton4'),30);
	giClearTimeoutTrans();
	giTimeOutTrans=window.setTimeout('giShowTransTimer()', 250);
}

function giShowTransTimer() {
	document.getElementById('gitranspopup').style.visibility='visible';
	giTimeOutTrans=null;
}

function giHideTrans() {
	f00(document.getElementById('gibutton4'),0);
	giClearTimeoutTrans();
	giTimeOutTrans=window.setTimeout('giHideTransTimer()', 250);
}

function giHideTransTimer() {
	document.getElementById('gitranspopup').style.visibility='hidden';
	giTimeOutTrans=null;
}

function giClearTimeoutProc() {
	if (giTimeOutProc!=null) {
			window.clearTimeout(giTimeOutProc);
			giTimeOutProc=null;
	}
}

function giShowProc() {
	f00(document.getElementById('gibutton3'),30);
	giClearTimeoutProc();
	giTimeOutProc=window.setTimeout('giShowProcTimer()', 250);
}

function giShowProcTimer() {
	document.getElementById('giprocpopup').style.visibility='visible';
	giTimeOutProc=null;
}

function giHideProc() {
	f00(document.getElementById('gibutton3'),0);
	giClearTimeoutProc();
	giTimeOutProc=window.setTimeout('giHideProcTimer()', 250);
}

function giHideProcTimer() {
	document.getElementById('giprocpopup').style.visibility='hidden';
	giTimeOutProc=null;
}

function giClearTimeoutEvents() {
	if (giTimeOutEvents!=null) {
			window.clearTimeout(giTimeOutEvents);
			giTimeOutEvents=null;
	}
}

function giShowEvents() {
	f00(document.getElementById('gibutton2'),30);
	giClearTimeoutEvents();
	giTimeOutEvents=window.setTimeout('giShowEventsTimer()', 250);
}

function giShowEventsTimer() {
	document.getElementById('gieventspopup').style.visibility='visible';
	//giShowMarks();
	giTimeOutEvents=null;
}

function giHideEvents() {
	f00(document.getElementById('gibutton2'),0);
	giClearTimeoutEvents();
	giTimeOutEvents=window.setTimeout('giHideEventsTimer()', 250);
}

function giHideEventsTimer() {
	//giHideMarks();
	document.getElementById('gieventspopup').style.visibility='hidden';
	giTimeOutEvents=null;
}

function giClearTimeoutInfo() {
	if (giTimeOutInfo!=null) {
			window.clearTimeout(giTimeOutInfo);
			giTimeOutInfo=null;
	}
}

function giShowInfo() {
	f00(document.getElementById('gibutton6'),30);
	giClearTimeoutInfo();
	giTimeOutInfo=window.setTimeout('giShowInfoTimer()', 250);
}

function giShowInfoTimer() {
	document.getElementById('giinfopopup').style.visibility='visible';
	giTimeOutInfo=null;
}

function giHideInfo() {
	f00(document.getElementById('gibutton6'),0);
	giClearTimeoutInfo();
	giTimeOutInfo=window.setTimeout('giHideInfoTimer()', 250);
}

function giHideInfoTimer() {
	document.getElementById('giinfopopup').style.visibility='hidden';
	giTimeOutInfo=null;
}

function giClearTimeoutSpecial() {
	if (giTimeOutSpecial!=null) {
			window.clearTimeout(giTimeOutSpecial);
			giTimeOutSpecial=null;
	}
}

function giShowSpecial() {
	f00(document.getElementById('gispecialbutton'),24);
	giClearTimeoutSpecial();
	giTimeOutSpecial=window.setTimeout('giShowSpecialTimer()', 250);
}

function giShowSpecialTimer() {
	document.getElementById('gispecialpopup').style.visibility='visible';
	giTimeOutSpecial=null;
}

function giHideSpecial() {
	f00(document.getElementById('gispecialbutton'),0);
	giClearTimeoutSpecial();
	giTimeOutSpecial=window.setTimeout('giHideSpecialTimer()', 250);
}

function giHideSpecialTimer() {
	document.getElementById('gispecialpopup').style.visibility='hidden';
	giTimeOutSpecial=null;
}

function giClearTimeoutNews() {
	if (giTimeOutNews!=null) {
			window.clearTimeout(giTimeOutNews);
			giTimeOutNews=null;
	}
}

function giShowNews() {
	f00(document.getElementById('ginewsbutton'),24);
	giClearTimeoutNews();
	giTimeOutNews=window.setTimeout('giShowNewsTimer()', 250);
}

function giShowNewsTimer() {
	document.getElementById('ginewspopup').style.visibility='visible';
	giTimeOutNews=null;
}

function giHideNews() {
	f00(document.getElementById('ginewsbutton'),0);
	giClearTimeoutNews();
	giTimeOutNews=window.setTimeout('giHideNewsTimer()', 250);
}

function giHideNewsTimer() {
	document.getElementById('ginewspopup').style.visibility='hidden';
	giTimeOutNews=null;
}

function giClearTimeoutFAQ() {
	if (giTimeOutFAQ!=null) {
			window.clearTimeout(giTimeOutFAQ);
			giTimeOutFAQ=null;
	}
}

function giShowFAQ() {
	f00(document.getElementById('gifaqbutton'),24);
	giClearTimeoutFAQ();
	giTimeOutFAQ=window.setTimeout('giShowFAQTimer()', 250);
}

function giShowFAQTimer() {
	document.getElementById('gifaqpopup').style.visibility='visible';
	giTimeOutFAQ=null;
}

function giHideFAQ() {
	f00(document.getElementById('gifaqbutton'),0);
	giClearTimeoutFAQ();
	giTimeOutFAQ=window.setTimeout('giHideFAQTimer()', 250);
}

function giHideFAQTimer() {
	document.getElementById('gifaqpopup').style.visibility='hidden';
	giTimeOutFAQ=null;
}

function giClearTimeoutStaff() {
	if (giTimeOutStaff!=null) {
			window.clearTimeout(giTimeOutStaff);
			giTimeOutStaff=null;
	}
}

function giShowStaff() {
	f00(document.getElementById('gistaffbutton'),24);
	giClearTimeoutStaff();
	giTimeOutStaff=window.setTimeout('giShowStaffTimer()', 250);
}

function giShowStaffTimer() {
	document.getElementById('gistaffpopup').style.visibility='visible';
	giTimeOutStaff=null;
}

function giHideStaff() {
	f00(document.getElementById('gistaffbutton'),0);
	giClearTimeoutStaff();
	giTimeOutStaff=window.setTimeout('giHideStaffTimer()', 250);
}

function giHideStaffTimer() {
	document.getElementById('gistaffpopup').style.visibility='hidden';
	giTimeOutStaff=null;
}

function giClearTimeoutMap() {
	if (giTimeOutMap!=null) {
			window.clearTimeout(giTimeOutMap);
			giTimeOutMap=null;
	}
}

function giShowMap() {
	f00(document.getElementById('gimapbutton'),24);
	giClearTimeoutMap();
	giTimeOutMap=window.setTimeout('giShowMapTimer()', 250);
}

function giShowMapTimer() {
	document.getElementById('gimappopup').style.visibility='visible';
	giTimeOutMap=null;
}

function giHideMap() {
	f00(document.getElementById('gimapbutton'),0);
	giClearTimeoutMap();
	giTimeOutMap=window.setTimeout('giHideMapTimer()', 250);
}

function giHideMapTimer() {
	document.getElementById('gimappopup').style.visibility='hidden';
	giTimeOutMap=null;
}



function giGetScreen() {
	if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
    giScreenVisibleX=document.documentElement.clientWidth;
    giScreenVisibleY=document.documentElement.clientHeight;
  } else if(document.body && (document.body.clientWidth || document.body.clientHeight)) {
    giScreenVisibleX=document.body.clientWidth;
    giScreenVisibleY=document.body.clientHeight;
  }

	if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
    giScreenScrollX=document.body.scrollLeft;
    giScreenScrollY=document.body.scrollTop;
	} else {
		giScreenScrollX=document.documentElement.scrollLeft;
		giScreenScrollY=document.documentElement.scrollTop;
	}
	
	giScreenVisibleXMax=giScreenVisibleX;
	
	if (document.getElementById('giallcontent').clientWidth) {
		giScreenVisibleX=document.getElementById('giallcontent').clientWidth;
	}
}

function giCenter(a,b) {
var c=document.getElementById(a);
var aa=c.offsetTop;
var bb=c.offsetHeight;

	if (aa != 0+(giScreenVisibleY - bb-b)) {
		c.style.top=(0+(giScreenVisibleY - bb-b))+'px';
	}
}

function preLoadVars() {
	c1=document.getElementById('gibottombar');
	c2=document.getElementById('gisearchpopup');
	c3=document.getElementById('giallcontent');
	c6=document.getElementById('gimapouter');
	c7=document.getElementById('gimapinner');
	c8=document.getElementById('gimapinner2');
	c9=document.getElementById('gimapbutton1');
	c10=document.getElementById('gimapbutton2');
	c10b=document.getElementById('gimapbutton3');
	c11=document.getElementById('gimapinfo');
	c12=document.getElementById('gibuttonbar');
	c13=document.getElementById('gimaincontent');
	c14=document.getElementById('giheader');
	
	c50=document.getElementById('giinfopopup');
	c51=document.getElementById('gieventspopup');
	c52=document.getElementById('giprocpopup');
	c53=document.getElementById('gitranspopup');
	c54=document.getElementById('ginutripopup');
	c55=document.getElementById('giresearchpopup');
	
	c56=document.getElementById('gibutton6');
	c57=document.getElementById('gibutton2');
	c58=document.getElementById('gibutton3');
	c59=document.getElementById('gibutton4');
	c60=document.getElementById('gibutton5');
	c61=document.getElementById('gibutton7');
}

function giSetVars() {
	dd50=c50.offsetWidth;
	xx50=c50.offsetLeft;
	dd51=c51.offsetWidth;
	xx51=c51.offsetLeft;
	dd52=c52.offsetWidth;
	xx52=c52.offsetLeft;
	dd53=c53.offsetWidth;
	xx53=c53.offsetLeft;
	dd54=c54.offsetWidth;
	xx54=c54.offsetLeft;
	dd55=c55.offsetWidth;
	xx55=c55.offsetLeft;
	tt1=c56.offsetLeft;
	tt2=c57.offsetLeft;
	tt3=c58.offsetLeft;
	tt4=c59.offsetLeft;
	tt5=c60.offsetLeft;
	tt6=c61.offsetLeft;
}

function giOnScroll() {
	var debugcount=0;
	
	if (giFirstLoadVar) {
		preLoadVars();	
		giFirstLoadVar=false;
	}

	var aa=c1.offsetTop;
	var bb=c1.offsetHeight;
	var dd=c1.offsetWidth;
	var aa2=c2.offsetTop;
	var bb2=c2.offsetHeight;
	var bb3=c3.offsetHeight;
	var aa6=c6.offsetTop;
	var bb6=c6.offsetHeight;
	var dd6=c6.offsetWidth;
	var bb12=c12.offsetHeight;
	var dd12=c12.offsetWidth;
	var dd13=c13.offsetWidth;
	var dd14=c14.offsetWidth;
	
	giSetVars();
	
	//0==giScreenScrollY
	
	giCenter('gistaffpopup',bb);
	giCenter('gimappopup',bb);
	giCenter('gifaqpopup',bb);
	giCenter('ginewspopup',bb);
	giCenter('gispecialpopup',bb);
	
	if (aa != 0+(giScreenVisibleY - bb)) {
		c1.style.top=(0+(giScreenVisibleY - bb))+'px';
		debugcount++;
	}

	if (aa2 != 0+(giScreenVisibleY - (bb+bb2))) {
		c2.style.top=(0+(giScreenVisibleY - (bb+bb2)))+'px';
		debugcount++;
	}
	
	if (bb3 != (giScreenVisibleY-bb-bb12)) {
		c3.style.height=(giScreenVisibleY-bb-bb12)+'px';
		debugcount++;
	}

	if (bb6 != (giScreenVisibleY-bb-20)) {
		c6.style.height=(giScreenVisibleY-bb-22)+'px';
		c7.style.height=(giScreenVisibleY-bb-65)+'px';
		c8.style.height=(giScreenVisibleY-bb-65)+'px';
		c9.style.top=(giScreenVisibleY-bb-52)+'px';
		c10.style.top=(giScreenVisibleY-bb-52)+'px';
		c10b.style.top=(giScreenVisibleY-bb-52)+'px';
		c11.style.top=(giScreenVisibleY-bb-52)+'px';
		debugcount++;
	}
	
			/*if ((dd < 770) || dd != (giScreenVisibleX)) {
				if ((giScreenVisibleX) >= 770) {
					c1.style.width='100%';
				} else {
					c1.style.width='770px';
				}
			}*/

	if (dd6 != (giScreenVisibleX-20)) {
		c6.style.width=(giScreenVisibleX-22)+'px';
		c7.style.width=(giScreenVisibleX-44)+'px';
		c8.style.width=(giScreenVisibleX-44)+'px';
		c11.style.width=(giScreenVisibleX-122)+'px';
		debugcount++;
	}
	
	if ((dd12 < 750) || dd12 != (giScreenVisibleXMax-0)) {
		if ((giScreenVisibleXMax-0) >= 750) {			
			c12.style.width=(giScreenVisibleXMax-0)+'px';
		} else {
			c12.style.width='750px';
		}
		debugcount++;
	}
	
	if ((dd13 < 730) || dd13 != (giScreenVisibleX-0)) {
		if ((giScreenVisibleX-20) >= 730) {			
			c13.style.width=(giScreenVisibleX-20)+'px';
		} else {
			c13.style.width='730px';
		}
		debugcount++;
	}
	
	if ((dd14 < 750) || dd14 != (giScreenVisibleX-0)) {		
		if ((giScreenVisibleX-0) >= 750) {
			c14.style.width=(giScreenVisibleX-0)+'px';
		} else {
			c14.style.width='750px';
		}
		debugcount++;
	}
	
	if ((tt1+dd50) >= giScreenVisibleX) {
		c50.style.left=(giScreenVisibleX-dd50)+'px';
		debugcount++;
	} else if (xx50!=(tt1-1)) {
		c50.style.left=(tt1-1)+'px';
		debugcount++;
	}

	if ((tt2+dd51) >= giScreenVisibleX) {
		c51.style.left=(giScreenVisibleX-dd51)+'px';
		debugcount++;
	} else if (xx51!=(tt2-1)) {
		c51.style.left=(tt2-1)+'px';
		debugcount++;
	}
	
	/*if ((tt3+dd52) >= giScreenVisibleX) {
		c52.style.left=(giScreenVisibleX-dd52)+'px';
		debugcount++;
	} else*/ if (xx52!=(tt3-1)) {
		c52.style.left=(tt3-1)+'px';
		debugcount++;
	}

	if ((tt4+dd53) >= giScreenVisibleX) {
		c53.style.left=(giScreenVisibleX-dd53)+'px';
		debugcount++;
	} else if (xx53!=(tt4-1)) {
		c53.style.left=(tt4-1)+'px';
		debugcount++;
	}

	if ((tt5+dd54) >= giScreenVisibleX) {
		c54.style.left=(giScreenVisibleX-dd54)+'px';
		debugcount++;
	} else if (xx54!=(tt5-1)) {
		c54.style.left=(tt5-1)+'px';
		debugcount++;
	}
	
	if ((tt6+dd55) >= giScreenVisibleX) {
		c55.style.left=(giScreenVisibleX-dd55)+'px';
		debugcount++;
	} else if (xx55!=(tt6-1)) {
		c55.style.left=(tt6-1)+'px';
		debugcount++;
	}

			/*if (aa6 != 0+(giScreenVisibleY - bb6-bb-10)) {
				c6.style.top=(0+(giScreenVisibleY - bb6-bb-10))+'px';
			}*/
	
	return debugcount;
}

function giAdjustButtons() {
	var w=giScreenVisibleXMax;
	var c=null, d=null;

	p=w/822;
	var t=0;
	d=f01(2,1);
	d.style.left='0px';
	c=f01(1,1);
	x=Math.round(77*p);
	c.style.left='0px'; c.style.width=x+'px';
	c=f01(1,2);
	t+=x+1;
	d=f01(2,2);
	d.style.left=(t-2)+'px';
	x=Math.round(79*p);
	c.style.left=t+'px'; c.style.width=x+'px';
	c=f01(1,3);
	t+=x+1;
	d=f01(2,3);
	d.style.left=(t-2)+'px';
	x=Math.round(112*p);
	c.style.left=t+'px'; c.style.width=x+'px';
	c=f01(1,4);
	t+=x+1;
	d=f01(2,4);
	d.style.left=(t-2)+'px';
	x=Math.round(125*p);
	c.style.left=t+'px'; c.style.width=x+'px';
	c=f01(1,5);
	t+=x+1;
	d=f01(2,5);
	d.style.left=(t-2)+'px';
	x=Math.round(94*p);
	c.style.left=t+'px'; c.style.width=x+'px';
	c=f01(1,6);
	t+=x+1;
	d=f01(2,6);
	d.style.left=(t-2)+'px';
	x=Math.round(113*p);
	c.style.left=t+'px'; c.style.width=x+'px';
	c=f01(1,7);
	t+=x+1;
	d=f01(2,7);
	d.style.left=(t-2)+'px';
	x=Math.round(97*p);
	c.style.left=t+'px'; c.style.width=x+'px';
	c=f01(1,8);
	t+=x+1;
	d=f01(2,8);
	d.style.left=(t-2)+'px';
	x=w-t;
	c.style.left=t+'px'; c.style.width=x+'px';
	t+=x+1;
	d=f01(2,9);
	d.style.left=(t-3)+'px';
}

function giCheckScreenChange() {
	giGetScreen();
	
	if (giLastScreenX!=giScreenVisibleX || giLastScreenY!=giScreenVisibleY) {
		giAdjustButtons();
		giOnScroll();
		
		if (giLastScreenX == -1 && giLastScreenY == -1) {
			document.getElementById('gibuttonbar').style.visibility='visible';
			document.getElementById('gibottombar').style.visibility='visible';
		}
		
		giLastScreenX=giScreenVisibleX;
		giLastScreenY=giScreenVisibleY;
	}
	
	giTimeout=window.setTimeout('giCheckScreenChange()', 100);
}
