/* ----------------------------------
jQuery browserSizr

tested with jQuery v1.3+
©2009 CSSLab.cl
free for any use, of course... :D
instructions: http://www.csslab.cl/2009/07/22/jquery-browsersizr/
---------------------------------- */

var resizeTimer = null;

jQuery.fn.browserSizr = function(options){
	// default plugin settings
	settings = jQuery.extend({
		containerDiv: '#container',		// value: any HTML tag of #id, default to #container
		lower1024: 'on',				// value: on | off, default to 'on'
		over1024: 'on'					// value: on | off, default to 'on'
	}, options);
	

	$(window).bind('resize load', function(e) {
		// get browser width
		var browserWidth = $('body').width();
		//alert (browserWidth);

		// search for the layout's container to inject the class'es
		var containerDiv = settings.containerDiv;
		
		// get de current class of the container an insert it to the debug window
		var containerClass = $(settings.containerDiv).attr('class');
		
		// filling the debug window with the current browser's width
		if(settings.debug=='on') {
			$('#debug #currentWidth').text(browserWidth+'px');
			if(containerClass == "") {
				$('#debug #currentClass').text('-');
			} else {
				$('#debug #currentClass').text(containerClass);
			};
		};

		// if statements for each resolution
		if(settings.lower1024=='on'){
			if(browserWidth<1451) {
				$(containerDiv).removeClass();
				if (resizeTimer) clearTimeout(resizeTimer);
				resizeTimer = setTimeout(lower1024, 10);
			};
		} else if(settings.lower1024=='off') {
			if(browserWidth<1451) {
				$(containerDiv).removeClass();
			};
		};
		if(settings.over1024=='on'){	
			if(browserWidth>1452 || browserWidth==1454) {
				if (resizeTimer) clearTimeout(resizeTimer);
				resizeTimer = setTimeout(over1024, 10);
			};
		} else if(settings.over1024=='off') {
			if(browserWidth>1452 || browserWidth==1454) {
				$(containerDiv).removeClass();
			};
		};
		
		function lower1024() {
			$(containerDiv).removeClass().addClass('lower1024');
		};
		function over1024() {
			$(containerDiv).removeClass().addClass('over1024');
		};
	});
	
};
