
function hoodCalcs(){

// this hood can only be attached if there is no neckline drop. 
// its knit from side to side, and must have the same hem depth as the body of the sweater.

hoodRows=2*(neckRowsP1+2+ halfTopSleeveRows+2)+RCextraBit; // the four are the final shape rows in eachraglan region.

edgeLength= divide(hoodRows, p.mainRowIn.value);
hoodRows=Math.round(hoodRows/2)*2; // Neck edge includes those two final rows.

minHoodWidth=Math.ceil( divide(hoodRows+1, p.mainRowIn.value) *1.07*10)/10; p.minHoodWidth.value=minHoodWidth;// this is half.
maxHoodWidth=Math.floor(divide(hoodRows-1, p.mainRowIn.value)*2*10)/10; p.maxHoodWidth.value=maxHoodWidth;

twiceHoodRows=2*hoodRows;


if(custom==0 ){
    hoodHeight= 8.2 + divide(p.chest.value,9);
    p.hoodHeight.value = Math.round(hoodHeight*10)/10;
    p.hoodWidth.value= Math.round(hoodHeight*  12.2/13*10)/10; // this is really half.

    }
p.hoodWidth.value=Math.max(minHoodWidth, p.hoodWidth.value); // this is really half.
p.hoodWidth.value=Math.min(maxHoodWidth,eval(p.hoodWidth.value));
    
hoodHeight=eval(p.hoodHeight.value);
hoodNeedles=Math.ceil(mult(hoodHeight,p.mainStIn.value));
shortHoodNeedles=Math.ceil(hoodNeedles/15);

totalRows=Math.round( mult(p.hoodWidth.value,p.mainRowIn.value)/2 ) * 2;// must be even.

extraRows=Math.min(totalRows-hoodRows, hoodRows-2); // make sure rounding up  never screws things up.
totalRows=hoodRows+extraRows;
extraTimes=extraRows/2;
 
totalRows=hoodRows+extraRows; totalRowsM1=totalRows-1; 
// calculate short rows.
halfHood = (hoodRows-2)/2;

smallHoodRows=2* Math.floor(halfHood/extraTimes); smallHoodRowsP2=smallHoodRows+2;
largeHoodRows=2* Math.ceil(halfHood/extraTimes); largeHoodRowsP2= largeHoodRows+2;


firstHoodRows=Math.round(Math.floor(smallHoodRows/4)*2) +2;firstHoodRowsP2=firstHoodRows+2;

largeHoodTimes=halfHood%extraTimes
smallHoodTimes=extraTimes-largeHoodTimes-1;

rowCountHood1=firstHoodRowsP2+largeHoodRowsP2*largeHoodTimes;
rowCountHood2 = rowCountHood1+smallHoodRowsP2*smallHoodTimes
leftOver= (hoodRows+extraRows)-rowCountHood2;leftOverP2=leftOver+2;

rowCountHood22 =leftOverP2 + smallHoodRowsP2*smallHoodTimes;
rowCountHood12=rowCountHood22 + largeHoodRowsP2*largeHoodTimes;

seamHoodNeedles= mult( edgeLength, p.mainStIn.value);
topSeamNeedles=mult(p.hoodWidth.value,p.mainStIn.value);

//alert(seamHoodNeedles +"  :  "+topSeamNeedles )

halfSeamHoodNeedles= Math.round(topSeamNeedles);
seamHoodNeedles = Math.round(2*seamHoodNeedles);


if( (extraTimes < 1) || (2 < shortHoodNeedles)){ warning +="Use finer yarn to knit a hood for this size"; }

}

