var IE = /*@cc_on!@*/false;
var IE6 = (IE && (navigator['appVersion'].indexOf('MSIE 6') > 0)) ? true : false;

System =
{

    getUrl: function(url) {
        var tags = document.getElementsByTagName('base');
        if (!/^http:\/\//.test(url) && tags.length > 0) {
            var base = tags.item(0);
            url = base.getAttribute('href') + url;
        }
        return url;
    },

    openUrl: function(url, target) {
        window.open(System.getUrl(url), target != null ? target : '_self');
    },

    openPopup: function(url, name, options, params) {
        if (options == null) options = {};
        if (options.width == null) options.width = 500;
        if (options.height == null) options.height = 500;
        if (options.scrollbars == null) options.scrollbars = 1;
        if (options.top == null)
            options.top = Math.floor((screen.height - options.height - 50) / 2);
        if (options.left == null)
            options.left = Math.floor((screen.width - options.width) / 2);
        if (params != null) {
            for (key in params) {
                url += url.indexOf('?') > -1 ? '&' : '?';
                url += key + '=' + encodeURI(params[key]);
            }
        }
        popup = window.open(System.getUrl(url), name,
			'width=' + options.width +
			',height=' + options.height +
			',left=' + options.left +
			',top=' + options.top +
			',scrollbars=' + options.scrollbars
		);
        popup.focus();
        if (options.close != null)
            window.onfocus = function() { try { popup.close(); } catch (e) { } };
        return popup;
    },

    insertApplet: function(id, attrs, params) {
        var html = '<applet';
        for (var key in attrs)
            html += ' ' + key + '="' + attrs[key] + '"';
        html += '>\n';
        if (params != null) {
            for (var key in params)
                html += '<param name="' + key + '" value="' + params[key] + '" />\n';
        }
        html += '</applet>\n';
        document.getElementById(id).innerHTML = html;
    },

    insertVideo: function(id, url, width, height, autoStart, preview, title) {
        if (true && (getSilverlightVersion() == 'Silverlight/2.0')) {
            var html = '<object type="application/x-silverlight-2" data="data:application/x-silverlight,"' +
				' height="' + height + '"' +
				' width="' + width + '">' +
				'<param name="source" value="/VideoPortal/ClientBin/MTV.VideoPortal.Player.xap"/>' +
            //				'<param name="onerror" value="onSilverlightError" />' +
				'<param name="background" value="black" />' +
				'<param name="minRuntimeVersion" value="2.0.31005.0" />' +
				'<param name="autoUpgrade" value="true" />' +
				'<param name="initParams" value="media=' + url + ',preview=' + preview + ',title=' + title + '" />' +
			'</object><iframe style=\'visibility:hidden;height:0;width:0;border:0px\'></iframe>';
            document.getElementById(id).innerHTML = html;
        } else {
            if (IE) {
                var html = '<object' +
					' height="' + height + '"' +
					' width="' + width + '"' +
					' type="application/x-oleobject"' +
					' standby="Videó töltése..."' +
					' codebase="http://www.microsoft.com/ntserver/netshow/download/en/nsmp2inf.cab#Version=5,1,51,415"' +
					' classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6"' + 
					' codebase="http://www.microsoft.com/ntserver/netshow/download/en/nsmp2inf.cab#Version=5,1,51,415"' + 
					' type="application/x-oleobject"' + 
					' standby="Videó töltése...">' + 
					'<param name="url" value="' + url + '">' +
					'<param name="autoStart" value="' + (1 == autoStart ? "true" : "false") + '">' +
					'<param name="uiMode" value="full">' +
					'<param name="PlayCount" value="1">' +
					'<param name="showControls" value="1">' +
					'<param name="showStatusBar" value="1">' +
					'<param name="autosize" value="false">' +
					'<param name="enableContextMenu" value="1">' +
					'<param name="stretchToFit" value="0">' +
					'<param name="Volume" value="100">' +
				'</object>';
                document.getElementById(id).innerHTML = html;
            } else {
                var html = '<embed src="' + url + '" autostart="' + autoStart + '" width="' + width + '" height="' + height + '" showcontrols="1" enablecontextmenu="1" playcount="1" showstatusbar="1" showcontrols="1" autosize="0" stretchtofit="0" loop="false" uimode="mini" volume="100" type="video/x-ms-asf-plugin" pluginspage="http://www.microsoft.com/windows/mediaplayer/download/default.asp">';
                $('div#' + id).append($(html));
            }
        }
    }

}

function getSilverlightVersion() {
    var version = 'NoSilverlight';
    var container = null;
    try {
        var control = null;
        if (window.ActiveXObject) {
            control = new ActiveXObject('AgControl.AgControl');
        }
        else {
            if (navigator.plugins['Silverlight Plug-In']) {
                container = document.createElement('div');
                document.body.appendChild(container);
                container.innerHTML = '<embed type="application/x-silverlight" src="data:," />';
                control = container.childNodes[0];
            }
        }
        if (control) {
            if (control.isVersionSupported('2.0')) { version = 'Silverlight/2.0'; }
            else if (control.isVersionSupported('1.0')) { version = 'Silverlight/1.0'; }
        }
    }
    catch (e) { }
    if (container) {
        document.body.removeChild(container);
    }
    return version;
}
