/*InfoPlayer-Copyright (c)2008 InfoPlayer.jp. All Rights Reserved/concept design ID-G
このプログラムの無断転載と無断利用、複製、流用、改ざん、改変、転載、リバースエンジニアリング、並びにそれに伴う本サイトプログラムの無断での使用を禁じます。
 */
(function(){
var coIn=function(){$o=this;return this instanceof coIn ? this.create() : new coIn();};
window.coIn=coIn;
coIn.prototype={
create:function(){
	$j.inherit(coIn,coinDI);
	var self=this;
	this.initDI("template/ipex.tpl");
	$o.newUrl="infoplayer/";
	var d=this.imgDir;
	$o.wizNew={};
	$o.noChange=true;
	$o.type.swidth=28;
	this.hashRedef($o.type,{"-2":d+"news.gif","-1":d+"enqs.gif","0":d+"infos.gif","1":d+"urls.gif","2":d+"pics.gif","3":d+"sounds.gif","4":d+"movies.gif","5":d+"files.gif","6":d+"docs.gif"},"s");
	$j("#oIW_btnOpen").click(function(){$o.infoWrite();});
	$j("#oGrid_btnAdd").click(function(){$o.gridCellAdd();}).oHover();

	$j(function(){
		if ($o.IE6) {
		$j(".btnFlat").hover(function(){
			$j(this).css("color", "red");
		}, function(){
			$j(this).css("color", "black");
		});
		$j(".btnText").hover(function(){
			$j(this).css("color", "red");
		}, function(){
			$j(this).css("color", "gray");
		});
		}
		$j().oDecoButton();
		$o.moving=true;
		$j(window).scroll(function(){$j().oDialog("refresh");}).resize(function(){$j().oDialog("refresh");});
		if (typeof(_o)!="undefined") {
		$j().o.setHistory(false);
		$o.checkReadOnly("noDialog",function(){
			var isIn = ($o.serverStatus.userName!="");
			$j("#oGrid_btnAdd,#oAtag_btnFavorite").ifShow(isIn);

			$j("#oIW_entry").find("#oIW_btnWTxt,#oIW_btnWImg,#oIW_btnWSnd,#oIW_btnWMov")
			.oToggleEffect(isIn).each(function(){
				if (isIn) $j(this).click(function(){
					$o.wizEntry($j(this).attr("id").match("...$")[0].toLowerCase());
				});
			});
			$j("#oIW_signup").ifShow(!isIn).click(function(){location.href=$o.baseDir;});
		});
		if ($o.nowTop.topCoinId>=1) self.TopCoinLoad($o.nowTop.topCoinId); else  $o.urlInt=$j.historyInit($o.pageload);
		}
	});
},
refreshInterfaces:function(emp){
	$o.refreshTitle(emp);
	$j("#oIF_cellNo").html("");
	if (emp){
	$o.jQRV.empty();
	return;
	}
	var jQSd=$j("#oSound_btnImg").hide(),tp=$o.cnt.contentType,txt=(tp<3);
	$j("#oGrid_btnAdd").ifShow($o.free&&$o.serverStatus.userName!="");
	$j("#oHeader_theme span").html($o.tp.theme.themeWord);
	$j("#oAtag_sid").text($o.tp.coinCd);
	$j("#oAtag_title").text($o.tp.coins.title);
	$j("#oStatistics")
	.find(".infoVv").text($o.tp.vv).end()
	.find(".infoTotalup").text($o.tp.totalup).end()
	.find(".infoTxt").text($o.tp.ctTxt).end()
	.find(".infoImg").text($o.tp.ctImg).end()
	.find(".infoMov").text($o.tp.ctMov).end()
	.find(".infoSnd").text($o.tp.ctSnd);

	if ($o.filter.selected!=null) $o.refreshFilterButton();
	$j("#oDoc_btnOpen").hide();
	$j("#oIF_Media").isShow(!txt);
	$j("#oDisp_size").isShow(txt);
	if (txt){
		if ((_o.mode != "view")&&($o.jQP.css("display")!="none")) $o.playPanel.close();
	}else{
		clearInterval($o.interval);
		if ((tp==3)||(tp==4)){
			if (tp==3) jQSd.show();
			$o.playPanel.open();
			$j("#oPlay_icon > img",$o.jQP).attr("src", $o.type[$o.cnt.contentType].icon);
		}else if (tp==6){
			$j("#oFilter_icons").html("");
			$j("#oDoc_btnOpen").show();
		}
		$j("#oDisp_btnHistory").oToggleEffect($o.historySW);
	}
	$o.drawRoot();
},
refreshTitle:function(){
	//if (o.abone) jQT.html($o._.deleted); else jQT.text(o.title);
	//$j("#oTitle_info").html((o.abone)?$o._.deleted:o.titleInfo);
	$o.jQA.find("#oTitle_title").text($o.o.title).end()
	.find("#oTitle_cell").html(($j().o.opt.oneCell?'One':($o.o.cellPatternId<0?"Free":"Grid"))+'&nbsp;cell');
	$o.jQTV.html($o.o.titleInfo);
	$o.jQTP.find("#oTitle_user").find('span').text(($o.o.users!=null&&$o.o.users.userName!=null)?$o.o.users.userName:$o._.anonimouse).end()
	.find('img').attr('src',(($o.o.users.thumbnailUrl==null)?($o.imgDir+"anoni.gif"):($o.medDir+$o.o.users.thumbnailUrl))).end()
	.find('a').attr('href',$o.baseDir+$o.o.users.userName).end().end()
	.find("#oTitle_status").html($o.dateFormat($o.o.created)+"&nbsp;");
	//$j("#oTitle_status",$o.jQTP).html($o.dateFormat($o.o.created)+"&nbsp;"+$o.checkNanashi($o.o.hname));
	
	$o.titleScroll(0);
},
updateInfoList:function(coinInfos){
	$o.nowInfos=coinInfos;
	var jQS=$j("#oIF_slider");
	var c=$j().o.opt.cellCode,id=-1;
	if ((c!=-1)&&($o.cells[c])) id=$o.cells[c].coinCellId;
	$o.root[$o.root.no].coinCellId=id;
	var jQl=$o.jQIV,html=null,jQEq=$j("#oIF_Enq,#oEnq_btnView"),jt=$o.jTmp._templates,t=null;
	if ((c<0)||(c==null)) {
	t=($o.filter.selected==null)?(($j().o.opt.free)?jt.no_select_free:jt.no_select):jt.no_data;
	}else{
	$j("#cellNo").html("Coin No."+$o.nowTop.coins.coinId+" / Cell No."+$j().o.grid.getCellNo(c));
	if (($o.cells[c]) && (coinInfos.length > 0)) {normal();return;}
	t=($j().o.opt.oneCell)
		?jt.one_cell
		:(($o.enquetes[c])?jt.enqonly_cell:jt.blank_cell);
	}
	if (!t) return;
	jQS.hide();
	$o.jQIV.html("");
	$j("#oIF_message",$o.jQIF).html(t.get({count:$o.cellCount},[],document.body));

	function normal(){
	$j("#oIF_message",$o.jQIF).html("");
	var title,info,chk=false,id,sid,ncol,tp,img,nm,func=null,infoNew="",ab=false;
	var output="<table class='oIFTable'><tbody>",el=coinInfos.length-1,nw="",ni="";
	$o.nowInfos.parts={};
	for(var n=0;n<=el;n++){
		var i=coinInfos[n];
		iid=i.coinInfoId; sid=i.subCoinCd; tp=i.contentType; img=$o.type[tp].icon; ab=false;
		if (i.title==null) i.title="";
		if (i.titleInfo==null) i.titleInfo="";
		if (tp<2){
			if (tp<0) tp=0;
			title="";
			info=i.information;
			img=$o.type[tp].icon;
			func="";
			if ((tp==1)&&(!i.abone)){
				var p=$o.isPartsTag(info);
				if (p) {
					$o.nowInfos.parts[String(n)]=p; func ="href='javascript:$o.partsViewer("+String(n)+");'"; info=info.replace(p,"");
					if (info.length==0) info="&nbsp;&nbsp;";
				}else{
					var u=info.match(/<a href="(.*)" target="_blank">?/); func ="href='"+RegExp.$1+"' target='_blank'";
				}
			}
		}else{
			title=i.title+"<br>";
			info=i.titleInfo;
			switch (tp){
				case 2://picture
				img=$o.contentsDir.ithumb(i);
				case 3:case 4:case 5:case 6:
				func="href='javascript:$o.nextCoin("+n+");'";
				break;
				case 7://Document
				func="href='javascript:$o.docViewer('"+ $o.contentsDir.file(i) +"');'";
				break;
			}
		}
		info=(info==null)?"":"<font color='#000'>"+info+"</font>";
		if (i.abone){
			title = $o._.deleted;
			info = "";
			img = $o.type[tp].icon + "' class='oAboneIcon'";
		}
		infoNew=(i.itsNew)?"New":"";
		if (n==el){
		nw="<span class='oIFNew'>NEW</span>";
		ni=" oIFNewImg";
		}
		nm=$o.toNanashi(i.hname)+"&nbsp;&nbsp;";
		output+="<tr><td class='oIFTag"+ni+"' rowspan=2><a title='"+$o.type[tp].tip+"' "+func+"><img src='"+ img+"'"+ni+"></a></td>"
		+"<td class='oIFCell'>"
		//+"<span style='text-align:left; float:left;'>No."+(n+1)+"</span><span class='oIFTime'>"+$o.dateFormat(i.created)+" ID:"+i.hostId+"</span><br>"+ title +"</td>"
		+"<span style='text-align:left; float:left;'>No."+(n+1)+nw+"</span></span><span class='oIFTime'>"+$o.dateFormat(i.created)+"</span><br>"+ title +"</td></tr>"
		+"<tr><td class='oIFCell'><div class='oIFTd'><div class='oIFBubble'><div class='c1 t1'><span></span></div><div class='c2 t2'><span></span></div><div class='c2 t3'><span></span></div><div class='oIFInfo'>"+info+"</div><div class='c2 b3'><span></span></div><div class='c2 b2'><span></span></div><div class='c1 b1'><span></span></div></div>"
		+"<div class='oIFUser'>"+(i.userName==null?$o._.anonimouse:i.userName)+"<br><a href='"+$o.baseDir+i.userName+"'><img src='"+((i.thumbnailUrl==null)?($o.imgDir+"anoni.gif"):($o.medDir+i.thumbnailUrl))+"'></a></div><div class='oIFBubMark'></div></div></td></tr><tr colspan=2 class='oIFSpace'></tr>";
	}
	jQl.html(output+"</tbody></table>");
	var sc={v:true,frameDiv:$o.jQIF,viewDiv:$o.jQIV,slider:jQS,toLast:false};
	if ($o.showLast) sc.toLast=true;
	$o.showLast=false;
	$o.scrollTo(0,sc);
	if (jQl.height()<=$o.jQIF.height()) jQS.hide(); else jQS.innerShow();
	$o.moving=false;
	$o.topLoading=false;
	}
},
partsViewer:function(no){
	if (typeof($o.nowInfos.parts)!="object") return;
	_o.player.div.hide();
	var jQW=$j("#oWizard"),p=$o.nowInfos.parts[no][0],
		m=p.match(/width="([0-9]+)".*height="([0-9]+)"/),w=Number(m[1]),h=Number(m[2]);
	w=(isNaN(w))?478:w+50;
	h=(isNaN(h))?400:h+53;
	jQW.html($o.jTmp._templates.partsViewer.get({},[],document.body));
	$j(".oMessage",jQW).height(h-50);
	jQW.oDecoButton().oWizard(null,1,{mode:"",step:1,modal:["on"],width:w,height:[h]},function(){
	$j("#oParts_parts").html("" + p).show();
	});
	$j("#oParts_btnClose").click(function(){jQW.oWizard("close");});
},
drawInfo:function(c,callback){
	if ((c >= 0)&&($o.jQIm.css("display")!= "none")) $o.jQIm.hide();
	var p=null,id=null,r=true;
	if ($o.cells[c]) id=$o.cells[c].coinCellId;
	switch ($o.wizEnq.step) {
	case 1:case 4:return;break;
	case 2:$o.receiveEnqueteData(c);r=false;break;
	case 3:$o.wizard(3,($o.enquetes[c])?5:4,$o.wizEnq);r=false;break;
	}
	$o.receiveInfoByCellCode(c,callback);
},

formItem:function (formItem,ret,fn){
	var v,r={},cl;
	(formItem.length)?cl=formItem.length:cl=1;
	for (var i=0; i<cl; i++) {
	(cl==1)?v=ck.value:v=ck[i].value;
	fn(v,ret);
	}
	return ret;
},
//Coin Data Entry
createTopCoin:function(fn){
	var topCoin ={publicType:4,theme:{themeCd: $o.wizNew.themeCd},category:{categoryId: $o.wizNew.categoryId}};
	$o.root={no:-1};
	var coin=$o.setNewCoin();
	coin.parentCoinId=null;
	$o.root={no:0};
	$o.jQLd.oAjaxMon($o._.saving,true);
	CoinApi.createTopCoin(topCoin, coin, function(topCoin){
		if (topCoin.coinCd==null) {
			$j().oError("0x204");
			$o.wizEntry.close("esc");
			return;
		}
		$o.jQLd.oAjaxMon();
		$o.nowTop=topCoin;
		$o.tp=$o.nowTop;
		$o.o=$o.nowTop.coins;
		$j("#oWizard").find("#oUp_sid").text(topCoin.coinCd).end().find("#oUp_url").text("http://"+location.host+$o.baseDir+$o.newUrl+topCoin.coinCd).end();
		if ($j.isFunction(fn)) fn();
	});
},
setNewCoin:function(opt){
	var w=$o.wizNew,u=w.up;
	if (w.grid==0){
		var r=$j().o.grid.getRecommend(u.width,u.height);
	}else{
		var r=$j().o.grid.getRecommend(u.width,u.height,32);
		r.w=r.h=r.size;
	}
	if ((u.contentType > 2)||(w.grid==1)) {w.grid=0;r={w:1,h:1};};
	var parent=null;
	if ($o.root[0]) parent=$o.root[$o.root.no].coinCd;
	var coins =$j.extend({
	startingCd:   ($o.nowTop.topCoinId)?($o.nowTop.coinCd):null,
	parentCoinCd:parent,
	publicType:4,
	title:w.title,
	titleInfo:w.titleInfo,
	width:u.widht,
	height:u.height,
	gridColor:"#000000",
	cellStyle:0,
	cellColor:"#F0F0F00A",
	cellPatternId:w.grid,
	cellW:r.w,
	cellH:r.h,
	hname:w.hname
	},opt);
	return coins;
},
addCell:function(cl,fn){
	var cell ={
	coinCd:cl.coinCd,
	cellCode:cl.cellCode,
	cellW:Math.floor(cl.cellW),
	cellH:Math.floor(cl.cellH)
	};
	$o.jQLd.oAjaxMon($o._.saving,true);
	CoinApi.addCell(cell,function(cell){
	$o.jQLd.oAjaxMon();
	if ($j.isFunction(fn)) fn(cell);
	return cell;
	});
},
addCellArray:function(cl,fn){
	var cd=$j().o.cell2CellCode(cl);
	$o.cells[cd]={coinCd:$o.o.coinCd, cellCode:$j().o.cell2CellCode(cl), cellW:cl.cellW,cellH:cl.cellH, modified:1};
	$o.cellCount++;
	$j().o.grid.show();
},
jump:function(){
	var cd = document.frmJump.sid.value;
	if ($o.isNotFound(1,cd)) return;
	CoinApi.checkCD(cd,function(ct){
	if (!$o.isNotFound(ct,cd)) location.href=$o.baseUrl+cd;
	});
},
gridCellAdd:function(){
	$o.checkReadOnly(null,function(){$o.wizAddCell();});
},
wizAddCell:function(){
	if ($o.wizNew.addcell) return;
	$j().o.cursor.jumpCellNo(-1);
	var fntMode={b:false,i:false},fntRGB=null,jQD=$j().o.opt.disp.div,d=jQD.offset();
	$o.wizNew={mode:"",sending:false,addcell:true,step:1,modal:["grid","grid","on","on","on"],cellCode:null,offset:{top:d.top+jQD.height()+1,left:d.left},width:jQD.width(),height:[104,122]};
	$j.extend($o.wizAddCell,{
	close:function(md,fn){
		diag(md,fn);
	}
	});
	var jQW=$j("#oWizard");

//   var tmpCells=$o.cloneCells($o.cells);
	jQW.html($o.jTmp._templates.addcell_wiz.get({},[],document.body)).oDecoButton().hide();
	var jQWn=jQW.children("#oWiz_window");
	//Step.1
	$j("#oAdd_btnPosEsc", jQW).click(function(){endAim();diag('esc');});
	$j("#oAdd_btnSizeEsc", jQW).click(function(){diag("esc");});
	$j("#oAdd_btnSizeOk", jQW).click(function(){
	$o.checkReadOnly(function(){diag("esc");},function(){
		$o.wizNew.cellCode=$j().o.opt.cellCode;
		$o.wizNew.cell=$o.clone($o.cells[$o.wizNew.cellCode]);
		$o.showCell(true,function(){
		if ($j().o.rect.hit($o.wizNew.cell)) {
			$j().oDialog("error", $o._.err_onCell, $o._.yes,function(){diag("esc");});
		} else {
			$j().o.rect.toggle(false);
			jQW.o.setMode("");
			$o.wizEntry();
		}
		},function(){diag("esc");});
	});
	});
	jQW.oWizard(null,1,$o.wizNew);
	$j().o.aim.toggle(true);

	jQW.o.setMode("adjust");
	var v=$j().o.opt.rect.visible;
	$o.wizNew.cell=$j().o.rect.toggle(false);
	$j().o.grid.click(function(e,cl){
	cl=$j().o.aim.set(cl);
	if ($j().o.rect.hit(cl)){
		$j().oDialog("error", $o._.err_dubCell, $o._.yes);
	}else{
		$o.addCellArray(cl);
		endAim();
		$j().o.rect.set(cl);
		$j().o.rect.toggle(true);
		jQW.oWizard(1,2,$o.wizNew);
	}
	});
	$j().o.grid.mouseover(function(e,c){
		$j().o.aim.set(c);
	});
	function endAim(){
		$j().o.grid.click(null);
		$j().o.grid.mouseover(null);
		$j().o.aim.toggle(false);
	}
	function diag(mode,fn){
		var cd=$j().o.opt.cellCode;
		$j().o.rect.toggle(false);
		jQW.fadeOut($o.noIE(200),function(){
			$j(this).empty();
			if ($j.isFunction(fn)) fn();
		});
		jQW.o.setMode("");
		if (mode=="esc") {
			delete $o.cells[cd];
			delete $o.wizNew;
			$j().o.grid.show();
			return;
		} else if (mode=="wesc") {
			delete $o.cells[$o.wizNew.cell.cellCode];
			delete $o.wizNew;
			$j().o.grid.show();
			return;
		}
		/*
		if ($o.wizNew.addCell) {
			$j().o.cursor.setCellCode(cd);
			$j().o.grid.show();
			delete $o.wizNew;
			return;
		}
		*/
		$o.showCell(function(){
			$o.wizNew={};
			if (!mode&&cd>0) $j().o.cursor.setCellCode(cd);
		});
	}
},
dialogIE6:function(){
	if (!$j.browser.msie) return;
	var jQ=$j("#oModal");
	if (jQ.css("display")!="none"){
	var o=$j("#oDisplay").offset();
	jQ.css({position:"absolute",left:-o.left,top:-o.top}).width($j(document.body).width()).height($j(document.body).height());
	}
	if (!$o.jQDg.length) return;
	if ($o.jQDg.css("display")=="none") return;
	var wd=$j(window),dc=$j(document.body),h=dc.height(),w=dc.width();
	$o.jQDg.width(w).height(h);
	var jW=$j("#oDiag_window",$o.jQDg),y=wd.scrollTop()+((wd.height()-jW.height())>>1),x=(wd.width()-jW.width())>>1;
	jW.css({left:x,top:y});
}
};
/*
	partsViewer:function(no){
	if (typeof($o.nowInfos.parts)!="object") return;
	_o.player.div.hide();
	var jQW=$j("#oWizard");
	$o.wizNew={mode:"",step:1,modal:["on"],width:500,height:[400]};
	jQW.html($o.jTmp._templates.addcell_wiz.get({},[],document.body)).oDecoButton().hide();
	$j(".oWizHide").hide();
	var jQWn=jQW.children("#oWiz_window");

	var jQDc=$j('#oDocViewer'),jQIf=$j("#oDoc_parts",jQDc);
	$j("#oParts_btnClose").click(function(){jQDc.hide();});

	jQDc.hide();
	if  ($o.isIE6()) {window.open(pdf, '_blank', 'menubar=no,toolbar=no'); return;}
	var w=$j(document).width(),h=Math.floor($j(document).height()*0.9);
	var wx=Math.floor(w*0.7),x=Math.floor((w-wx)/2);
	jQDc.hide().css({position:"fixed", left:0,top:0,width:"100%", height:"100%",zIndex:1007})
	.children("#oDoc_modal").show().end()
	.children("#oDoc_frame").css({position:"absolute", left:x,top:32,width:wx+"px", height:"80%"})
	.children("#oDoc_title").show().end();
	//jQIf.replaceWith($o.nowInfos.parts[no]);
	var w=$o.nowInfos.parts[no];
	jQIf.html(""+w);
	jQDc.show();
	},
*/
})();

