var track=0;
jQuery(document).ready(function ($) {
		function clearColor(){
			$('body').removeClass('color-green color-blue color-violet color-red color-orange color-turquoise color-color1')
		}
		$('body').prepend('<div class="tt-colorswatch"><div class="tt-colorswatch-options coloroptions"><a href="#" data-color="" class="colorswatch1 active js-swatch-color"></a><a href="#" class="colorswatch2 js-swatch-color" data-color="color2"></a><a href="#" class="colorswatch3 js-swatch-color" data-color="color3"></a><a href="#" class="colorswatch4 js-swatch-color" data-color="color4"></a><a href="#" class="colorswatch5 js-swatch-color" data-color="color5"></a><a href="#" class="colorswatch6 js-swatch-color" data-color="color6"></a><a href="#" class="colorswatch7 js-swatch-color" data-color="color7"></a><a href="#" class="colorswatch8 js-swatch-color" data-color="color8"></a><a href="#" class="colorswatch9 js-swatch-color" data-color="color9"></a></div><div class="tt-colorswatch-btn btn-primary js-colorswatch"><img src="'+colorswatch_object.colorswatchimg+'" alt=""></div></div>')
		var $cookievar=readCookie('template');
		if(typeof($cookievar)!='undefined' && $cookievar!='' ){
			$('body').addClass($cookievar)
		}
		$(document).on('click','.tt-colorswatch-btn', function(e){
			$(this).closest('.tt-colorswatch').toggleClass('tt-open-swatch');
			return false;
		});
		$(document).on('click','.js-swatch-color', function(e){
			e.preventDefault()
			$('.js-swatch-color').removeClass('active')
			$(this).addClass('active')
			if(track>0)
				setTimeout(function(){ $("#stylesheetclass").first().remove(); }, 500);
			if($(this).data('color')!=''){
				var head  = document.getElementsByTagName('head')[0];
				var link  = document.createElement('link');
				link.rel  = 'stylesheet';
				link.id  = 'stylesheetclass';
				link.type = 'text/css';
				link.href = colorswatch_object.color_url+$(this).data('color')+'.css' ;
				link.media = 'all';
				head.appendChild(link);
				track=track+1;
			}else{
				track=0;
				$("#stylesheetclass").remove();
			}
			
		})
	})
	
	
	
	function createCookie(name,value,days) {
		var expires = "";
		if (days) {
			var date = new Date();
			date.setTime(date.getTime() + (days*24*60*60*1000));
			expires = "; expires=" + date.toUTCString();
		}
		document.cookie = name + "=" + value + expires + "; path=/";
	}
	
	function readCookie(name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	}
	
	function eraseCookie(name) {
		createCookie(name,"",-1);
	}


	jQuery(document).ready(function ($) {
	
		$('body').prepend('<div class="tt-colorswatch layoutswatch"><div class="tt-colorswatch-btn btn-primary js-layoutswatch"><img src="'+changetemplateimg_object.setting_icon+'" /></div><div class="tt-colorswatch-options"><a href="https://smartdata.tonytemplates.com/bestel/" class="active skin-1"><img src="'+changetemplateimg_object.layout1_img+'" alt="" class="img-responsive"></a><a href="https://smartdata.tonytemplates.com/bestel/demo2/" class="active skin-2"><img src="'+changetemplateimg_object.layout2_img+'" alt="" class="img-responsive"></a><a href="https://smartdata.tonytemplates.com/bestel/demo3/" class="active skin-2"><img src="'+changetemplateimg_object.layout3_img+'" alt="" class="img-responsive"></a><div class="clearfix"></div><div class="title">Choose layout</div></div></div>');

		$('.js-colorswatch, .js-layoutswatch').on('click',function (e){
			$(this).parent().toggleClass('opened');
		})

	});