/*
/* Please call all plugins from within here
/* We dont want to mess up the template with js code
*/
		
if (typeof stuttgart === 'undefined') {
	stuttgart = {};
}

stuttgart.micro = {
  
  init: function() 
  {
    
    /*
    /* Okay lets try to adjust the main page a bit
    */  
    var page    = $('#page_wrapper');
    var page_height = page.height();
    var modulus   = page_height % 225;

    // We cut a bit from the page (-20px)
    if ( modulus <= 20 ) 
    { 
      page.css({'overflow':'hidden'});
      page.height( page_height - modulus - 10);
    } else if (modulus >= 205) 
    {
      page.css({'overflow':'hidden'});
      page.height( page_height + ( 225 - 10 - modulus));
    }
    
    if (typeof(portletmanager)!=='undefined') {
      $("#main").sortable({
        items : '>div.msnrysortable',
        update : function(e, ui) {
          sort = $(this).sortable('serialize');
          $.get(portletmanager.basepath + 'portlet/resort/1?' + sort + '&list=portlets');
        }
      });
    } else {
      this.initMasonry();
    }
    
    this.sharePop();
  },

  /*
  /* Init Maisonry
   */
  initMasonry: function() {
    $('#main').masonry({
      columnWidth: 230,
      animate: true
    });
    return true;
  },
  
  /*
   * Sharing
   */
  sharePop: function() 
  {
    /*
    /* Make the share windows nicer
    */
    $('.facebook, .twitter').click(function(e) {
            
      e.preventDefault();

      var height  = $(this).hasClass('twitter') ? '240' : '400';
      var url   = $(this).attr('href');
      
      var win = window.open(  url,
                    'Teilen',
                    'width=600, height=' + height + ', location=no, menubar=no, status=no, toolbar=no, scrollbars=no, resizable=no');
      win.focus();

    });
  },
  
  reorderEvenOdd: function() {
    $('.portlet.msnry').each(function(i,e){
      $(e).removeClass('even');
      $(e).removeClass('odd');
      $(e).addClass(i%2==1 ? 'even' : 'odd');
    });
  },
}

jQuery(document).ready(function () {
  stuttgart.micro.init();
});

