jQuery(document).ready(function() {
	var $ = jQuery.noConflict();
	
	function myTabs(div){
			//check if cookie exists
			var cookie = $.cookie(div + '_tabs');
			//if cookie is not null show the conresponding tab
			if(cookie)
			{
				//if so hide others and add active class to link
				$('.' + div + '_tab:not(#'+cookie+')').hide();
				$('#'+cookie).show();
				$('a[href="#'+cookie+'"]').addClass('tab-current').parent('li').addClass('tab-current');			
			}
			else //if cookie doesnt exist show first tab
			{
				//if this is not the first tab, hide it
				$('.' + div + '_tab:not(:first)').hide();
				//to fix u know who
				$('.' + div + '_tab:first').show();
				//ad active class to first link
				$('ul#' + div + '_htabs li:first').find('a').addClass('tab-current');
				$('ul#' + div + '_htabs li:first').addClass('tab-current');
			}

			//=== so to keep tabs the same size and avoid column colapse
			// keep track of the tallest column
			var tallest = 0;
			//make sure each is floated as display block will shop the non active tabs being hidden
			$('.' + div + '_tab').css('float', 'left');
			// loop through columns and find the tallest
			$('.' + div + '_tab').each(function(){
				if ($(this).outerHeight() > tallest) tallest = $(this).outerHeight();
			});
			//set the height of all to the tallest
			$('.' + div + '_tab').setOuterHeight(tallest);
	
		 //when we click one of the tabs
		 $('ul#' + div + '_htabs li a').click(function(){
			
			$('ul#' + div + '_htabs li').removeClass('tab-current');
			$(this).parents('li').addClass('tab-current');
			//add an active class to the links							   
			$(this).parents('ul#' + div + '_htabs').find('li a.tab-current').toggleClass('tab-current');
			$(this).toggleClass('tab-current');
										   
			 //get the ID of the element we need to show
			 stringref = $(this).attr("href").split('#')[1];
			 //write a cookie with the div id name
			  $.cookie(div + '_tabs', stringref);

			 //hide the tabs that doesn't match the ID
			 $('.' + div + '_tab:not(#'+stringref+')').hide();
			 //fix
			 if ($.browser.msie && $.browser.version.substr(0,3) == "6.0") 
			 {
				$('.' + div + '_tab#' + stringref).show();
			 }
			 else
			 {
				 //display our tab fading it in
				 $('.' + div + '_tab#' + stringref).show();
			 }

			 //stay with me
			 return false;
		 });
	}
	//myTabs('sidebar_upper');


});
