$(document).ready( function() {

	$('.ddmenu').singleDropMenu({parentMO: 'ddmenu-hover', childMO: 'ddchildhover'});

	
	// Adjust sidebar height to multiples of 'ring' image height?
	
	// toggle .ddmenu
	
	$('#togglemenu').click(function() {
//		$('.ddmenu').slideToggle('normal');
	});
	// Set colours
	$('.setcolor').click(function() {
		bgc = $(this).css("backgroundColor");
		switchStylesheet($(this).attr("id"), bgc);
		createCookie('style', $(this).attr("id"), 365);
		});
	// Set FONT size
	$('.setsize').click(function() {
		$('body').removeClass('s m l xl').addClass($(this).text());
		createCookie('font-size', $(this).text(), 365);
		return false;
		});
	// Change FONTS
	$('.TextStyleField').click(function() {
		$('body').css('font-family',$(this).css('fontFamily'));
		createCookie('font-face', $(this).css('fontFamily'), 365);
		return false;
		});
	// Switching styles	
	$('#switcher a').click(function() {
		switchStylesheet(this.getAttribute("rel"));
		createCookie('style', this.getAttribute("rel"), 365);
		return false;
	});
	function switchStylesheet (styleName, bgc) {
		$('body').append('<div id="overlay" />');
		$('body').css({height:'100%'});
		$('#overlay')
			.css({
				display: 'none',
				position: 'absolute',
				top:0,
				left: 0,
				width: '100%',
				height: '100%',
				zIndex: 1000,
				background: bgc
			})
			.fadeIn(500,function(){
			
			// Needs to have root passed in from php in header.php!!
				$('#switchable').attr('href',themeroot+'/style/css/style-' + styleName + '.css');
			
			})
			.fadeOut(500,function(){
							$(this).remove();
						});
	}
	
	// Reseting all styles
	$('#reset a').click(function() {
		$('body').removeClass('s m l xl');
		switchStylesheet('ffffff');
		eraseCookie('style');
		eraseCookie('font-size');
		eraseCookie('font-face');
		eraseCookie('color');
		return false;
	});
	
	// Toggling panel
	$('#closepanel').click( function () {
		$('#acc-panel-main').toggle();
		return false;
	});

	
	// Reading the cookies and setting off functions
	var d = readCookie('font-size');
	var f = readCookie('font-face');
	if (d) $('body').removeClass('s m l xl').addClass(d);
	if (f) $('body').css('font-family',f);

	// Fading in panel on load
	$('#side #acc-panel').hide().fadeIn("slow");
	
//	Show nav as treeview loaded
//	$('.nav').toggle();
	

	

	
});
