

var maxImageHeight = 0;

var browserIE = {
  version: function() {
    var version = 999;
    if (navigator.appVersion.indexOf("MSIE") != -1)
      version = parseFloat(navigator.appVersion.split("MSIE")[1]);
    return version;
  }
}


function startResize() {
  $(window).resize(doThaDance);
}
function doThaDance() {
  $winW = $(window).width();
  if (mobile) {
    $winH = $('body').height();
  } else {
    $winH = $(window).height();
  }
  
  $multiplyer = 0;
  $('.image-wrapper').each(function() {
    $image = $(this).children('img');
    $iHeight = maxImageHeight + maxImageHeight * (2* marginY/100);
    //alert($iHeight);
    $multiplyer = $winH / $iHeight;
    $origHeight = parseInt($image.attr('original-height'));
    $origWidth = parseInt($image.attr('original-width'));
    
    $padding = Math.max(0,$winH - $image.height());
    $(this).css('marginTop', (($iHeight - $origHeight)*0.38 * $multiplyer) + 'px');
    if (mobile) {
      $(this).css('marginRight', ((maxImageHeight * marginX/100+10) * $multiplyer) + 'px');
    } else {
      $(this).css('marginRight', ((maxImageHeight * marginX/100+4) * $multiplyer) + 'px');
    }
    $image.height($origHeight * $multiplyer);
    $image.width($origWidth * $multiplyer);
  });
  if ($multiplyer != 0) {
    $('.image-wrapper').last().css('marginRight', ((maxImageHeight * marginLastX/100) * $multiplyer) + 'px');
  }
  //$menuWrapper.css('padding-bottom', ($padding * 0.57) + 'px');

  $menuWrapper = $('#menu-wrapper');
  if (mobile) {
    $padding = Math.max(50,$winH - $menuWrapper.height());
    $menuWrapper.css('margin', ($padding * 0.38) + 'px ' + (100 * $winH/800) + 'px ' + ($padding * 0.38) + 'px ' + (90 * $winH/800) + 'px');
  } else {
    $padding = Math.max(0,$winH - $menuWrapper.height());
    $menuWrapper.css('margin', ($padding * 0.38) + 'px ' + (200 * $winH/800) + 'px 0 ' + (160 * $winH/800) + 'px');
  }

  $rightContent = $('#right-content');
  $padding = Math.max(0,$winH - $rightContent.height());
  $rightContent.css('margin', ($padding * 0.38) + 'px ' + (170 * $winH/800) + 'px 0 ' + (190 * $winH/800) + 'px');
}


$(document).ready(function() {


  lastY = 0;
  //Sätter dit slashar i menyn
  
  Cufon.replace('a', {hover:true});
  Cufon.replace('span');
  Cufon.replace('p');
  
  $('#menu-wrapper li li').each(function() {
    if (lastY == 0) {
      lastY = $(this).offset().top;
    } else if (Math.abs($(this).offset().top - lastY) < 5) {
      $(this).before('<li class="level-1 slash"><span class="level-1">/</span></li>');
    } else {
      lastY = $(this).offset().top;
    }
  });

  $('#menu-wrapper li.expanded a').click(function() {
    $('.image-wrapper').each(function() {
      $(this).fadeTo(120,0);
    });
  });

  Cufon.replace('li.slash span');
  

  $('.image-wrapper img').each(function() {
    maxImageHeight = Math.max(maxImageHeight, $(this).height());
  });
  
  startResize();
  doThaDance();

  $('.image-wrapper img').load (function() {
    $(this).delay(200).fadeTo(200,1);
  });

  if (browserIE.version() <= 7) {
    
  }
  
  

});


