$(document).ready(function() {
  
  var images = $("#content img.vlevo, #content img.vpravo, #content img.spopiskem");
  for(i = 0; i < images.length; i++)
  {
    var image = $(images[i]);
    var alt   = image.attr('alt'); 
    var cssClass = image.attr('class');
    if(alt)
    {      
      /*
      <div class="card">
        <div class="card-photo"><img src="" /></div>'
        <div class="card-desc">Description</div>';
      </div>
      */
      var html = '<div class="card-photo"><img src="' + image.attr('src') + '" /></div>';
      html    += '<div class="card-desc">' + alt + '</div>';  
      var width = image.width();
      var replaceWith = $('<div class="card" />').addClass(cssClass).html(html);
      
      // chrome does not set width properly
      if(width > 0)
      {
        replaceWith.css({width: image.width()});
      }
      
      image.replaceWith(replaceWith);
    }
  }  
  
  $('#styleswitcher_1').click(function(){
    switchTheme('small');    
    $.cookie('theme', 'small', { expires: 365, path: '/' });
    $('#styleswitcher_2').removeClass('selected');
    $('#styleswitcher_3').removeClass('selected');
    $('#styleswitcher_1').addClass('selected');
    return false;
  });
  
  $('#styleswitcher_2').click(function(){
    switchTheme('medium');
    $.cookie('theme', 'medium', { expires: 365, path: '/' }); 
    $('#styleswitcher_1').removeClass('selected');
    $('#styleswitcher_3').removeClass('selected');
    $('#styleswitcher_2').addClass('selected');    
    return false;
  });
  
  $('#styleswitcher_3').click(function(){
    switchTheme('large');  
    $.cookie('theme', 'large', { expires: 365, path: '/' });
    $('#styleswitcher_1').removeClass('selected');
    $('#styleswitcher_2').removeClass('selected');
    $('#styleswitcher_3').addClass('selected');      
    return false;
  });
    
});

