/*
 * Functions for bestof special page
 * @author Robert
 * @used-on bestof
 */
function spotBox() {
  var parts = document.location.href.split("#");
  if (parts[1]) { // anchor has been set
    var split = parts[1].split("-");
    var os = split[0];
    if (os == "windows") {
      $('mac').hide();
    } else {
      $('windows').hide();
    }
    $(os).show();
    showPanel(parts[1]);
    showOSLink();
  }
}

function showOSLink() {
  $$(".oslink").each(function(e){e.show();});
}

function showPanel(panel) {
  var type = panel.gsub(/\-([0-9])+/, "");
  var show = $(type + '-panel');
  show.innerHTML = $(panel).innerHTML;
  $(type + '-1').hide();
  show.hide();
  Effect.Appear(show, {duration:0.3});
  $$('#' + type + ' .items li a').each(function(e) {
    if (e.href.gsub(/(.*)\#/, "") == panel) {
      e.addClassName("active");
    } else {
      e.removeClassName("active");
    }
  });
}

function showBox(os) {
  if (os == "win") {
    $('mac').hide();
    box = $('windows');
    box.show();
    box.style.opacity = 0;
    box.appear({duration:0.3});
    $('windows').show();
  } else {
    $('windows').hide();
    box = $('mac');
    box.show();
    box.style.opacity = 0;
    box.appear({duration:0.3});
  }
  return false;
}

document.observe('dom:loaded', function(){
  $$('.items li a').each(function(node){
    node.observe("click", function() {
      panel = node.href.gsub(/(.*)\#/, "");
      showPanel(panel);
    });
  });

  var hide = "";
  if (navigator.appVersion.indexOf("Win") != -1) {
    hide = "mac";
  }
  if (navigator.appVersion.indexOf("Mac") != -1) {
    hide = "windows";
  }
  if (e = $(hide)) {
    e.hide();
    showOSLink();
  }

  spotBox();
});
