$(function() {

  var $layout = $('.layout-header'), update_lamp1, $light1, $light2;
  $layout.wrap('<div class="header-light"/>').wrap('<div class="header-light2"/>');  $light1 = $('.header-light');
  $light2 = $('.header-light2');

  (update_lamp1 = function() {

    var w = $layout.offset()['left'];
    var pos = w/2 - 160;
    
    if (pos < 0) pos = pos * 1.75;
    $light1.css('background-position', pos+'px 50px');
    
    pos = w + $layout.width() - 40;
    
    $light2.css('background-position', pos+'px 50px');
    
  })();

  $(window).resize(update_lamp1);
  
  
  var $cnt = $('.cnt'), update2, $plant, $lamp2;
  $cnt.wrapInner('<div class="cnt-plant"/>').wrapInner('<div class="cnt-lamp"/>');
  $plant = $('.cnt-plant');
  $lamp2 = $('.cnt-lamp');
  
  (update2 = function() {
  
    // 40 -- half of image
    var w = $layout.offset()['left'];
    var pos = w/2 - 40;


    if (pos < 0) pos = pos * 3.5;
    $plant.css('background-position', pos+'px bottom');
    
    var p2 = (w/2 - 145);
    p2 = p2 < 0 ? p2 * -1 * 0.1 : p2;
    pos = w + $layout.width() + p2;
    
    $lamp2.css('background-position', pos+'px center');
  
  })();
  
  $(window).resize(update2);

});


