//Плагин cookie
(function($,document){var pluses=/\+/g;function raw(s){return s}function decoded(s){return decodeURIComponent(s.replace(pluses," "))}$.cookie=function(key,value,options){if(arguments.length>1&&(!/Object/.test(Object.prototype.toString.call(value))||value==null)){options=$.extend({},$.cookie.defaults,options);if(value==null)options.expires=-1;if(typeof options.expires==="number"){var days=options.expires,t=options.expires=new Date;t.setDate(t.getDate()+days)}value=String(value);return document.cookie=[encodeURIComponent(key),"=",options.raw?value:encodeURIComponent(value),options.expires?"; expires="+options.expires.toUTCString():"",options.path?"; path="+options.path:"",options.domain?"; domain="+options.domain:"",options.secure?"; secure":""].join("")}options=value||$.cookie.defaults||{};var decode=options.raw?raw:decoded;var cookies=document.cookie.split("; ");for(var i=0,parts;parts=cookies[i]&&cookies[i].split("=");i++)if(decode(parts.shift())===key)return decode(parts.join("="));return null};
$.cookie.defaults={}})(jQuery,document);

	function setFontSize(fontSize) {
		saveSettings('fontSize', fontSize);
		$('html').removeClass('fs-small fs-normal fs-big').addClass(fontSize);
	}
	
	function setColorSite(color) {
		saveSettings('color', color);
		$('html').removeClass('color1 color2 color3 color4 color5').addClass(color);
	}
	
	function setFontFamily(fontFamily) {
		saveSettings('fontFamily', fontFamily);
		$('html').removeClass('serif sans-serif').addClass(fontFamily);
	}
	
	function setSpacing(letterSpace) {
		saveSettings('letterSpace', letterSpace);
		$('html').removeClass('spacing-normal spacing-big spacing-small').addClass(letterSpace);
	}
	
	function setImageVisible(showImgs) {
		saveSettings('showImgs', showImgs);
		$('html').removeClass('imagesoff imageson').addClass(showImgs);
		$('.a-images a').attr('rel', (showImgs=='imagesoff')?'imageson':'imagesoff');
	}

	function setNormal(normalVer) {
		saveSettings('normalVer', normalVer);
		$('html').removeClass('specialversion normalvesion').addClass(normalVer);
	}
	
	function setDefSpecialSettings() {
		setColorSite('color1');
		setFontFamily('sans-serif');
		setFontSize('fs-normal');
		setSpacing('spacing-small');
		setNormal('specialversion');
		setImageVisible('imageson');
	}

	function setNormalMode() {
		setColorSite(def_settings.color);
		setFontFamily(def_settings.fontFamily);
		setFontSize(def_settings.fontSize);
		setSpacing(def_settings.letterSpace);
		setNormal(def_settings.normalVer);
		setImageVisible(def_settings.showImgs);
	}
	
	function setUserSettings() {
		var getSettings = { 
			color:			$.cookie('color') || window.def_settings.color,
			fontFamily:		$.cookie('fontFamily') || window.def_settings.fontFamily,
			fontSize:		$.cookie('fontSize') || window.def_settings.fontSize,
			letterSpace:	$.cookie('letterSpace') || window.def_settings.letterSpace,
			normalVer:		$.cookie('normalVer') || window.def_settings.normalVer,
			showImgs:		$.cookie('showImgs') || window.def_settings.showImgs
		};
		setColorSite(getSettings.color);
		setFontFamily(getSettings.fontFamily);
		setFontSize(getSettings.fontSize);
		setSpacing(getSettings.letterSpace);
		setNormal(getSettings.normalVer);
		setImageVisible(getSettings.showImgs);
	}
	
	function saveSettings(name, value) {
		$.cookie(name, value, { expires: 2*365, path: '/', secure: false });
	}
	
	
$(document).ready(function(){
	window.def_settings = {
			// color:			'color1',
			// fontFamily:		'sans-serif',
			// fontSize:		'fs-normal',
			// letterSpace:	'spacing-small',
			// normalVer:		'specialversion',
			// showImgs:		'imageson'
			color:			'',
			fontFamily:		'',
			fontSize:		'',
			letterSpace:	'',
			normalVer:		'normalvesion',
			showImgs:		'imageson'
		};
	setUserSettings();
	
	$('.choose-font-family a').click(function(){
		setFontFamily($(this).attr('rel'));
		return false;
	});
	$('.choose-letter-spacing a').click(function(){
		setSpacing($(this).attr('rel'));
		return false;
	});
	$('.a-images a').click(function(){
		setImageVisible($(this).attr('rel'));
		return false;
	});

	$('.a-fontsize a').click(function(){
		setFontSize($(this).attr('rel'));
		return false;
	});
	$('.a-colors a, .choose-colors a').click(function(){
		setColorSite($(this).attr('rel'));
		return false;
	});

	$('.a-settings a,.saveit .closepopped').click(function(){
	$('.popped').slideToggle('fast');
		return false;
	});

	$('.saveit .default, #specialversion').click(function(){
		setDefSpecialSettings();
		return false;
	});

	$('#normalversion').click(function(){
		setNormalMode($(this).attr('rel'));
		return false;
	});
  
});