/*editor:cls, updated:30.JUL.2008 
revisions:date:20.MAY.2008, edited: 05.JUN.2008 removed check for pf_id on swatchs
from pfID_red_sm.jpg to red_sm.jpg
	UniteU swatch Images
	MSR 10/26/07
	
*/




// Image array
var swatchImages = new Array();

//there are swatches
var swHeader = true;
function swatches()
{
	// Capture original main image
	var OriginalImage = document.getElementById("mainimg").src;
	
	// Configure image path
	var swatchPath = "assets/images/swatches/";	
	
	// Image views array
	var swatchViews = new Array();

	// Output buffer
	var swatch_Output = "";
	
	// If there are info attributes...
	if(info_attributes != "" && info_attributes.indexOf(":") != -1){
		
		// Split info attributes
		var InfoAttributes = info_attributes.split(",");
		
		// For each attribute...
		for(CurrentAttribute in InfoAttributes){
			
			// Add the view 
			swatchViews.push(InfoAttributes[CurrentAttribute].split(":"));
		}
	} else {
	
// if no swatches 	- used to remove header text in Prod page
    swHeader =false;
		
	} 
	
	// If there are swatch images...
	if(swatchViews.length > 0){
	
		// Start feature tag
		swatch_Output += "<!-- FEATURE BEGIN: SWATCHES -->";
		
		// Start div
		swatch_Output += "<div style='margin:4px 14px 10px 10px;' id='swatchImages-Container'>";
		
		// Start ul
		swatch_Output += "<table border=0 cellpadding=2 cellspacing=2>";
		
		// For each view...
		for (i=0; i < swatchViews.length; i++)
		{	
		
			// Setup the corresponding images
            /* old version add pf_id to look for images new just looks for image color ex. red_sm.jpg
            */
            swatchImages[i] = new swatchImageObject(swatchPath + swatchViews[i][1] + "_sm.jpg", swatchPath + pf_id + "_" + swatchViews[i][1] + "_lg.jpg", swatchViews[i][0]);
            
            
			//swatchImages[i] = new swatchImageObject(swatchPath + swatchViews[i][1] + "_sm.jpg", swatchPath + pf_id + "_" + swatchViews[i][1] + "_lg.jpg", swatchViews[i][0]);
	
			// Show a link
			swatch_Output += "<tr><td align=center class='altImg'>";
			swatch_Output += "<a href=\"javascript:;\" onClick=\"ShowLgImage('" + swatchImages[i].ImageURL + "')\" >";
			swatch_Output += "<img name=\"" + swatchImages[i].Label + "\" id=\"" + swatchImages[i].Label + "\" src=\"" + swatchImages[i].ThumbImageURL + "\" onerror=\"getElementById('" + swatchImages[i].Label + "').style.display ='none'; HideOnNoswatchImages();\" border=0 >";
			swatch_Output += "</a><br>" + swatchImages[i].Label;
			swatch_Output += "</td></tr>";
		}
	
		// End ul
		swatch_Output += "</table>";
	
		// End div
		swatch_Output += "</div>";
	
		// End feature tag
		swatch_Output += "<!-- FEATURE END: swatch Images -->";
		
		// Show output
		document.write(swatch_Output);
	
	}
	
}
function HideOnNoswatchImages(){
	
	// If there are no swatch images...
	if(NoswatchImages()){
		
		// Hide the swatch images container
		document.getElementById("swatchImages-Container").style.display = "none";
	}
}

function NoswatchImages(){
	
	// For each swatch image label...
	for(CurImage in swatchImages){
		
		// If the image is loaded/visible...
		if(document.getElementById(swatchImages[CurImage].Label).style.display != "none"){
			
			return false;
		}
	}
	
	return true;
}

function ShowLgImage(ImageURL){

	// Change the main image to ImageURL
	document.getElementById("mainimg").src = ImageURL;
}

function seeoriginal(){
	document.getElementById('mainimg').src = "assets/product_images/" + product_image[1].image;
}

function swatchImageObject(ThumbImageURL, ImageURL, Label){

	// swatchImage constructor
	this.ThumbImageURL = ThumbImageURL;
	this.ImageURL = ImageURL;
	this.Label = Label;
}

