var FlvVideoPlayer_Global;

function FlvVideoPlayer(swf_fl,swf_w,swf_h,htp_x,htp_y,d_name) {
	this.src=swf_fl;
	this.width=swf_w;
	this.height=swf_h;
	this.Position;
	this.Location=new this.Point();
	this.Location.X=htp_x;
	this.Location.Y=htp_y;
	this.PositionMode='absolute';
	this.positionFrom='fromBottom';
	this.positionHorizontalFrom='fromLeft';
	this.ReferenceID='cmsite_reg';
	this.RequiredVersionMajor=9;
	this.RequiredVersionMinor=0;
	this.needFlashString="Flash Version "+this.RequiredVersionMajor+"."+this.RequiredVersionMinor+" is needed.<br/><a href='http://www.adobe.com/go/getflash/' target='_blank'>Get it here</a>";
	if(document.body.attachEvent) { this.isIE=true;} else { this.isIE=false;}
	this.ParseBrowser();
	this.backgroundImage='images/transparent.gif';
	this.NeedsFix=false;
	this.WriteWrapper=true;
	this.FlashVars='';
	this.urlArray=null;
	this.anchorMode='static';
	this.InitialX=0;
	this.d_name = d_name;
}

//必要
FlvVideoPlayer.prototype.Point=function(x,y){
	this.X=x;
	this.Y=y;
}
//必要
FlvVideoPlayer.prototype.ParseBrowser=function() {
	this.isNetscape=false;
	this.isFirefox=false;
	this.isIE=false;
	this.isOpera=false;
	this.isSafari=false;
	this.appName=navigator.appName;
	this.appVersion=navigator.appVersion;
	if(this.appName=="Netscape"&&parseFloat(this.appVersion)>4.7) {
		var uai=navigator.userAgent.indexOf("Firefox");
		if(uai!=-1) {
			this.isFirefox=true
			this.browserVersionMaj=parseInt(navigator.userAgent.charAt(uai+8));
		} else {
			this.isNetscape=true;
			this.browserVersionMaj=parseFloat(this.appVersion);
		}
	} else {
		var uai=navigator.appVersion.indexOf("MSIE");
		if(uai!=-1) {
			this.isIE=true;
			var temp=navigator.appVersion.split("MSIE")
			this.appVersion=parseFloat(temp[1]);
			this.browserVersionMaj=parseInt(this.appVersion);
			if(this.appVersion == 6){
				this.Ime_no_flag = true;
//				alert("AAA" + this.appVersion);
			}

		} else {
			var uai=navigator.userAgent.indexOf("Opera");
			if(uai!=-1){
				this.isOpera=true;
				this.browserVersionMaj=parseInt(navigator.userAgent.charAt(uai+6));
			}
		}
	}
	if(document.compatMode=='CSS1Compat') {
		this.isCompatible=true;
	} else {
		this.isCompatible=false;
	}
}
//必須
FlvVideoPlayer.prototype.el=function(e) {
	return document.getElementById(e);
}

//必須
FlvVideoPlayer.prototype.Intialize=function() {
	FlvVideoPlayer_Global=this;	
	this.InitialX=this.Location.X;
		if(this.ReferenceID!=null && this.el(this.ReferenceID)!=null) {
			this.AnchorToObjectX();
			this.LockInitialX();
		}
	if(this.anchorMode=='static') {
		this.positionMode='fixed';
		if(this.isIE) {
			if(this.appVersion==8){
			
			}else{
				if(this.appVersion!=7 || !this.isCompatible)	{
					this.positionMode='absolute';
					this.NeedsFix=true;
				}
			}
		}
		if(this.isFirefox && this.browserVersionMaj<2) {
			this.positionMode='absolute';
			window.addEventListener('scroll',RestorePosition,false);
			window.addEventListener('size',RestorePosition,false);
	
		}
		this.WriteDiv();
	} else {
		this.positionMode='absolute';
		this.WriteDiv();
	}
	if(this.ReferenceID!=null && this.el(this.ReferenceID)!=null) {
		this.AnchorToObjectX();
	}
}

