// JavaScript Document
//var mysheet=document.styleSheets[0]
//var myrules=mysheet.cssRules? mysheet.cssRules: mysheet.rules
//for (i=0; i < myrules.length; i++)
//{
//  if(myrules[i].selectorText.toLowerCase()=="#variantForms .variantForms")
//  {
//      targetrule=myrules[i];
//      targetrule.style.position = "absolute; ";
//      break;
//  }
//}




function popOptionsArray() {
var inThere = false;
var arrOptions = new Array();
var arrVarOptions = new Array();
//arrVarOptions[0]=0;
var iObj = new Array();
var thisnode;
iObj = document.getElementById("variantImages").getElementsByTagName("div");
for (i=0;i<iObj.length; i++) 
    { 
        if (iObj.item(i).className.indexOf("variantImagesImage") >= 0)
            thisnode = iObj.item(i);
            thisnode.insize = "yep";
            if (iObj.item(i).sizes != null)
            {
                arrVarOptions = iObj.item(i).sizes.split(",");
                for (a=0;a<arrVarOptions.length; a++) 
                    { 
                     inThere = false;
                     for (b=0;b<arrOptions.length; b++) 
                         {  
                            //alert("arroptions:"+arrOptions[b]);
                            if (arrVarOptions[a].toLowerCase() == arrOptions[b].toLowerCase())
                            {inThere = true;}
                         }
                     if (!inThere) {arrOptions[arrOptions.length] = arrVarOptions[a];}
                    }
             }
         
    }
//document.forms['sizeOptionForm'].sizeOptionSelect.options[0] = new Option(SizeOptionPrompt,'All');
// populate the dropdown with sizes that are in stock

//for (i=0;i<arrOptions.length; i++) 
//                 {
//                    document.forms['sizeOptionForm'].sizeOptionSelect.options[i+1] = new Option(arrOptions[i],arrOptions[i]);
//                 }

//populate dropdown with all sizes
//for (i=0;inventVID[i] == inventVID[0]; i++)
//{
//    document.forms['sizeOptionForm'].sizeOptionSelect.options[i+1] = new Option(inventSize[i],inventSize[i]);
//}


//clear select box options that aren't available
var sObj;
  for (i=0;i<inventVID.length; i++)
    {
        if (inventQty[i] == 0)
        {
               
               sObj = document.getElementById("FProductPic"+inventVID[i]).getElementsByTagName("select");
               for (s=0;s<sObj.length; s++) {
                       if (sObj.item(s).className == "SizeText")
                            {
                               for (o=0;o<sObj.item(s).options.length; o++) {  
                                            if (sObj.item(s).options[o].text.toLowerCase() == inventSize[i].toLowerCase())
                                            {if (sObj.item(s).options[o].instock == null) {sObj.item(s).options[o].instock == false;} }
                            }
                       }
                }
           
        }
        else 
        {
               sObj = document.getElementById("FProductPic"+inventVID[i]).getElementsByTagName("select");
               for (s=0;s<sObj.length; s++) {
                       if (sObj.item(s).className == "SizeText")
                            {
                               for (o=0;o<sObj.item(s).options.length; o++) {  
                                            if (sObj.item(s).options[o].text.toLowerCase() == inventSize[i].toLowerCase())
                                            {sObj.item(s).options[o].instock = true;}
                            }
                       }
                }
        
        }
    }

sObj = document.getElementsByTagName("select");
for (s=0;s<sObj.length; s++) 
    {
       if (sObj.item(s).className == "SizeText")
            {
               sObj.item(s).style.display = "none";
               for (o=0;o<sObj.item(s).options.length; o++) {  
                            if (sObj.item(s).options[o].instock == false)
                            {sObj.item(s).options[o].instock = null;}
            }
       }
    }
               
}

popOptionsArray()

var thesize;

