var Sentres = {

  times: {},

  startTime: function(name) {
    //this.times[name] = new Date().getTime();
    return false;
  },

  stopTime: function(name) {
    // var duration = new Date().getTime() - this.times[name];
    // console.info(name + ": " + duration+"ms");
    return false;
  },

  initStandardClasses: function() {
    $("html").addClass("javascript");
    $('.hidden').hide();

    // :last-child for non-webkit browsers
    $('.onecol .row:last-child').addClass("lastitem");

    // rel=external is the new target=_blank
    $('a[rel=external], a.external').live("click", function(e) {
      e.preventDefault();
      window.open($(this).attr("href"));
    });
  },

  initJqueryUniform: function() {
    //TODO is this only needed for user profiles?
    /* jquery uniform */
    $(".uf input:checkbox, .uf select, .uf input:radio, input.uf, select.uf, .uf input:file").uniform({
      fileDefaultText: 'Datei wählen:',
      fileBtnText: 'Neue Datei hochladen'
    });
  },

  initFeedLinks: function() {
    $('#feed-link').click(function(){
      $(this).hide();
      $('li.feed-link').show();
      return false;
    });
  },

  initPostLoadImages: function() {
    $('img.post-load').each(function(i) { 
      this.src = this.getAttribute("data-url");
      // var elem = $(this); 
      // elem.attr("src", elem.attr("data-url"));
    });
  },

  initDatepicker: function() {
    $.datepicker.regional['de'] = {
      closeText: 'schließen',
      prevText: '',
      nextText: '',
      currentText: 'heute',
      monthNames: ['Januar','Februar','März','April','Mai','Juni',
        'Juli','August','September','Oktober','November','Dezember'],
        monthNamesShort: ['Jan','Feb','Mär','Apr','Mai','Jun',
          'Jul','Aug','Sep','Okt','Nov','Dez'],
          dayNames: ['Sonntag','Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag'],
          dayNamesShort: ['So','Mo','Di','Mi','Do','Fr','Sa'],
          dayNamesMin: ['So','Mo','Di','Mi','Do','Fr','Sa'],
          weekHeader: 'Wo',
          dateFormat: 'dd.mm.y',
          firstDay: 1,
          defaultDate: +1,
          isRTL: false,
          showMonthAfterYear: false,
          yearSuffix: ''
    };
    $.datepicker.regional['it'] = {
      closeText: 'Chiudi',
      prevText: '',
      nextText: '',
      currentText: 'Oggi',
      monthNames: ['Gennaio','Febbraio','Marzo','Aprile','Maggio','Giugno',
        'Luglio','Agosto','Settembre','Ottobre','Novembre','Dicembre'],
        monthNamesShort: ['Gen','Feb','Mar','Apr','Mag','Giu',
          'Lug','Ago','Set','Ott','Nov','Dic'],
          dayNames: ['Domenica','Luned&#236','Marted&#236','Mercoled&#236','Gioved&#236','Venerd&#236','Sabato'],
          dayNamesShort: ['Dom','Lun','Mar','Mer','Gio','Ven','Sab'],
          dayNamesMin: ['Do','Lu','Ma','Me','Gi','Ve','Sa'],
          calendarWeek: '',
          weekHeader: 'Sm',
          dateFormat: 'dd.mm.y',
          defaultDate: +1,
          firstDay: 1,
          isRTL: false,
          showMonthAfterYear: false,
          yearSuffix: ''
    };
    $.datepicker.setDefaults($.datepicker.regional[$('body').attr('data-locale')]);
    $('input.date').datepicker();
  },

  plugins: [],

  // Sentres.registerPlugin(Sentres.Spinner)
  // That way, the init() method will be called after page load
  registerPlugin: function(plugin) {
    this.plugins.push(plugin);
  },
  onReady: function() {

    Sentres.startTime("sentres-init");

    Sentres.startTime("sentres-standard");
    Sentres.initStandardClasses();
    Sentres.stopTime("sentres-standard");

    Sentres.startTime("sentres-uniform");
    Sentres.initJqueryUniform();
    Sentres.stopTime("sentres-uniform");

    Sentres.startTime("postload");
    Sentres.initPostLoadImages();
    Sentres.stopTime("postload");

    Sentres.startTime("datepicker");
    Sentres.initDatepicker();
    Sentres.stopTime("datepicker");

	 	Sentres.startTime("disableAllFlyoutLinks");
		Sentres.FlyoutAndLogin.disableAllFlyoutLinks();
		Sentres.stopTime("disableAllFlyoutLinks");
		
    Sentres.initFeedLinks();


    $.each(Sentres.plugins, function(index, value) { 
      if(typeof value.init == 'function') {
        Sentres.startTime(value.name);
        value.init() 
        Sentres.stopTime(value.name);
      }
    })
    Sentres.stopTime("sentres-init");
  }

}
$(Sentres.onReady);


//////////////////////////////////////////////////////
// Refactoring ends here
//////////////////////////////////////////////////////


// TODO: move to CMS.js ?
$(function(){

	$('.photo_overview').hover(function() {
	  $('h4', this).hide();

	}, function() {
	  $('h4', this).show();

	});
});


// helper
// TODO Can this be moved to CMS ?
var delay = (function(){
  var timer = 0;
  return function(callback, ms){
    clearTimeout(timer);
    timer = setTimeout(callback, ms);
  };
})();


$(function() {


  // make whole col clickable
  /*
  $('.col.clickable').each(function() {
    var self = $(this);
    var href = false;

    if (href = self.find("a img:only-child").parent().attr("href")) {
      self.click(function(b) {

        document.location.href = href;

        return false;
      });

    } else {
      self.removeClass("clickable");
    }

  });
  */


 
});