//必須
FlvVideoPlayer.prototype.CheckFlashVersion = function() {
	var maj=0;
	var min=0;
	if(navigator.plugins != null && navigator.plugins.length > 0) {
		if(navigator.plugins["Shockwave Flash"]) {
			var d=navigator.plugins["Shockwave Flash"].description;
			var a=d.split(" ");
			var version=a[2];
			var a1=version.split(".");
			maj=a1[0];
			min=a1[1];
			
		} 
	} else {
		try {
			// version will be set for 7.X or greater players
			var o = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		 	var d = o.GetVariable("$version");
			var a=d.split(" ");
			var version=a[1];
			var a1=version.split(",");
			maj=a1[0];
			min=a1[1];
		} catch (e) {
			
		}
	}
	if(maj>this.RequiredVersionMajor || (maj==this.RequiredVersionMajor && min>=this.RequiredVersionMinor)) {
		return true;
	} else {
		return false;
	}	
}


//必須
FlvVideoPlayer.prototype.WriteStandardContainer= function(){
	document.write('<div id="FlvVideoPlayer_Container" style="z-index:1000;');
	this.WritePositionStyleInfo();
	document.write('border: 0px;height:'+this.height+';">');
}

//必須
FlvVideoPlayer.prototype.WritePositionStyleInfo=function() {
	document.write('position: '+this.positionMode+'; ');
	if(this.positionFrom=='fromBottom') {
		document.write('bottom: ');
	}
	else {document.write('top: ');}
	
	document.write(this.Location.Y+'px; ');
	if(this.positionHorizontalFrom=='fromLeft') {
		document.write('left: ');
	} else {
		document.write('right: ');
	}
	document.write(
	this.InitialX+'px;'); 
//	this.Location.X
}

FlvVideoPlayer.prototype.WriteNeedFlashContainer= function(){
	document.write('<div id="LayerMoviePlayer_Container" style="');
	this.WritePositionStyleInfo();
	document.write('z-index: 100;border: 0px; width:'+this.width+'px; background-color:#FFF; padding:4px 4px 4px 4px; border:inset 3px #F00 ">');
}

//必須
FlvVideoPlayer.prototype.WriteDiv=function() {
	if(this.CheckFlashVersion()) {
		if(this.WriteWrapper) {
			this.WriteStandardContainer();
		}
		if(this.Ime_no_flag){
			//IE6は別に動作
			//alert("Ime_no_flag=" + this.Ime_no_flag);
			//this.WriteMovieObject();
		}else{
			this.WriteMovieObject();
		}
	} else {
		this.WriteNeedFlashContainer();
		this.WriteNeedFlash();
	}
	if(this.NeedsFix){
		this.FixIEFixed();
	}
	if(this.WriteWrapper) {
		document.write('</div>');
	}
}

var shown=0;
var lastNum=0;

