package gov.nih.nci.ncia.util;

import gov.nih.nci.ncia.search.ImageSearchResult;

import java.util.List;

public class SlideShowUtil {
	public static String getImageSeriesJavascript(
			List<ImageSearchResult> thumbnailList) {
		StringBuffer js = new StringBuffer("[");
		for (int i = 0; i < thumbnailList.size(); i++) {
			ImageSearchResult image = thumbnailList.get(i);
			int frameSize = image.getFrameNum().intValue();

			if (frameSize <= 1) {
				String tnURL = "'"+image.getThumbnailURL()+"'";
				js.append(tnURL);
			}
			if (frameSize > 1) {
				for (int j = 0; j < frameSize; ++j) {
					if (frameSize > 1) {
						js
								.append("'" + image.getThumbnailURL() + "-" + j
										+ "'");
						if (j != frameSize - 1) {
							js.append(',');
						}
					}
				}
			
			}
			if (i != thumbnailList.size() - 1) {
				js.append(',');
			}

		}
		js.append(']');
		//System.out.println("java script:" + js.toString());
		return js.toString();
	}
}

@@ -385,21 +385,25 @@
 %0A%09%09%09
-i
+I
 nt
+eger
  frame
-Size
+NumI
  = i
@@ -420,16 +420,71 @@
 ameNum()
+;%0D%0A%09%09%09int frameSize = (frameNumI==null) ? 0 : frameNumI
 .intValu
@@ -598,28 +598,33 @@
 ;%0D%0A%09%09%09%7D%0D%0A%09%09%09
-if (
+else %7B //
 frameSize %3E 
@@ -620,27 +620,24 @@
 rameSize %3E 1
-) %7B
 %0D%0A%09%09%09%09for (i
@@ -673,53 +673,17 @@
  %7B%0D%0A
-%09%09%09%09%09if (frameSize %3E 1) %7B
 %0D%0A%09%09%09%09%09
-%09
 js
-%0D%0A%09%09%09%09%09%09%09%09
 .app
@@ -692,16 +692,27 @@
 d(%22'%22 + 
+%0D%0A%09%09%09%09%09%09%09  
 image.ge
@@ -733,36 +733,57 @@
 ) + 
+%0D%0A%09%09%09%09%09%09%09  
 %22-%22 + 
-j
 %0D%0A%09%09%09%09
+%09%09%09  j +%0D%0A
 %09%09%09%09%09%09
-+
+%09 
  %22'%22);%0D%0A
 %09%09%09%09
@@ -774,25 +774,24 @@
 %09%09%09  %22'%22);%0D%0A
-%09
 %09%09%09%09%09if (j !
@@ -812,25 +812,24 @@
 1) %7B%0D%0A%09%09%09%09%09%09
-%09
 js.append(',
@@ -829,25 +829,24 @@
 pend(',');%0D%0A
-%09
 %09%09%09%09%09%7D%0D%0A%09%09%09%09
@@ -849,19 +849,9 @@
 %09%09%09%09
-%09%7D%0D%0A%09%09%09%09%7D%0D%0A
+%7D
 %09%09%09%0D
@@ -925,18 +925,16 @@
 %0D%0A%09%09%09%7D%0D%0A
-%0D%0A
 %09%09%7D%0D%0A%09%09j

simplify logic and handle null frameNum