// product pages functions
var lastRand;

function doPreload()
{
	var theImages = document.getElementsByTagName("img");
    for (var img in theImages)
    {
        newImage = new Image();
        newImage.src = img.src;
        img = newImage;                
    }
}

function prodShot(ref){	
	theImg = document.images['productShot'];
	theImg.src = 'images/'+root+ref+ext;
}

function showHide(e, element){	
	var el = document.getElementById(element);
	if (el.className == 'hide')
	{       	
        el.style.top =  e.clientY + getYOffset() - 30 + "px";
        el.style.left = e.clientX + 20 + "px";
        
        el.className = 'show';
	}
	else if (el.className == 'show' || el.style.display == 'none')
	    el.className = 'hide';		
}

function getYOffset()
{
    var scrOfY = 0;
      
    if (typeof( window.pageYOffset ) == 'number') 
        scrOfY = window.pageYOffset;
    else if (document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) 
        scrOfY = document.body.scrollTop;
    else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) 
        scrOfY = document.documentElement.scrollTop;
    
    return scrOfY;
}

/* 'randomly' swap the src of an image with name equal to var setName */
function swapRand(){
    var image = document.getElementById("productBlurb");
    if (image)
    {
        var randNum = Math.floor(Math.random() * 7) + 1;
	    if (lastRand == randNum) 
	        swapRand();
	    lastRand = randNum;
	    image.src='img/products/productLanding/productLanding' + randNum + '.jpg';
	}
}

function swapImg(name, src)
{
    var image = document.images[name];
    image.src = src;
}