function calcMaxProportions(width, height, maxWidth, maxHeight) {
  if(width > maxWidth || height > maxHeight) {
    if(width / height > maxWidth / maxHeight) {
      k = maxWidth / width;
      width = width * k;
      height = height * k;
    } else {
      k = maxHeight / height;
      width = width * k;
      height = height * k;
    }
  }
  var res = new Array();
  res[0] = width;
  res[1] = height;
  return res;
}

function openMaximized(imageId, width, height) {
  var wh = calcMaxProportions(width, height, screen.width, screen.height);
  width = wh[0];
  height = wh[1];
  var winl = (screen.width - width) / 2;
  var wint = (screen.height - height) / 2;
  winprops = 'height='+height+',width='+width+',top='+wint+',left='+winl+',scrollbars=0,resizable=0';
  win = window.open("/exec/performergallery/maximized/" + imageId, '', winprops);
  if (parseInt(navigator.appVersion) >= 4) {
    win.window.focus();
  }
}

function openVideo(imageId, width, height, highQuality) {
  var wh = calcMaxProportions(width, height, screen.width, screen.height);
  width = wh[0];
  height = wh[1];
  var winl = (screen.width - width) / 2;
  var wint = (screen.height - height) / 2;
  winprops = 'height='+height+',width='+width+',top='+wint+',left='+winl+',scrollbars=0,resizable=0';
  win = window.open("/exec/performergallery/video/" + imageId + "?high=" + (highQuality ? "true" : "false"), '', winprops);
  if (parseInt(navigator.appVersion) >= 4) {
    win.window.focus();
  }
}

function openSupport(supportId) {
  width = 672;
  height = 512;
  var winl = (screen.width - width) / 2;
  var wint = (screen.height - height) / 2;
  winprops = 'height='+height+',width='+width+',top='+wint+',left='+winl+',scrollbars=0,resizable=0';
  win = window.open("/exec/chat/" + supportId + "?support=1", '', winprops);
  if (parseInt(navigator.appVersion) >= 4) {
    win.window.focus();
  }
  return false;
}

function initSwfObject(params) {
  var version = params['version'].split('.');
  delete params['version'];
  var flashNotFound = params['notfound'];
  delete params['notfound'];
  params['flashvars'] = "";
  for(var key in params['vars']) {
    params['flashvars'] += params['flashvars'].length > 0 ? "&amp;" : "";
    params['flashvars'] += key + "=" + params['vars'][key];
  }
  delete params['vars'];
  params['movie'] = params['file'].replace(/\.swf/, '');
  delete params['file'];
  var args = [];
  for(key in params) {
    args[args.length] = key;
    args[args.length] = params[key];
  }
  if(DetectFlashVer(version[0],version[1],version[2])) {
    AC_FL_RunContent.apply(null, args);
  } else {
    document.write(flashNotFound);
  }
}