var selectedLanguage;
var totalWidth;
var mTitle = 'Magda Hrudková - Fundraising Zone';
var oTitle = 'Ondřej Zloský - IT Zone';
var opacity = 0.6;

var jsOK = (document.getElementById && document.getElementsByTagName);
if (jsOK) {
  document.write ('<link rel="stylesheet" type="text/css" media="screen,projection" href="/css/bilingual.css" />');
  window.onload = init;
  }

function init()
{
  var o = document.getElementById('ondrej');
  o.onclick = sizeText;
  o.title = oTitle;
  var m = document.getElementById('magda');
  m.onclick = sizeText;
  m.title = mTitle;
  setWidths();
}

function exit()
{
  if (selectedLanguage)
    createCookie('bilingual',selectedLanguage,180);
}

window.onresize = setWidths;

function setWidths()
{
  totalWidth = parseInt(document.body.offsetWidth);
  if (totalWidth > 1018) totalWidth = 1018;
  var lang = (selectedLanguage) ? selectedLanguage : readCookie('bilingual');
  if (lang) {
    document.getElementById(lang).onclick();
  } else {
    document.getElementById('ondrej').onclick();
  }
}

function sizeText()
{
  var thisid = this.id;
  var thistop = (this.id == 'magda') ? 'magdatop' : 'ondrejtop';
  this.className = 'large';
  //this.style.width = parseInt(totalWidth*.80)+'px';
  this.style.width = '758px';
  this.style.opacity = 1;
  document.getElementById(thistop).style.width = '773px';
  document.getElementById(thistop).style.opacity = 1;
  document.getElementById(this.id).onmouseout = function () {document.getElementById(thistop).style.opacity = 1;};
  document.getElementById(this.id).onmouseout = function () {document.getElementById(this.id).style.opacity = 1;};

//  this.style.height = 'auto';
  this.style.cursor = 'auto';
  this.title = '';
  var other = (this.id == 'magda') ? 'ondrej' : 'magda';
  var othertop = (this.id == 'magda') ? 'ondrejtop' : 'magdatop';
  document.getElementById(other).className = 'small';
  //document.getElementById(other).style.width = parseInt(totalWidth*.20)+'px';
  document.getElementById(other).style.width = '163px';
  document.getElementById(other).style.opacity = opacity;
  document.getElementById(othertop).style.opacity = opacity;
  document.getElementById(other).onmouseover = function () {
    document.getElementById(other).style.opacity = 1;
    document.getElementById(othertop).style.opacity = 1;
    document.getElementById(thisid).style.opacity = opacity;
    document.getElementById(thistop).style.opacity = opacity;
  };
  document.getElementById(other).onmouseout = function () {
    document.getElementById(other).style.opacity = opacity;
    document.getElementById(othertop).style.opacity = opacity;
    document.getElementById(thisid).style.opacity = 1;
    document.getElementById(thistop).style.opacity = 1;
  };
  document.getElementById(othertop).style.width = '178px';
  //document.getElementById(other).style.height = this.offsetHeight;
  document.getElementById(other).style.cursor = 'pointer';
  document.getElementById(other).title = (other == 'magda') ? mTitle : oTitle;
  selectedLanguage = this.id;
  createCookie('bilingual',selectedLanguage,180);
  if (top.navi && top.navi.switchLang)
    top.navi.switchLang(selectedLanguage);
}

// Cookies

function createCookie(name,value,days)
{
  if (days)
  {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else var expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++)
  {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

function eraseCookie(name)
{
  createCookie(name,"",-1);
}

