$(document).ready(function () {  
  var pcurrent = 1;
  var gcurrent = 1;
  
  $(function() {
    // Map Highlighting
    $('.map').maphilight({stroke: false, groupBy:'title'});
  });
  
  $('ul.projects_type').masonry({
    itemSelector: 'li'
  });
  
  // Store the original position with 
  // var a=$(".popup_container"); 
  // a.data('initial', a.offset().left);
  
  $(".gallery").click(function () {
    var that = this;    
    $(".popup").animate({"left": "-=720"}, 500);
  });

  $(".proj_list").click(function () {
    var that = this;
    $(".popup").animate({"left": "+=720"}, 500);
  });

  $(".projects").each(function () {
    prcurrent = 1;
    var that = this;
    var total = $(".popup_container .bin", that).length;
              
    function prev() {

        if (prcurrent >= 2) {

            $(".popup_container", that).animate({"left": "+=720"}, 500);
            
            prcurrent--;

        } else {

          return false;
        }

    }

    function next() {  
      
        if (prcurrent != total) {

            $(".popup_container", that).animate({"left": "-=720"}, 500);

            prcurrent++;
            
        } else {
            
            return false;
        }

    }
    
    $(this).find('a.prev').click(prev);
    $(this).find('a.next').click(next);
    
  });
  
  $(".photos").each(function () {
    phcurrent = 1;
    var that = this;
    var total = $(".popup_container .bin", that).length;
    
    function prev() {

        if (phcurrent >= 2) {

            $(".popup_container", that).animate({"left": "+=720"}, 500);
            
            phcurrent--;

        } else {

            return false;

        }

    }

    function next() {

        if (phcurrent != total) {

            $(".popup_container", that).animate({"left": "-=720"}, 500);

            phcurrent++;

        } else {

            return false;

        }

    }
    
    $(this).find('a.prev').click(prev);
    $(this).find('a.next').click(next);
  });

});
