function initTabs() {
  renderScreen();
  for (var i = 1; i < 6; i++) {
    $("li#pp-" + i.toString()).click(function() {
      $("#video_id").empty();
      var o = $(this);
      var id = o.attr("id");
      id = id.substr(id.indexOf("-") + 1, 2);
      activeImage = parseInt(id);
      renderScreen();
      $('#img-' + id).zooms({ImageId: $('a', o).attr('rel')});
    });
  }
}

function renderScreen() {
  $("div.pbc-c-content").hide();
  $("div.pbc-c-content:first").show();
  $("div.pbc-c-content:first").attr("id", "img-" + activeImage.toString());
  if (($.browser.msie == true) && (parseFloat($.browser.version) <= 6.0)) {
    switch (activeImage) {
      case 0: $("div.ie-mini-arrow").css("display", "none");
      case 1: $("div.ie-mini-arrow").css({left: 370 + "px" });
      case 2: $("div.ie-mini-arrow").css({left: 494 + "px" });
      case 3: $("div.ie-mini-arrow").css({left: 620 + "px" });
      case 4: $("div.ie-mini-arrow").css({left: 746 + "px" });
      case 5: $("div.ie-mini-arrow").css({left: 870 + "px" });
    }
  }
  else {
    if (activeImage == 0) {
      $("div.mini-arrow").css("display", "none");
    }
    else {
      $("div.mini-arrow").attr("id", "pa-" + activeImage.toString());
      $("div.mini-arrow").css("display", "block");
    }
  }
  clearAllStates();
  $("li#pp-" + activeImage.toString()).find("a").addClass("active");
}

function initHoverTab() {
  if (($.browser.msie == true) && (parseFloat($.browser.version) <= 6.0)) {
    for (var y = 1; y < 6; y++) {
      $("li#pp-" + y.toString()).hover(function() {
        var o = $(this);
        var liid = o.attr("id");
        liid = liid.substr(liid.indexOf("-") + 1, 2);
        if(parseInt(liid) != activeTab) {
          o.find("a").addClass("active");
        }
      }, function() {
        var o = $(this);
        var liid = o.attr("id");
        liid = liid.substr(liid.indexOf("-") + 1, 2);
        if(parseInt(liid) != activeTab) {
          $(this).find("a").removeClass("active");
        }
      });
    }
  }
}

function clearAllStates() {
  $("li.product-par a").removeClass("active");
  $("li.product-par-right a").removeClass("active");
}

function getActiveTab() {
    var hash = location.hash;
    var res = null;

    if ($('#tab-1').length)
        res = 1;
    else if ($('#tab-2').length)
        res = 2;
    else if ($('#tab-3').length)
        res = 3;
    else if ($('#tab-5').length)
        res = 5;
    else
        res = 4;
    
    if (hash != '')
    {
        if (hash == '#features')
            res = 1;
        else if (hash == '#descr')
            res = 2;
        else if (hash == '#spec')
            res = 3;
        else if (hash == '#docs')
            res = 5;
        else if (hash == '#reviews')
            res = 4;
    }
    
    return res;
}

function initListsTab() {
  renderTabs();
  $("li.tab-li").click(function() {
    clearListsTab();
    hideLists();
    var id = $(this).attr("id");
    id = id.substr(id.indexOf("-") + 1, 2);
    $("li#tab-" + id.toString()).addClass("active");
    $("div#tc-" + id.toString()).show(0);
  });
}

function clearListsTab() {
  $("li.tab-li").removeClass("active");
}

function hideLists() {
  $("div.tab-content").hide(0);
}

function renderTabs() {
  activeTab = getActiveTab();
  $("li#tab-" + activeTab.toString()).addClass("active");
  $("div#tc-" + activeTab.toString()).show(0);
}

$(document).ready(hideLists);
$(document).ready(initListsTab);
$(document).ready(initTabs);
$(document).ready(initHoverTab);

