/*	Functions
	writeList: write out strip of thumbnails for browsing discovery items
	moveNext: functions to move forward through list of discovery items
	movePrevious: functions to move back through list of discovery items

	Variables 
	iURL: array of URLs for discovery item landing pages
	iDisplay: display state of thumbnail in strip (on = inline, off = none)
	iSRC: array of source path for thunbnail image file of discovery items
	iALT: array of alternative text for image of discovery items
	display Count: # of discovery items to display in the strip
	itemTotal: # of discovery items in list
	firstFound: boolean variable used to identify when first visible item in list is encountered
	itemCount: used to keep track of items while looping through the list
*/	

//Variable Arrays with Discovery Item Details
var iURL = new Array("soft_skin_adhesive.aspx","silicone_tubing.aspx","silicone_gels.aspx","conformal_coatings.aspx","silicone-modified_plastics.aspx","silicone_rubber.aspx","silicone_valves.aspx","antimicrobial_silicone_coatings.aspx","weather_resistant_textiles.aspx","screen-printing_silicone.aspx","impact_protection.aspx","silicone_foam.aspx","hot-melt_silicone.aspx","anti-fingerprint_silicone_coating.aspx");

var iSRC = new Array("stick-thumb.jpg","bend-thumb.jpg","dampen-thumb.jpg","grip-thumb.jpg","both-thumb.jpg","shape-thumb.jpg","flow-thumb.jpg","odor-thumb.jpg","breathe-thumb.jpg","stretch-thumb.jpg","softie-thumb.jpg","cushy-thumb.jpg","bond-thumb.jpg","clean-thumb.jpg");

var iALT = new Array("Soft Skin Adhesive","Silicone Tubing","Silicone Gels","Conformal Coatings","Silicone-Modified Plastics","Silicone Rubber","Silicone Valves","Antimicrobial Silicone Coatings","Weather Resistant Textiles","Screen-Printing Silicone","Flexible Impact Protection","Silicone Foam","Hot-Melt Silicone","Anti-Fingerprint Silicone Coating");


//Variables to control thumbnail strip
var itemTotal = iURL.length;
var displayCount = 7;


function writeList(itemName) {
	//Code to Write out Strip of Thumbnails
	document.write("<div style='padding-left: 3px; background-color: #ECEAE4; padding-right: 0px; padding-top: 4px; padding-bottom: 2px;'>");	
	document.write("	<img style='display: inline; cursor: pointer; border: 0px;' src='/images/design/cards/first.gif' width='20' height='46' alt='Move to First Item' onClick='moveFirst();' />");
	document.write("	<img style='display: inline; cursor: pointer; border: 0px;' src='/images/design/cards/previous.gif' width='20' height='46' alt='Move to Previous Item' onClick='movePrevious();' />");
	
	//Reset variables to default
	var itemCount = 0;
	var itemNum = null;
	var iStyle = "border: 1px solid #FFFFFF;";
	
	//Find location of item in array
	for(i=0; i<itemTotal; i++) {
		if(iALT[i]==itemName)
			itemNum = i;
	}

	//Check to ensure that strip has right number of items (displayCount value)
	var iCheck = itemTotal - itemNum;
	if((iCheck < displayCount) && (iCheck > 0)) {
		iCheck = -1 * (displayCount - iCheck -1);
	} else {
		iCheck = 0;
	}

	itemStart = itemNum - 1;
	for(i=0; i<itemTotal; i++) {
		if((i<itemStart + iCheck) || (itemCount >= displayCount)) {
			iDisplay = "none"
		} else {
			iDisplay = "inline"
			if(i == itemNum) {
				iStyle = "border: 1px solid #CC3300;";
			} else {
				iStyle = "border: 1px solid #FFFFFF;";
			}
			itemCount = ++itemCount;
		}
		document.write("	<a href='" + iURL[i] + "'><img style='display: " + iDisplay + "; " + iStyle + "'  src='/images/design/cards/" + iSRC[i] + "' width='50' height='46' alt='" + iALT[i] + "' name='thumb" + (i+1) + "' /></a>");
	}

	document.write("	<img style='display: inline; cursor: pointer; border: 0px;' src='/images/design/cards/next.gif' width='20' height='46' alt='Move to Next Item' onclick='moveNext();' />");	
	document.write("	<img style='display: inline; cursor: pointer; border: 0px;' src='/images/design/cards/last.gif' width='20' height='46' alt='Move to Last Item' onclick='moveLast();' />");	
	document.write("</div>");
}

function moveNext() {
	//Reset variables to default
	var firstFound = "no";
	var itemCount = 0;
	
	for(i=1; i<=itemTotal; i++) {
		if ((document.images['thumb'+i].style.display == "inline") && (firstFound == "no") && (i <= itemTotal-displayCount)) {
			document.images['thumb'+i].style.display = "none";
			firstFound = "yes";
			itemCount = 1;
		} else {
			if ((itemCount <= displayCount) && (firstFound == "yes")) {
				document.images['thumb'+i].style.display = "inline";
				itemCount = ++itemCount;
			} else {
				if (i <= itemTotal-displayCount)
					document.images['thumb'+i].style.display = "none";
			}
		}
	}		
}

function movePrevious() {
	//Reset variables to default
	var displayCount = displayCount - 1;
	var displayCount2 = 0;
	var firstFound = "no";
	var itemCount = 0;
	
	for(i=1; i<=itemTotal; i++) {
		if (document.images['thumb'+i].style.display == "inline")
			displayCount2 = ++displayCount2;
	}
	if(displayCount2 < displayCount)
		displayCount2 = ++displayCount2;
	
	for(i=itemTotal; i>0; i--) {
		if ((document.images['thumb'+i].style.display == "inline") && (firstFound == "no") && (i > displayCount2)) {
			document.images['thumb'+i].style.display = "none";
			firstFound = "yes";
			itemCount = 1;
		} else {
			if ((itemCount <= displayCount2) && (firstFound == "yes")) {
				document.images['thumb'+i].style.display = "inline";
				itemCount = ++itemCount;
			} else {
				if (i > displayCount2)
					document.images['thumb'+i].style.display = "none";
			}
		}
	}		
}

function moveFirst() {
	for(i=1; i<=itemTotal; i++) {
		if (i<=displayCount) {
			document.images['thumb'+i].style.display = "inline";
		} else {
			document.images['thumb'+i].style.display = "none";
		}
	}			
}

function moveLast() {
	var lastItem = itemTotal - displayCount;
	for(i=itemTotal; i>0; i--) {
		if (i>lastItem) {
			document.images['thumb'+i].style.display = "inline";
		} else {
			document.images['thumb'+i].style.display = "none";
		}
	}
}
