jQuery(document).ready(function() {
	var $ = jQuery.noConflict();
	
	//now with cookie suppport
	function contentTabs(){

		//to make up for some inconsistencies
		//make sure the user hasnt just logged out, if so only show first tab
		if ($('#content.loggedout').length)
		{
			$(".content_tab").hide();
			$('#content.loggedout').show();
			$('ul#content_htabs li a.loggedout').addClass('active');
			 $.cookie('content_tabs', null);
		}
		else
		{
			//otherwise
			//check if cookie exists
			var cookie = $.cookie('content_tabs');
			//if cookie is not null show the conresponding tab
			if(cookie)
			{
				//if so hide others and add active class to link
				$('.content_tab:not(#'+cookie+')').hide();
				$('#'+cookie).show();
				$('a[href="#'+cookie+'"]').addClass('active');
			}
			else //if cookie doesnt exist show first tab
			{
				//if this is not the first tab, hide it
				$(".content_tab:not(:first)").hide();
				//to fix u know who
				$(".content_tab:first").show();
				//ad active class to first link
				$('ul#content_htabs li:first').find('a').addClass('active');
			}
		}
		
		 //when we click one of the tabs
		 $("#content_htabs li a").click(function(){
			
			//add an active class to the links							   
			$(this).parents('ul#content_htabs').find('li a.active').toggleClass('active');
			$(this).toggleClass('active');
										   
			 //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('content_tabs', stringref);
			 
			 //hide the tabs that doesn't match the ID
			 $('.content_tab:not(#'+stringref+')').hide();
			 //fix
			 if ($.browser.msie && $.browser.version.substr(0,3) == "6.0") 
			 {
				$('.content_tab#' + stringref).show();
			 }
			 else
			 {
				 //display our tab fading it in
				 $('.content_tab#' + stringref).show();
			 }
				//get both height of sidebar and content area
				var mid = $('.content_tab#' + stringref).outerHeight();
				var side = $('#sidebar_wrapper').outerHeight();
				
				//if sidebar is larger than content area in focus
				if (side >= mid)
				{
					//alert('1:'+'mid='+mid+' side='+side);
					//reset both heights to auto
					$('.content_tab#' + stringref).css('height', 'auto');
					$("#sidebar_wrapper").css('height', 'auto'); 
					//$("#sidebar_wrapper").setOuterHeight(mid); 
					//$("#sidebar_wrapper").setOuterHeight(mid);  	
				}
				else	if (side <= mid)
				{
					//alert('2:'+'mid='+mid+' side='+side);
					//set sidebar to mid's height
					$("#sidebar_wrapper").setOuterHeight(mid);  				
				}

			 //stay with me
			 return false;
		 });
	}
	contentTabs();
});

