// menu START
function showAndHide(objId) {
  if (document.getElementById(objId).style.display == "none")
  //document.getElementById(objId).style.display = "block";
  $("#" + objId).show(1000);
  else
  //document.getElementById(objId).style.display = "none";
  $("#" + objId).hide(1000);
  return false;
}
function toshow(objId) {
  document.getElementById(objId).style.display = "block";
}
// menu End

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 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 showM(objId) {
  if (readCookie('homesoft') == null) createCookie('homesoft', 'mini', 365);
  if (readCookie('webmaster') == null) createCookie('webmaster', 'mini', 365);
  if (readCookie('ircchat') == null) createCookie('ircchat', 'mini', 365);

  if (readCookie(objId) == "mini") document.getElementById(objId).className += ' minitags';
}

function mini(objId) {
  var ob = document.getElementById(objId),
  c = ' minitags',
  n = ob.className;
  ob.className = (n.indexOf(c) == -1) ? n += c: n.replace(c, '');

  if (readCookie(objId) == 'mini') {
    createCookie(objId, 'on', 365);
  } else {
    createCookie(objId, 'mini', 365);
  }
}

function resizeText(multiplier) {
  var fontsz = "11"; //Default to 1em
  if (readCookie('site_font_size') != null) {
    // Set fontsz to the cookie value if it exists
    fontsz = readCookie('site_font_size');
  }
  fontsz = parseFloat(fontsz) + (multiplier * 1) + "px";
  // Change body text size
  document.body.style.fontSize = fontsz;
  //Set a new cookie 
  createCookie('site_font_size', fontsz, '365')
}

function popupfoto(url) {
  newwindow = window.open(url, 'name', 'width=459, height=408, top=100, left=200');
  if (window.focus) {
    newwindow.focus()
  }
  return false;
}

function SetHomePage(ob) {
  if (navigator.appName != "Microsoft Internet Explorer") {
    self.location.href = '/ntr/help.html#hHP';
  } else {
    ob.style.behavior = 'url(#default#homepage)';
    ob.setHomePage('http://www.privet.lv');
  }
}

function obj(id) {
  return document.getElementById(id);
}
// Tabs
function objTab(prefix) {
  this.active = 1;
  this.t = prefix + "-t"; // tab prefix
  this.p = prefix + "-p"; // page prefix
  this.Tab = changeTab;
}
function changeTab(id) {
  var a = this.active;
  if (id != a) {
    if (a > 0) {
      obj(this.t + a).className = obj(this.t + a).className.substring(0, obj(this.t + a).className.indexOf("active") - 1);
      if (obj(this.p + a)) obj(this.p + a).style.display = "none";
    }
    obj(this.t + id).className = obj(this.t + id).className + " active";
    //if (obj(this.p+id)) $(obj(this.p+id)).show(1000);
    if (obj(this.p + id)) obj(this.p + id).style.display = "block";
    this.active = id;
    createCookie('people', id, 365);
  }
}
var people = new objTab("ch"); // Chart

function showT(objId) {
  if (readCookie('people') == '2') {
    people.Tab(2);
  }
}

function lessmore(e, objId) {
  var div = document.getElementById(objId);
  if (!div.p) {
    div.p = div.getElementsByTagName('p');
    div.index = div.last_index = div.p.length;
  }
  if (e) {
    if (div.last_index == div.index) alert('Все доступные элементы уже открыты.');
    else {
      div.p[div.last_index].className = div.p[div.last_index].className.replace(/\s*none/, '');
      div.last_index++;
      var lm = div.p.length - div.last_index;
      createCookie(objId, lm, 365);
    }
  } else {
    if (div.last_index == 1) alert('Все доступные элементы уже закрыты.');
    else {
      div.p[div.last_index - 1].className += ' none';
      div.last_index--;
      var lm = div.p.length - div.last_index;
      createCookie(objId, lm, 365);
    }
  }
}

function checkLogin(objId) {
  if (readCookie('Y2User-75353') != null) {
    document.getElementById(objId).style.display = "none";
  }
}

$(document).ready(function() {

  $("#Skype a").append("<em></em>");

  $("#Skype a").hover(function() {
    $(this).find("em").animate({
      opacity: "show",
      top: "-75"
    },
    "slow");
    var hoverText = $(this).attr("title");
    $(this).find("em").text(hoverText);
  },
  function() {
    $(this).find("em").animate({
      opacity: "hide",
      top: "-85"
    },
    "fast");
  });
});