var curPage;

function showPic() 
{	
	var prepareSite = function(element) 
	{
		var mainpic = document.getElementById("mainpic");
		
		var xhr = new Hijax();
		xhr.setContainer(element);
		if(curPage == "webdesign")
		{
			xhr.setUrl("webswitcher.php");
		}
		else if(curPage == "illustration")
		{
			xhr.setUrl("illustrationSwitcher.php");
		}
		xhr.setCanvas(mainpic);
		xhr.setLoading(function() 
		{
			displayLoading(mainpic);
			prepareSite(element)
		});
		xhr.setCallback(function() 
		{
			highlightThumb();
			var title = document.getElementById("title");
			if(title.firstChild.getAttribute("a") == null)
			{
				fadeUp(title,255,255,221);
			}
		});
		xhr.captureData();
	};
		
		
	var displayLoading = function(element) 
	{
		while(element.hasChildNodes())
		{
			element.removeChild(element.lastChild);
		}
		var image = document.createElement("div");
		image.setAttribute("id", "loading");
		element.appendChild(image);
	};
	var thumbnails = document.getElementById("thumbnails");
	prepareSite(thumbnails);
	thumbnails = null;
}

function highlightThumb()
{	
	if (!document.getElementById) return false;
	if (!document.getElementById("thumbnails")) return false;
	if (!document.getElementById("mainpic")) return false;
	if (!document.getElementsByTagName) return false;
	
	var mainpic = document.getElementById("mainpic");
	var mainImage = mainpic.getElementsByTagName("img")[0];
	
	var thumbnails = document.getElementById("thumbnails");
	var images = thumbnails.getElementsByTagName("img");
	
	if(curPage == "webdesign")
	{
		var mainSource = mainImage.getAttribute("src").split("webdesign/")[1];
	}
	else if(curPage == "illustration")
	{
		var mainSource = mainImage.getAttribute("src").split("illustration/")[1];
	}
	
	for (var i=0; i<images.length; i++)
	{
		var thumbSrc = images[i].getAttribute("src").split("thumbs/")[1];
		if(thumbSrc == mainSource)
		{
			images[i].parentNode.className = "here";
		}
		else
		{
			images[i].parentNode.className = "out";
		}
	}
}

// check which page so we can combine the script
function getCurPage()
{
	if (!document.getElementsByTagName) return false;
	
	var bodyTag = document.getElementsByTagName("body")[0];
	curPage = bodyTag.getAttribute("id").toString();	
}

addLoadEvent(getCurPage);
addLoadEvent(showPic);
addLoadEvent(highlightThumb);