var CROSSMINE = CROSSMINE || {};

(function(window, document, $, CROSSMINE){
  
  CROSSMINE = {
	
    exec : function() {
	
      CROSSMINE.setYear();
	    CROSSMINE.colorBox();
	    CROSSMINE.condense();
	    CROSSMINE.mailChimp();

    }, 

  	setYear : function () {
  		var d=new Date();
  		document.getElementById('year').innerHTML = d.getFullYear();
  	},
	
  	colorBox : function() {
  	  $("a.colorBox").colorbox({
  	    slideshow: false,
  	    opacity: 0.5,
  	    maxWidth: '80%',
  	    maxHeight: '95%',
  	    scalePhotos: true,
  	    current: "{current} of {total}"
  	  });
  	}, 
	
  	condense : function() {
  	  $(".bio p").condense({
        condensedLength: 220, 
        moreText : '<span class="button-more">More<strong> &gt; </strong></span>',
        lessText : '<span class="button-more"><strong> &lt; </strong>Less</span>',
        moreSpeed : 200,
        lessSpeed : 200,
        ellipsis : '&hellip;'
      });
  	},
  	
  	mailChimp : function() {
  	  try {
      	$('#archive-list li:even').addClass("odd");
          $('.field-group, .field-group input, .field-group select').live('click',function(event){		 			
      		if (event.type == 'click') {
       			if ($(this).hasClass('field-group')){
       			    var fg = $(this);
       			    if($(this).children('.datefield').length == 1){
       			        // Do not select 1st input so date picker will work.
       			    } else {
       			        $(this).find('input, select').slice(0,1).focus();
      		        }
       			} else {
       			    var fg = $(this).parents('.field-group');
      			    $(this).focus();
       			}
              	fg.not('.focused-field').addClass('focused-field').children('.field-help').slideDown('fast');
              	$('.focused-field').not(fg).removeClass('focused-field').children('.field-help').slideUp('fast');
      		}
        });
        // Allow select inputs to be width:auto up to 500px (because max-width doesn't work in IE7)
        $("select").each(function(){
            $(this).css("width", "auto");
            if($(this).width() > 500){
                $(this).css("width", "500px");
            }
        });

        } catch(e){ console.log(e); }
  	}
  };

  $(document).ready(CROSSMINE.exec);
  
}(window, document, jQuery, CROSSMINE));
