//iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
function max_img_size($w, $h, $maxW, $maxH )
//javascript version
//determines if the width or height is the size limiter
//adjusts width and/or height, maintaining aspect ratio, 
//adjusting to largest size image can be, within the maxW and maxH
//if $grow is TRUE size images larger than their current size 
// as long as the size is still within the max.
//otherwise only resize images which are too large

{

var w = $w;
var h = $h;
var maxW = $maxW;
var maxH = $maxH;

var hw_ratio = h/w;

var calcImgA =  new Array(2); 
calcImgA[0] = 0;
calcImgA[1] = 0;

var nw = w;
var nh = h;

//alert('maxH=' + maxH + '  maxW=' + maxW + '  w=' + w + '  h=' + h );
 
//determine if H or W will control size  
var  h_r = h/maxH;
var  w_r = w/maxW;

//below assumes we will enlarge if space allows
//this is the less complex option
  if (h_r > w_r)
   {
      nh = maxH;
      nw = Math.floor(nh/hw_ratio);
   }
   
  else
   { 
      nw = maxW;
      nh = Math.floor(hw_ratio * nw);
   }
//do I want to add back the option for maintaining smaller sizes?
//
//return values in array
calcImgA[0] = nw;
calcImgA[1] = nh;

return calcImgA;

} 
//iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii


//iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
function doNewStyleIE($n, $apply_to, $apply_this) 
//this function only works for IE 
//n = change the style sheet with index n
//I like this, but not as much as some other methods    
{
var n = $n;
var apply_to = $apply_to;
var apply_this = $apply_this;

//if style already exists for this $apply_to, remove it
var styleBlock=document.styleSheets[n];

for (i=0; i<styleBlock.rules.length; i++)
  {
//alert ("apply_to:" + apply_to + ";  selectorText:" + styleBlock.rules[i].selectorText);

  if (styleBlock.rules[i].selectorText==$apply_to)
    { 
//alert ("YES match")
      styleBlock.removeRule(i)
    }
  else
   {
//alert ("NO match")
   }
  }

//now add the new style
document.styleSheets[n].addRule($apply_to, $apply_this, -1);

//I should probably return something?  
}

//iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
function doNewStyle($n, $apply_to, $apply_this) 
{


}
//iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii

