function StreamPlayer(){this.name="Stream Player(β)";this.version="0.1.1";this.videoAspectRatio=16/9;this.backgrounds=[['#000000','url(./images/chrono.jpg)','no-repeat','left top'],['#396ea4','url(./images/miku.jpg)','no-repeat','right bottom'],['#ffffff','url(./images/nagato.png)','no-repeat','center bottom'],['#79caf9','url(./images/dot.png)','no-repeat','left top'],['#9cad9d','url(./images/zelda.png)','no-repeat','right bottom'],['#174e8f','url(./images/sharks.jpg)','no-repeat','right top'],['#00a9d9','url(./images/okotowari.png)','no-repeat','center top'],['#404040','','',''],['#396ea4','','',''],['#4c4884','','',''],['#3b7e68','','',''],['#bd9559','','','']];this.windowSizeLarge={videoWidth:640,videoHeight:360,chatWidth:534,chatHeight:506};this.windowSizeSmall={videoWidth:512,videoHeight:288,chatWidth:410,chatHeight:430};this.initialize.apply(this,arguments)}StreamPlayer.prototype={initialize:function(){this.hashNow=null;this.hashAgo=null;this.timerId=null;this.bgIndex=0;if(screen.width<1280||screen.height<=800){this.windowSize=this.windowSizeSmall}else{this.windowSize=this.windowSizeLarge}this.initialend=false},start:function(){this.registerChangeBackground();this.registerHelp();var that=this;this.timerId=setInterval(function(){that.hashNow=that.getHashObject();if(!that.ago||that.hashNow.irc!=that.ago.irc||that.hashNow.jtv!=that.ago.jtv||that.hashNow.ust!=that.ago.ust||that.hashNow.btv!=that.ago.btv){that.registerPreference();if(!that.ago||that.hashNow.jtv!=that.ago.jtv||that.hashNow.ust!=that.ago.ust||that.hashNow.btv!=that.ago.btv){that.registerVideoHolder()}if(!that.ago||that.hashNow.irc!=that.ago.irc||that.hashNow.ust!=that.ago.ust||that.hashNow.jtv!=that.ago.jtv){that.registerChatHolder()}if((!Ext.getCmp('window-video')||Ext.getCmp('window-video').hidden)&&(!Ext.getCmp('window-chat')||Ext.getCmp('window-chat').hidden)){Ext.getCmp('window-preference').show()}else if(!Ext.getCmp('window-preference').hidden){Ext.getCmp('window-preference').hide()}that.ago=that.hashNow;that.initialend=true}},64)},registerChangeBackground:function(){var length=this.backgrounds.length;var index=Math.floor(Math.random()*length);this.setBackground(index);Ext.get('btn-background').dom.innerHTML='背景'+'（'+(index+1)+'/'+length+'）';var that=this;Ext.get('btn-background').removeClass('btn-disabled');Ext.get('btn-background').on('click',function(){var index=that.bgIndex;index++;if(index>=that.backgrounds.length){index=0}that.setBackground(index);this.dom.innerHTML='背景'+'（'+(index+1)+'/'+that.backgrounds.length+'）';that.bgIndex=index})},registerHelp:function(){var help=new Ext.Window({id:'window-help',el:'help-win',layout:'fit',width:540,height:400,plain:true,animateTarget:'btn-help',closeAction:'hide',shadow:false,constrain:true,listeners:{beforeshow:function(self){Ext.get('btn-help').addClass('btn-pressed')},beforehide:function(self){Ext.get('btn-help').removeClass('btn-pressed')}},items:[new Ext.Panel({border:false,layout:'accordion',items:[new Ext.Panel({el:'help-how-panel',autoScroll:true,border:false}),new Ext.Panel({el:'help-other-panel',autoScroll:true,border:false})]})],buttons:[{text:"閉じる",handler:function(){help.hide()}}]});help.render(Ext.getBody());Ext.get('btn-help').removeClass('btn-disabled');Ext.get('btn-help').on('click',function(){if(help.hidden){if(Ext.getCmp('window-video')){Ext.getCmp('window-video').hide()}if(Ext.getCmp('window-chat')){Ext.getCmp('window-chat').hide()}help.show()}else{help.hide()}})},registerPreference:function(){var now=this.hashNow;if(Ext.getCmp('window-preference')){Ext.get('param-ustream-chat').dom.value='#'+now.irc;Ext.get('param-justin').dom.value=now.jtv;Ext.get('param-ustream-video').dom.value=now.ust;Ext.get('param-blogtv-video').dom.value=now.btv;return}var pref=new Ext.Window({id:'window-preference',title:'設定 - 視聴ページ作成',renderTo:'desktop',width:330,height:190,layout:'fit',resizable:false,plain:true,bodyStyle:'padding:5px;',buttonAlign:'right',animateTarget:'btn-preference',closeAction:'hide',shadow:false,constrain:true,listeners:{beforeshow:function(self){Ext.get('btn-preference').addClass('btn-pressed')},beforehide:function(self){Ext.get('btn-preference').removeClass('btn-pressed')}},items:new Ext.form.FormPanel({baseCls:'x-plain',defaultType:'textfield',labelWidth:140,defaults:{width:150},items:[{fieldLabel:'Ustream IRCチャンネル',id:'param-ustream-chat',allowBlank:false,value:now.irc?'#'+now.irc:'#'},{fieldLabel:'JustinのチャンネルID',id:'param-justin',allowBlank:true,value:now.jtv?now.jtv:''},{fieldLabel:'UstreamのチャンネルID',id:'param-ustream-video',allowBlank:true,value:now.ust?now.ust:''},{fieldLabel:'blogTVのチャンネルID',id:'param-blogtv-video',allowBlank:true,value:now.btv?now.btv:''}]}),buttons:[{id:'btn-preference-ok',text:'OK',handler:function(){var justin=Ext.get('param-justin');var ustChat=Ext.get('param-ustream-chat');var ustVideo=Ext.get('param-ustream-video');var blgVideo=Ext.get('param-blogtv-video');if(!ustChat.getValue().length){Ext.MessageBox.show({title:'エラー',msg:'UstreamのIRCチャンネルを入力してください',buttons:Ext.MessageBox.OK,animEl:'btn-preference-ok',icon:Ext.MessageBox.ERROR});return false}if(!ustChat.getValue().match(/#.+/)){Ext.MessageBox.show({title:'エラー',msg:'UstreamのIRCチャンネル名が不正です',buttons:Ext.MessageBox.OK,animEl:'btn-preference-ok',icon:Ext.MessageBox.ERROR});return false}if(justin.getValue().length&&!justin.getValue().match(/^[\w_]+$/)){Ext.MessageBox.show({title:'エラー',msg:'justinのチャンネルIDが不正です',buttons:Ext.MessageBox.OK,animEl:'btn-preference-ok',icon:Ext.MessageBox.ERROR});return false}if(ustVideo.getValue().length&&!ustVideo.getValue().match(/[0-9]+/)){Ext.MessageBox.show({title:'エラー',msg:'Ustreamの動画IDは外部プレイヤー用のURLの後ろの数字です',buttons:Ext.MessageBox.OK,animEl:'btn-preference-ok',icon:Ext.MessageBox.ERROR});return false}var hashParam=ustChat.getValue()+'/'+justin.getValue()+'/'+ustVideo.getValue()+'/'+blgVideo.getValue();Ext.getCmp('window-preference').hide();location.href=hashParam;location.reload(true);return false}},{text:'キャンセル',handler:function(){Ext.get('param-ustream-chat').dom.value='#'+now.irc;Ext.get('param-justin').dom.value=now.jtv;Ext.get('param-ustream-video').dom.value=now.ust;Ext.get('param-blogtv-video').dom.value=now.btv;Ext.getCmp('window-preference').hide()}}]});pref.render(Ext.getBody());Ext.get('btn-preference').removeClass('btn-disabled');Ext.get('btn-preference').on('click',function(){if(pref.hidden){if(Ext.getCmp('window-video')){Ext.getCmp('window-video').hide()}if(Ext.getCmp('window-chat')){Ext.getCmp('window-chat').hide()}pref.show()}else{pref.hide()}})},registerVideoHolder:function(){var that=this;var now=this.hashNow;var ago=this.hashAgo;var vjtv;var vacv;var vust;var vbtv;if(now.jtv.length>0){vjtv='<iframe src="./vjtv.html?'+now.jtv+'" frameborder="0" scrolling="no" width="100%" height="100%"></iframe>';vacv='<iframe src="./vacv.html?'+now.jtv+'" frameborder="0" scrolling="no" width="100%" height="100%"></iframe>'}if(now.ust.length>0){vust='<iframe src="./vust.html?'+now.ust+'" frameborder="0" scrolling="no" width="100%" height="100%"></iframe>'}if(now.btv.length>0){vbtv='<iframe src="./vbtv.html?'+now.btv+'" frameborder="0" scrolling="no" width="100%" height="100%"></iframe>'}if(Ext.getCmp('window-video')){Ext.getCmp('window-video').close()}if(!Ext.getCmp('window-video')){var videoTabs=new Ext.TabPanel({id:'video-tabs',activeTab:vjtv?0:vust?2:vbtv?3:0,border:false,width:'100%',height:'100%',resizeTabs:true,minTabWidth:50,tabWidth:80,items:[{id:'video-tab-jtv',title:'Justin',html:vjtv,disabled:vjtv?false:true,bodyStyle:'background-color:#000000;'},{id:'video-tab-acv',title:'Archive',html:vacv,disabled:vacv?false:true,bodyStyle:'background-color:#000000;'},{id:'video-tab-ust',title:'Ustream',html:vust,disabled:vust?false:true,bodyStyle:'background-color:#000000;'},{id:'video-tab-btv',title:'blogTV',html:vbtv,disabled:vbtv?false:true,bodyStyle:'background-color:#000000;'}],listeners:{beforetabchange:function(self,newTab,currentTab){if(currentTab&&currentTab.body){currentTab.body.dom.innerHTML=''}if(newTab.body){if(newTab.title=='Justin'){newTab.body.dom.innerHTML=vjtv}if(newTab.title=='Archive'){newTab.body.dom.innerHTML=vacv}if(newTab.title=='Ustream'){newTab.body.dom.innerHTML=vust}if(newTab.title=='blogTV'){newTab.body.dom.innerHTML=vbtv}}var h=Math.floor((Ext.getCmp('window-video').getWidth()-14)/that.videoAspectRatio);if(newTab.title=='Justin'){}else if(newTab.title=='Archive'){h=h+235}else if(newTab.title=='Ustream'){h=h+26}else if(newTab.title=='blogTV'){if(that.videoAspectRatio==4/3){h=Math.floor((Ext.getCmp('window-video').getWidth()-14)/(640/618))}else{h=Math.floor((Ext.getCmp('window-video').getWidth()-14)/(640/465))}}Ext.getCmp('window-video').setSize({height:h+58})}}});var videoWindow=new Ext.Window({id:'window-video',layout:'fit',title:'Video',x:10,y:39,width:(this.windowSize.videoWidth+14),height:(this.windowSize.videoHeight+58),minWidth:(300+14),minHeight:(225+58),animateTarget:'btn-video-holder',maximizable:true,minimizable:true,shadow:false,constrainHeader:true,listeners:{minimize:function(self){self.hide()},beforeshow:function(self){Ext.get('btn-video-holder').dom.innerHTML='Video';Ext.get('btn-video-holder').addClass('btn-pressed');Ext.get('btn-video-reload').removeClass('btn-disabled');Ext.get('btn-video-aspect').removeClass('btn-disabled')},beforehide:function(self){Ext.get('btn-video-holder').dom.innerHTML='<span style="color:#ff3333;">●</span>Video';Ext.get('btn-video-holder').removeClass('btn-pressed');Ext.get('btn-video-reload').addClass('btn-disabled');Ext.get('btn-video-aspect').addClass('btn-disabled')},close:function(self){Ext.get('btn-video-holder').dom.innerHTML='Video';Ext.get('btn-video-holder').removeClass('btn-pressed');Ext.get('btn-video-holder').addClass('btn-disabled');Ext.get('btn-video-reload').addClass('btn-disabled');Ext.get('btn-video-aspect').addClass('btn-disabled')}},items:videoTabs})}if(vjtv||vust||vbtv){Ext.get('btn-video-holder').removeClass('btn-disabled');if(!this.initialend){Ext.get('btn-video-holder').on('click',function(){if(!Ext.getCmp('window-video')){return}if(Ext.getCmp('window-video').hidden){Ext.getCmp('window-preference').hide();Ext.getCmp('window-help').hide();Ext.getCmp('window-video').show()}else{Ext.getCmp('window-video').hide()}})}Ext.getCmp('window-video').show()}else if(Ext.getCmp('window-video')){Ext.getCmp('window-video').hide()}if(Ext.getCmp('window-video')&&!Ext.getCmp('window-video').hidden){Ext.get('btn-video-reload').removeClass('btn-disabled');if(!this.initialend){Ext.get('btn-video-reload').on('click',function(){if(!Ext.getCmp('window-video')||Ext.getCmp('window-video').hidden){return}var tab=Ext.getCmp('video-tabs').getActiveTab();tab.getLayoutTarget().dom.innerHTML=tab.body.dom.innerHTML})}}else{Ext.get('btn-video-reload').addClass('btn-disabled')}if(Ext.getCmp('window-video')&&!Ext.getCmp('window-video').hidden){Ext.get('btn-video-aspect').removeClass('btn-disabled');if(!this.initialend){Ext.get('btn-video-aspect').on('click',function(){if(!Ext.getCmp('window-video')||Ext.getCmp('window-video').hidden){return}var tab=Ext.getCmp('video-tabs').getActiveTab();this.videoAspectRatio=(this.videoAspectRatio==4/3)?16/9:4/3;var h=Math.floor((Ext.getCmp('window-video').getWidth()-14)/this.videoAspectRatio);if(tab.title=='Justin'){}else if(tab.title=='Archive'){h=h+235}else if(tab.title=='Ustream'){h=h+26}else if(tab.title=='blogTV'){if(this.videoAspectRatio==4/3){h=Math.floor((Ext.getCmp('window-video').getWidth()-14)/(640/618))}else{h=Math.floor((Ext.getCmp('window-video').getWidth()-14)/(640/465))}}Ext.getCmp('window-video').setSize({height:h+58});this.dom.innerHTML=(this.videoAspectRatio==4/3?'16:9':'4:3')+"に変更"})}}else{Ext.get('btn-video-aspect').addClass('btn-disabled')}},registerChatHolder:function(){var now=this.hashNow;var ago=this.hashAgo;var cust,cjtv,cmbt,csoc;if(now.irc.length>0){cust='<iframe src="./cust.html?'+now.irc+'" frameborder="0" scrolling="no" width="100%" height="100%"></iframe>';cmbt='<iframe src="http://widget.mibbit.com/?settings=c7d873cfc748b0599fc49fa49085caf0&amp;'+'channel=%23'+now.irc+'&amp;noServerTab=true&amp;nick=ust-%3F%3F%3F%3F%3F" '+'frameborder="0" scrolling="no" width="100%" height="100%"></iframe>'}if(now.ust.length>0){csoc='<iframe width="100%" height="100%" src="http://www.ustream.tv/socialstream/'+now.ust+'?bg=deecfd" scrolling="no" frameborder="0"></iframe>'}if(now.jtv.length>0){cjtv='<iframe src="http://www.justin.tv/chat/embed'+'?channel='+now.jtv+'&amp;default_chat=jtv&amp;popout_chat=true" '+'frameborder="0" scrolling="no" width="100%" height="100%"></iframe>'}if(Ext.getCmp('window-chat')){Ext.getCmp('window-chat').close()}if(!Ext.getCmp('window-chat')){var chatTabs=new Ext.TabPanel({id:'chat-tabs',activeTab:cust?0:csoc?1:cmbt?3:cjtv?2:0,border:false,width:'100%',height:'100%',resizeTabs:true,minTabWidth:60,tabWidth:95,items:[{title:'Ustream',html:cust,disabled:cust?false:true},{title:'SocialStream',html:csoc,disabled:csoc?false:true},{title:'Justin',html:cjtv,disabled:cjtv?false:true},{title:'Mibbit',html:cmbt,disabled:cmbt?false:true}],listeners:{beforetabchange:function(self,newTab,currentTab){if(currentTab&&currentTab.body){currentTab.body.dom.innerHTML=''}if(newTab.body){if(newTab.title=='Ustream'){newTab.body.dom.innerHTML=cust}if(newTab.title=='SocialStream'){newTab.body.dom.innerHTML=csoc}if(newTab.title=='Justin'){newTab.body.dom.innerHTML=cjtv}if(newTab.title=='Mibbit'){newTab.body.dom.innerHTML=cmbt}}}}});var chatWindow=new Ext.Window({id:'window-chat',layout:'fit',title:'Chat',renderTo:'desktop',x:(this.windowSize.videoWidth+30),y:39,width:(this.windowSize.chatWidth+14),height:(this.windowSize.chatHeight+58),minWidth:(320+14),minHeight:(251+58),animateTarget:'btn-chat-holder',maximizable:true,minimizable:true,shadow:false,constrainHeader:true,listeners:{minimize:function(self){self.hide()},beforeshow:function(self){Ext.get('btn-chat-holder').dom.innerHTML='Chat';Ext.get('btn-chat-holder').addClass('btn-pressed');Ext.get('btn-chat-reload').removeClass('btn-disabled')},beforehide:function(self){Ext.get('btn-chat-holder').dom.innerHTML='<span style="color:#ff3333;">●</span>Chat';Ext.get('btn-chat-holder').removeClass('btn-pressed');Ext.get('btn-chat-reload').addClass('btn-disabled')},close:function(self){Ext.get('btn-chat-holder').dom.innerHTML='Chat';Ext.get('btn-chat-holder').removeClass('btn-pressed');Ext.get('btn-chat-holder').addClass('btn-disabled');Ext.get('btn-chat-reload').addClass('btn-disabled')}},items:chatTabs})}if(cust||csoc||cjtv||cmbt){Ext.get('btn-chat-holder').removeClass('btn-disabled');if(!this.initialend){Ext.get('btn-chat-holder').on('click',function(){if(!Ext.getCmp('window-chat')){return}if(Ext.getCmp('window-chat').hidden){Ext.getCmp('window-preference').hide();Ext.getCmp('window-help').hide();Ext.getCmp('window-chat').show()}else{Ext.getCmp('window-chat').hide()}})}Ext.getCmp('window-chat').show()}else if(Ext.getCmp('window-video')){Ext.getCmp('window-chat').hide()}if(Ext.getCmp('window-chat')&&!Ext.getCmp('window-chat').hidden){Ext.get('btn-chat-reload').removeClass('btn-disabled');if(!this.initialend){Ext.get('btn-chat-reload').on('click',function(){if(!Ext.getCmp('window-chat')||Ext.getCmp('window-chat').hidden){return}var tab=Ext.getCmp('chat-tabs').getActiveTab();tab.getLayoutTarget().dom.innerHTML=tab.body.dom.innerHTML})}}else{Ext.get('btn-chat-reload').addClass('btn-disabled')}},setBackground:function(index){var bg=this.backgrounds[index];var style=document.body.style;if(bg[0]&&bg[0].length>0){style.backgroundColor=bg[0]}else{style.backgroundColor=''}if(bg[1]&&bg[1].length>0){style.backgroundImage=bg[1]}else{style.backgroundImage=''}if(bg[2]&&bg[2].length>0){style.backgroundRepeat=bg[2]}else{style.backgroundRepeat=''}if(bg[3]&&bg[3].length>0){style.backgroundPosition=bg[3]}else{style.backgroundPosition=''}this.bgIndex=index},getHashObject:function(){var h=location.hash;var i=h.indexOf("#");if(i>=0){var array=(h.substr(i+1)).split('/');return{irc:array[0]?array[0]:'',jtv:array[1]?array[1]:'',ust:array[2]?array[2]:'',btv:array[3]?array[3]:''}}return{irc:'',jtv:'',ust:'',btv:''}}};Ext.onReady(function(){var sp=new StreamPlayer();Ext.get('btn-link').on('click',function(){var list=Ext.get('links').dom;if(list.style.top==''){Ext.get('btn-link').addClass('btn-pressed');list.style.top='21px'}else{Ext.get('btn-link').removeClass('btn-pressed');list.style.top=''}});sp.start()});