// Fancybox with Multi Product Images tweaks V4.00
function setlbimage(anc, seq, swap, image_set){	// called when icon clicked - swap main image and remember setting
	anc = 'im-' + anc;
	if ( document.getElementById(anc) ) 
		{
		document.getElementById(anc).src = swap;
		seq++;
		document.getElementById(anc).onclick = function() { GB_showImageSet(image_set, seq) };
		}
}

function gb_setimage(img, anc){			// called when product image mouseovered - set style and onclick
	if( eval('window.gbset_' + anc) &&  (! img.onclick) )	// if image set defined and first mouseover
		{
		img.style.cursor = 'pointer';
		img.onclick = function() { GB_showImageSet(eval('window.gbset_' + anc), 1) }
		}
}

function auxbutton(anc){			// called from auxiliary expand button - fire off image onclick event
	imgid = 'im-' + anc;
	if ( document.getElementById(imgid) ) 	
		{
		var mainimg = document.getElementById(imgid);
		gb_setimage(mainimg, anc);	// in case this is first call - setup main image onclick
		if ( mainimg.onclick ) mainimg.onclick();
		}
}

function GB_showImageSet(image_set, seq){	// convert Greybox call to to Fancybox one
	var fancyset = new Array();
	// v10.0.3 fix path name if Previewing
	var path = (location.href.indexOf('PreviewHTML') > -1) ? document.getElementById('fb_js').src.replace(/fancyboxwithmultiimagesupport\.js/, '') : '';
	for (var i=0; i<image_set.length; i++) fancyset.push({'href' : path + image_set[i].url, 'title' : image_set[i].caption});
	$.fancybox(fancyset, {'index' : seq - 1, 'cyclic' : true, 'titleFormat' : formatTitle});
}

function formatTitle(title, currentArray, currentIndex, currentOpts) {		// override normal "outside" title to include image sequence
	return   ('<table id="fancybox-title-float-wrap" cellpadding="0" cellspacing="0"><tr><td id="fancybox-title-float-left"></td>'
		+ '<td id="fancybox-title-float-main">' + title + '<span style="color:silver"> - Image ' + (currentIndex + 1) + ' of ' + currentArray.length + '</td>'
		+ '<td id="fancybox-title-float-right"></td></tr></table>');
}

