/* Created: Rollover elements in bundle pages */

/* scripting for bundle pages */
// create function for loading more than one function on a page
window.onload = function()
{
	prepareGallery();
}

// create function for preparing gallery area
function prepareGallery()
{
	// check that elements are supported in browsers
	if(!document.getElementsByTagName) return false;
	if(!document.getElementById) return false;
	
	// check that id exists within the markup
	if(!document.getElementById("magThumbs")) return false;
	
	var thumbnails = document.getElementById("magThumbs");
	var links = thumbnails.getElementsByTagName("a");
	var source = thumbnails.getElementsByTagName("img");
	
	// create a loop for going through each link and getting its href
	for (var i=0; i < links.length; i++)
	{
		links[i].onmouseover = function()
		{
			changeMainLink(this);
			return false;
		}
	}
	
	// create a loop for going through each image and getting its source
	for (var i=0; i < source.length; i++)
	{
		source[i].onmouseover = function()
		{
			changeMainImg(this);
		}
	}
}

// function to show the thumbnail and larger image
function changeMainImg(whichImg)
{
	if(!document.getElementById("mainImg")) return false;
	var imgSource = whichImg.getAttribute("src");
	var indx = imgSource.indexOf("?sURL");
	rawImgURL = imgSource.substring(indx);
	var mainImg = document.getElementById("mainImg");
	var mainImgSource = mainImg.getAttribute("src");
	indx = mainImgSource.indexOf("?sURL");
	imgScalerURL = mainImgSource.substring(0,indx);
	newMainImgSource = imgScalerURL + rawImgURL;
	mainImg.setAttribute("src", newMainImgSource);
}

// function to show the thumbnail and larger image
function changeMainLink(whichLink)
{
	if(!document.getElementById("magLink")) return false;
	var linkHref = whichLink.getAttribute("href");
	var magLink = document.getElementById("magLink");
	magLink.setAttribute("href", linkHref);
}