function showHideOptions() {

var iObj = new Array();
	    iObj = document.getElementById("variantForms").getElementsByTagName("div");
        for (i=1;i<iObj.length; i++) {  
            if (iObj.item(i).className == "variantForms")
                {       
                    iObj.item(i).style.display = "none";
                }  
        }
        iObj.item(0).style.display = "block";
        

var inThere = false;
theSize = document.forms['sizeOptionForm'].sizeOptionSelect;
theSize = theSize.options[theSize.selectedIndex].value;
var arrVarOptions = new Array();
var iObj = new Array();
var myEffect = new Array();
var thisnode;
iObj = document.getElementsByTagName("div");
for (i=0;i<iObj.length; i++) 
      {  
        if (iObj.item(i).className.indexOf("variantImagesImage") >= 0)
           {        
                inThere = false;
                if (iObj.item(i).sizes != null)
                {   
                        arrVarOptions = iObj.item(i).sizes.split(",");
                        for (a=0;a<arrVarOptions.length; a++) 
                            { 
                                if (arrVarOptions[a].toLowerCase() == theSize.toLowerCase() || theSize.toLowerCase() == "all")
                                {inThere = true;}
                            }
                            
                        if (inThere) 
                                {
                                    thisnode = iObj.item(i);
                                    if (thisnode.insize == "yep") {thisnode.insize = "yep"}
                                    else {  thisnode.insize = "yep";
                                            myEffect[i] = new fx.Opacity(thisnode , {duration: 500 });
                                            myEffect[i].hide();                  
                                            myEffect[i].custom(0,1);
                                         }
                                    
                                }
                        else 
                                {
                                    thisnode = iObj.item(i);
                                    if (thisnode.insize == "nope") {thisnode.insize = "nope";}
                                    else {  thisnode.insize = "nope"
                                            myEffect[i] = new fx.Opacity(thisnode , {duration: 500});
                                            myEffect[i].custom(1,0);
                                           }
                                 }  
                } 
                else 
                {
                    thisnode = iObj.item(i);
                    if (thisnode.insize == "nope") {thisnode.insize = "nope";}
                    else {  thisnode.insize = "nope"
                            myEffect[i] = new fx.Opacity(thisnode , {duration: 500});
                            myEffect[i].custom(1,0);
                           }
                }
            }
        }
        
   
pickedSize = true;
//document.getElementById("msg").style.color = "Orange";
//document.getElementById("msg").childNodes[0].nodeValue = "Viewing: ";
//document.getElementById("msgViewing").childNodes[0].nodeValue = theSize;
document.getElementById("instructions").style.color = "Black";
document.getElementById("instructions").style.fontWeight = "normal";
document.getElementById("instructions").style.border = "0px";
document.getElementById("instructions").childNodes[0].nodeValue = "Now viewing: "+theSize;
document.getElementById("instruction2").childNodes[0].nodeValue = "Click a swatch to view its details.";

}



function customAnimate() {
var iObj = new Array();

iObj = document.getElementById("variantImages").getElementsByTagName("img");
for (i=0;i<iObj.length; i++) 
    {
        iObj.item(i).onmouseover = switchOver;
        iObj.item(i).onclick = switchClick;
        iObj.item(i).onmouseout = switchBack;
    }
    
iObj = document.getElementById("variantForms").getElementsByTagName("div");
for (i=1;i<iObj.length; i++) {	   
	 if (iObj.item(i).className == "variantForms")
        {
        iObj.item(i).style.display = "none";
        }	
	}
}
var pickedSize;
customAnimate();

function switchOver() {
if (pickedSize)
    {
        var vID = this
        var vIDp = this.parentNode;
        vIDp.style.height = vID.offsetHeight + 'px';
        vID.style.position = "absolute";
        vID.style.width = "100px";
        vID.style.marginLeft = "-25px";
        vID.style.marginTop = "-25px";
        vID.style.borderWidth = "2px";
        vID.parentNode.style.zIndex = "10";


        vIDp.className += " viiOver";
        //vIDp.childNodes[1].style.bottom = (vID.offsetHeight * 0.75) + 'px';

        var iObj = new Array();
        iObj = document.getElementById("variantImages").getElementsByTagName("img");
        for (i=0;i<iObj.length; i++) 
            {  
                if (iObj.item(i) != vID) 
                {
                    iObj.item(i).style.width = "50px";
                    iObj.item(i).style.position = "relative";
                    iObj.item(i).style.margin = "0px";
                    iObj.item(i).style.borderWidth = "0px";
                    iObj.item(i).parentNode.style.zIndex = "1";
                    iObj.item(i).parentNode.style.height = iObj.item(i).offsetHeight + 'px';
                }
            }  
    }

}

function switchBack() {
var vID = this
vID.style.position = "relative";
vID.style.width = "50px";
vID.style.margin = "0px";
vID.style.borderWidth = "0px";
vID.parentNode.style.zIndex = "1";
vID.parentNode.className = vID.parentNode.className.replace(" viiOver", ""); 
}

function switchClick(){
if (pickedSize)
    {
        var vID = "F"+this.getAttribute("id");
        vID =   document.getElementById(vID);
        vID.style.display = "block"; 

        var iObj = new Array();
	    iObj = document.getElementsByTagName("div");
        for (i=0;i<iObj.length; i++) {  
            if (iObj.item(i).className == "variantForms" && iObj.item(i) != vID)
                {       
                       iObj.item(i).style.display = "none";
                }  
            if (iObj.item(i).className == "variantNowViewing")
                {       
                       iObj.item(i).childNodes[0].nodeValue = theSize;
                }  
        }
        
        
        
        var sObj;
         sObj = vID.getElementsByTagName("select");
               for (s=0;s<sObj.length; s++) {
                       if (sObj.item(s).className = "SizeText")
                            {
                               for (o=0;o<sObj.item(s).options.length; o++) {  
                                            //alert(sObj.item(s).options[o].text.toLowerCase() + " and " + theSize.toLowerCase());
                                            if (sObj.item(s).options[o].text.toLowerCase() == theSize.toLowerCase())
                                            {sObj.item(s).options[o].selected = true;}
                            }
                       }
                }
        
        
        
    }

else {
              document.getElementById("instructions").style.color = "#FF0000";        
        document.getElementById("instructions").style.fontWeight = "Bold";
        document.getElementById("instructions").style.border = "2px solid #FF0000";
        document.getElementById("instructions").style.padding = "5px";
        window.location.href = "#pickasize";
        //document.getElementById("msg").childNodes[0].nodeValue = "Please pick a size first.";
        //document.getElementById("msgViewing").childNodes[0].nodeValue = "";
        }
    
}
