//javascript의 prototype이라는 것으로  내부함수 만드는 법
//사용법:onClick="var movie = new movingPicture('flvfilename',800,600); movie.run();"
function movingPicture(url,width,height,attr){
	this.isNS = getBrowserInfo('appName')=="Netscape" ? true:false;
	this.MediaURL=url;
	this.Width = width ? width:800
	this.Height = height ? height:600;
	this.displayBox = 'box_screen';
	this.attr = attr ? attr:'';

	this.getValue=function(Name){
		var config = new RegExp(Name+"=([^,]+)", "i"); //get name/value config pair (ie: width=400px,)
		return (config.test(this.attr)) ? RegExp.$1:0; //return value portion or 0 (false) if none found
	}//

	this.setDisplayBox=function(displayBox){
		this.displayBox = displayBox;
	}//

	this.getMediaPlayerVersion=function(){
		//미디어플레이어가 7이하이면 아예 ActiveX 컨트롤을 new 로 생성할 수 없다
		try {
			switch(this.isNS){
				case 'Netscape': 
					return window.GeckoActiveXObject ? new GeckoActiveXObject("WMPlayer.OCX.7"):false;//미디어플레이어 7이상
					break;
				default:
					return window.ActiveXObject ? new ActiveXObject("WMPlayer.OCX.7"):false;//미디어플레이어 7이상
					break;
			}
		} catch (e) { return false; }
	}//

	this.run=function(boxId,boxsId){
		var box = document.getElementById(boxId);
		var boxs = document.getElementById(boxsId);

        for(var i=0; i<boxs.getElementsByTagName('div').length; i++){
			boxs.getElementsByTagName('div')[i].style.backgroundColor = '';
			boxs.getElementsByTagName('div')[i].style.fontWeight = '';
			boxs.getElementsByTagName('div')[i].style.color = '';
		}
		box.style.backgroundColor='#7799bb'; 
		box.style.fontWeight='bold'; 
		box.style.color='white'; 
		this.play();
	}//

    this.play=function(){
        var ext = this.MediaURL.substr(this.MediaURL.indexOf('.')+1).toUpperCase();
        switch(ext){
            case 'ICF':
                document.getElementById(this.displayBox).innerHTML = this.icf();
                break;
            case 'RPS':
                document.getElementById(this.displayBox).innerHTML = this.rps();
                break;
            case 'FLV':
                this.flv();
                break;
            case 'ASF':
                document.getElementById(this.displayBox).innerHTML = this.media();
                break;
            default:
                document.getElementById(this.displayBox).innerHTML = this.youtube();
                break;
        }//
    }//

	this.media=function (){
		this.MediaID = this.getValue('MediaID') ? this.getValue('MediaID'):'MediaPlayer';
		this.ShowControls = this.getValue('ShowControls') ? this.getValue('ShowControls'):1;
		this.ShowStatusBar = this.getValue('ShowStatusBar') ? this.getValue('ShowStatusBar'):1;
		this.TransParentatStart = this.getValue('TransParentatStart') ? this.getValue('TransParentatStart'):1;
		this.Loop = this.getValue('Loop') ? this.getValue('Loop'):0;
		this.ShowDisplay = this.getValue('ShowDisplay') ? this.getValue('ShowDisplay'):0;
		this.AnimationAtStart = this.getValue('AnimationAtStart') ? this.getValue('AnimationAtStart'):0;
		this.AutoStart = this.getValue('AutoStart') ? this.getValue('AutoStart'):0;

		var buffers = new StringBuffer();
		if ( this.isNS ) {
			buffers.append(sprintf('<EMBED type="application/x-mplayer2"'));
			buffers.append(sprintf('    pluginspage="http://www.microsoft.com/windows/windowsmedia/"'));
			buffers.append(sprintf('    src="%s"',this.MediaURL));
			buffers.append(sprintf('    Name="%s"',this.MediaID));
			buffers.append(sprintf('    AutoStart="%s"',1));
			buffers.append(sprintf('    ShowControls="%s"',this.ShowControls));
			buffers.append(sprintf('    ShowDisplay="%s"',this.ShowDisplay));
			buffers.append(sprintf('    ShowStatusBar="%s"',this.ShowStatusBar));
			buffers.append(sprintf('    width="%s"',this.Width));
			buffers.append(sprintf('    height="%s"',this.Height));
			buffers.append(sprintf('    loop="%s" />',this.Loop));
			buffers.append(sprintf('</EMBED>'));
			return buffers.toString();
		}//

		// Windows Media Player 7 Code
		buffers.append(sprintf('<OBJECT ID="%s" ',this.MediaID));
		if ( this.getMediaPlayerVersion() ) {
			buffers.append(sprintf(' CLASSID=CLSID:6BF52A52-394A-11D3-B153-00C04F79FAA6'));
			buffers.append(sprintf(' standby="Loading Microsoft Windows Media Player components..."'));
			buffers.append(sprintf(' TYPE="application/x-oleobject" width="%s" height="%s">',this.Width,this.Height));
			buffers.append(sprintf('	<PARAM NAME="url" VALUE="%s">',this.MediaURL));
			buffers.append(sprintf('	<PARAM NAME="AnimationAtStart" VALUE="%s">',this.AnimationAtStart));
			buffers.append(sprintf('	<PARAM NAME="TransParentatStart" VALUE="%s">',this.TransParentatStart));
			buffers.append(sprintf('	<PARAM NAME="AutoStart" VALUE="%s">',this.AutoStart));
			buffers.append(sprintf('	<PARAM NAME="ShowControls" VALUE="%s">',this.ShowControls));
			buffers.append(sprintf('	<PARAM NAME="ShowStatusBar" VALUE="%s">',this.ShowStatusBar));
			buffers.append(sprintf('	<PARAM NAME="Loop" VALUE="%s">',this.Loop));
			buffers.append(sprintf('	<PARAM NAME="uiMode" VALUE="mini">'));
		} else {// Windows Media Player 6.4 Code
			buffers.append(sprintf('CLASSID=CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95 '));
			buffers.append(sprintf('CODEBASE=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715 '));
			buffers.append(sprintf('standby="Loading Microsoft Windows Media Player components..." '));
			buffers.append(sprintf(' TYPE="application/x-oleobject" width="%s" height="%s">',this.Width,this.Height));
			buffers.append(sprintf('	<PARAM NAME="FileName" VALUE="%s">',this.MediaURL));
			buffers.append(sprintf('	<PARAM NAME="AnimationAtStart" VALUE="%s">',this.AnimationAtStart));
			buffers.append(sprintf('	<PARAM NAME="TransParentatStart" VALUE="%s">',this.TransParentatStart));
			buffers.append(sprintf('	<PARAM NAME="AutoStart" VALUE="%s">',this.AutoStart));
			buffers.append(sprintf('	<PARAM NAME="ShowControls" VALUE="%s">',this.ShowControls));
			buffers.append(sprintf('	<PARAM NAME="ShowStatusBar" VALUE="%s">',this.ShowStatusBar));
			buffers.append(sprintf('	<PARAM NAME="Loop" VALUE="%s">',this.Loop));
		}
		buffers.append(sprintf('</OBJECT>'));
		return buffers.toString();
	}//media

	this.icf=function (){
		this.MediaID = this.getValue('MediaID') ? this.getValue('MediaID'):'ICFViewer Control';
		this.AutoRotate=this.getValue('AutoRotate') ? this.getValue('AutoRotate'):'0.0,1.0,0.0,0.1';
		this.Antialiasing=this.getValue('Antialiasing') ? this.getValue('Antialiasing'):1;
		this.BackgroundTexture=this.getValue('BackgrounTexture') ? this.getValue('BackgrounTexture'):'';
		this.BackgroundColor=this.getValue('BackgroundColor') ? this.getValue('BackgroundColor'):'255,255,255';
		this.MenuOption=this.getValue('MenuOption') ? this.getValue('MenuOption'):'all=1,phong shading=0';
		this.LightPosition=this.getValue('LightPosition') ? this.getValue('LightPosition'):'light0=(1,1,1,0),light1=(-1,0,1,0)';

		var buffers = new StringBuffer();
		if ( this.isNS ) {
			buffers.append(sprintf('ICF file can only execute on "Internet Exploer(IE) browser"'));
		}
		else {
			buffers.append(sprintf('<OBJECT ID="%s" ',this.MediaID));
			//buffers.append(sprintf('CLASSID=clsid:B038A6C8-441B-11D4-BD8F-000021E2C68B '));
			buffers.append(sprintf('	CLASSID=clsid:B43EAF23-8643-4CBF-836B-3FD7E16076DE '));
			buffers.append(sprintf('	CODEBASE=http://www.rapidform.com/public/downloadweb/ICFViewerXO.cab#Version=1,0,0,23 '));
			buffers.append(sprintf('	width="%s" height="%s" />',this.Width,this.Height));
			buffers.append(sprintf('	<PARAM NAME="IcfPath" VALUE="%s">',this.MediaURL));
			buffers.append(sprintf('	<PARAM NAME="AutoRotate" VALUE="%s">',this.AutoRotate));
			buffers.append(sprintf('	<PARAM NAME="Antialiasing" VALUE="%s">',this.Antialiasing));
			buffers.append(sprintf('	<PARAM NAME="BackgroundTexture" VALUE="%s">',this.BackgroundTexture));
			buffers.append(sprintf('	<PARAM NAME="BackgroundColor" VALUE="%s">',this.BackgroundColor));
			buffers.append(sprintf('	<PARAM NAME="MenuOption" VALUE="%s">',this.MenuOption));
			buffers.append(sprintf('	<PARAM NAME="LightPosition" VALUE="%s">',this.LightPosition));
			buffers.append(sprintf('</OBJECT>'));
		}
		return buffers.toString();
	}//icf

	this.rps=function (){
		this.MediaID=this.getValue('MediaID') ? this.getValue('MediaID'):'RPSViewer Control';
		this.MaterialAmbient=this.getValue('MaterialAmbient') ? this.getValue('MaterialAmbient'):'0.100 0.300 0.550';
		this.MaterialDiffuse=this.getValue('MaterialDiffuse') ? this.getValue('MaterialDiffuse'):'0.200 0.400 0.808';
		this.MaterialSpecular=this.getValue('MaterialSpecular') ? this.getValue('MaterialSpecular'):'0.500 0.500 0.500';
		this.MaterialShininess=this.getValue('MaterialShininess') ? this.getValue('MaterialShininess'):'19.200';
		this.LightDiffuse=this.getValue('LightDiffuse') ? this.getValue('LightDiffuse'):'0.3 0.3 0.3';
		this.LightSpecular=this.getValue('LightSpecular') ? this.getValue('LightSpecular'):'0.9 0.9 0.9';
		this.Antialiasing=this.getValue('Antialiasing') ? this.getValue('Antialiasing'):1;
		this.ZoomLimitMethod=this.getValue('ZoomLimitMethod') ? this.getValue('ZoomLimitMethod'):'No Limit';
		this.BackgroundColor=this.getValue('BackgroundColor') ? this.getValue('BackgroundColor'):'1.000 1.000 1.000';

		var buffers = new StringBuffer();
		if ( this.isNS ) {
			buffers.append(sprintf('<EMBED RPSFilePath="%s"',this.MediaURL));
			buffers.append(sprintf('    width="%s"',this.Width));
			buffers.append(sprintf('    height="%s"',this.Height));
			buffers.append(sprintf('    MaterialAmbient="%s"',this.MaterialAmbient));
			buffers.append(sprintf('    MaterialDiffuse="%s"',this.MaterialDiffuse));
			buffers.append(sprintf('    MaterialSpecular="%s"',this.MaterialSpecular));
			buffers.append(sprintf('    MaterialShininess="%s"',this.MaterialShininess));
			buffers.append(sprintf('    LightDiffuse="%s"',this.LightDiffuse));
			buffers.append(sprintf('    Antialiasing="%s"',this.Antialiasing));
			buffers.append(sprintf('    ZoomLimitMethod="%s"',this.ZoomLimitMethod));
			buffers.append(sprintf('    BackgroundColor="%s" />',this.BackgroundColor));
			buffers.append(sprintf('</EMBED>'));
		}
		else {
			buffers.append(sprintf('<OBJECT ID="%s" ',this.MediaID));
			buffers.append(sprintf('	CLASSID=clsid:9B50BC6A-9DFC-4795-9FD8-7FA8D6427796 '));
			buffers.append(sprintf('	CODEBASE=http://www.rapidform.com/public/downloadweb/RPSViewer.cab#version=1,2,0,7 '));
			buffers.append(sprintf('	width="%s" height="%s" >',this.Width,this.Height));
			buffers.append(sprintf('	<PARAM NAME="RPSFilePath" VALUE="%s" />',this.MediaURL));
			buffers.append(sprintf('	<PARAM NAME="MaterialAmbient" VALUE="%s">',this.MaterialAmbient));
			buffers.append(sprintf('	<PARAM NAME="MaterialDiffuse" VALUE="%s">',this.MaterialDiffuse));
			buffers.append(sprintf('	<PARAM NAME="MaterialSpecular" VALUE="%s">',this.MaterialSpecular));
			buffers.append(sprintf('	<PARAM NAME="MaterialShininess" VALUE="%s">',this.MaterialShininess));
			buffers.append(sprintf('	<PARAM NAME="LightDiffuse" VALUE="%s">',this.LightDiffuse));
			buffers.append(sprintf('	<PARAM NAME="LightSpecular" VALUE="%s">',this.LightSpecular));
			buffers.append(sprintf('	<PARAM NAME="Antialiasing" VALUE="%s">',this.Antialiasing));
			buffers.append(sprintf('	<PARAM NAME="ZoomLimitMethod" VALUE="%s">',this.ZoomLimitMethod));
			buffers.append(sprintf('	<PARAM NAME="BackgroundColor" VALUE="%s">',this.BackgroundColor));
			buffers.append(sprintf('</OBJECT>'));
		}//
		return buffers.toString();
	}//

	this.youtube=function (){
		this.MediaID=this.getValue('MediaID') ? this.getValue('MediaID'):'Youtube Control';
		this.allowFullScreen=this.getValue('allowFullScreen') ? this.getValue('allowFullScreen'):'true';
		this.allowscriptaccess=this.getValue('allowscriptaccess') ? this.getValue('allowscriptaccess'):'always';

		var buffers = new StringBuffer();
		if ( this.isNS ) {
			return '<EMBED src="'+this.MediaURL+'" width="'+this.Width+'" height="'+this.Height+'" allowFullScreen="'+this.allowFullScreen+'" allowscriptaccess="'+this.allowscriptaccess+'"></EMBED>';
			/*buffers.append(sprintf('<EMBED src="%s"',this.MediaURL));
			buffers.append(sprintf('    width="%s"',this.Width));
			buffers.append(sprintf('    height="%s"',this.Height));
			buffers.append(sprintf('    allowFullScreen="%s"',this.allowFullScreen));
			buffers.append(sprintf('    allowscriptaccess="%s">',this.allowscriptaccess));
			buffers.append(sprintf('</EMBED>'));*/
		}
		else {
			return '<OBJECT ID="'+this.MediaID+'" width="'+this.Width+'" height="'+this.Height+'"> '+
					'<PARAM NAME="movie" VALUE="'+this.MediaURL+'"> '+
					'<PARAM NAME="allowFullScreen" VALUE="'+this.allowFullScreen+'"> '+
					'<PARAM NAME="allowscriptaccess" VALUE="'+this.allowscriptaccess+'"> '+
					'<EMBED src="'+this.MediaURL+'" width="'+this.Width+'" height="'+this.Height+'" allowFullScreen="'+this.allowFullScreen+'" allowscriptaccess="'+this.allowscriptaccess+'"></EMBED></OBJECT>';
			/*buffers.append(sprintf('<OBJECT ID="%s" ',this.MediaID));
			buffers.append(sprintf('	width="%s" height="%s" >',this.Width,this.Height));
			buffers.append('	<PARAM NAME="movie" VALUE="'+this.MediaURL+'">');
			buffers.append(sprintf('	<PARAM NAME="allowFullScreen" VALUE="%s">',this.allowFullScreen));
			buffers.append(sprintf('	<PARAM NAME="allowscriptaccess" VALUE="%s">',this.allowscriptaccess));
			buffers.append('<EMBED src="'+this.MediaURL+'"');
			buffers.append(sprintf('    width="%s"',this.Width));
			buffers.append(sprintf('    height="%s"',this.Height));
			buffers.append(sprintf('    allowFullScreen="%s"',this.allowFullScreen));
			buffers.append(sprintf('    allowscriptaccess="%s">',this.allowscriptaccess));
			buffers.append(sprintf('</EMBED>'));
			buffers.append(sprintf('</OBJECT>'));*/
		}//
		return buffers.toString();
	}//

	this.flv=function (){
		var flashPlayer = new SWFObject("/flash/player.swf","ply",this.Width,this.Height,"9",this.bgcolor);
		flashPlayer.addParam("allowfullscreen","true");
		flashPlayer.addParam("allowscriptaccess","always");

		this.preview = this.getValue('preview') ? this.getValue('preview'):'/flash/preview.jpg';
		flashPlayer.addParam("flashvars",sprintf("file=/%s&image=%s",this.MediaURL,this.preview));
		flashPlayer.write(this.displayBox);
	}//

	this.flv_org=function (){
		this.MediaID=this.getValue('MediaID') ? this.getValue('MediaID'):'FlashViewer Control';
		this.allowScriptAccess=this.getValue('allowScriptAccess') ? this.getValue('allowScriptAccess'):'sameDomain';
		this.quality=this.getValue('quality') ? this.getValue('quality'):'high';
		this.bgcolor=this.getValue('bgcolor') ? this.getValue('bgcolor'):'#ffffff';
		this.align=this.getValue('align') ? this.getValue('align'):'middle';
		this.wmode=this.getValue('wmode') ? this.getValue('wmode'):'transparent';
		this.allowfullscreen=this.getValue('allowfullscreen') ? this.getValue('allowfullscreen'):'true';
		this.menu=this.getValue('menu') ? this.getValue('menu'):'false';
		this.flashvars=this.getValue('flashvars') ? this.getValue('flashvars'):'image=/video/oroitsme/heavenly-days.jpg&amp;backcolor=0x333333&amp;frontcolor=0xaaaaaa&amp;lightcolor=0xeeeeee&amp;showstop=true&amp;volume=100&amp;callback=analytics';
		//flashvars="height=360&amp;width=480&amp;displayheight=360&amp;file=/video/oroitsme/heavenly-days.flv&amp;image=/video/oroitsme/heavenly-days.jpg&amp;backcolor=0x333333&amp;frontcolor=0xaaaaaa&amp;lightcolor=0xeeeeee&amp;link=/video/oroitsme/heavenly-days.flv&amp;showstop=true&amp;volume=100&amp;callback=analytics"

		var buffers = new StringBuffer();
		if ( this.isNS ) {
			buffers.append(sprintf('<EMBED name="%s"',this.MediaID));
			buffers.append(sprintf('	type="application/x-shockwave-flash"'));
			buffers.append(sprintf('	pluginspage="http://get.adobe.com/flashplayer/"'));
			buffers.append(sprintf('	src="/flash/player.swf%s"',this.MediaURL));
			buffers.append(sprintf('	quality="%s"',this.quality));
			buffers.append(sprintf('	bgcolor="%s"',this.bgcolor));
			buffers.append(sprintf('	width="%s"',this.Width));
			buffers.append(sprintf('	height="%s"',this.Height));
			buffers.append(sprintf('	align="%s"',this.align));
			buffers.append(sprintf('	wmode="%s"',this.wmode));
			buffers.append(sprintf('	flashvars="%s"',this.flashvars));
			buffers.append(sprintf('	allowfullscreen="%s"',this.allowfullscreen));
			buffers.append(sprintf('	allowScriptAccess="%s" />',this.allowScriptAccess));
			buffers.append(sprintf('</EMBED>'));
		}
		else {
			buffers.append(sprintf('<OBJECT id="%s"',this.MediaID));
			buffers.append(sprintf('	classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"'));
			buffers.append(sprintf('	codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0"'));
			buffers.append(sprintf('	width="%s"',this.Width));
			buffers.append(sprintf('	height="%s"',this.Height));
			buffers.append(sprintf('	align="%s" />',this.align));
			buffers.append(sprintf('	<param name="movie" value="/flash/player.swf?file=%s&size=false&aplay=true&autorew=false&title=Demo">',this.MediaURL));
			buffers.append(sprintf('	<param name="allowScriptAccess" value="%s">',this.allowScriptAccess));
			buffers.append(sprintf('	<param name="quality" value="%s">',this.quality));
			buffers.append(sprintf('	<param name="bgcolor" value="%s">',this.bgcolor));
			buffers.append(sprintf('	<param name="menu" value="%s">',this.menu));
			buffers.append(sprintf('	<param name="flashvars" value="%s">',this.flashvars));
			buffers.append(sprintf('</OBJECT>'));
		}//
		return buffers.toString();
	}//flv
}//movingPicture
