function obj(id) {
  return document.getElementById(id);
}
function objTab(prefix) {
  this.selected = 1;
  this.t = prefix + "-t"; // tab prefix
  this.p = prefix + "-p"; // page prefix
  this.Tab = changeTab;
}
function changeTab(id) {
  var a = this.selected;
  if (id != a) {
    if (a > 0) {
      obj(this.t + a).className = obj(this.t + a).className.substring(0, obj(this.t + a).className.indexOf("selected") - 1);
    }
    obj(this.t + id).className = obj(this.t + id).className + " selected";
    //if (obj(this.p+id)) $(obj(this.p+id)).show(1000);
    if (obj(this.p + id)) obj(this.p + id).style.display = "block";
    this.selected = id;
  }
}
var blok = new objTab("ch");
function fhome(sites) {
  $.cookie('home', sites, {
    expires: 365
  });
  initialize(sites);
  blok.Tab(1);
}

function addrss(rss) {
  $.cookie('home', rss, {
    expires: 365
  });
  initialize(rss);
  var idformyrss = 'rh' + Math.floor(Math.random() * 100000);

  for (var i = 0; i < 10; i++) {
    if ($.cookie('rh' + i) == null) {
      var nku = 'rh' + i;
      document.getElementById('rsslist').innerHTML += "<span id=\"" + nku + "\"><img height=\"14\" width=\"14\" src=\"http://favicon.yandex.net/favicon/" + rss.split('/')[2] + "\" align=\"absmiddle\" /> <a href=\"#\" onclick=\"fhome('" + rss + "');\">" + rss.split('/')[2] + "<\/a><a href=\"#\" onclick=\"showAndHide('" + nku + "'); $.cookie('" + nku + "', null);\" class=\"del\"><\/a><br /><\/span>";
      $.cookie(nku, rss, {
        expires: 365
      });
      return;
    }
  }
  blok.Tab(1);
}

function showAndHide(objId) {
  if (document.getElementById(objId).style.display == "none") $("#" + objId).show(1000);
  else $("#" + objId).hide(1000);
}

function startnew() {
  for (var i = 0; i < 20; i++) {
    var lods = Array("http://www.tvnet.lv/rss/latest.xml", "http://rus.tvnet.lv/rss/latest.xml", "http://www.delfi.lv/rss.xml", "http://rus.delfi.lv/rss.xml", "http://www.ogrenet.lv/rss/", "http://rus.ogrenet.lv/rss/", "http://www.apollo.lv/rss/", "http://www.db.lv/rss/", "http://www.mixnews.lv/rss/", "http://www.novonews.lv/rss.php", "http://www.dni.lv/rss.xml", "http://www.news.lv/news/rss.xml", "http://www.gorod.lv/rss", "http://www.easyget.lv/rss/", "http://www.iauto.lv/rss/", "http://www.times.lv/rss.php");
    if (lods[i] != null) {
      var nku = 'rh' + i;
      document.getElementById('rsslist').innerHTML += "<span id=\"" + nku + "\"><a href=\"#\" onclick=\"fhome('" + lods[i] + "');\">" + lods[i].split('/')[2] + "<\/a><a href=\"#\" onclick=\"showAndHide('" + nku + "'); $.cookie('" + nku + "', null);\" class=\"del\"><\/a><br /><\/span>";
    }
  }
}

function language(objId) {

      $.cookie('lang', objId, {
        expires: 365
      });

    window.location.reload(true);
}

window.onload = function() {
  if (window.location != null && window.location.search.length > 8) {
    addrss(window.location.search.substring(1));
  }
}


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

function convert() {
$('#kjhfjh').html(' = '+(Number($('#currency_val')[0].value) * Number($('#currency_to')[0].value) / Number($('#currency_from')[0].value)).toFixed(2)+' '+$('#currency_from option:selected').html());
}

$(document).ready(function() {
//social link
$("#the_copyright h3 a[href^='http://']").click(function(){window.open(this.href, "myWindowName", "width=700, height=500");return false;});
$("#popup_notice a[href^='http://']").click(function(){window.open(this.href, "myWindowName", "width=700, height=500");return false;});
});
