﻿$(document).ready(function () {
  $("#text").autocomplete("/search/autocomplete/", {
    limit: 10,
    selectFirst: true
  }).result(function (event, item) {
    location.href = "/search/?text=" + item.val();
  });
  $("#citypicker").click(function (e) {
    e.preventDefault();
    $(".cities").toggle();
  });
  $("#periodpicker").click(function (e) {
    e.preventDefault();
    $(".periods").toggle();
  });
  $(".comment_link").each(function () {
    var url = "http://graph.facebook.com/?callback=?&ids=http://www.profit.kz" + $(this).attr("href");
    var tag = $(this).parent().next();
    $.getJSON(url, function (data) {
      for (comments_num in data) {
        var user = data[comments_num];
        var count = user.comments + 0;
        if (!isNaN(count)) { tag.html(count); tag.show("slow"); }
      }
    });
  });
});
document.onkeydown = NavigateThrough;
function NavigateThrough(event) {
  if (!document.getElementById) return;
  if (window.event) event = window.event;
  if (event.ctrlKey) {
    var link = null;
    var href = null;
    switch (event.keyCode ? event.keyCode : event.which ? event.which : null) {
      case 0x25:
        link = document.getElementById('PrevLink');
        break;
      case 0x27:
        link = document.getElementById('NextLink');
    }
    if (link) document.location = link.href;
  }
}
