$(function() {
	var $sections = $('#main > div:not(#sidebar)'),
		activeSection = 0,
		$nav = $('#nav ul'),
		$navItems = $('#nav ul li');
	
	$nav.kwicks({
		min : 100,
		sticky: true
	});
	
	$nav.mouseleave(function(){
		console.log('mouseout :(');
		$nav.data('kwicks').openKwick(activeSection);
	});
	
	$navItems.click(function(){
		var index = $navItems.index(this);
		
		// Do nothing for musicplayer item
		if(index == $navItems.length - 1)
			return;
		
		if(index == activeSection)
			return;
		
		activeSection = index;
		$nav.data('kwicks').openKwick(activeSection);
		
		// load correct page! :-)
		var $newActiveSection = $($sections.get(activeSection));
		$sections.hide();
		$newActiveSection.fadeIn();
	});
	
	$('.widget_expander').live('click', function(){
		$(this).removeClass('widget_expander').addClass('widget_shrinker');
	});
	$('.widget_shrinker').live('click', function(){
		$(this).removeClass('widget_shrinker').addClass('widget_expander');
	});
	
	$('#widget_related .widget_expander').live('click', function(){
		$ul = $(this).parent().find('li');
		$($ul.splice(8,8)).slideDown();
	});
	
	$('#widget_related .widget_shrinker').live('click', function(){
		$ul = $(this).parent().find('li');
		$($ul.splice(8,8)).slideUp();
	});
	
	var playlist = new jPlayerPlaylist({
		jPlayer: "#jquery_jplayer_1",
		cssSelectorAncestor: "#jp_container_1"
	}, [
		{
            title:	"IFK 1983",
            mp3:	"music/IFK%20-%201983.mp3",
			oga:	"music/IFK%20-%201983.ogg"
        },
        {
            title:	"IFK 1993",
            mp3:	"music/IFK%20-%201993.mp3",
			oga:	"music/IFK%20-%201993.ogg"
        },
        {
            title:	"IFK 2003",
            mp3:	"music/IFK%20-%202003.mp3",
			oga:	"music/IFK%20-%202003.ogg"
        },
        {
            title:	"Gamla Fina Vänersborg",
            mp3:	"music/Gamla%20Fina%20Vanersborg.mp3",
			oga:	"music/Gamla%20Fina%20Vanersborg.ogg"
        },
        {
            title:	"Matchdax",
            mp3:	"music/Matchdax.mp3",
			oga:	"music/Matchdax.ogg"
        },
        {
            title:	"Vi Äro Älgar",
            mp3:	"music/Vi%20Aro%20Algar.mp3",
			oga:	"music/Vi%20Aro%20Algar.ogg"
        },
	], {
		swfPath: "jPlayer",
		supplied: "oga, mp3",
		wmode: "window",
		loop: true,
		play: function() {
			$("#music .song-title").text(playlist.playlist[playlist.current].title);
		},
	});	
	$('.jp-shuffle').click();
});
