
// gomtvx ¿¢Æ¼ºê¿¢½º ÀÎ½ºÅç
// ÁÖÀÇ : ÀÌ ÇÔ¼ö´Â NON-BLOCKING À¸·Î ÀÛµ¿ÇÑ´Ù.



function NotSupported()
{
	alert('Áö±Ý Á¢¼ÓÇÏ½Å ºê¶ó¿ìÀú´Â ÇöÀç Áö¿øÇÏÁö ¾Ê°í ÀÖ½À´Ï´Ù.');
}

function gomtvxInstall()
{
	var ua = navigator.userAgent;
	var isChrome = false;
	var isFirefox = false;
	var isOpera = false;
	var isIE = false;
	var isSafari = false;
	var isWindow = false;
	var isMac = false;
	if( ua.indexOf('Chrome') != -1 ) isChrome = true;
	else if( ua.indexOf('Safari') != -1 ) isSafari = true;
	else if( ua.indexOf('Opera') != -1 ) isOpera = true;
	else if( ua.indexOf('Firefox') != -1 ) isFirefox = true;
	else isIE = true;
	if( ua.indexOf('Window') != -1 ) isWindow = true;
	else if( ua.indexOf('Mac') != -1 ) isMac = true;

	if( isOpera == true || isChrome == true ) { NotSupported(); return; }
//	if( isMac == true && isSafari != true ) { NotSupported(); return; }
//	if( isMac == true ) { NotSupported(); return; }
//	if( isSafari == true ) { NotSupported(); return; }
//	if( isMac == false && isSafari == true ) { NotSupported(); return; }

    if( document.getElementById('gomtvx') )
    {
        return; 
    }
	else 
	{
		if( isFirefox == true || isSafari == true )
		{
			HTMLElement.prototype.insertAdjacentElement = function(where,parsedNode){ 
				switch (where){ 
					case 'beforeBegin': 
						this.parentNode.insertBefore(parsedNode,this) 
						break; 
					case 'afterBegin': 
						this.insertBefore(parsedNode,this.firstChild); 
						break; 
					case 'beforeEnd': 
						this.appendChild(parsedNode); 
						break; 
					case 'afterEnd': 
						if (this.nextSibling) this.parentNode.insertBefore(parsedNode,this.nextSibling); 
						else this.parentNode.appendChild(parsedNode); 
						break; 
				} 
			} 

			HTMLElement.prototype.insertAdjacentHTML = function(where,htmlStr) { 
				var r = this.ownerDocument.createRange(); 
				r.setStartBefore(this); 
				var parsedHTML = r.createContextualFragment(htmlStr); 
				this.insertAdjacentElement(where,parsedHTML) 
			}     

			HTMLElement.prototype.insertAdjacentText = function(where,txtStr){ 
				var parsedText = document.createTextNode(txtStr) 
				this.insertAdjacentElement(where,parsedText) 
			} 

			if( isFirefox == true && isWindow == true )
			{
				// Firefox for window
				var str="<OBJECT ID='gomtvx' WIDTH=0 HEIGHT=0 type='application/gomtvx-plugin,version=1.0.0.2' codebase='http://app.gomtv.com/gomtv/GOMTVXNIESETUP.EXE'></OBJECT>";
				document.body.insertAdjacentHTML('beforeEnd', str);
			}
			if( isSafari == true && isMac == true ) 
			{
				// Safari for mac
				var vsrc = "http://121.125.69.108:8231/view.cgi?systype=500&subtype=50&hid=100&cid=1502&nid=20&title=test&key=0&impurl=0";
				var str="<object id='gomtvx' name='gomtvx' src='' width='0' height='0' type='video/x-webkitmovie' pluginspage='http://sample.gomtv.com/mac/downtest.html'></object>";
				document.body.insertAdjacentHTML('beforeEnd', str);
			}
    	}
    	else     
    	{
			// IE
			var str="<OBJECT ID='gomtvx' WIDTH=0 HEIGHT=0 CLASSID='CLSID:BBFD2D10-EC6E-4259-91D1-1E38C826E5E2' codebase='http://app.gomtv.com/gomtv/gomtvx.cab#version=1,0,0,1'></OBJECT>";
    		document.body.insertAdjacentHTML('beforeEnd', str );
   		}
   	
	}
}

function gsocketInstall()
{
    if( document.getElementById('gsocket') )
    {
        return; 
    }
	else
	{
		var str="<OBJECT ID='gsocket' WIDTH=0 HEIGHT=0 CLASSID='CLSID:7DC79AE8-4C0D-4327-A459-F6F32358462C' codebase='http://app.gomtv.com/gomtv/gomtvx.cab#version=1,0,0,1'></OBJECT>";
    	document.body.insertAdjacentHTML('beforeEnd', str );
	}
}
