/**
 * @author trixta
 */
(function($){
	$.userMode = (function(){
		var userBg, timer, testDiv;
		function testBg(){
			testDiv.css({backgroundColor: '#000000'});
			var black = jQuery.curCSS( testDiv[0], 'backgroundColor', true);
			testDiv.css({backgroundColor: '#ffffff'});
			var white = jQuery.curCSS( testDiv[0], 'backgroundColor', true);
			var newBgStatus = (black === white || white === 'transparent')?true:false;
			if(newBgStatus != userBg){
				userBg = newBgStatus;
				$.event.trigger('usermode',[{'usermode': userBg}]);
			}
		}
		return {
			get: function(){
				testBg();
				return userBg;
			},
			init: function(time){
				testDiv = $('<div></div>').css({position: 'absolute', left: '-999em', top: '-999px', width: '0px', height: '0px'}).appendTo('body');
				timer = setInterval(testBg, time || 5000);
			},
			stop: function(){
				clearInterval(timer);
				testDiv.remove();
			}
		};
	})();
	$($.userMode.init);
})(jQuery);
