$(document).ready(function() {

//scroll

$(function() {
	$('#filters a').bind('click',function(event){
		var $anchor = $(this);

		$('html, body').stop().animate({
			scrollTop: $('.wrapper').offset().top
		}, 1500,'easeInOutExpo');
		event.preventDefault();
	});
});

// end scroll

	
/* isotope 1.5 */


  // modified Isotope methods for gutters in masonry
  $.Isotope.prototype._getMasonryGutterColumns = function() {
    var gutter = this.options.masonry && this.options.masonry.gutterWidth || 0;
        containerWidth = this.element.width();
  
    this.masonry.columnWidth = this.options.masonry && this.options.masonry.columnWidth ||
                  // or use the size of the first item
                  this.$filteredAtoms.outerWidth(true) ||
                  // if there's no items, use size of container
                  containerWidth;

    this.masonry.columnWidth += gutter;

    this.masonry.cols = Math.floor( ( containerWidth + gutter ) / this.masonry.columnWidth );
    this.masonry.cols = Math.max( this.masonry.cols, 1 );
  };

  $.Isotope.prototype._masonryReset = function() {
    // layout-specific props
    this.masonry = {};
    // FIXME shouldn't have to call this again
    this._getMasonryGutterColumns();
    var i = this.masonry.cols;
    this.masonry.colYs = [];
    while (i--) {
      this.masonry.colYs.push( 0 );
    }
  };

  $.Isotope.prototype._masonryResizeChanged = function() {
    var prevSegments = this.masonry.cols;
    // update cols/rows
    this._getMasonryGutterColumns();
    // return if updated cols/rows is not equal to previous
    return ( this.masonry.cols !== prevSegments );
  };
  

  //end fix for glutters
 
 //manuel	

  var $container = $('#boxes,#related'),
      isIsotopeEnabled = true,
      isMasonryLayoutMode = true,
      isotopeOptions = {
        masonry: {
		  itemSelector: '.post',
          columnWidth: 280,
          //not working
     	  gutterWidth: 40
        },
        fitRows: {
		  itemSelector: '.post',
          columnWidth: 280,
          gutterWidth: 20
        }
      };
  
  $container.isotope( isotopeOptions );
   
   
   
  //layout 
  
  
  $('#layout-list').click(function(){
 	 
 	/* $container.isotope({ layoutMode : 'fitRows' }); */
  	/*$container.isotope({ layoutMode : 'straightAcross' });*/

	$container.isotope({  itemSelector : '.post',
                          layoutMode : 'fitRows',
                          fitRows : { columnWidth : 280, gutterWidth: 20 } 
                       });

	$container.isotope( 'reLayout', callback )
  });
 
 
  $('#toggle-layout').click(function(){
    if ( isIsotopeEnabled ) {
      isMasonryLayoutMode = !isMasonryLayoutMode;
      isotopeOptions.layoutMode = isMasonryLayoutMode ? 'masonry' : 'fitRows';
      $container.isotope( isotopeOptions );
    }
  });
 
  $('#toggle-box').click(function(){
  
	     if ($(this).attr("state") == "open"){
			 $(this).attr("state", "close");
			 $(this).html("show images");
			//alert("open");
			$('.cover').slideDown("fast");
			$('.rel').slideUp("fast");
			$('h1').slideUp("fast",function(){
				$('#boxes').isotope();
                return false;
            });
			
		}else{
			$(this).attr("state", "open");	
			$(this).html("show texts");
			//alert("close");
			$('.cover').slideUp("fast");
			$('.rel').slideUp("fast");
			$('h1').slideDown("fast",function(){
				$('#boxes').isotope();
                return false;
            });
			
		}
		
		
    });

  



//manuel filtering

$('#filters a').click(function(){
  var selector = $(this).attr('data-filter');
  $('#boxes').isotope({ filter: selector });
  return false;
}); 



     
	
});

