/* Alpha release of halfTab, developed and released by Jay Michael Del Greco, March 01, 2011.
Feel free to use and re-use it at will. Just give credit where it's due. Thanks! */
$.fn.halfTab=function(settings){
	settings = $.extend({}, $.fn.halfTab.defaults, settings);
	size = settings.size;
	panelWidth = settings.panelWidth;
	panelHeight = settings.panelHeight;
	//If we are set to full sceen we need to grab the window dimensions. If not, we're just going to use the passed ones or defaults
	if (size == 'full'){
		var uAgent = navigator.userAgent.toLowerCase();
		if (uAgent.indexOf('msie') != -1) {
			//If we're IE we'll need to grab the browser dimentions this way
			var yourWidth = document.documentElement.clientWidth;
			var yourHeight = document.documentElement.clientHeight;
		} else {
			//Everybody else works with this
			var yourWidth = window.innerWidth;
			var yourHeight = window.innerHeight;
		}
		var totalTabWidth = yourWidth/2;
	} else {
		var yourWidth = parseInt(panelWidth);
		var yourHeight = parseInt(panelHeight);
		var totalTabWidth = parseInt(yourWidth);
	}
	var theTab = $(this).attr('id');
	$('#'+theTab).css('width',totalTabWidth+'px').css('height',(yourHeight+4)+'px');
	$('#sideCar').css('display','block').css('width',totalTabWidth-76+'px').css('height',yourHeight+'px').css('float','left');//78 instead of 74, because of the 2px border on either side
	var tabPosition = (yourHeight/2) - ($('#theTab').height()/2);//we want the tab vertically centered
	$('#theTab').css('margin-top',tabPosition+'px');
	var sideTabInPos = 74-totalTabWidth;
	var sideTabOutPos = 0;
	$('#'+theTab).css('position','absolute').css('top','10px').css('left',sideTabInPos+'px');
	$('.in').live('click', function(){
	   //$('#sideTab').css('left',totalTabWidth+'px');
	   $('#'+theTab).css('z-index','33');
	   $('#'+theTab).animate({ left: sideTabOutPos}, 1000, 'easeInQuad', function() {
			//Animation complete, maybe have a party or suh'um
			$('#theTab').addClass('out');
			$('#theTab').removeClass('in');
		});
		return false;
	});
	$('.out, #closeTab').live('click', function(){
	   $('#'+theTab).animate({ left: sideTabInPos}, 1000, 'easeInQuad', function() {
			//Animation complete, maybe have a party or suh'um
			$('#theTab').addClass('in');
			$('#theTab').removeClass('out');
			$('#'+theTab).css('z-index','31');
		});
		return false;
	});
};
//Default values for the parameters in the extend.
$.fn.halfTab.defaults = {
	size				:	'full',
	panelWidth			:	500,
	panelHeight			:	400
};

