/*!
 * 
 * RT-Theme 19 WordPress Theme Admin - Skin Selector
 * Copyright (C) 2014 RT-Themes
 * http://rtthemes.com
 *
 */
jQuery(document).ready(function(a){function b(){0==a("#customize-preview rt_loading_bar").length?a("#customize-preview").prepend('<div class="rt_loading_bar"></div>'):a("#customize-preview rt_loading_bar").show()}function c(){setTimeout(function(){a(".rt_loading_bar").hide()},2e3)}a(".highlight-section").each(function(){a(this).on("click",function(b){b.preventDefault();var c=a("#customize-preview iframe"),d=a(this).data("section-selector"),e=c.contents().find(d);e.each(function(){var b=a('<div class="highlight-element" style="position:absolute;background:#ffc200;opacity:0.5;z-index:999999999"></div>');b.appendTo(c.contents().find("body")),b.css({width:a(this).outerWidth(),height:a(this).outerHeight(),top:a(this).offset().top,left:a(this).offset().left}).animate({opacity:0},{duration:1200,complete:function(){b.remove()}})})})}),a("body").on("rt_skin_selector",function(){var b=a(this);b.hasClass("selecting-skins")?(b.removeClass("selecting-skins"),a(".rt-skin-selector").removeClass("selected")):(b.addClass("selecting-skins"),b.hasClass("skins-loaded")||a.fn.rt_load_skins())}),a(".rt-skin-selector").on("click",function(b){return b.preventDefault(),(!a("body").hasClass("selecting-skins")||a(this).hasClass("selected"))&&a("body").trigger("rt_skin_selector"),a(".rt-skin-selector").removeClass("selected"),a("body").hasClass("selecting-skins")&&a(this).addClass("selected"),a("#available-rt-skins").attr("data-selecting-skins",a(this).data("value")),!1}),a("body").on("click",function(b){a(this).hasClass("selecting-skins")&&"available-rt-skins"!=b.target.id&&"rt-skin-selector"!=b.target.id&&(a(b.target).hasClass("skin-image")||a(this).trigger("rt_skin_selector"))}),a(document.body).on("click","#available-rt-skins .skin",function(){var d=confirm(rtframework_params.apply_skin);if(!d)return!1;var e,f,g=a(this).data("skin-id");a("body").trigger("rt_skin_selector"),a(".rt-skin-selector").removeClass("selected"),b(),a.ajax({type:"POST",url:ajaxurl,data:{action:"rt_ajax_get_skin_data","skin-id":g},success:function(b){b&&(e=a.parseJSON(b),a.each(e,function(b,c){field=a('[data-customize-setting-link="'+b+'"]'),0==field.length&&(field=a("#customize-control-"+b+" .wp-color-picker")),0!=field.length&&(f=field.prop("type")||field.prop("tagName").toLowerCase(),"select-one"==f||"select-multiple"==f?(a.isArray(c)?field.find("option").each(function(){a.inArray(a(this).val(),c)>-1?a(this).attr("selected","selected"):a(this).attr("selected",null)}):(field.find("option:selected").attr("selected",null),field.find('[value="'+c+'"]').attr("selected","selected")),field.trigger("change")):"checkbox"==f?(c?field.prop("checked",!0):field.prop("checked",!1),field.trigger("change")):"radio"==f?(c&&a('[data-customize-setting-link="'+b+'"][value="'+c+'"]').prop("checked",!0),field.trigger("change")):(field.val(c),field.trigger("change")))}),wp.customize.requestChangesetUpdate(),c())},error:function(a,b,d){console.log(d),c()}})}),a.fn.rt_load_skins=function(){a.ajax({type:"POST",url:ajaxurl,data:{action:"rt_ajax_skin_loader"},success:function(b){a("#available-rt-skins").append(b),a("body").addClass("skins-loaded"),a(".skins-loading-spinner").hide()},error:function(a,b,c){console.log(c)}})}});