// JavaScript Variables that will be referenced in the viewer initialization and viewer argument list.

/**
 * This needs to match the ID and NAME in the flash initialization below. This is generated randomly
 * dependant on curent time in order to prevent multiple page instances from interfering with each other
 * by having the same instance name declared
 */
var myName=genInstance();

var flashvars = {
}; 

// Setup param tag elements for the flash object to embed in the page 
var params = {
  allowScriptAccess: "Always",
  menu:              "false",
  quality:           "high",
  scale:             "noscale",
  salign:            "LT",
  bgcolor:           "#FFFFFF",
  wmode:             "transparent"
};  

// Setup object tag elements for the flash object to embed in the page
var attributes = {
  id:    myName,
  name:  myName
};

var viewerUrl = "";  //Build Viewer Path to Viewer swf
viewerUrl += S7Config.isViewerRoot;
viewerUrl += "flash/" + viewerType + ".swf?";
viewerUrl += "&serverUrl=" + S7Config.isRoot;
viewerUrl += "&contentRoot=" + S7Config.skinsRoot;
viewerUrl += "&instanceName=" + myName;
viewerUrl += "&image=" + ImageName;
//viewerUrl += "&transition=" + flyoutTransitionMode;
viewerUrl += "&config=" + configName;
//viewerUrl += "&border=ffffff,-5";
//viewerUrl += "&tips=Hover mouse cursor over this image to bring up the zoom view, Mouse out of the image to close the zoom view,black,9,Verdana"; //Text may be displayed at the bottom of the main view to provide a hint the user that hovering the cursor over the image will provide a magnified view. The text area is filled with the color specified with border=.  tips = normString, activeString [ , fontColor [ , fontSize ] ]
viewerUrl += "&flyout=410,293,340,27"; //Specifies the pixel size and position of the flyout window  flyout = wid , hei [ , left , top ]
viewerUrl += "&wmode=transparent";

function flyoutAlt(obj, iID) {

	var i ="";  //Iterator for the main for loop
	var x=0;  // conditional variable for the while loop is always set as the index of the next semi colon (indicating another image in the image set) in the json response currently evaluated
	var y=0;  // variable set to the index of the next comma in the json response evaluated
	var z=-1;
	var altImagesFound = false;  
                                              
      
	for (i = 0 ; i < iID; i++){
		z += imagset_index[i];
	}
      
	var altView="";
	var retstr="<div id='altImages'>";
	for (i in obj){                               //Step through the imageset JSON array in a for loop
		x=obj[i].indexOf(";",0);        //  Look for the first occurence of ; which denotes a swatch image
		y=obj[i].indexOf(",",0);        //  Look for the first occurence of , which denotes an alternate image
		if (y==-1) {                         //  If there are no specified swatch images 
			y=obj[i].length;              //  Set the y index to the end of the array
		}
		
		if(x != -1) // Alt images found
		    altImagesFound = true;
                
		while (x>0)                       //Start a while loop to go through each JSON response  loop is active as long as there's a , in the json response 
		{  
			z++;                             //Increment the counter that's used to reference the position in the altImageUrl array
			//appl y formats  to initial  image
			if(z == 0)
            {
				altView = ImageName;             
				altParams =  "&wid=50&hei=50&$altimage$";
				altViewName  = escape(ImageName);
			}
			else
			{
				altView=obj[i].substring(x+1,y);
				altParams = "?wid=50&hei=50&$altimage$";
				altViewName  = altView  + "?$feature-large$" ;
			}
			 //take the first character after the comma up to the character before the semi colon in the json response
			altView=S7Config.isRoot + '/' +altView;               //complete the image path with server url and company info
			altImageURL[z]=altView;                                          //append this full url path to the alt view image to an array
                                
			retstr=retstr + '<img src="' + altView + altParams + '" onclick="setImage(\''+altViewName+'\', myName)"/>';           //setup the response that would go into the page for the swatch images
			
			
			x=obj[i].indexOf(";",y);                    //x is incremented to the next occurence of a comma that comes after the occurence of a semi-colon.  If there is no other comma then kick out of the while loop and return
			y=obj[i].indexOf(",",y+1);
			if (y==-1) {
				y=obj[i].length;
			} 

		}
	}
	retstr = retstr + "</div>";
	
	if(altImagesFound)
	    retstr = retstr + '<div class="altImagesText">Click to see additional views</div>';
	         
	return retstr;
}


// Hide any dropdowns to make IE6 happy
function s7onFlyoutStart(id, wid, hei){
  $('#content .right .details select').each(function () {
    var $this = $(this);
    $this.data('visibility', $this.css('visibility'));
    $this.css('visibility', 'hidden');
  });
}

// Show any dropdowns that were hidden
function s7onFlyoutEnd(id, wid, hei){
  $('#content .right .details select').each(function () {
    var $this = $(this);
    $this.css('visibility', $this.data('visibility'));
  });
}


//Global variables referencd by the methods and functions in this page
var baseURL = S7Config.isRoot + '/' + companyName + '/';
    
var imagset_test = new Object;  //Global variable first used to hold the IPS ID's of all the image sets passed to the page, then after initialization to hold the json responses for each image set listing the images in the set
var altImageURL= new Object;  //used to store image path information for the alternate images
var parentSwatches = '';
   
//Page initialization all methods necessary to parse imageset information from the url, generate a list of initial swatches, and perform the necessary JSON requests to load arrays of image information are included in the initialization.js file
var imageName = initializeJSON(imagesets); //call that starts processing from a comma separated list of imagesets, this is used to also generate the image argument that is passed to the viewer which is just a comma separeted list of company/imageset to load

var imagset_index=new Array();
imagset_index=countAltsinSets(imagset_test);
