window.onload = function(){
	init();
	//doIE6NavFix();
}

function init(){
	if (document.getElementById("scrollobj")){
		c=document.getElementById("scrollobj").childNodes;
		for(i=0;i<c.length;i++){
			if (c[i].nodeName == 'DIV'){
				counter = (c[i].childNodes.length / 2);
				//IE sees childNodes[2] as the link, others see [1]:
				if (c[i].childNodes[2].nodeName == 'A') imgW = c[i].childNodes[2].childNodes[0].width;
				if (c[i].childNodes[1].nodeName == 'A') imgW = c[i].childNodes[1].childNodes[0].width;
			}
		}
		if (! imgW) imgW = 131;
		imgW = imgW + 5 // add margin;
		maxWidth = (imgW * counter);
		document.getElementById("scrollobj").style.width = maxWidth+'px';
	}
}

function doIE6NavFix(){
	if (navigator.userAgent.indexOf('MSIE 6') != -1){
		if (document.getElementById('productContent')){
			divs = document.getElementById('productContent').getElementsByTagName('div');
			for(i=0;i<divs.length;i++){
				divs[i].onmouseover = function(){
					this.className = 'productCell over';
				}
				divs[i].onmouseout = function(){
					this.className = 'productCell';
				}
			}
		}
	}
}


function scroll(dir){
	objLeft=parseInt(document.getElementById("scrollobj").style.left);
	if (! objLeft){
		objLeft=0;
	}
	if (dir=="l"){
		if (objLeft > (800-maxWidth)){
			objLeft=objLeft-10;
		}
		scrollTimeOut = setTimeout("scroll('l')",1);
	} else if (dir=="r"){
		if (objLeft < 0){
			objLeft=objLeft+10;
		}
		scrollTimeOut = setTimeout("scroll('r')",1);
	} else {
		clearTimeout(scrollTimeOut);
	}
	document.getElementById("scrollobj").style.left=objLeft+"px";
}

function showGallery(img){
	c = document.getElementById('productContent').getElementsByTagName('div');
	for(i=0;i<c.length;i++){
		if (c[i].className.indexOf('photoCell') >=0) c[i].style.border='1px solid #fff';
	}
	document.getElementById("largeImage").src="gallery_images/"+img;
}
