// www.zusprerov.cz - width.js

// Require general.js (functions: createCookie, readCookie, bezdiak; var BASE)
var DAYS="1" // platnost cookie ve dnech - málo kvůli změnám rozměrů prohlížeče

function getBrowserWidth() {
  if (window.innerWidth) return window.innerWidth-18; // -scrollbar ve FF
  else if (document.documentElement && document.documentElement.clientWidth != 0) return document.documentElement.clientWidth;
  else if (document.body) return document.body.clientWidth;
  return 1899; // původní šířka v CSS
}

function set_widht(from) {
  var resol = getBrowserWidth();
  createCookie("users_resolution1",resol,DAYS);
  //if (readCookie("users_resolution1")) {
    //location = './index.php'; // ne / kvůli kešování na proxy a následnému cyklení
    var Width = resol;
    if (Width<997) Width=997;
    var width_side = (Width-997)/2; // šířka postranních částí
    // vycentrování pro větší rozlišení než 1024
    if (Width>1024) var width_left = width_side-36;
    else var width_left = width_side;
    width_left = width_left.toString();
    if (Width>1024) var width_right = width_side+36;
    else var width_right = width_side;
    width_right = width_right.toString();
    if (width_right.substring(3)==".5") width_right=width_right-0.5;
    if (width_right.length>3 && width_right.substring(4)==".5") width_right=width_right-0.5;
    if (width_left.substring(3)==".5") width_left=width_left+0.5;
    if (width_left.length>3 && width_left.substring(4)==".5") width_left=width_left+0.5;
    var Style = readCookie("style");
    if (!Style) Style = "style1";
    if ((Style=="style1") || (Style=="style2")) {
      document.getElementById('page').style.width = Width+'px';
      document.getElementById('top').style.width = Width+'px';
      document.getElementById('header_a').style.width = width_left+'px';
      document.getElementById('header_b').style.width = width_right+'px';
      document.getElementById('middle').style.margin = '0 '+width_right+'px 0 '+width_left+'px';
      document.getElementById('bottom').style.width = Width+'px';
      document.getElementById('footer_a').style.width = width_left+'px';
      if (from != "toplist") document.getElementById('footer_b').style.width = width_right+'px'; // protože toplist.js je ještě před #footer_b
    }
    //return true;
  //}
  //return false;
}

function getBrowserWidth1() {
  if (window.innerWidth) return window.innerWidth-18; // -scrollbar ve FF
  else if (document.documentElement && document.documentElement.clientWidth != 0) return document.documentElement.clientWidth;
  else if (document.body) return document.body.clientWidth;
  return 1000;
}

function scrll() {
  var width=getBrowserWidth1();
  if (width<983) width=983; // pro menší rozlišení než 1024
  //alert (width);
  var scrl = (1899-width)/2; // o kolik posunout (šířka nezobrazené části)
  if (width>1024) scrl=scrl+37; // vycentrování pro větší rozlišení než 1024
  //alert (scrl);
  scroll(scrl,null);
}

if (window.addEventListener) window.addEventListener('load', set_widht, false);
else window.attachEvent('onload', set_widht)
//if (window.addEventListener) window.addEventListener('load', scrll, false);
//else window.attachEvent('onload', scrll)
