var stimer = null;

function initPage() {
  $("#Header").ajaxcontrol();
  $("#ProdInfo").ajaxcontrol({width:400, height:280, allowRichPaste:true});
  $("#search").inputwithhelp("SÖK");
  getProducts("");

  hashListener.onHashChanged = hashChanged;
  hashListener.init();

  if ($("#ProdInfo").html().length > 0) $("#one_prod").css("display","block");
}

function hashChanged() {
  var spicename = hashListener.getHash();
  $("#ProdInfo").ajaxcontrol_setPropertyName(spicename, hashChanged2);
}
function hashChanged2() {
  $("#ProdInfo").append(
    '<br /><div class="addthis addthis_toolbox addthis_default_style" addthis:url="' + _url + "/" + _pageId + ".aspx?prodid=" + id +'">'
    + '<a class="addthis_button_facebook"></a>'
    + '<a class="addthis_button_email"></a>'
    + '</div>'
  );

  if (window.addthis){
  window.addthis.ost = 0;
  window.addthis.ready();
     }
  return false;
  var top = $(window).height()/2 - $("#one_prod").height()/2 + $(window).scrollTop();
  var left = $("#prod_container").width()/2 - $("#one_prod").width()/2 + $(window).scrollLeft();
  $("#one_prod").css({"top":top, "margin-left":left}).show("normal", function() {
    $("#prod_list").addClass("dimmed");
  });
}

function getProducts(search) {
  ProductPage.GetProducts(_pageId, search, getProducts2);
}
function getProducts2(response) {
  $('#prod_list').html(response.value);
}

function showProduct(obj, spicename) {
  id = jQuery( obj ).prev().val();
  hashListener.setHash(spicename);
}

function closeProduct() {
  $("#prod_list").removeClass("dimmed");
  $("#one_prod").hide("normal");
}

function checksearch() {
  if (stimer) clearTimeout(stimer);
  stimer = setTimeout(dosearch, 500);
}

function dosearch() {
  getProducts($('#search').val());
}