function hoodDirections(){
stuff ="";
stuff +="<h2>Knit Hood<\/h2>";
stuff +="The top of the hood is on the right hand side of the machine and will be seamed; the seam will be "+p.hoodWidth.value+" inches wide. The part that attaches to the "+edgeLength+ " inch long neck edge of the sweater is on the left.  The cast on and bind off edges frame the wearer's face and will be " +p.hoodHeight.value+ " inches tall.";
// hung hem.  Note that this option only makes sense if they aren't workign a Vneck. I'm using it for my hoodie.
 stuff +=" <ol><li>Set row counter to zero (RC=0).  Begin COR (carriage on right.) Raise "+ hoodNeedles +" needles to work position, if you are working a button band, e-wrap or latchtool cast on. If you are hanging a hem, work a provisional cast on so you can hang the hem.";

    if( 0 < hemRows){
	stuff +="<li>Set carriage tension one setting lower than for main portion of knitting. Knit to RC = " + hemRows + " rows ending COR (carriage on right).  Hang hem or mark to sew later.<br><\/li><li>Set row counter to zero. RC=0<br><\/li>";  	   
    }

 patternWindow.document.writeln(stuff);  stuff ="";
  stuff +="<li>You will knit " + hoodRows + " full rows and "+ extraRows + " partial rows, mark the center, and then  mirror the shaping. <\/li> ";
 stuff +="<li>Set carriage tension to main tension. Begin COR; set carriage to hold (for partial knitting). <\/li> ";
 stuff +=" <li>Knit "+ firstHoodRows +" rows; COR. Move " + shortHoodNeedles +" needles on left side of bed to NWP (E), knit 1 row, wrap , knit 1 row. Move needles in NWP to UWP so the knit on the next pass. (COR, RC= "+firstHoodRowsP2 + ")<\/li>";

if( 0<largeHoodTimes){ 
    stuff +=" <li>Do the following " + largeHoodTimes + " times: Knit " + largeHoodRows + " rows;  move " + shortHoodNeedles +" needles on left side of bed to NWP (E), knit 1 row, wrap , knit 1 row. Move needles in NWP to UWP. (COR, RC= " + rowCountHood1 + "). <\/li>";
 }
 if( 0<smallHoodTimes){
    stuff +="<li>Do the following " + smallHoodTimes + " times: Knit " + smallHoodRows + " rows;  move " + shortHoodNeedles +" needles on left side of bed to NWP (E), knit 1 row, wrap , knit 1 row. Move needles in NWP to UWP. (COR, RC= "+ rowCountHood2 +" ). <\/li>"; 
 }
   stuff +="<li>Knit "+ leftOver + " rows. (COR, RC = "+ totalRows +"). Mark center back. Set row counter to zero.<hr><\/li>"; 
   
// mirror   

    stuff +="<li>Knit "+ leftOver + " rows. Move " + shortHoodNeedles +" needles on left side of bed to NWP (E), knit 1 row, wrap , knit 1 row. Move needles in NWP to UWP so the knit on the next pass. (COR, RC = "+ leftOverP2 +").<\/li>"; 

 if( 0<smallHoodTimes){  
    stuff +="<li>Do the following " + smallHoodTimes + " times: Knit " + smallHoodRows + " rows;  move " + shortHoodNeedles +" needles on left side of bed to NWP (E), knit 1 row, wrap , knit 1 row. Move needles in NWP to UWP. (COR, RC= "+ rowCountHood22 +" ). <\/li>"; 
    }
    
if( 0<largeHoodTimes){ 
    stuff +=" <li>Do the following " + largeHoodTimes + " times: Knit " + largeHoodRows + " rows;  move " + shortHoodNeedles +" needles on left side of bed to NWP (E), knit 1 row, wrap , knit 1 row. Move needles in NWP to UWP. (COR, RC= " + rowCountHood12 + "). <\/li>";
    }
    
stuff +="<li>Knit to RC = "+ totalRows +" (COR) <\/li>"; 
  

  if( 0 < hemRows){
	stuff +="<li>Mark for hem. Set row counter to zero. RC=0<br><li>Set carriage tension one setting lower than for main portion of knitting.  Knit to RC = " + hemRows + " rows ending COR (carriage on right).  Hang hem. Knit 1 row to seal. <br><\/li><\/li>";  	   
    }

    stuff +="<li>Bind off.<br><\/li>";
    stuff +="<li> Raise "+ halfSeamHoodNeedles +"  needles on machine.  Fold hood in half with right sides together with top edges parallel. Hang the top edges on the machine. If you hung a hem and want to insert a cord, make sure you don't hang the hem. (Seam that by hand later).  Place carriage on left. Set carriage to full knitting (N). Pull needles all the way out to E, push work against gate pegs, Knit 1 row; latchtool bind off to seam. Hand seam the remaining portion closed leaving a gap for the cord. <\/li>";
   stuff +=" <li> Attach neck edge hood to neck edge of sweater; if you are seaming on the machine, hang edges over "+ seamHoodNeedles +" needles.  If you are inserting a cord, be careful not to seam shut the opening for the cord.  Insert cord into gap in hung hem.  <\/li><li>If you want a cord, you can a commercial one, make a crochet chain or make <a href='http://www.thedietdiary.com/blog/index.php?p=25' target='_blank'>I-diot cord<\/a>. (I like the I-cord, and recommend you click the link to learn how to  make it.)<\/li>"; 
    stuff +="<\/ol>"
 patternWindow.document.writeln(stuff);  stuff ="";
 
}
