function fixAspectRatio(element, width, height, desiredAspectRatio, rotated) {
    if (!width) width = parseInt(OT.$.width(element.parentNode), 10);
    else width = parseInt(width, 10);

    if (!height) height = parseInt(OT.$.height(element.parentNode), 10);
    else height = parseInt(height, 10);

    if (width === 0 || height === 0) return;

    if (!desiredAspectRatio) desiredAspectRatio = defaultAspectRatio;

    var actualRatio = (width + 0.0)/height,
        props;

    props = {
      width: '100%',
      height: '100%',
      left: 0,
      top: 0
    };

    if (actualRatio > desiredAspectRatio) {
        // Width is largest so we blow up the height so we don't have letterboxing
      var newHeight = (actualRatio / desiredAspectRatio) * 100;

      props.height = newHeight + '%';
      props.top = '-' + ((newHeight - 100) / 2) + '%';
    } else if (actualRatio < desiredAspectRatio) {
      // Height is largest, blow up the width
      var newWidth = (desiredAspectRatio / actualRatio) * 100;

      props.width = newWidth + '%';
      props.left = '-' + ((newWidth - 100) / 2) + '%';
    }

    OT.$.css(element, props);

    var video = element.querySelector('video');
    if(video) {
      if(rotated) {
        var w = element.offsetWidth,
            h = element.offsetHeight,
            diff = w - h;
        props = {
          width: h + 'px',
          height: w + 'px',
          marginTop: -(diff / 2) + 'px',
          marginLeft: (diff / 2) + 'px'
        };
        OT.$.css(video, props);
      } else {
        OT.$.css(video, { width: '', height: '', marginTop: '', marginLeft: ''});
      }
    }
  }
// this calculation will become incorrect.
this calculation will become incorrect.
this calculation will become incorrect .
function fixAspectRatio(element, width, height, desiredAspectRatio, rotated) {
    if (!width) width = parseInt(OT.$.width(element.parentNode), 10);
    else width = parseInt(width, 10);
    if (!height) height = parseInt(OT.$.height(element.parentNode), 10);
    else height = parseInt(height, 10);
    if (width === 0 || height === 0) return;
    if (!desiredAspectRatio) desiredAspectRatio = defaultAspectRatio;
    var actualRatio = (width + 0.0)/height,
        props;
    props = {
      width: '100%',
      height: '100%',
      left: 0,
      top: 0
    };
    if (actualRatio > desiredAspectRatio) {
      var newHeight = (actualRatio / desiredAspectRatio) * 100;
      props.height = newHeight + '%';
      props.top = '-' + ((newHeight - 100) / 2) + '%';
    } else if (actualRatio < desiredAspectRatio) {
      var newWidth = (desiredAspectRatio / actualRatio) * 100;
      props.width = newWidth + '%';
      props.left = '-' + ((newWidth - 100) / 2) + '%';
    }
    OT.$.css(element, props);
    var video = element.querySelector('video');
    if(video) {
      if(rotated) {
        var w = element.offsetWidth,
            h = element.offsetHeight,
            diff = w - h;
        props = {
          width: h + 'px',
          height: w + 'px',
          marginTop: -(diff / 2) + 'px',
          marginLeft: (diff / 2) + 'px'
        };
        OT.$.css(video, props);
      } else {
        OT.$.css(video, { width: '', height: '', marginTop: '', marginLeft: ''});
      }
    }
  }
function fixAspectRatio ( element , width , height , desiredAspectRatio , rotated ) { if ( ! width ) width = parseInt ( OT . $ . width ( element . parentNode ) , 10 ) ; else width = parseInt ( width , 10 ) ; if ( ! height ) height = parseInt ( OT . $ . height ( element . parentNode ) , 10 ) ; else height = parseInt ( height , 10 ) ; if ( width === 0 || height === 0 ) return ; if ( ! desiredAspectRatio ) desiredAspectRatio = defaultAspectRatio ; var actualRatio = ( width + 0.0 ) / height , props ; props = { width : '100%' , height : '100%' , left : 0 , top : 0 } ; if ( actualRatio > desiredAspectRatio ) { var newHeight = ( actualRatio / desiredAspectRatio ) * 100 ; props . height = newHeight + '%' ; props . top = '-' + ( ( newHeight - 100 ) / 2 ) + '%' ; } else if ( actualRatio < desiredAspectRatio ) { var newWidth = ( desiredAspectRatio / actualRatio ) * 100 ; props . width = newWidth + '%' ; props . left = '-' + ( ( newWidth - 100 ) / 2 ) + '%' ; } OT . $ . css ( element , props ) ; var video = element . querySelector ( 'video' ) ; if ( video ) { if ( rotated ) { var w = element . offsetWidth , h = element . offsetHeight , diff = w - h ; props = { width : h + 'px' , height : w + 'px' , marginTop : - ( diff / 2 ) + 'px' , marginLeft : ( diff / 2 ) + 'px' } ; OT . $ . css ( video , props ) ; } else { OT . $ . css ( video , { width : '' , height : '' , marginTop : '' , marginLeft : '' } ) ; } } }
this calculation will become incorrect.
this calculation will become incorrect .
// Width is largest so we blow up the height so we don't have letterboxing // Height is largest, blow up the width