var browser=navigator.appName;
var currentPopup;

var current_screenshot=3;
var total_screenshots=9;

var screenshot_title=new Array
(
  "",
  "Начало пути",
  "Битва в Библиотеке",
  "Сюрприз для противника",
  "Тамер в ближнем бою",
  "Держите флаг!",
  "Три стихии",
  "Финал морского горбуна",
  "Человек против хуртара",
  "В Гнезде затишье"
);

function button_start_game_on()
{
    document.getElementById('buttonstartgame').src="images/button-start-game-h.png";   
}

function button_start_game_off()
{
   document.getElementById('buttonstartgame').src="images/button-start-game.png";   
}

var fvo=1;

function button_start_game_flare()
{
  var flare=document.getElementById('buttonstartgamef');
  fvo=fvo-0.05;
  flare.style.opacity=fvo;
  if (fvo<0.1)
  {
    flare.style.display="none";
  }
  else
  {
    setTimeout (button_start_game_flare,30);
  }
}

/*
function flare_loop()
{
  setInterval(button_start_game_flare,50);
}   
*/
function screenX()
{
  var width = 0;
  if(typeof(window.innerWidth) == 'number') 
  {
    width = window.innerWidth; //Non-IE
  } 
  else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) 
  {
    width = document.documentElement.clientWidth; //IE 6+ in 'standards compliant mode'
  }
  return width;
}

function screenY()
{
  var height = 0;
  if( typeof(window.innerWidth) == 'number')
  {
    height = window.innerHeight;
  } 
  else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
  {
    height = document.documentElement.clientHeight;
  }
  return height;
}

function fadeOut()
{
  var shade=document.getElementById('shade');
  
  shade.style.visibility="visible";
  shade.style.width=screenX()+"px";
  shade.style.height=screenY()+"px";
}

function fadeIn()
{
  var shade=document.getElementById('shade');
  
  shade.style.visibility="hidden";
  shade.style.width="1px";
  shade.style.height="1px";
}

function popup(status, id, caption)
{
  var popup=document.getElementById("popupWindow");
  var popImage=document.getElementById("popImage");
  var popCaption=document.getElementById("popCaption");
  
  if (status == "show")
  {
    fadeOut();
    popImage.src="images/busy.gif";
    popup.style.visibility="visible";
    popup.style.left=(screenX()-816)/2+"px";
    popup.style.top=(screenY()-700)/2+"px";
    popup.style.width=800+"px";
    popup.style.height=682+"px";
    popImage.src="images/"+id+".jpg";
    popCaption.value=caption;
    currentPopup=popup;
  }
  else if(status == "hide")
  {
    popImage.src="images/busy.gif";
    popup.style.width="1px";
    popup.style.height="1px";
  }
  
  return false;
}

function popup_about()
{
  var popup=document.getElementById('about');
  fadeOut();

  popup.style.visibility="visible";
  popup.style.left=(screenX()-616)/2+"px";
  popup.style.top=(screenY()-545)/2+"px";
  popup.style.width=600+"px";
  popup.style.height=475+"px";
  popup.style.padding="24px";
  currentPopup=popup;
  
  return false;
}

function popup_clear()
{
  if(!currentPopup) return;
  currentPopup.style.visibility="hidden";
  fadeIn();
}


function reset()
{
  current_screenshot=2;
}

function show_screenshot(n)
{
  current_screenshot=n;
  popup_clear(); 
  popup('show', 'screenshot-0'+current_screenshot, screenshot_title[current_screenshot]);

    if (current_screenshot>total_screenshots)
    {
      //buttonNextShot.style.visibility="hidden";
    }
    if (current_screenshot<3)
    {
      //buttonPrevShot.style.visibility="hidden";
    }
  
  return false;
}

function next_screenshot()
{
  if (current_screenshot<total_screenshots)
  {
    current_screenshot+=1;  
    popup_clear(); 
    popup('show', 'screenshot-0'+current_screenshot, screenshot_title[current_screenshot]);
  }
  else 
  {
	current_screenshot=1;
	popup_clear(); 
    popup('show', 'screenshot-0'+current_screenshot, screenshot_title[current_screenshot]);
  }

  return false;
}

function previous_screenshot()
{
  if (current_screenshot!=1)
  {
    current_screenshot-=1;
    popup_clear(); 
    popup('show', 'screenshot-0'+current_screenshot, screenshot_title[current_screenshot]);
  }
  else 
  {
	current_screenshot=total_screenshots;
	popup_clear(); 
    popup('show', 'screenshot-0'+current_screenshot, screenshot_title[current_screenshot]);
  }
  return false;
}
