$(document).ready(function(){
  
  $("nav#main ul li a:first").addClass("first");
  $("nav#shops ul li a:first").addClass("first");
  
  $("ul.posts li.post:odd").addClass("odd");
  $("ul.posts li.post:even").addClass("even");
  
  $("div#tabs ul li:first").addClass("active");
  $("div#tabs").children(".shop_content:first").addClass("active");
  $("div#tabs ul li a").click(function(event) { 
    $(this).parent().siblings("li").removeClass("active");
    $(this).parent().addClass("active");
    var href = $(this).attr("href");
    $("div#tabs").children(".shop_content").removeClass("active");
    $("div#tabs").children("#" +href).addClass("active");
    return false;
  });
  
  $("a.fancybox2").fancybox({
    'padding'    : 0,
    'transitionIn'  :  'elastic',
    'transitionOut'  :  'elastic',
    'speedIn'    :  600, 
    'speedOut'    :  200, 
    'overlayShow'  :  false
  });
  
  $("a.fancybox").attr("rel", "gallery").fancybox({
    'padding'    : 0,
    'transitionIn'  :  'elastic',
    'transitionOut'  :  'elastic',
    'speedIn'    :  600, 
    'speedOut'    :  200, 
    'overlayShow'  :  false
  });

  $("a[href=#shop_map]").click(function() {
    if (!window.geocoder) {
      window.geocoder = new google.maps.Geocoder();
      window.geocoder.geocode({ 'address': $("#map").data("location") }, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
          window.map = new google.maps.Map(document.getElementById("map"), {
            zoom: 15,
            center: results[0].geometry.location,
            mapTypeId: google.maps.MapTypeId.ROADMAP,
            mapTypeControl: false,
            streetViewControl: false
          });
          var marker = new google.maps.Marker({
            map: window.map,
            position: results[0].geometry.location
          });
        } else {
          $("#map").html("Kļūda: Nevar atvērt karti");
        }
      });
    }
  });
});


