var logo = {
	init : function(){
		$("#kk_logo").hover( 
			function() { $(this).attr({ src: "/images/kk-logo-over.jpg"}); },
			function() { $(this).attr({ src: "/images/kk-logo.jpg"}); } 
		);
	}
};

var nav = {
	init : function(){
		$("#nav > li").addClass("closed").find('h3 a').click(this.clickIt);
		$('#current').parent().parent('ul').show();
	},
	clickIt : function(){
		$(this).parent().siblings('ul').slideToggle("slow"); // toggle the submenu ul
		$(this).parent().parent('li').toggleClass("closed");
		return false;
	}
};

var tabs = {
	init : function(){
		// Display as a tabset and hide the tabboxes
		$("#extra").
		addClass("tabset").
		children('.tabbox'). // all but the first tabbox
		hide();
		// Set the classes for the visible tab and tabbox
		var tab = '#extra .tab:eq(0)';
		if ((window.location.hash != '') & ($('#extra '+window.location.hash))) { // if the hash is not empty and if the hash value has a matching id in #extra
			tab = window.location.hash; // set the tab to the hash
		}
		$(tab). // the tab
		addClass('selected').
		next('.tabbox'). // and its tabbox
		addClass('selected').
		show();
		$("#extra.tabset .tab").click(this.clickIt);
	},
	clickIt : function(){
		// hide the current .tabbox
		$(this).siblings('.tabbox:visible').slideUp("slow",function(){
			// when done show the newly selected .tabbox
			$(".tabbox.selected").slideDown('slow');
		});
		// remove .selected from current section
		$(".tab.selected").removeClass("selected");
		$(".tabbox.selected").removeClass("selected");
		
		// add .selected to clicked tab
		$(this).addClass("selected");
		$(this).next(".tabbox").addClass("selected");
		
		// get the id of the currently selected tab and set the window.location.hash to that id
		window.location.hash = '#'+$(this).attr("id");
		
		return false;
	}
};

jQuery.noConflict();
jQuery(document).ready(function($){

	// LOGO ROLLOVER
	logo.init();
	// NAVIGATION
	nav.init();
	// TABS
	tabs.init();
});