(function($){
	$.widget("sg.sg_sizeswitch", {
		
		options: {
			switches: null,
			state: null
		},
		
		_create: function(){			
			var $widget = this;
			var $options = this.options;
			
			$(window).resize(function() {
				$widget.onResize();
			});
			$widget.onResize();
		},
		
		getState: function(){
			return this.options.state;
		},
		
		onResize: function(){
			var $options = this.options;
			var $state;
			
			$.each($options.switches, function(key, value){
				if($(window).width() > value){
					$state = key;	
				}
			});
			
			if($options.state != $state){
				$options.state = $state;
				this.element.trigger('sg_sizeswitch.statechange', $options.state);	
			}
		}
	});
}( jQuery ) );
