﻿    var imgMousedOver = false;
    var divMousedOver = false;
    
    function hideElem( inElemID ) {
        $get(inElemID).style.visibility = "hidden";
       }


    function ShowColors(inElemID, targetID, imgSrc, catalog, product, inEvent) {
        
        if( typeof( inEvent ) == "undefined" && typeof( window.event ) != "undefined" )
            inEvent = window.event;
            
        var sender = (typeof( window.event ) != "undefined" ) ? inEvent.srcElement : inEvent.target;
	    var xcord = getPositionLeft(sender) ; 
	    var ycord = getPositionTop(sender);
	    var objRegion = YAHOO.util.Dom.getRegion(sender);
	    xcord = objRegion.left;
	    ycord = objRegion.top;
	    Nygard.com.CatalogWebService.GetProductSwatches(catalog, product, function(result) {
	        var Swatches = result.getElementsByTagName("Swatch");
	        $get(inElemID).innerHTML = "";

	        if (Swatches.length > 1) {
	            $get(inElemID).style.visibility = "visible";
	            var holder = document.createElement("table");
	            holder.style.backgroundColor = "white";
	            holder.style.border = "1px solid #A9A9A9";
	            var tblbody = document.createElement("tbody");
	            holder.appendChild(tblbody);
	            var tr = document.createElement("tr");
	            tblbody.appendChild(tr);

	            for (var i = 0; i < Swatches.length; i++) {
	                if (i > 0 && i % 2 == 0) {
	                    tr = document.createElement("tr");
	                    tblbody.appendChild(tr);
	                }
	                var td = document.createElement("td");
	                if (i == Swatches.length - 1 && Swatches.length % 2 == 1) {
	                    td.setAttribute("colSpan", "2");
	                    td.setAttribute("align", "center");
	                }

	                var link = document.createElement("a");
	                if (Swatches[i].attributes.getNamedItem("SwatchURL") == null) { continue; }
	                var colPosition = Swatches[i].attributes.getNamedItem("SwatchURL").value.indexOf("COL=") + 4;
	                if (colPosition > 4) {
	                    link.setAttribute("href", "javascript:change_image('" + targetID + "', null, '" + Swatches[i].attributes.getNamedItem("SwatchURL").value.toUpperCase().substring(colPosition, colPosition + 3) + "')");
	                }
	                var img = document.createElement("img");
	                img.setAttribute("border", 1);
	                img.style.borderColor = "silver";
	                img.setAttribute("src", Swatches[i].attributes.getNamedItem("SwatchURL").value);
	                img.setAttribute("alt", Swatches[i].attributes.getNamedItem("Color").value);
	                link.appendChild(img);
	                td.appendChild(link);
	                tr.appendChild(td);
	            } 
	            $get(inElemID).appendChild(holder);
	            YAHOO.util.Dom.setXY($get(inElemID), [(xcord + 110), ycord]);
	        } 
	    });  
    }
    
    function divOnMouseOver( ) {
        divMousedOver = true;
        window.status='';
        return true;
    }
    
    function divOnMouseOut( ) {
        divMousedOver = false;
    }
    
    function imgOnMouseOut( ) {
        // this timeout effectively flips the order in which the mouseover event for the swatch and mouseout event for the image occurs
        setTimeout("if (!divMousedOver) hideElem('floatingMsgBox');", 1);
    }

    