var viewportwidth;
var viewportheight;

// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
if (typeof window.innerWidth != 'undefined')
{
	viewportwidth = window.innerWidth,
	viewportheight = window.innerHeight
} // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0)
{
	viewportwidth = document.documentElement.clientWidth,
	viewportheight = document.documentElement.clientHeight
} // older versions of IE
else
{
	viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
	viewportheight = document.getElementsByTagName('body')[0].clientHeight
}
if(window.scrollbars && window.scrollbars.visible)
{
	viewportwidth -= 16;
	viewportheight -= 16;
}

function GetNewRandQuote()
{
	quoteObj = document.getElementById('logoRight');
		
	aniOpOut = new OpacityTween(quoteObj, Tween.regularEaseInOut, 100, 0, 0.25);
	aniOpOut.onMotionFinished = function()
	{
		xmlhttp = GetXmlReqObject();
		if(xmlhttp)
		{
			xmlhttp.open('GET', 'randQuote.php', true);
			xmlhttp.onreadystatechange=function()
			{
				if (xmlhttp.readyState==4) 
				{
					quoteObj.innerHTML = xmlhttp.responseText;
					aniOpIn = new OpacityTween(quoteObj, Tween.regularEaseInOut, 0, 100, 0.25);
					aniOpIn.start();
				}
			}
			xmlhttp.send(null);
		}
	}
	aniOpOut.start();
}
function SlideImageRow(Left)
{
	aniRow.stop();
	element = document.getElementById('imageRow');
	
	initRowPos = parseInt(element.style.left);
	if(Left)
		finalRowPos = initRowPos - (thumbSize * 3);
	else
		finalRowPos = initRowPos + (thumbSize * 3);
	
	if(finalRowPos > 0)
	{
		if(initRowPos == 0)
			finalRowPos = (imgRowWidth * -1) + (thumbSize * 3);
		else
			finalRowPos = 0;
	}
	if(finalRowPos < imgRowWidth * -1)
		finalRowPos = 0;
		
	aniRow = new Tween(element.style, 'left', Tween.regularEaseInOut, initRowPos, finalRowPos, 1.0, 'px');
	aniRow.start();
}
function MenuItemOver(elementName, isOver)
{
	if(elementName == lastElement)
	{
		colorTween.stop();
//		opacityTween.stop();
	}
	
	if(isOver)
	{
		colorTween = new ColorTween(document.getElementById(elementName+'text').style, 'color', Tween.strongEaseOut, '666666', '000000', 0.5);
//		opacityTween = new OpacityTween(document.getElementById(elementName+'bar'),Tween.strongEaseOut, 1, 100, 0.5);
	}
	else
	{
		colorTween = new ColorTween(document.getElementById(elementName+'text').style, 'color', Tween.strongEaseOut, '000000', '666666', 0.5);
//		opacityTween = new OpacityTween(document.getElementById(elementName+'bar'),Tween.strongEaseOut, 100, 1, 0.5);
	}
	
	lastElement = elementName;
	colorTween.start();
//	opacityTween.start();
}
function SetOpacity(ElementName, OpacityPerc)
{
	opObj = document.getElementById(ElementName);
	opObj.style['opacity'] = OpacityPerc / 100;
	opObj.style['-moz-opacity'] = OpacityPerc / 100;
	if(opObj.filters) opObj.filters.alpha['opacity'] = OpacityPerc;
}
function SetVisible(ElementName, Visible)
{
	vObj = document.getElementById(ElementName);
	if(Visible)
		vObj.style['visibility'] = 'inherit';
	else
		vObj.style['visibility'] = 'hidden';
}
function RandImg()
{
	cache = document.getElementById('randImgCache');
	randIndex = parseInt(Math.random()*bgImgs.length);
	
	nextRandImg = cache.src;
	cache.src = bgImgs[randIndex];

	return nextRandImg;
}
function SlideNewContent(GetUrl, ImageUrl, BorderVis)
{
//	SetOpacity('leftContent', 100);
//	SetOpacity('fullContent', 1);
	SetVisible('leftContent', true);
//	SetVisible('rightContent', true);
	SetVisible('slideContent', true);
	SetVisible('fullContent', false);

	bodyObj = document.getElementById('bodyContent');
	leftObj = document.getElementById('leftContent');
	rightObj = document.getElementById('rightContent');
	slideObj = document.getElementById('slideContent');
	
	
	var image = new Image();
	image.onload = function()
	{
		slideObj.style.backgroundImage = "url('"+ ImageUrl +"')";
		SetOpacity('slideContent', 1);
	
		aniX = new Tween(slideObj.style, 'left', Tween.regularEaseInOut, 50,0, 0.5, 'px');
		aniY = new Tween(slideObj.style, 'top', Tween.regularEaseInOut, 100,0, 0.5, 'px');
		opAni = new OpacityTween(slideObj,Tween.regularEaseIn, 1, 100, 0.5);
		opAni.onMotionFinished = function()
		{
			xmlhttp = GetXmlReqObject();
			if(xmlhttp)
			{
				xmlhttp.open('GET', GetUrl, true);
				xmlhttp.onreadystatechange=function()
				{
					if (xmlhttp.readyState==4) 
					{
						leftObj.innerHTML = xmlhttp.responseText;
						leftObj.className = BorderVis ? "singleBorder" : "";
						xStart = parseFloat(leftObj.style.left);
						xEnd = parseFloat(rightObj.style.left);
						posAni = new Tween(slideObj.style, 'left', Tween.regularEaseInOut, xStart, xEnd, 0.5, 'px');
						posAni.onMotionFinished = function()
						{
							rightObj.style.backgroundImage = slideObj.style.backgroundImage;
	//						SetOpacity('leftContent',100);
							SetOpacity('rightContent',100);
	//						SetOpacity('fullContent', 1);
	//						SetVisible('leftContent', true);
							SetVisible('rightContent', true);
	//						SetVisible('fullContent', false);
						}
						posAni.start();
					}
				}
				xmlhttp.send(null);
			}
		}
		slideObj.style.visibility = 'visible';
		opAni.start();
		aniX.start();
		aniY.start();
	}
	image.src = ImageUrl;
}
function NewFullContent(GetUrl, BorderVis)
{
//	SetOpacity('leftContent', 1);
//	SetOpacity('rightContent', 1);
//	SetOpacity('slideContent', 1);
	SetVisible('leftContent', false);
	SetVisible('rightContent', false);
	SetVisible('slideContent', false);
	SetVisible('fullContent', true);
	SetOpacity('fullContent', 1);

	fullObj = document.getElementById('fullContent');
	leftObj = document.getElementById('leftContent');
	leftObj.innerHTML="";
	
	xmlhttp = GetXmlReqObject();
	if(xmlhttp)
	{
		xmlhttp.open('GET', GetUrl, true);
		xmlhttp.onreadystatechange=function()
		{
			if (xmlhttp.readyState==4) 
			{
				fullObj.innerHTML = xmlhttp.responseText;
				fullObj.className = BorderVis ? "singleBorder" : "";
				opAni = new OpacityTween(fullObj, Tween.strongEaseOut, 1, 100, 1);
				opAni.onMotionFinished = function()
				{
					SetVisible('rightContent', false);
//					SetOpacity('leftContent', 1);
//					SetOpacity('rightContent', 1);
//					SetOpacity('slideContent', 1);
				}
				opAni.start();
			}
		}
		xmlhttp.send(null);
	}
}
function GetTopCenter(ObjHeight)
{
	return (viewportheight / 2) - (ObjHeight / 2);
}
function GetLeftCenter(ObjWidth)
{
	return (viewportwidth / 2) - (ObjWidth / 2);
}
lastSlide = -1;
function NextSlide()
{
	lastSlide++;
	if(rowImgs.length == lastSlide)
		lastSlide = 0;
	DisplaySlide(lastSlide);
}
function PrevSlide()
{
	lastSlide--;
	if(lastSlide < 0)
		lastSlide = rowImgs.length - 1;
	DisplaySlide(lastSlide);
}
function DisplaySlide(SlideIndex)
{
	lastSlide = SlideIndex;
	SlideId = rowImgs[SlideIndex];
	containerObj = document.getElementById('imgDisplayImageContainer');
	imageObj = document.getElementById('imgDisplayImage');
	cacheObj = document.getElementById('displayImgCache');
	leftObj = document.getElementById('imgDisplayLeft');
	rightObj = document.getElementById('imgDisplayRight');
	titleObj = document.getElementById('imgDisplayTitle');
	descObj = document.getElementById('imgDisplayDesc');
	
	containerObj.style['background'] = 'transparent';
	containerObj.style['width'] = 32 + 'px';
	containerObj.style['height'] = 32 + 'px';
	imageObj.src = "Images/ajax-loader.gif";
	containerObj.style['left'] = GetLeftCenter(32) + 'px';
	containerObj.style['top'] = GetTopCenter(32) + 'px';
	SetVisible('imgDisplayTitle',false);
	SetVisible('imgDisplayDesc',false);
	SetVisible('imgDisplayLeft',false);
	SetVisible('imgDisplayRight',false);
	SetVisible('imgDisplay',true);
	
	
	xmlhttp = GetXmlReqObject();
	if(xmlhttp)
	{
		xmlhttp.open('GET', 'getImageRowData.php?data='+SlideId, true);
		xmlhttp.onreadystatechange=function()
		{
			if (xmlhttp.readyState==4) 
			{
				if(xmlhttp.responseXML.childNodes.length == 1)
					imgData = xmlhttp.responseXML.childNodes[0];
				else
					imgData = xmlhttp.responseXML.childNodes[1];
				imgUrl = imgData.attributes[0].nodeValue;
				titleObj.innerHTML = imgData.attributes[1].nodeValue;
				descObj.innerHTML = imgData.attributes[2].nodeValue;
				imgWidth = parseInt(imgData.attributes[3].nodeValue);
				imgHeight = parseInt(imgData.attributes[4].nodeValue);
				
				var image = new Image();
				image.onload = function()
				{
					aniX = new Tween(containerObj.style, 'left', Tween.regularEaseInOut, GetLeftCenter(32),GetLeftCenter(imgWidth), 0.5, 'px');
					aniY = new Tween(containerObj.style, 'top', Tween.regularEaseInOut, GetTopCenter(32),GetTopCenter(imgHeight), 0.5, 'px');
					aniW = new Tween(containerObj.style, 'width', Tween.regularEaseInOut, 32,imgWidth, 0.5, 'px');
					aniH = new Tween(containerObj.style, 'height', Tween.regularEaseInOut, 32,imgHeight, 0.5, 'px');
					aniH.onMotionChanged = function()
					{
						if(imageObj.src != 'blank.gif')
						{
							imageObj.src = 'blank.gif';
							containerObj.style['background'] = 'black';
						}
					}
					aniH.onMotionFinished = function()
					{
						imageObj.src = image.src;
						leftEdge = GetLeftCenter(32) - ((imgWidth/2)+8);
						rightEdge = GetLeftCenter(32) + ((imgWidth/2)+8);
						topEdge = GetTopCenter(32) - ((imgHeight/2)+8);
						bottomEdge = GetTopCenter(32) + ((imgHeight/2)+8);
						aniL = new Tween(leftObj.style, 'left', Tween.regularEaseInOut, leftEdge -64,leftEdge, 0.5, 'px');
						aniR = new Tween(rightObj.style, 'left', Tween.regularEaseInOut, rightEdge +64,rightEdge, 0.5, 'px');
						aniT = new Tween(titleObj.style, 'top', Tween.regularEaseInOut, topEdge -64,topEdge+8, 0.5, 'px');
						aniD = new Tween(descObj.style, 'top', Tween.regularEaseInOut, bottomEdge +64,bottomEdge-8, 0.5, 'px');

						leftObj.style['top'] = GetTopCenter(62) + 'px';
						rightObj.style['top'] = GetTopCenter(62) + 'px';
						titleObj.style['left'] = leftEdge + 'px';
						descObj.style['left'] = leftEdge + 'px';
						SetVisible('imgDisplayLeft',true);
						SetVisible('imgDisplayRight',true);
						SetVisible('imgDisplayTitle',true);
						SetVisible('imgDisplayDesc',true);
						
						aniL.start();
						aniR.start();
						aniT.start();
						aniD.start();
					}
					aniX.start();
					aniY.start();
					aniW.start();
					aniH.start();
				}
				image.src = 'ImageRow/'+ imgUrl;
			}
		}
		xmlhttp.send(null);
	}
}
function GetXmlReqObject()
{
	xmlhttp = false;
	if(window.XMLHttpRequest && !(window.ActiveXObject))
	{
		try 
		{
			xmlhttp = new XMLHttpRequest();
		} 
		catch(e)
		{
			xmlhttp = false;
		}
	} 
	else 
	{
		if(window.ActiveXObject)
		{
			try 
			{
				xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
			} 
			catch(e)
			{
				try 
				{
					xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
				} 
				catch(e) 
				{
					xmlhttp = false;
				}
			}
		}
	}
	return xmlhttp;
}