/**
	Set control link to normal / bold
*/
function toggleBold(isOpen){
	$("#mySettingsLink").blur();
	if(!isOpen){ 
		$("#mySettingsLink").css("font-weight", "bold");
		return false;	
	} else {
		$("#mySettingsLink").css("font-weight", "normal");	
		return true;
	}
	return false;
}
/**
	Toggle layer up/down and change control element accordingly (normal/bold)
*/
function toggleLayer(){
	$("#mySettingsLink").attr("href", "javascript:void(0)");
	var isOpen; isOpen = false; 
		
	if($("#mysettings").css("display") == "block"){
		isOpen = true;
	}
	isOpen = toggleBold(isOpen);

	$("input[@name=save]").
		click(function(){
			animatedcollapse.hide("mysettings");
			isOpen = false;
			toggleBold(isOpen);
			return false;
	});
	
	$("#mySettingsLink").
		click(function(){	
			if(!isOpen){
				animatedcollapse.show("mysettings");
				isOpen = true;
				toggleBold(isOpen);
			} else {
				animatedcollapse.hide("mysettings");
				isOpen = false;
				toggleBold(isOpen);
			}
	});
}

var SIZE_COOKIE; SIZE_COOKIE = 'textsize';
var STYLE_COOKIE; STYLE_COOKIE = 'textstyle';
var PICS_COOKIE; PICS_COOKIE = 'showpics';
var THEME_COOKIE; THEME_COOKIE = 'showtheme';
function initFontSize(){
	// Get size
	var fontSize; fontSize = $.cookie(SIZE_COOKIE);
	var fontSizeCSS; fontSizeCSS = parseInt($("body").css("font-size"));
	
	if(!fontSize) {
		fontSize = fontSizeCSS;
		$.cookie(SIZE_COOKIE, fontSize, { expires: 0, path: '/' });
	} else if(fontSize != fontSizeCSS) {
		$("body").css("font-size", fontSize + "px");
	}
	$("input[@value="+fontSize+"]").attr("checked", "checked");
}
function initFontStyle(){
	// Get style
	var fontStyle; fontStyle = $.cookie(STYLE_COOKIE);
	var fontStyleCSS; fontStyleCSS = $("body").css("font-family");
	
	if(!fontStyle) {
		fontStyle = fontStyleCSS;
		$.cookie(STYLE_COOKIE, fontStyle, { expires: 0, path: '/' });
	} else if(fontStyle != fontStyleCSS) {
		$("body").css("font-family", fontStyle);
	}
	$("input[@value="+fontStyle+"]").attr("checked", "checked");
}
function initShowPics(){
	// Get style
	var showPics; showPics = $.cookie(PICS_COOKIE);
	var showPicsCSS; showPicsCSS = $("img.picture").css("display");
	
	if(!showPics) {
		showPics = showPicsCSS;
		$.cookie(PICS_COOKIE, showPics, { expires: 0, path: '/' });
	} else if(showPics != showPicsCSS) {
		$("img.picture").css("display", showPics);
		$("div.pictureCaption").css("display", showPics);
	}
	$("option[@value="+showPics+"]").attr({selected:"selected"});
}

function initShowTheme(){
	// Get style
	var showPics; showTheme = $.cookie(THEME_COOKIE);
	var showThemeCSS; showThemeCSS = $("body").attr("id");
	
	if(!showTheme) {
		showTheme = 'theme1';
		$.cookie(THEME_COOKIE, showTheme, { expires: 0, path: '/' });
	} else if(showTheme != showThemeCSS) {
		$("body").attr("id", showTheme);
	}
	$("input[@value="+showTheme+"]").attr("checked", "checked");
}

function toggleSizeStyle(){
	initFontSize();
	initFontStyle();
	$("input[@name=textsize]").
		click(function(){
			$("body").css("font-size", $(this).val() + "px");
			$.cookie(SIZE_COOKIE, $(this).val(), { expires: 0, path: '/' });
	});
	$("input[@name=textstyle]").
		click(function(){
			$("body").css("font-family", $(this).val());
			$.cookie(STYLE_COOKIE, $(this).val(), { expires: 0, path: '/' });
	});
}

function togglePics(){
	initShowPics();
	
	$("select[@name=showimages]").
		change(function(){
			$("img.picture").css("display", $("select[@name=showimages] option:selected").val());
			$("div.pictureCaption").css("display", $("select[@name=showimages] option:selected").val());
			$.cookie(PICS_COOKIE, $("select[@name=showimages] option:selected").val(), { expires: 0, path: '/' });
	});
}
function toggleTheme(){
	initShowTheme();
	
	$("input[@name=theme]").
		click(function(){
			$("body").attr("id", $(this).val());
			$.cookie(THEME_COOKIE, $(this).val(), { expires: 0, path: '/' });
	});
	
	$(".theme").
		click(function(){
			$(this).find("input[@name=theme]").attr("checked", "checked");
			$("body").attr("id", $(this).find("input[@name=theme]").val());
			$.cookie(THEME_COOKIE, $(this).find("input[@name=theme]").val(), { expires: 0, path: '/' });
	});

}