$(function() {
		// sets current tab;
		$(".tabs li a").each(function(i) {
			$(this).click(function() {
				tabSwitch(i); 
				this.blur();
				return false;
			});
		});
		if (document.getElementById("tabcontent1")) {
			tabSwitch(currTab-1); // sets first tab if tab content exists
		}

		// color mouseover; attaches mouseover event to select color li's
		$("#selector li a").each(function(i) {
			$(this).mouseover(function() {
				changeImg(i); 
				var c = theImages[i][2]; // currency variable
				var p = theImages[i][3]; // price variable
				var n = theImages[i][1]; // pn variable 
				//$(".pn").empty().append("PN "+n); // place new part number
				//$(".purchase h2").empty().append("<span>"+c+"</span> "+p); // place new price.  To solve font issue: (c+" "+p)
				$(".purchase input").val(n); // put part number in hidden form field
			});
		});
		if (document.getElementById("selector")) {
			changeImg(currColor); // sets current color swatch and image if options exist
		}
});

// product details color image swap		
function changeImg(x){
	if(document.getElementById('clrs') != undefined) {
		// change the value following "&retailers=" in the href to match the moused-over color
		var temp = document.getElementById('clrs').href; 
		temp = temp.substr(0,temp.length-1);
		temp += parseInt(x)+1;  // x is the currentrow in the commerce query results; in JS, x starts at 0, and we have to start at 1
		document.getElementById('clrs').href = temp;
	}
	document.getElementById('img_color').src = theImages[x][0]; // grab first item in multidimensional array	 
	document.getElementById('p_href').href = theHrefs[x];
	document.getElementById('part').innerText = thePNs[x];
	document.getElementById('part').textContent = thePNs[x];
}

// image gallery scripts; changes images and current number
var curGal = 0;
var curSrc = "";
function nextImg() {
	if (curGal < theGallery.length-1) {
		curGal = curGal+1;
		}
	else {
		curGal = 0;
		}
	curSrc = theGallery[curGal];
	//document.getElementById('testsrc').innerHTML = curSrc; //for testing
	document.getElementById('curNum').innerHTML = curGal+1;
	document.getElementById('galleryImage').src = curSrc;
}

function prevImg() {
	if (curGal != 0) {
		curGal = curGal-1;
	}
	else {
		curGal = theGallery.length-1;
	}
	curSrc = theGallery[curGal];
	//document.getElementById('testsrc').innerHTML = curSrc; //for testing						
	document.getElementById('curNum').innerHTML = curGal+1;
	document.getElementById('galleryImage').src = curSrc;
}

// tab switcher
function tabSwitch(num) {
	currTab = num+1;
	document.getElementById('content_body').className = "tabon-"+currTab;			
}
