﻿/*
 * JavaScript module handler for Luckan 3
 *
 * Requires j-query
 */

 $(document).ready(function(){
	// modules to hide by default
	if ($.cookie('last-blog-posts') == null) { $.cookie('last-blog-posts', 'hide'); }
	if ($.cookie('last-bulletin-posts') == null) { $.cookie('last-bulletin-posts', 'hide'); }
	// check visibility on load
	jQuery.each($(".module"), function() {
		if ($.cookie($(this).attr("id")) == 'hide') {
			$(this).hide(); // hide content
			$(this).prev().css({backgroundImage:"url(grafik/modul-huvud-min.gif)"}); // change heading style
		} else {
			if ($(this).attr("id") != "features") {
				// Fix IE7 errors
				/*$(this).fadeTo(1, 0.99);
				$(this).fadeTo(1, 1);*/
				// Or fix IE7 errors with a nice fade
				$(this).hide();
				$(this).fadeIn(350);
			}
		}
    });
	// change visiblity on click
	$(".module-header").click(function(){
		$moduleid = $(this).next().attr("id");
		if ($(this).next().is(':visible')) {
			$(this).next().hide(350); // hide content			
			$(this).css({backgroundImage:"url(grafik/modul-huvud-min.gif)"}); // change heading style
			if ($moduleid != "profile" && $moduleid != "big-module") { $.cookie($moduleid, 'hide');} // set cookie
		} else {
			$(this).next().show(350); // show content
			$(this).css({backgroundImage:"url(grafik/modul-huvud-max.gif)"}); // change heading style
			$.cookie($moduleid, 'show'); // set cookie
		}
    });
 });