/*
 *  global JS
 */

var browserGecko, browserOpera, browserIE, browserIE5;
var heslaEl, indexyEl, searchEl, geckoEl;
var searchBtn, searchWindow;
var searchLowLimit = 3;

function init() {
  // detect browser
  var tmpNav = navigator.userAgent;
  browserGecko = (tmpNav.indexOf('Gecko') != -1);
  browserOpera = (tmpNav.indexOf('Opera') != -1);
  browserIE    = (tmpNav.indexOf('MSIE') != -1) && !(browserOpera);
  browserIE5   = (tmpNav.indexOf('MSIE 5.0') != -1) && (browserIE); 
  // resize
  var availableHeight = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight;
  if (browserIE5) { availableHeight = document.body.clientHeight; }
  var availableWidth  = window.innerWidth  ? window.innerWidth  : document.documentElement.clientWidth;
  if (browserIE5) { availableWidth = document.body.clientWidth; }
  var horniMenuHeight = document.getElementById('cast-horniMenu').offsetHeight;
  // CONTENT
  heslaEl = document.getElementById('cast-hesla');
  var heslaWidth = availableWidth - 220 - 57;
  var heslaHeight = availableHeight - 140 - horniMenuHeight - 36;
  heslaEl.style.width  = heslaWidth + 'px';
  if (heslaEl.offsetHeight < heslaHeight)
    heslaEl.style.minHeight = heslaHeight - 3 + 'px';
  // INDEXY
  indexyEl = document.getElementById('cast-indexy');
  indexyEl.style.height = availableHeight - 140 - 15 + 'px';
  // SEARCH BOX
  searchEl = document.getElementById('search');
  searchBtn = document.getElementById('searchButton');
  //searchEl.style.width = 200 - searchBtn.offsetWidth - 5 + 'px';
  // GECKO LOGO
  geckoEl = document.getElementById('cast-gecko');
  var visibleHeight = 140 + horniMenuHeight + heslaEl.offsetHeight;
  geckoEl.style.top = visibleHeight - 133 - 20 + 'px';
  // SPACER
  var spacer = document.getElementById('cast-spacer');
  spacer.style.top = visibleHeight + 'px';
}
function initResize() {
  var availableHeight = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight;
  var availableWidth  = window.innerWidth  ? window.innerWidth  : document.documentElement.clientWidth;
  var horniMenuHeight = document.getElementById('cast-horniMenu').offsetHeight;
  // 
  var heslaWidth = availableWidth - 220 - 57;
  var heslaHeight = availableHeight - 140 - horniMenuHeight - 36;
  heslaEl.style.width  = heslaWidth + 'px';
  if (heslaEl.offsetHeight < heslaHeight)
    heslaEl.style.minHeight = heslaHeight - 3 + 'px';
  // 
  indexyEl.style.height = availableHeight - 140 - 15 + 'px';
  // 
  var visibleHeight = 140 + horniMenuHeight + heslaEl.offsetHeight;
  geckoEl.style.top = visibleHeight - 133 - 20 + 'px';
}

function searchFor(what) {
  // encode string value for passing between windows
  var whatEncoded = '';
  if (window.encodeURI) {
    whatEncoded = encodeURI(what);
  } else {
    whatEncoded = escape(what);
  }
  // get handler for search window and search
  var searchStr = 'search.html?' + whatEncoded;
  searchWindow = window.open( searchStr, 'gbSearch', 'location=no,menubar=no,resizable=yes,scrollbars=yes,titlebar=yes,toolbar=no');
}
function searchCheckState(searchInputValue) {
  if (searchInputValue.length <= searchLowLimit) {
    searchBtn.disabled = true;
  } else {
    searchBtn.disabled = false;
  }
}


window.onresize = initResize;

