var version=8;
var browserAgent=navigator.userAgent;
var msie=false;
var opacity='opacity:0;';
var imgOffset=0;
var divOffset=0;
var Pause=parseInt(175);
var interval= parseInt(2);
var opacityIncrement=1;
var slideIncrement=3;
if(navigator.userAgent.indexOf("MSIE")>=0)
{
	if(navigator.userAgent.indexOf("MSIE 7")>=0)
	{
		version=7;
	}
	msie=true;
	opacity='zoom:1;filter:alpha(opacity=0);';
}
else
{
	imgOffset=0;
	divOffset=0;
	Pause=parseInt(250);
	interval=parseInt(1);
	opacityIncrement=2;;
	slideIncrement=2;
}
var firstPic=1;
var imgArrayL = new Array;
var h3ArrayL = new Array;
var pArrayL = new Array;
var nodeArrayL = new Array;
var groupL;
var nodeL;
var imgInIDL="";
var imgOutIDL="";
var imgInL="";
var imgOutL="";
var imgL;
var maxHeightL=0;
var totHeightL=0;
var heightArrayL = new Array;
var opacityIn=0;
var opacityOut=1;
var picLoad= new Array;
var imgIndex=parseInt(0);
var fadeCount=0;
var intervalID;
var intervalIDLoad;
var cycleCount=0;
var i=0;
var j=0;
var top=parseInt(0);
var out=parseInt(1);
var divIDL='';
var divWidthL;
var marginInL;
var marginOutL;
var bodyHeight=0;
var bodyWidth=0;
var objParent;
var divTop=0;
var maxHeight=0;
var totHeight=0;
//********************************************************************************************************************
// Init function from javaxript at bottom of page
//********************************************************************************************************************
function LoadimgDiv(DivIDL)
{
	divIDL=DivIDL;
	if(typeof divIDL!="string")
	{
		alert('DivID is not valid');
	}
	else
	{
// init left side
		objParent=document.getElementById(divIDL).parentNode;
		var obj=document.getElementById(divIDL);
		var group=obj.childNodes;
		var j=0;
		var k=0;
		var m=0;
		var z=0;
		imgL='';
		for(i=0;i<group.length;i++)
		{
			if(group[i].nodeType==1)
			{
				if(group[i].tagName.toLowerCase()=="img")
				{
					imgArrayL[j]= new imgArrayLoad(group[i]);
					nodeArrayL[z]= new createDivNode("PicL"+z);
					createImgNode(nodeArrayL[z].node,imgArrayL[j]);
					z++;
					j++;
				}
				if(group[i].tagName.toLowerCase()=="h3")
				{
					h3ArrayL[k]= new h3ArrayLoad(group[i]);
					nodeArrayL[z]= new createDivNode("PicL"+z);
					createH3Node(nodeArrayL[z].node,h3ArrayL[k]);
					nodeArrayL[z].node.style.textAlign="right";
					k++;
				}
				if(group[i].tagName.toLowerCase()=="p")
				{
					pArrayL[m]= new pArrayLoad(group[i]);
					createPNode(nodeArrayL[z].node,pArrayL[m]);
					z++;
					m++;
				}
			}
		}
		// remove left side nodes
		numNodes=group.length;
		for(i=0;i<numNodes;i++)
		{
			obj.removeChild(obj.firstChild);
		}
		// insert left side nodes
		for(i=0;i<nodeArrayL.length;i++)
		{
			obj.appendChild(nodeArrayL[i].node);
		}
		if(intervalID)
		{
			clearInterval(intervalID);
		}
		intervalID=setInterval("imgLoadDivWait()",interval);
	}
}
function imgLoadDivWait()
{
	var done=1;
	// have all of the pictures finished loading?
	var obj=document.getElementById(divIDL);
	groupL=obj.childNodes;
	for(i=0;i<groupL.length;i++)
	{
		var picGroupL=groupL[i].childNodes;
		for(j=0;j<picGroupL.length;j++)
		{
			if(picGroupL[j].nodeType==1)
			{
				if(picGroupL[j].tagName.toLowerCase()=="img")
				{
					if(picGroupL[j].complete===false)
					{
						done=0;
					}
				}
			}
		}
	}
	// pictures are loaded
	if(done==1)
	{
		calcHeights();
		imgOutIDL="";
		imgInIDL="PicL0";
		if(msie)
		{
			opacityIn=parseInt(0);
			opacityOut=parseInt(100);
		}
		else
		{
			opacityIn=0.0;
			opacityOut=1.0;
		}
		if(intervalID)
		{
			clearInterval(intervalID);
		}
		out=0;
		document.getElementById(divIDL).style.display='';
		divWidthL=document.getElementById(divIDL).offsetWidth+12;
		intervalID=setInterval("imgFade()",interval);
	}
}
function calcHeights()
{
	// load left side heights
	var z=0;
	for(i=0;i<groupL.length;i++)
	{
		if(groupL[i].nodeType==1)
		{
			if(groupL[i].tagName.toLowerCase()=="div")
			{
				heightArrayL[z++]=groupL[i].offsetHeight+divOffset;
			}
		}
	}
	setHeights();
}
function setHeights()
{
	// init the left side
	document.getElementById("PicL0").style.top="0px";
	var top=0;
	for(i=1;i<heightArrayL.length;i++)
	{
		top+=heightArrayL[i-1];
		document.getElementById("PicL"+i).style.top="-"+top+"px";
	}
	bodyHeight=document.documentElement.clientHeight;
	bodyWidth=document.documentElement.clientWidth;
	maxHeightL=0;
	totHeightL=0;
	for(i=1;i<heightArrayL.length;i++)
	{
		if(heightArrayL[i]>maxHeightL)
		{
			maxHeightL=heightArrayL[i];
		}
		totHeightL+=heightArrayL[i]-12;
	}
	totHeight=totHeightL;
	maxHeight=maxHeightL;
	document.getElementById(divIDL).style.height=maxHeight+'px';
}
function imgFade()
{
	if((bodyHeight!=document.documentElement.clientHeight)||(bodyWidth!=document.documentElement.clientWidth))
	{
		calcHeights();
	}
	fade();
}
//***********************************************************************************************************
//   fade the divs
//***********************************************************************************************************
function fade()
{
	if(msie)
	{
		if(firstPic==1)
		{
			document.getElementById(imgInIDL).filters.alpha.opacity=opacityIn;
			opacityIn+=opacityIncrement;
			if(opacityIn>=100)
			{
				opacityIn=100;
			}
		}
		if(out==0)
		{
			fadeCount++;
			if(fadeCount>Pause)
			{
				fadeCount=0;
				opacityIn=0;
				opacityOut=100;
				imgIndex++;
				if(imgIndex>=heightArrayL.length)
				{
					imgIndex=0;
				}
				imgOutIDL=imgInIDL;
				imgInIDL="PicL"+imgIndex;
				document.getElementById(imgOutIDL).filters.alpha.opacity="100";
				document.getElementById(imgInIDL).filters.alpha.opacity="0";
				out=1;
				firstPic=0;
			}
		}
		if(out==1)
		{
			document.getElementById(imgOutIDL).filters.alpha.opacity=opacityOut;
			opacityOut-=opacityIncrement;
			document.getElementById(imgInIDL).filters.alpha.opacity=opacityIn;
			opacityIn+=opacityIncrement;
			if((opacityIn>=100)||(opacityOut<0))
			{
				out=0;
				cycleCount++;
				if(cycleCount>3)
				{
					cycleCount=0;
				}
			}
		}
	}
	else
	{
		if(firstPic==1)
		{
			document.getElementById(imgInIDL).style.opacity=opacityIn;
			opacityIn+=opacityIncrement/100;
			if(opacityIn>=1.0)
			{
				opacityIn=1.0;
			}
		}
		if(out==0)
		{
			fadeCount++;
			if(fadeCount>Pause)
			{
				fadeCount=0;
				opacityIn=0;
				opacityOut=1;
				imgIndex++;
				if(imgIndex>=heightArrayL.length)
				{
					imgIndex=0;
				}
				imgOutIDL=imgInIDL;
				imgInIDL="PicL"+imgIndex;
				document.getElementById(imgOutIDL).style.opacity="1";
				document.getElementById(imgInIDL).style.opacity="0";
				out=1;
				firstPic=0;
			}
		}
		if(out==1)
		{
			document.getElementById(imgOutIDL).style.opacity=opacityOut;
			opacityOut-=opacityIncrement/100;
			document.getElementById(imgInIDL).style.opacity=opacityIn;
			opacityIn+=opacityIncrement/100;
			if((opacityIn>=1.0)||(opacityOut<0))
			{
				out=0;
				cycleCount++;
				if(cycleCount>3)
				{
					cycleCount=0;
				}
			}
		}
	}
}
//***********************************************************************************************************
//   slide the divs out
//***********************************************************************************************************
function slideOut()
{
	if(out==0)
	{
		if(msie)
		{
			opacityIn=0;
			opacityOut=100;
		}
		else
		{
			opacityIn=0;
			opacityOut=1;
		}
		fadeCount++;
		if(fadeCount>Pause)
		{
			fadeCount=0;
			marginInL=+divWidthL;
			marginOutL=0;
			imgIndex++;
			if(imgIndex>=heightArrayL.length)
			{
				imgIndex=0;
			}
			imgOutIDL=imgInIDL;
			imgInIDL="PicL"+imgIndex;
			opacityOff();
			out=1;
		}
	}
	if(out==1)
	{
		slideInOut()
		marginOutL-=slideIncrement;
		marginInL-=slideIncrement;
		if((marginInL<=0)||(marginOutL<=-divWidthL))
		{
			out=0;
			cycleCount++;
			if(cycleCount>3)
			{
				cycleCount=0;
			}
			opacityOn();
			marginOutL=0;
			marginInL=0;
			slideInOut();
		}
	}
}
//***********************************************************************************************************
//   slide the divs In
//***********************************************************************************************************
function slideIn()
{
	if(out==0)
	{
		if(msie)
		{
			opacityIn=0;
			opacityOut=100;
		}
		else
		{
			opacityIn=0;
			opacityOut=1;
		}
		fadeCount++;
		if(fadeCount>Pause)
		{
			fadeCount=0;
			marginInL=-divWidthL;
			marginOutL=0;
			imgIndex++;
			if(imgIndex>=heightArrayL.length)
			{
				imgIndex=0;
			}
			imgOutIDL=imgInIDL;
			imgInIDL="PicL"+imgIndex;
			opacityOff();
			out=1;
		}
	}
	if(out==1)
	{
		slideInOut();
		marginOutL+=slideIncrement;
		marginInL+=slideIncrement;
		if((marginInL>=0)||(marginOutL>=divWidthL))
		{
			out=0;
			cycleCount++;
			if(cycleCount>3)
			{
				cycleCount=0;
			}
			opacityOn();
			marginOutL=0;
			marginInL=0;
			slideInOut();
		}
	}
}
//***********************************************************************************************************
//   slide the divs in or out
//***********************************************************************************************************
function slideInOut()
{
	if((msie)&&(version==7))
	{
		for(i=0;i<document.getElementById(imgOutIDL).childNodes.length;i++)
		{
			document.getElementById(imgOutIDL).childNodes[i].style.marginLeft=marginOutL+"px";
			document.getElementById(imgOutIDL).childNodes[i].style.marginRight=-marginOutL+"px";
		}
		for(i=0;i<document.getElementById(imgInIDL).childNodes.length;i++)
		{
			document.getElementById(imgInIDL).childNodes[i].style.marginLeft=marginInL+"px";
			document.getElementById(imgInIDL).childNodes[i].style.marginRight=-marginInL+"px";
		}
	}
	else
	{
		document.getElementById(imgOutIDL).style.marginLeft=marginOutL+"px";
		document.getElementById(imgOutIDL).style.marginRight=-marginOutL+"px";
		document.getElementById(imgInIDL).style.marginLeft=marginInL+"px";
		document.getElementById(imgInIDL).style.marginRight=-marginInL+"px";
	}
	if(msie)
	{
		document.getElementById(imgOutIDL).filters.alpha.opacity=opacityOut;
		opacityOut-=opacityIncrement;
	}
	else
	{
		document.getElementById(imgOutIDL).style.opacity=opacityOut;
		opacityOut-=opacityIncrement/100;
	}
	setHeights();
}
//***********************************************************************************************************
//   slide the divs Up
//***********************************************************************************************************
function slideUp()
{
	if(out==0)
	{
		if(msie)
		{
			opacityIn=0;
			opacityOut=100;
		}
		else
		{
			opacityIn=0;
			opacityOut=1;
		}
		fadeCount++;
		if(fadeCount>Pause)
		{
			fadeCount=0;
			marginInL=-divWidthL;
			marginOutL=0;
			imgIndex++;
			if(imgIndex>=heightArrayL.length)
			{
				imgIndex=0;
			}
			imgOutIDL=imgInIDL;
			imgInIDL="PicL"+imgIndex;
			opacityOff();
			out=1;
		}
	}
	if(out==1)
	{
		slideInOut();
		marginOutL+=slideIncrement;
		marginInL+=slideIncrement;
		if((marginInL>=0)||(marginOutL>=divWidthL))
		{
			out=0;
			cycleCount++;
			if(cycleCount>3)
			{
				cycleCount=0;
			}
			opacityOn();
			marginOutL=0;
			marginInL=0;
			slideInOut();
		}
	}
}
//***********************************************************************************************************
//   slide the divs down
//***********************************************************************************************************
function slideDown()
{
	if(out==0)
	{
		if(msie)
		{
			opacityIn=0;
			opacityOut=100;
		}
		else
		{
			opacityIn=0;
			opacityOut=1;
		}
		fadeCount++;
		if(fadeCount>Pause)
		{
			fadeCount=0;
			marginInL=-divWidthL;
			marginOutL=0;
			imgIndex++;
			if(imgIndex>=heightArrayL.length)
			{
				imgIndex=0;
			}
			imgOutIDL=imgInIDL;
			imgInIDL="PicL"+imgIndex;
			opacityOff();
			out=1;
		}
	}
	if(out==1)
	{
		slideInOut();
		marginOutL+=slideIncrement;
		marginInL+=slideIncrement;
		if((marginInL>=0)||(marginOutL>=divWidthL))
		{
			out=0;
			cycleCount++;
			if(cycleCount>3)
			{
				cycleCount=0;
			}
			opacityOn();
			marginOutL=0;
			marginInL=0;
			slideInOut();
		}
	}
}
//***********************************************************************************************************
//   slide the divs up or down
//***********************************************************************************************************
function slideUpDown()
{
	if((msie)&&(version==7))
	{
		for(i=0;i<document.getElementById(imgOutIDL).childNodes.length;i++)
		{
			document.getElementById(imgOutIDL).childNodes[i].style.marginLeft=marginOutL+"px";
			document.getElementById(imgOutIDL).childNodes[i].style.marginRight=-marginOutL+"px";
		}
		for(i=0;i<document.getElementById(imgInIDL).childNodes.length;i++)
		{
			document.getElementById(imgInIDL).childNodes[i].style.marginLeft=marginInL+"px";
			document.getElementById(imgInIDL).childNodes[i].style.marginRight=-marginInL+"px";
		}
	}
	else
	{
		document.getElementById(imgOutIDL).style.marginLeft=marginOutL+"px";
		document.getElementById(imgOutIDL).style.marginRight=-marginOutL+"px";
		document.getElementById(imgInIDL).style.marginLeft=marginInL+"px";
		document.getElementById(imgInIDL).style.marginRight=-marginInL+"px";
	}
	if(msie)
	{
		document.getElementById(imgOutIDL).filters.alpha.opacity=opacityOut;
		opacityOut-=opacityIncrement;
	}
	else
	{
		document.getElementById(imgOutIDL).style.opacity=opacityOut;
		opacityOut-=opacityIncrement/100;
	}
	setHeights();
}
//***********************************************************************************************************
//   Turn opacity off
//***********************************************************************************************************
function opacityOff()
{
	if(msie)
	{
		document.getElementById(imgOutIDL).filters.alpha.opacity="100";
		document.getElementById(imgInIDL).filters.alpha.opacity="100";
	}
	else
	{
		document.getElementById(imgOutIDL).style.opacity="1";
		document.getElementById(imgInIDL).style.opacity="1";
	}
}
//***********************************************************************************************************
//   turn opacity on
//***********************************************************************************************************
function opacityOn()
{
	if(msie)
	{
		document.getElementById(imgOutIDL).filters.alpha.opacity="0";
		document.getElementById(imgInIDL).filters.alpha.opacity="100";
	}
	else
	{
		document.getElementById(imgOutIDL).style.opacity="0";
		document.getElementById(imgInIDL).style.opacity="1";
	}
}
//****************************************************************************************************************
//																														Load Arrays from Page
//****************************************************************************************************************
function imgArrayLoad(obj)
{
	this.img=new Image();
	this.img.src=obj.src;
	this.img.style.width="95%";
	this.Class=(obj.className)?' class="'+obj.className+'"':"";
	this.width=obj.width;
	this.Src=' src="'+obj.src+'"';
	this.Alt=(obj.alt)?obj.alt:"";
	this.height=obj.offsetHeight+18;
}
function h3ArrayLoad(obj)
{
	this.title=(obj.title)?' title="'+obj.title+'"':"";
	this.align=(obj.align)?' align="'+obj.align+'"':"";
	this.text=(obj.innerHTML.length>0)?obj.innerHTML:"&nbsp;";
	this.height=obj.offsetHeight+6;
}
function pArrayLoad(obj)
{
	this.title=(obj.title)?' title="'+obj.title+'"':"";
	this.align=(obj.align)?' align="'+obj.align+'"':"";
	this.text=(obj.innerHTML.length>0)?obj.innerHTML:"&nbsp;";
	this.height=obj.offsetHeight+6;
}
function picLoaded(picIndex)
{
	picLoad[picIndex]=1;
}
//************************************************************************************************************
//                create nodes
//************************************************************************************************************
function createDivNode(z)
{
	this.node=document.createElement("div");
	this.node.id=z;
	this.node.style.top="0px";
	this.node.style.position="relative";
	this.node.style.width="100%";
	this.node.style.overflow="hidden";
	this.node.style.padding=0;
	this.node.style.margin=" 0 auto";
	if(msie)
	{
		this.node.style.zoom=1;
		this.node.style.filter='alpha(opacity=0)';
	}
	else
	{
		this.node.style.opacity=0;
	}
}
function createImgNode(node,elem)
{
	node.appendChild(document.createElement("img"));
	node.lastChild.src=elem.img.src;
	node.lastChild.style.width="99%";
	//node.lastChild.align="right";
	node.lastChild.complete==false;
	if(elem.Class.length>0)
	{
		node.lastChild.Class=elem.Class;
	}
	if(elem.Alt.length>0)
	{
		node.lastChild.alt=elem.Alt;
	}
}
function createH3Node(node,elem)
{
	node.appendChild(document.createElement("h3"));
	if(elem.align.length>0)
	{
		node.lastChild.align=elem.align;
	}
	if(elem.title.length>0)
	{
		node.lastChild.title=elem.title;
	}
	if(elem.text.length>0)
	{
		node.lastChild.appendChild(document.createTextNode(elem.text));
	}
}
function createPNode(node,elem)
{
	node.appendChild(document.createElement("p"));
	if(elem.align.length>0)
	{
		node.lastChild.align=elem.align;
	}
	if(elem.title.length>0)
	{
		node.lastChild.title=elem.title;
	}
	if(elem.text.length>0)
	{
		node.lastChild.appendChild(document.createTextNode(elem.text));
	}
}
