<?php
// Copyright 1999-2016. Parallels IP Holdings GmbH. All Rights Reserved.
?>
<script type="text/javascript" src="/javascript/externals/swfobject.js"></script>
<script type="text/javascript">
//<![CDATA[
Jsw.namespace('Smb.Views.Tutorials');

Smb.Views.Tutorials = {
	webm: null,
	flv: null,
	width: null,
	height: null,

    loadTutorial: function() {
        if (this.webm) {
            this.embedHTML5();
        } else if (this.flv && this.checkFlash()) {
            this.embedSWF();
        }
    },

	checkFlash: function() {
		var obj;
		var flashFound = false;
		var flashPlug = 'application/x-shockwave-flash';
		var flashActiveX = 'ShockwaveFlash.ShockwaveFlash';

		if (navigator && navigator.plugins && navigator.plugins.length) {
			if (navigator.mimeTypes && navigator.mimeTypes[flashPlug]) {
				flashFound = true;
			}
		}

		if (!flashFound) {
			try {
				obj = new ActiveXObject(flashActiveX);
				flashFound = true;
			} catch(err) {}
		}
		return flashFound;
	},

	embedSWF: function() {
		var flashvars = {
			'file': this.flv,
			'http.startparam':'ec_seek',
			'provider':'http',
			'skin':"http://media.parallels.com/video/pd5/parallels_skin.swf",
			'autostart':"true",
			'stretching':"fill",
			'menu':"false"
		};
		var params = {};
		params.wmode = "opaque";
		params.allowscriptaccess="always";
		params.allowfullscreen="true";
		var attributes = {};
		swfobject.embedSWF("/javascript/externals/player5_.swf", "myAlternativeContent", this.width || "500", this.height || "320", "9.0.0","http://media.parallels.com/video/pd5/expressInstall.swf", flashvars, params, attributes);
	},

	embedHTML5: function() {
		var v = document.createElement('video');
		var vtype = '';

        try {
            if (!!(v.canPlayType && v.canPlayType('video/ogg; codecs="theora, vorbis"').replace(/no/, ''))) {
                vtype = 'video/ogg; codecs=\'theora, vorbis\'';
            }
            if (!!(v.canPlayType && v.canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"').replace(/no/, ''))) {
                vtype = 'video/mp4; codecs="avc1.42E01E, mp4a.40.2"';
            }
            if (!!(v.canPlayType && v.canPlayType('video/webm; codecs="vp8, vorbis"').replace(/no/, ''))) {
                vtype = 'video/webm; codecs="vp8, vorbis"';
            }
        } catch (e) {}

		if (vtype == '') {
			return;
		}
		v.width = this.width;
		v.height = this.height;
		v.controls = 'true';
		v.autoplay = 'true';
		v.preload = 'none';
		v.src = this.webm;
		document.getElementById('myAlternativeContent').replace(v);
	},

	OpenVideoWindow: function(title, webm, flv, width, height) {
		this.webm = webm;
		this.flv = flv;
		this.width = width;
		this.height = height;

		new Jsw.Popup({
			title: title,
			content: '<div id="myAlternativeContent" class="no-flash-info">\
                <div class="no-flash-info-area">\
                    <img src="<?php echo $this->skinUrl('/icons/64/plesk/no-flash.png'); ?>" alt=""><br>\
                    ' + <?php echo $this->jsLmsg('flashPlayerIsNotInstalled'); ?> + '<br>\
                    <a href="<?php echo Plesk_Config::get()->help->tutorials->getFlashPlayer; ?>" target="_blank">\
                        <b>' + <?php echo $this->jsLmsg('downloadFlashPlayer'); ?> + '</b>\
                    </a>\
                </div>\
            </div>',
			popupCls: 'popup-box pb-video-tutorial',
			closeButtonEnabled: true,
			contentHeight: this.height
		})

		this.loadTutorial();
	}
};

Jsw.onReady(function() {
    new Jsw.Container({
        renderTo: 'main',
        items: [{
            componentType: 'Jsw.Hint',
            hint: <?php echo $this->jsLmsg('buttonsAreaDescription'); ?>
        }, {
            componentType: 'Jsw.ListContainer',
            cls: 'tools-list tools-list-video-tutorial',
            itemClass: 'tools-item',
            items: <?php echo $this->bigButtons; ?>
        }]
    });
	if (document.location.href.split('#')[1]) {
		var element = $$('a[href=#' + document.location.href.split('#')[1] + ']')[0];
		var evt = document.createEvent("MouseEvents");
		evt.initEvent("click", true, true);
		element.dispatchEvent(evt);
	}
});
//]]>
</script>
