//
var splash = null;
var closer = null;
var object = null;

//
var FLASH_VERSION = [10, 0, 0];

//
function open_window(base, src, flvars, w, h){

  //
  if (splash != null) return false;

  //
  splash = jQuery("<div id='splash'></div>");
  jQuery("body").append(splash);
  jQuery("body").css('overflow', 'hidden');

  //
  closer = jQuery("<a id='splash_closer'><span>&times;</span> закрыть</a>");
  jQuery("body").append(closer);
  closer.click(close_window);

  //
  flash_object(base, src, flvars, w, h);

  //
  put_on_place();
  jQuery(window).resize(put_on_place);

  return false;

}

//
function close_window(){

  if (!splash) return false;

  jQuery("#object_container object").remove();
  jQuery("#object_container embed").remove();
  jQuery("#object_container").remove();
  jQuery("#splash").remove();
  jQuery("#splash_closer").remove();

  splash = object = closer = null;

  //
  jQuery("body").css('overflow', 'auto');

  return false;

}

//
function flash_object(base, src, flvars, w, h) {

  var flashOK = DetectFlashVer(FLASH_VERSION[0], FLASH_VERSION[1], FLASH_VERSION[2]);
  var obj;

  if (!w) w = 1024;
  if (!h) h = 768;
  if (!flvars) flvars = "";
  if (!base) base = "./";

  //
  if (flashOK) {

    // smart resize
    if (((jQuery(window).width()<w) || (jQuery(window).height()<h))){

      var msg = "Ой!\nРазрешение Вашего экрана недостаточно для запуска путешествия в полном размере!\n" + 
        "Рекомендуемое разрешение экрана — от 1280х1024 пикселей.\n" +
        "Запустить путешествие в меньшем размере (с худшим качеством графики),\n"  +
        "чтобы всё полностью поместилось на экране? ";

      if (confirm(msg)) { w = 800; h = 600;  }

    }

    obj = "<object allowFullScreen='true' width='" + w + "' height='" + h +"'>" +
        "<param name='classid' value='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' />" +
        "<param name='type' value='application/x-shockwave-flash' />" +
        "<param name='movie' value='" + base + src + "' />" +
        "<param name='src' value='" + base + src + "' />" +
        "<param name='base' value='" + base + "' />" +
        "<param name='flashvars' value='" + flvars + "' />" + 
        "<embed src='" + base + src + "' allowFullScreen='true' flashvars='" + flvars + "' base='" + base + "' width='" + w + "' height='" + h +"' classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' type='application/x-shockwave-flash'></embed>" +
        "</object>";

  
  } else {

    obj = "<div id='noflash'>" +
        "<img src='/journey/include/noflash.jpg' /><br/>" +
        "Для совершения путешествия нужен свежий проигрыватель Flash!<br/>(необходима версия " + FLASH_VERSION[0] + ")<br/>" +
        "Скачайте его с сайта <a href='http://www.adobe.com/go/getflashplayer' target='_blank'>adobe.com</a>." +
        "</div>";

    w = 640;
    h = 480;

  }

  object = jQuery("<div id='object_container'>" + obj + "</div>");

  object.css('width', w).css('height', h);
  jQuery("body").prepend(object);

  return false;

}

//
function put_on_place () {
  object.css('position', 'fixed').css('left', (jQuery(window).width()-object.width())/2).css('top', (jQuery(window).height()-object.height())/2);
  splash.css('width', jQuery(window).width()+20).css('height', jQuery(window).height()+20).css('opacity', 0.9);
}


