var JAVASCRIPT_IMAGES_PRELOAD = new Object();

function image_preload_init(key){
  if(typeof JAVASCRIPT_IMAGES_PRELOAD[key] != 'undefined') return false;
  
  JAVASCRIPT_IMAGES_PRELOAD[key] = new Array();

}

function image_preload_add(key,image){
  var newIndex = JAVASCRIPT_IMAGES_PRELOAD[key].length;
  JAVASCRIPT_IMAGES_PRELOAD[key][newIndex] = new Object();
  
  JAVASCRIPT_IMAGES_PRELOAD[key][newIndex]['name'] = image['name'];
  JAVASCRIPT_IMAGES_PRELOAD[key][newIndex]['src'] = image['src'];
}

function image_preload_get(key,index){
  return JAVASCRIPT_IMAGES_PRELOAD[key][index];  
}

function image_shrinkToFit(obj, new_w, new_h){
  
  obj = element_isObject(obj);
  var old = element_getSize(obj);
  
  ret = new Object();
  
  var ratio  = (old.width / old.height);
  if (old.width > old.height) {    
    ret['width']  = new_w;
    ret['height'] = new_w * ratio;
  } else {    
    ret['width']   = new_h * ratio;
    ret['height']  = new_h;    
  }
  if (old.width == old.height) {
    ret['width']  = new_w;
    ret['height'] = new_h;
  }

  return ret;
}