﻿// Set Dunhill video size
var tumblrVideoSize = { w: 465, h: 348 };

function flashVersion() {
    if (navigator.plugins && navigator.plugins.length > 0) {
        var mimeData = navigator.mimeTypes;
        if (mimeData && mimeData['application/x-shockwave-flash'] && mimeData['application/x-shockwave-flash'].enabledPlugin && mimeData['application/x-shockwave-flash'].enabledPlugin.description) {
            return parseInt(mimeData['application/x-shockwave-flash'].enabledPlugin.description.split(' ')[2].split('.')[0], 10)
        }
    } else if (navigator.appVersion.indexOf("Mac") == -1 && window.execScript) {
        try {
            var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
            var version = axo.GetVariable("$version");
            return version.split(',')[0].split(' ')[1]
        } catch (e) {}
        return 0
    }
}
function replaceIfFlash(version, element_id, replacement_string) {
    if (flashVersion() >= version) document.getElementById(element_id).innerHTML = replacement_string
}
function renderVideo(element_id, src, width, height, flashvars) {

    width = tumblrVideoSize.w;
    height = tumblrVideoSize.h;
    
    var agent = navigator.userAgent.toLowerCase();
    var is_iphone = (agent.indexOf('iphone') != -1);
    if (is_iphone) {
        document.getElementById(element_id).innerHTML = '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" width="' + width + '" height="' + height + '" codebase="http://www.apple.com/qtactivex/qtplugin.cab"><param name="src" value="' + src + '"><param name="qtsrc" value="' + src + '"><param name="autoplay" value="false"><embed src="' + src + '" qtsrc="' + src + '" width="' + width + '" height="' + height + '" pluginspage="http://www.apple.com/quicktime/"></embed></object>'
    } else {
        replaceIfFlash(10, element_id, '<embed type="application/x-shockwave-flash" src="http://www.tumblr.com/swf/video_player.swf?20" bgcolor="#000000" quality="high" class="video_player" allowfullscreen="true" height="' + height + '" width="' + width + '" flashvars="file=' + encodeURIComponent(src) + (flashvars ? '&amp;' + flashvars : '') + '"></embed>')
    }
}
