function showMenu(index)
{
	var subMenus = $(".divHiddenSubMenu");
	document.getElementById("divSubMenu").innerHTML = subMenus[index].innerHTML;

	var mainMenus = $(".divMainMenuItem");
	for (var i = 0; i < mainMenus.length; i++)
	{
		mainMenus[i].className = "divMainMenuItem";
		if (i == index)
		{
			mainMenus[i].className += " divMainMenuSelected";
		}
	}
}

function goHome()
{
	document.location = document.getElementById("ctl00_lsttheo_page_ctl00_ctltitle").href;
}

var testimonialIndex = 0;
var testimonialList = null;
var attestorList;
function loadTestimonial()
{
	if (testimonialList == null)
	{
		testimonialList = $(".divHideTestimonials .jqTestimonial");
		attestorList = $(".divHideTestimonials .jqAttestor");
	}
	$("#divFadeTestimonials").fadeTo("slow", 0.0, function() {
			if (testimonialIndex >= testimonialList.length)
			{
				testimonialIndex = 0;
			}
			document.getElementById("lblTestimonial").innerHTML = testimonialList[testimonialIndex].innerHTML;
			document.getElementById("lblAttestor").innerHTML = attestorList[testimonialIndex].innerHTML;
			testimonialIndex++;
			$(this).fadeTo("slow", 1.0, function () {setTimeout("loadTestimonial()", TheoTestimonialSeconds);});
		}
	);
}


/* Portfolio */

var SWATCH_WIDTH = 121; //width: 115 + 3 x 2 , height= 55 + 5 x 2
var SWATCH_PER_PAGE = 4; //overriden in gallery.aspx

var currentMargin = 0;
var currentIndex = 0;
function moveLeft()
{
	if (currentIndex <=  0)
	{
		currentIndex = swatches.length - SWATCH_PER_PAGE;
		movePhoto(-(SWATCH_WIDTH * (currentIndex)));
	}
	else
	{
		movePhoto(SWATCH_WIDTH);
		currentIndex--;
	}
}

function moveRight()
{
	if (currentIndex >= (swatches.length - SWATCH_PER_PAGE))
	{
		currentIndex = 0;
		movePhoto(SWATCH_WIDTH * (swatches.length - SWATCH_PER_PAGE));
	}
	else
	{
		movePhoto(-SWATCH_WIDTH);
		currentIndex++;
	}
}

function movePhoto(offset)
{
	currentMargin += offset;
	var val = currentMargin + "px";
	var duration = 1000;
	if ((offset != SWATCH_WIDTH) && (offset != -SWATCH_WIDTH))
	{
		duration = 2500;
	}
	$("#divPortfolioSlide").animate({marginLeft: val}, duration, "swing");
}

var grayscaleParameter = "&grayscale=true";
var currentlyLoading = "";
function colorImage(sender, newWidth)
{
	$('#imgHomeFeature').stop(true, true);//.fadeIn();
	$('#imgHomeFeature').fadeOut('slow', function() 
	{
		sender.src = sender.src.replace(grayscaleParameter, "");
		var largeImage = new Image();
		largeImage.onload = function() 
		{
			//alert(largeImage); //largeImage, sender
			//alert(sender);
			if (currentlyLoading == largeImage.src)
			{
				var imageList = $(".divPortfolioGalleryWrapper .imgGallery");
				var descriptionList = $(".divPortfolioGalleryWrapper .spanText");
				for (var i = 0; i < imageList.length; i++)
				{
					if (imageList[i] == sender)
					{
						var imgHomeFeature = document.getElementById("imgHomeFeature");
						imgHomeFeature.src = largeImage.src;
						$('#imgHomeFeature').fadeIn('slow');
						if (i < descriptionList.length)
						{
							document.getElementById("lblPortfolioDetails").innerHTML = descriptionList[i].innerHTML;
						}
					}
					else
					{
						if (imageList[i].src.indexOf(grayscaleParameter) < 0)
						{
							imageList[i].src = imageList[i].src + grayscaleParameter;
						}
					}
				}
			}
		}
		if (isGif(sender.src))
		{
			var fileParam = "&fileName=";
			var param = sender.src.lastIndexOf(fileParam);
			currentlyLoading = ("http://" + document.domain + sender.src.substr(param + fileParam.length, sender.src.length)).replace(" ", "%20");
		}
		else
		{
			currentlyLoading = sender.src.replace("width=115", "width=" + newWidth);
		}
		largeImage.src = currentlyLoading;
	});
}

function isGif(filename) 
{ 
	var dot = filename.lastIndexOf("."); 
	if( dot == -1 )
	{
		return false; 
	}
	else
	{
		var extension = filename.substr(dot,filename.length).toLowerCase(); 
		//alert(extension);
		return extension == ".gif"; 
	}
} 

function uncolorImage(sender)
{
	//sender.src = sender.src += grayscaleParameter;
}

