(function(){
  /*
   * Global initialization 
   * Initiate polling, subscribe count to poll, wire up alert and inbox drop downs.
   */
	Chemistry = {
        
        /**
         * Merges an objects properties into the Chemistry object. TODO: Allow namespacing.
         */
        include: function( name, includes ) {
                    
            if ( name instanceof Object ) 
            {
                includes = name;
                
                for (var ref in includes) {
                
                    Chemistry[ ref ] = includes[ ref ];
               
                }                
            }
        
        },
        
        /*
         * A set of channels to which data, that many widgets may need to be aware of, will frequently be published.
         */
        channels: {
    
            MASTER          : 'data received',
            COUNTS          : 'count data received',
            PRESENCE        : 'presence data received',
            ALERTS          : 'alert data received',
			OPEN_INVITE		: 'open invitation exists',
            INVITATION      : 'invitation data received',			
            NOTIFICATIONS   : 'notification data received'
                    
        }
       
    };
  
})();

(function(){

  /* Enable custom checkboxes, radios, selects, and ranges*/
    
	$('select').not('[multiple]').dropkick();

	/* Since the other checkbox code clashes with this one on account edit, we need to disable it. This will temporary do so... */
	/* TODO: Move to one or the other. */
	setTimeout(function(){
		if ($('.account').length){
			$('.theme1 .custom-checkbox').each(function(){
				var input = $('span input', this);
				var parent = input.parent();
				input.appendTo(this);
				parent.remove();
			});
		}
	},100);


	$('input[type="range"]').rangeinput({
	  css: {
      slider: 'slider',
      input:  'slider-range',
      progress: 'slider-progress',
      handle: 'slider-handle'
	  }
	});

  /* Wire up custom birthday field. */
  $('.fieldset-birthday').birthday_field();   

  /* Wire up text counters */
  $('.counter').counter()

  $('form').auto_submitable();
  $(function(){ $('html').removeClass('dk_fouc'); });
})(jQuery);

/* NAV MENU */
setIIYClass();

function setIIYClass() {
    var iiyCountSpan = $('#link-interested-span');
    if (iiyCountSpan.text() == '0' | iiyCountSpan.text() == '(0)' | iiyCountSpan.text() == '') {
        iiyCountSpan.removeClass('highlight');
    }
    else {
        iiyCountSpan.addClass('highlight');
    }

}

(function(){
	$.subscribe(Chemistry.channels.COUNTS, function(data){
		setTimeout(function(){
			setIIYClass();
		}, 20);
	});
})(jQuery);

