// auxiliary functions

function addStyle(s)
{
  document.write('<style type="text/css">'+s+'</style>');
}

function getElementsByClassName(tagName, className) 
{
  var result = []; 
  if (typeof document.getElementsByTagName != 'undefined')
  {
    var all = document.getElementsByTagName(tagName);
    for (var i = 0; i < all.length; i++) if (all[i].className == className) result[result.length] = all[i];
  }  
  return result;
}

function addEvent(object, event, func) 
{
  if (typeof object[0] != 'undefined') for (var i = 0; i < object.length; i++) addEvent(object[i], event, func);
	if (window.opera && (object == window)) object = document;	
	if (typeof object.addEventListener != 'undefined') object.addEventListener(event, func, true);
  else if (typeof object.attachEvent != 'undefined') object.attachEvent("on"+event, func);
  else return false;
}

function sourceElement(event)
{
  var source; 
  if (typeof event == 'undefined') var event = window.event;
  if (typeof event.target != 'undefined') source = event.target;
  else if (typeof event.srcElement != 'undefined') source = event.srcElement;
  else return false;
  if (source.nodeType == 3) source = targ.parentNode;
  return source;
}

function stopDefault(event) { if (typeof event.preventDefault != 'undefined') event.preventDefault(); return false; }
function doDefault() { return true; }

function externalLink(event)
{
  var source = sourceElement(event);
  if (source) 
  { 
    if (window.open(source.href)) 
      return stopDefault(event); 
    else
      return doDefault(); 
  } 
}

function miniLink(event)
{
  var source = sourceElement(event);
  if (source) 
  { 
    if (window.open(source.href, "_blank", "width=780, height=585, left=40, top=80, scrollbars=yes, resizable=yes, toolbar=no, location=no, directories=no, menubar=no")) 
      return stopDefault(event); 
    else
      return doDefault(); 
  } 
}

function openPhoto(href)
{
  var h = window.open(href, "_blank", "width=780, height=585, left=40, top=80, scrollbars=yes, resizable=yes, toolbar=no, location=no, directories=no, menubar=no");
  h.document.write('<html><head><style>body { margin: 5px; padding: 0; text-align: center; } a img { border: 0; }</style><title>Plná velikost</title></head><body><a href="#" onclick="window.close()"><img src="' + href + '" alt="Plná velikost fotografie" /></a></body></html>');
  
  // TODO: zabezpecit
  // alert(!h);
  
  // OK, shit happens. But why it happens ALWAYS in one particular browser, Microsoft? 
  // New slogan for Microsoft Internet Explorer - "covered in shit"
  
  return !h; 
}

// main code

var time = 0, guy, msie = false;

if ((window.navigator.userAgent.indexOf('MSIE') != -1) && 
    (window.navigator.userAgent.indexOf('Opera') == -1)) msie = true;

function tick()
{
  time++; 
  
  if (!guy) return; 
  
  // 
  // clovek by neveril, jak neuveritelne dokazou ruzne prohlizece zmrvit 
  // tak relativne primocarou vec, jako dynamicke meneni pruhlednosti
  // a to mluvim jak o MSIE, tak o Mozille; stesti, ze Opera to nepodporuje
  // vubec
  //
  
  if (time > 0) 
  {
    local = time % 180; 
    alpha = 0; 
    if (local <= 30) 
    {
      if (msie) 
        alpha = local / 31 + (1/31); 
      else
        alpha = local / 31;
    }
    else if ((local > 30) && (local <= 90)) 
    {
      if (msie) alpha = 1; else alpha = 0.99;
    }
    else if ((local > 90) && (local <= 120))
      alpha = (120 - local) / 30 + (1/31);
  
    if (msie)
    {
      guy.filters.alpha.style = 0;
      guy.filters.alpha.opacity = alpha * 100;
    }  
    else guy.style.MozOpacity = alpha; 
  }
}

function addEvents()
{
  addEvent(getElementsByClassName("a", "external"), "click", externalLink); 
  addEvent(getElementsByClassName("a", "mini"), "click", miniLink); 
  window.setInterval("tick()", 60); 
}

function load() 
{
  guy = document.getElementById('content-after');
  addEvents(); 
}

function openPanorama(url)
{
  return !window.open(url, "_blank", "width=600,height=235,left=150,top=185,toolbar=no,location=no,status=no,resizable=no,menubar=no,scrollbars=no");  
}

window.onload = load;

