jQuery(document).ready(function(){
	(function( $ ) {
		
		var styleSwitcher = $('.styleswitcher'); 
		var settingLayout = $('.settings-layout');
		var settingBackgroundLayout = $('.settings-background-layout');
		var settingBackground = $('.setting-background');
		var settingColors = $('.setting-colors');
		var body = $('body');
				
		$('.styleswitcher-trigger').toggle(
		   function() {
				styleSwitcher.animate({
					left: '+=200'
				}, 200);
			},
		    function() {
				styleSwitcher.animate({
					left: '-=200'
			}, 200);
		});

		settingLayout.find('a').on('click', function() {
			settingLayout.find('a.setting-active').removeClass('setting-active');
			$(this).addClass('setting-active');	

			if ( $(this).hasClass('setting-boxed') ) {
				$('#wrapper').removeClass('fullwidth').addClass('boxed');
			}

			if ( $(this).hasClass('setting-fullwidth') ) {
				$('#wrapper').removeClass('boxed').addClass('fullwidth');
			}

			return false;
		});

		settingBackgroundLayout.find('a').on('click', function() {
			settingBackgroundLayout.find('a.setting-active').removeClass('setting-active');
			$(this).addClass('setting-active');

			var test = 'url("img/backgrounds/bg1.jpg")';

			if ( body.hasClass('body-background') ) {
					var test = ($('body').css('background-image'));
				}

			if ( $(this).hasClass('setting-small-background') ) {
				body.removeClass('body-background').css('background-image', 'none');
				$('.header-background').css('background-image', test);
			}

			if ( $(this).hasClass('setting-full-background') ) { 
				body.addClass('body-background').css('background-image', test);
			}

			return false;
		});

		settingBackground.find('a').on('click', function() { 
			var image = $(this).data('bg');
			var imageUrl = 'img/backgrounds/' + image;

			settingBackgroundLayout.find('a.setting-active').removeClass('setting-active');
			$('.setting-full-background').addClass('setting-active'); 

			body.addClass('body-background').css('background-image', 'url("' + imageUrl + '")');
		});


		settingColors.find('a').on('click', function() { 
			var color = $(this).data('color');			
			var styleurl = 'css/styles/' + color + '.css';

			if (color.indexOf("light") >= 0) {
				$('.news-menu').removeClass('widgets-light').addClass('widgets-light');
			} else {
				$('.news-menu').removeClass('widgets-light');
			}

			$('head').find('link.colorscheme').remove();
			
			$('head').append('<link class="colorscheme" rel="stylesheet" type="text/css" media="all" href="' + styleurl + '?v1.0" />');
		});


	
	})( jQuery );
});