var currentImg;
var xmlhttp;
var dataObj = new Object();
var greenSections = 5;
var imagePath = '/images/green/';
var imageCount = 0;

function getImageInfo(whatImage)
{
	document.body.style.cursor = 'wait';
	currentImg = whatImage;
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	{
		return;
	}
	var url = 'green-data.asp';
	url += '?type=i';
	url += '&ref='+dataObj.section;
	url += '&image='+whatImage;
	xmlhttp.onreadystatechange=showImageInfo;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}

function showImageInfo()
{
	if(xmlhttp.readyState == 4)
	{
		document.body.style.cursor = 'default';
		var temp = xmlhttp.responseText;
		var objData = JSON.parse(temp);
		var imageFile = dataObj.section + '-' + currentImg + '.jpg';
		showImage(imageFile,objData.largeWidth,objData.largeHeight,currentImg);
		document.getElementById('imageCaption').innerHTML = objData.imageCaption;
	}
}

function greenGet(whatSection)
{
	document.body.style.cursor = 'wait';
	dataObj.section = whatSection;
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	{
		return;
	}
	var url = 'green-data.asp';
	url += '?type=t';
	url += '&ref='+whatSection;
	xmlhttp.onreadystatechange=greenShow;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}

function greenShow()
{
	if(xmlhttp.readyState == 4)
	{
		document.body.style.cursor = 'default';
		var temp = xmlhttp.responseText;
		var objData = JSON.parse(temp);
		document.getElementById('greenIntro').innerHTML = objData.greenIntro;
		document.getElementById('greenP1').innerHTML = objData.greenP1;
		document.getElementById('greenBody').innerHTML = objData.greenBody;
		document.getElementById('greenIntroImage').src = '/images/green-'+dataObj.section+'.jpg';
		setLinks();
		imageCount = objData.imageCount;
		imageSet(imageCount);
	}
}

function setLinks()
{
	var attName = 'class';
	if(isIE){attName = 'className';}
	var topL = '';
	var lowL = '';
	var checkAtt = '';
	for(i=0;i<greenSections;i++)
	{
		topL = 'tl-'+i;
		lowL = 'll-'+i;
		checkAtt = document.getElementById(topL).getAttribute(attName);
		if(checkAtt != null){document.getElementById(topL).removeAttribute(attName);}
		checkAtt = document.getElementById(lowL).getAttribute(attName);
		if(checkAtt != null){document.getElementById(lowL).removeAttribute(attName);}
		if(dataObj.section == i)
		{
			document.getElementById(topL).setAttribute(attName,'live');
			if(i>0){document.getElementById(lowL).setAttribute(attName,'live');}else{document.getElementById(lowL).setAttribute(attName,'live0');}
		}else{
			if(i>0){document.getElementById(lowL).setAttribute(attName,'standard');}
		}
	}
}	

function imageSet(imageCount)
{
	var imageString = '';
	var imageFile= '';
	for(i=1;i<parseInt(imageCount)+1;i++)
	{
		imageFile = '/images/green/' + dataObj.section + '-' + i + '.jpg';
		imageString += '<span style="background-image:url('+imageFile+');" onclick="getImageInfo('+i+');"></span>';
		
	}
	document.getElementById('greenColRight').innerHTML = imageString;
}

function getSize() {
  var myWidth = 0, myHeight = 0;
	var objSizes = new Object();
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
	objSizes.w = myWidth;
	objSizes.h = myHeight;
	return objSizes;
}

function prepBig()
{
	var objSizes = getSize();
	var winW = objSizes.w;
	var winH = objSizes.h;
	document.write('<div id="imageWindow" name="imageWindow"');
	document.write(' style="top:-'+winH+'px; left:-'+winW+'px; width:'+winW+'px; height:'+winH+'px;">');
	document.write('<div class="closeText" onclick="javascript:hideBig();">Close</div>');
	document.write('<div class="imageBox" onclick="javascript:hideBig();">');
	document.write('<img src="/graphics/loading.gif" name="bigImage" id="bigImage" border="0" /></div>');
	document.write('<div id="imageCaption"></div>');
	document.write('<div>');
	document.write('<span id="imageNavL" class="navText" onclick="javascript:nextSlide(-1);">&#0171;</span>');
	document.write('<span id="imageNavR" class="navText" onclick="javascript:nextSlide(1);">&#0187;</span>');
	document.write('</div>');
	document.write('</div>');
	document.write('<div id="imageScreen" name="imageScreen"');
	document.write(' style="width:'+winW+'px; height:'+winH+'px;');
	if(isIE == true)
	{
		document.write('filter:alpha(opacity=90);');
	}
	document.write('"></div>');
}

function showImage(whatImage,imgWidth,imgHeight,imgNum)
{
	if(imgWidth == 0 || imgHeight == 0)
	{
		imgWidth = 800;
		imgHeight = 600;
		imgObj = document.getElementById('bigImage').style;
		imgObj.height = '600px';
		imgObj.width = 'auto';		
	}
	var winW = parseInt(imgWidth) + 40;
	var winH = parseInt(imgHeight) + 80;
	grabBig(whatImage);
	changeObjectVisibility('imageWindow','visible',11);
	changeObjectVisibility('imageScreen','visible',10);
	var H = getHeight();
	var Hspace = Math.round((H - winH)/2);
	var W = getWidth();
	var Lft = Math.round((W - winW)/2);
	var ScrollTop = document.body.scrollTop;
	if (ScrollTop == 0)
	{
	  if (window.pageYOffset)
		{
			ScrollTop = window.pageYOffset;
			if(Hspace > 0){ScrollTop += Hspace;}
		}
   	else
		{
      ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
			if(Hspace > 0){ScrollTop += Hspace;}
		}
	}
	ScrollTop -= 40;
	ScrollTop += 'px';
	winW += 'px';
	winH += 'px';
	Lft += 'px';
	var styleObject = getStyleObject('imageWindow');
	styleObject.width=winW;
	styleObject.height=winH;
	styleObject.top=ScrollTop;
	styleObject.left=Lft;
	var screenObj = getStyleObject('imageScreen');
	screenObj.top=0;
	screenObj.left=0;
}

function hideBig()
{
	changeObjectVisibility('imageWindow','hidden',1);
	changeObjectVisibility('imageScreen','hidden',1);
	var styleObject = getStyleObject('imageWindow');
	var winH = document.documentElement.clientHeight;
	var winW = document.documentElement.clientWidth;
	winH += 'px';
	winW += 'px';
	styleObject.offsetTop -= winH;
	styleObject.offsetLeft -= winW;
	styleObject = getStyleObject('imageScreen');
	winH += 'px';
	winW += 'px';
	styleObject.offsetTop -= winH;
	styleObject.offsetLeft -= winW;
	document.getElementById('bigImage').src = '/graphics/loading.gif';
}

function grabBig(whatImage)
{
	loadPath = imagePath + 'large/' + whatImage;
	document.getElementById('bigImage').src = loadPath;
}

function nextSlide(dir)
{
	var slideNum = currentImg + dir;
	if(slideNum < 1){slideNum = imageCount;}
	if(slideNum > imageCount){slideNum = 1;}
	getImageInfo(slideNum);
}
