  var map;

$(document).ready(function(){

 /* Left MENU */
  $("#productMenu li a").click(function(){

    if($(this).hasClass("link"))
      return true;
    /*
    if($(this).parent().parent().hasClass("fourthLevel")){
      return true;
    }*/

    $(this).parent().parent().children().removeClass('active'); // Ja vajag atļaut tikai 1 atvērtu kategoriju
    $(this).children().children().hide();
    $(this).parent().toggleClass('active');


    return false;
  });

  $(".langselect div.active, #langMenuArrow").click(function(){
    $(".langselect div").css("display","block");
  });

  $(".langselect div").click(function(){
    $(".langselect div").css("display","block");
  });

  $(".langselect div.active").prependTo(".langselect");

   $(".langselect div:not(.active)").click(function(){
      var lang = $(this).attr('class');
      window.location = "/" + lang.substr(0,lang.length-1) + "/";
    });

    prepare_links();

    $("#productProperties tr:gt(1) td").click(function(){
      var id = $(this).parent().attr('id');
      if(id)
        window.open("http://enoliktava.iuna.lv/view.php?search=1&descr="+id,"IunA","width=900,height=450,scrollbars=yes");

    });

    init_map();






});

function prepare_links(){


  var count = 0;
  var nr_col = 1;

  $("#productProperties tr:eq(1) td").each(function(){
    count = count + 1;
    if($(this).html() == 'nr.'){
      nr_col = count;
    }
  });

  var col_count = count;
  count = 0;
  $("#productProperties tr:gt(1) td").each(function(){
    count++;
    if(count == nr_col){
      $(this).parent().attr("id",$(this).html());
    }

    if(count == col_count){
      count = 0;
    }

  });



}



function init_map()
{
  if (map != null) return;
  if(typeof($gm) === 'undefined') return;

      var latlng = new $gm.LatLng(56.980091469028726, 24.49951199999998);

        map = new $gm.Map(document.getElementById("map_canvas"), {
          zoom: 7,
          center: latlng,
          mapTypeId: $gm.MapTypeId.ROADMAP
        });

        map.scrollwheel = false;



  for (var i=0; i<map_shops.length; i++)
  {
    var b = map_shops[i];
    var icon = new $gm.MarkerImage(b.icon, new $gm.Size(34, 34) );
    var m = new $gm.Marker({
      position: new $gm.LatLng(b.lat, b.lng),
      icon: icon,
      map: map,
      title: b.name,
    });
    m.shop = b;
    //alert(b.icon);
    $gm.event.addListener(m, 'click', function(event)
    {
      window.location = this.shop.url;
    });

  }

}

