/* TABS WITH MEMORY BY DAVE REEDER */
(function($){
	memoryTabs = function() {
// ASSIGN A VARIABLE TO COOKIES VALUE
		var currentIndex = $.cookie("tabsMemory");
		
		// SET CURRENT TAB AND CURRENT PANELS
		if (currentIndex > 0) {
				var currentTab = $('#tabNavigation a').eq(currentIndex-1);		
				var currentPanel = $('#tabContent div').eq(currentIndex-1);
			}
		else {
				var currentTab = $('#tabNavigation a:first');
				var currentPanel = $('#tabContent div:first'); 
			}
		
		// SET CLASS TO MAKE CURRENT TAB STYLED CORRECTLY
		currentTab.addClass("currentTab");
		
		// HIDE ALL CONTENT PANELS, SHOW CURRENT TAB CONTENT PANEL
		$('#tabContent > div').fadeTo(0, 0).css("display", "none"); // FADE ALL TABS TO 0
										   // had to add in additional css to prevent ai elements from
										   // bleeding over into other panels
		currentPanel.css("display", "block").fadeTo(300, 1); // SHOW CURRENT TAB
		
		// CLICK EVENT FOR EACH TAB IN NAV
		$('#tabNavigation a').each(            
                function( intIndex ){           // FOR EACH ELEMENT RUN THIS FUNCTION intIndex IS THE LOOP ITERATION INDEX
                    $(this).click(function(event) {
                        $('#tabContent > div').fadeTo(0, 0).css("display", "none");  /* fade all others out and then hide them */
                        $('#tabContent > div').eq(intIndex).css("display", "block").fadeTo(300, 1); /* fade in required div */
						$('#tabNavigation a').removeClass();
						$(this).addClass('currentTab');
						// SET COOKIE
						var cookieValue = $(this).attr('rel');
						//alert(cookieValue);
						$.cookie("tabsMemory", cookieValue, { expires: 7 });
                    });
                }
            );

};
})(jQuery);