//必須
function getIEFixHeight() {
	var loc;
	var scrollTop;
	var clientHeight;
	if( typeof( window.innerWidth ) == 'number' ) { //Non-IE
		clientHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { //IE 6+ in 'standards compliant mode'
		clientHeight  = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { //IE 4 compatible
		clientHeight  = document.body.clientHeight;
	}
	if( typeof( window.pageYOffset ) == 'number' ) {	//Netscape compliant
		scrollTop = window.pageYOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) { //DOM compliant
		scrollTop = document.body.scrollTop;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrollTop = document.documentElement.scrollTop;
	} else {scrollTop=0;}
	if(FlvVideoPlayer_Global.positionFrom=='fromBottom'){
		loc=scrollTop+clientHeight-FlvVideoPlayer_Global.Location.Y-FlvVideoPlayer_Global.el('FlvVideoPlayer_Container').clientHeight ;	
	} else {
		loc=scrollTop+FlvVideoPlayer_Global.Location.Y;
	}
//	alert("AAA" + loc);
	//if(shown<2 && lastNum!=loc) 
	//	{ alert(loc);shown++;lastNum=loc;}	
	return loc;
}

//必須
FlvVideoPlayer.prototype.WriteMovieObject=function(){
	//alert("view_swf_A");
	this.Dimension = document.body.clientWidth;
	this.sp_wid		 = (Math.floor(this.Dimension - 900)/2) + parseInt(this.width);
	if(this.sp_wid < this.width){
		this.sp_wid = this.width;
	}
	
	
	//alert("width=" + this.width);
	//alert("sp_wid=" + this.sp_wid);
	document.write('<div id="firefox_div" style="width:' + this.sp_wid + 'px;">');

	document.write('<div style="float:right; width:'+this.width+'px; z-index:1000;"><div id="' + this.d_name + '" style="margin: 0px; padding: 0px"></div></div><div style="clear:both"></div>');
	document.write('</div>');
}

//必須
FlvVideoPlayer.prototype.FixIEFixed=function(){
	if(document.body.currentStyle['backgroundImage']=='none')
	{
		document.body.style.backgroundImage='url('+this.backgroundImage+')';
		document.body.style.backgroundRepeat='no-repeat';
		document.body.style.backgroundAttachment='fixed';
	}
	//2009/07/16
	//this.el('FlvVideoPlayer_Container').style.setExpression('top','getIEFixHeight()');
}


/**********************************************

***********************************************/

function swf_action(act,d_name) {
	switch(act){
		//
		case 'close':
			swf_out_action('stop',d_name);
			$(d_name).style.display='none';
			break;
		//
		case 'f_close':
			swf_out_action('stop',d_name);
			$(d_name).style.display='none';
			break;
		//
		case 'open':
			$(d_name).style.display='';
			//swf_out_action('restart',d_name);
			break;
		//ムービー終了時
		case 'mov_end':
			//$(d_name).style.display='none';
			break;
	}
	//window.event.cancelBubble = true;
}

//SWFへアクションを送る
function swf_out_action(act,d_name){
//	alert(act);
	$(d_name).setMessage(act);
}

/*------------------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------------------*/
	var LinkUrl		 = "";
	var Randnum		 = "";
	var site_id		 = "";
	var	url			 = "";
	var	rege		 = "";
	var	s_rege		 = "";
	
	var dome		 = "";
	var site		 = "";
	
	var Local_Flag	 = false;

	url		 = location.href;
	rege	 = new RegExp(/www.\S*.com+/g);
	s_rege	 = new RegExp(/[h|c][0-9]{4}/g);

	var clear_sw_wid	 = 180;
	var clear_sw_hei	 = 200;
	var Ie_6_flag		 = false;

	var Randnum = Math.floor( Math.random() * 100 ) + 1;
	
	site_id = String(url.match(s_rege));

	//alert("Randnum="+Randnum);

	switch (site_id){
		case "h4610":
			if(Randnum > 110){
				//チャット
				//alert("チャット");
				flv_name	 = "013_04.flv";
				LinkUrl		 = "http://www.h0874.com/home.html";
			}else{
				//ランキング
				//alert("ランキング");
				flv_name	 = "015_01.flv";
				LinkUrl		 = "http://www.dtiserv.com/cgi-bin/ranklink/ranklink.cgi?id="+site_id;
			}
			break;

		case "h0930":
			flv_name	 = "009.flv";
			LinkUrl		 = "http://www.dtiserv.com/cgi-bin/ranklink/ranklink.cgi?id="+site_id;
			break;

		case "c0930":
			flv_name	 = "008_02.flv";
			LinkUrl		 = "http://www.dtiserv.com/cgi-bin/ranklink/ranklink.cgi?id="+site_id;
			break;

		case "h0230":
			flv_name	 = "004_01.flv";
			LinkUrl		 = "http://www.dtiserv.com/cgi-bin/ranklink/ranklink.cgi?id="+site_id;
			break;

		default:
			Local_Flag	 = true;
			if(Randnum > 50){
				//チャット
				flv_name	 = "001_02.flv";
				
			}else{
				//ランキング
				flv_name	 = "001_02.flv";
				LinkUrl		 = "http://www.dtiserv.com/cgi-bin/ranklink/ranklink.cgi?id="+site_id;
			}
			break;

	}

	//---------------------------------------
	//	Func_clear_swf
	//---------------------------------------
	function Func_clear_swf(){
		if(Local_Flag){
			alert("HOST="+location.host);
			dome	 = String(location.host);
		}else{
			dome = url.match(rege);
		}
		Func_swf_typeA();
	}


	//---------------------------------------
	//	Func_swf_typeA
	//---------------------------------------
	function Func_swf_typeA(){
		//alert("dome="+dome);
		
		
		var site_url	 = "http://"+dome;
		//var site_url	 = "http://www."+site_id+".com:81";
		
		var height		 = clear_sw_hei;
		var width		 = clear_sw_wid;
		var name		 = "under_m";
		
		if(site_id=="h4610"){
			var flv_file	= site_url+"/clear_flv/"+flv_name;
		}else{		
			var flv_file	 = site_url+"/swf/clear_swf/"+flv_name;
		}
		
		var Svolume = "20";
		var j_act_cut	 = 1;
		var j_play_cut	 = 1;
		
		//*******************************************
		
		myIE = document.all;
		if(myIE){
			appName		 = navigator.appName;
			temp	 = navigator.appVersion.split("MSIE")
			appVersion	 = parseFloat(temp[1]);
			
			if(appVersion <= 6){
				//alert("appVersion=" + appVersion );
				Ie_6_flag	 = true;
			}
		}
		
		
		if(Ie_6_flag){
			//IE6以下

			document.write('<div id="firefox_div" style="width:150px; position:Fixed; position:absolute;">');
			document.write('<div style="float:right; width:'+width+'px; z-index:1000;"><div id="' +name+ '" style="margin: 0px; padding: 0px"></div></div><div style="clear:both"></div>');
			document.write('</div>');

//			document.write('<div ID="firefox_div" STYLE="position:absolute"><img src="http://www.red.oit-net.jp/tatsuya/image/link1.gif" width="88" height="31"></div>');

//			$("#firefox_div").top  = document.body.scrollTop  + document.body.clientHeight - height;
			
			Func_reside();
			
		}else{
			var mc = new FlvVideoPlayer(site_url+'/swf/clear_swf/006.swf', width, height, 0,0,name);
			mc.Intialize();
		}


		var flashvars = {
			 play_flv_url	: flv_file
			,link_url		: LinkUrl
			,swf_act_cut	: j_act_cut
			,swf_play_cut	: j_play_cut
			,swf_volume		: Svolume
		};
		var params = {
			 allowScriptAccess	: "sameDomain"
			, wmode				: "transparent"
		};
		var attributes = {};
		swfobject.embedSWF(site_url+"/swf/clear_swf/006.swf", name, width, height, "9.0.0", "", flashvars, params, attributes);

	}

	function Func_clear_resize(){
		//alert("clear_sw_wid="+clear_sw_wid);
		sp_wid		 = (Math.floor(document.body.clientWidth - 900)/2) + clear_sw_wid;
		if(sp_wid < 180){
			sp_wid = 180;
		}
		//alert("sp_wid=" + sp_wid);
		$("#firefox_div").width(sp_wid);
	}
	
	function Func_reside(){
		if(Ie_6_flag){
			my_sc_top	 = $(window).scrollTop();
			my_sc_he	 = $(window).height();
	
//			my_ch_x		 = document.body.scrollLeft + document.body.clientWidth - clear_sw_wid;
			my_ch_x		 = 0;
			my_ch_y		 = my_sc_top + my_sc_he - clear_sw_hei;
			$("#firefox_div").css({"left":my_ch_x,"top":my_ch_y});
	
			window.status = "my_ch_y="+my_ch_y;
		}
	}
