(function($) {

  $(function(){
    var top_nav = $('#top-nav');
    $('body').css('padding-top', $('body>.container-fluid').offset().top + 'px');
    top_nav.css('position', 'fixed');

    if($("#g-theme-menu")){
      $('#g-theme-menu li>a').click(function(){
        var $el = $(this);
        var themeHref = $el.data('css-href');
        $.save_user_settings("site-theme", themeHref, function(){

          var iframe = document.createElement("IFRAME");
          iframe.style.display = 'none';
          document.body.appendChild(iframe);

          var modal = $('<div id="load-theme-modal" class="modal hide fade" role="dialog"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button><h3>'+ 
            'Loading theme</h3></div><div class="modal-body"><div class="progress progress-striped active" style="width:50%; margin: 10px auto;"><div class="bar" style="width: 100%;"></div></div></div></div>');
          $('body').append(modal);
          modal.modal();

          modal.on('hidden', function(e){
            if(iframe){
              $(iframe).unbind('load');
              iframe.parentNode.removeChild(iframe);
              iframe = null;
            }
            modal.remove();
          });

          $(iframe).load(function () {
            $('#site-theme').attr('href', themeHref);

            setTimeout(function(){
              var nav_height = $('#top-nav').height();
              $('body').animate({'padding-top': (nav_height + 18)}, 500, 'easeOutBounce');
            }, 500);

            modal.modal('hide');
            iframe.parentNode.removeChild(iframe);
            iframe = null;
          })

          var ifmDoc = iframe.contentDocument || iframe.contentWindow.document;
          ifmDoc.open();
          ifmDoc.write('<!doctype><html><head></head><body>');
          ifmDoc.write('<link rel="stylesheet" href="'+themeHref+'" />');
          ifmDoc.write('</body></html>');
          ifmDoc.close();


          $('#g-theme-menu li').removeClass('active');
          $el.parent().addClass('active');
        });
      })
    }
  });

})(jQuery);
@@ -332,221 +332,9 @@
 ');%0A
-        $.save_user_settings(%22site-theme%22, themeHref, function()%7B%0A%0A          var iframe = document.createElement(%22IFRAME%22);%0A          iframe.style.display = 'none';%0A          document.body.appendChild(iframe);%0A%0A  
+%0A
     
@@ -748,34 +748,32 @@
 div%3E');%0A        
-  
 $('body').append
@@ -781,24 +781,25 @@
 modal);%0A
+%0A
         
   modal.
@@ -794,26 +794,260 @@
     
-  modal.modal(
+modal.on('shown', function()%7B%0A%0A          $.save_user_settings(%22site-theme%22, themeHref, function()%7B%0A%0A            var iframe = document.createElement(%22IFRAME%22);%0A            iframe.style.display = 'none';%0A            document.body.appendChild(iframe
 );%0A%0A
+  
     
@@ -1096,16 +1096,18 @@
         
+  
 if(ifram
@@ -1106,24 +1106,26 @@
 if(iframe)%7B%0A
+  
             
@@ -1158,32 +1158,34 @@
 ;%0A              
+  
 iframe.parentNod
@@ -1213,32 +1213,34 @@
 ;%0A              
+  
 iframe = null;%0A 
@@ -1250,18 +1250,22 @@
         
-%7D%0A
+  %7D%0A  
         
@@ -1294,21 +1294,25 @@
         
+  
 %7D);%0A%0A
+  
         
@@ -1342,16 +1342,18 @@
 on () %7B%0A
+  
         
@@ -1395,24 +1395,26 @@
 hemeHref);%0A%0A
+  
             
@@ -1446,24 +1446,26 @@
             
+  
 var nav_heig
@@ -1489,24 +1489,26 @@
 ).height();%0A
+  
             
@@ -1598,16 +1598,18 @@
         
+  
 %7D, 500);
@@ -1606,24 +1606,26 @@
   %7D, 500);%0A%0A
+  
             
@@ -1649,32 +1649,34 @@
 ');%0A            
+ 
+ 
 iframe.parentNod
@@ -1702,32 +1702,34 @@
 e);%0A            
+  
 iframe = null;%0A 
@@ -1741,12 +1741,16 @@
     
+ 
+ 
 %7D)%0A%0A
+  
     
@@ -1831,24 +1831,26 @@
 ;%0A          
+ 
+ 
 ifmDoc.open(
@@ -1848,24 +1848,26 @@
 Doc.open();%0A
+  
           if
@@ -1913,24 +1913,26 @@
 d%3E%3Cbody%3E');%0A
+  
           if
@@ -1995,32 +1995,34 @@
 /%3E');%0A          
+  
 ifmDoc.write('%3C/
@@ -2033,24 +2033,26 @@
 %3E%3C/html%3E');%0A
+  
           if
@@ -2073,24 +2073,26 @@
 %0A%0A          
+  
 $('#g-theme-
@@ -2134,16 +2134,18 @@
         
+  
 $el.pare
@@ -2177,17 +2177,54 @@
         
-%7D
+  %7D);%0A        %7D)%0A%0A        modal.modal(
 );%0A     

fix loading theme bugs.