mcd.util = function () {
    
    var D = mcd.dom;
    var E = mcd.event;
    
    return {
        /**
         * Generic rollover callback
         * 
         * @param {Event} event
         * @param {String} suffix The filename suffix for over states
         */
        rollOver : function (event, suffix) {
            var target  = E.getTarget(event),
                matches = target.src.match(/\.[a-zA-Z]+$/),
                suffix  = suffix || '-on';
            
            target.src = target.src.replace(matches[0], '-on' + matches[0]);
        },
        
        /**
         * Generic rollout callback
         * 
         * @param {Event} event
         * @param {String} suffix The filename suffix for over states
         */
        rollOut : function (event, suffix) {
            var target  = E.getTarget(event),
                suffix  = suffix || '-on',
                matches = target.src.match(
                	new RegExp('^(.)*(' + suffix + ')\.[a-zA-Z]+$')
                );
			
            target.src = target.src.replace(matches[2], '');
        },
        
        /**
         * Check if object is empty
         * 
         * @param {Object} The object to check for emptiness
         * @return {boolean} 
         */
         
		objectEmpty : function (o) {
			for (var i in o) {
				return false;
			}
			return true;
		},
		
		/**
		 * Scan page for any print-trigger classes and add events
		 * to them calling the print window
		 * 
		 * @param {String} An optional additional string that should be used
		 * 		  to call the print window other than the default print-trigger
		 */
		 
		printTriggers : function (optionalClass) {
			var triggerList = mcd.dom.getElementsByAttribute('class', 'print-trigger', document.body, 'a', true);
				
			for (var i = 0; i < triggerList.length; i++) {
				mcd.event.add(triggerList[i], 'click', mcd.util.printWindow);
			}
			if (optionalClass) { // If we have an optional class name
				var triggerList = mcd.dom.getElementsByAttribute('class', optionalClass, document.body, 'a', true);
				
				for (var i = 0; i < triggerList.length; i++) {
					mcd.event.add(triggerList[i], 'click', mcd.util.printWindow);
				}
			}
		},
		
		/**
		 * A wrapper function for the print window command so that print window
		 * can be used as a callback function
		 * 
		 */
		printWindow : function (event) {
			if (mcd.event.getTarget(event).nodeName === 'A') {
				mcd.event.preventDefault(event);
			}
			
			window.print();
		},
		
		/**
		 * Catches any links that have a relationship of "external" and opens them
		 * in new windows
		 */
		externalLinkHandler : function () {
			var triggerList = mcd.dom.getElementsByAttribute('rel', 'external', document.body, 'a');
			
			for (var i = 0; i < triggerList.length; i++) {
				mcd.event.add(triggerList[i], 'click', function (event) {
					mcd.event.preventDefault(event);
					window.open(this.getAttribute('href'), '_blank')	
				});
			}
		}
    };
}();
