﻿/*******************************************************************************
 * Tekki PilotData JS library for Official Site 
 * 2009.10.20 Daemonkim at GAMEYAROU Inc.
 * IE 6/7/8,  FF 3, Safari, Opera, Chrome Supported
 ******************************************************************************/

if ( typeof(AC_FL_GetContent) == "undefined")
	document.write(unescape("%3Cscript type='text/javascript' src='/blogparts/_js/AC_OETagsExtend.js'%3E%3C/script%3E"));
if ( typeof(pilotLayerPopup) == "undefined")
	document.write(unescape("%3Cscript type='text/javascript' src='/blogparts/_js/layer_popup/layer_popup.js'%3E%3C/script%3E"));

var tkPilotDataOffcial = {

	id			: "swfTkPilotData",
	swfUrl		: "/blogparts/swf/TK_Web_PilotData",
	installUrl	: "/blogparts/swf/playerProductInstall",
	width		: "1010",
	height		: "500",
	wating		: false,
	documentOnWheel	: null,

	show		: function(pilot, cp_code) {
		if (this.wating) return;
		else this.wating = true;

		if (!pilotLayerPopup) return;
		var obj = document.getElementById(this.id);

		if (obj) {
			obj.load(pilot, cp_code);
			this.wheelInit();
		}else{
			pilotLayerPopup.createFlash( this.getTag(pilot, cp_code) );
		}
		
		if (MainTekkiNewsControls && MainTekkiNewsControls.Stop) MainTekkiNewsControls.Stop();
		
		pilotLayerPopup.open(this.width, this.height, this.id, false);
	},

	getTag		: function(pilot, cp_code) {
		pilot = pilot ? pilot.toString() : "";

		var hasProductInstall = DetectFlashVer(6, 0, 65);
		var hasRequestedVersion = DetectFlashVer(9, 0, 124);
		if ( hasProductInstall && !hasRequestedVersion ) {
			var MMPlayerType = (isIE == true) ? "ActiveX" : "PlugIn";
			var MMredirectURL = window.location;
			document.title = document.title.slice(0, 47) + " - Flash Player Installation";
			var MMdoctitle = document.title;
			return AC_FL_GetContent(
				"id", this.id,
				"src", this.installUrl,
				"flashvars", "MMredirect"+MMredirectURL+'&MMplayerType='+MMPlayerType+'&MMdoctitle='+MMdoctitle+"",
				"width", this.width,
				"height", this.height,
				"quality", "high",
				"wmode", "transparent",
				"name", this.id,
				"allowScriptAccess", "always",
				"type", "application/x-shockwave-flash",
				"pluginspage", "http://www.adobe.com/go/getflashplayer"
			);
		} else if (hasRequestedVersion) {
			return AC_FL_GetContent(
			"id", this.id,
			"src", this.swfUrl,
			"flashvars", "pilot=" + encodeURIComponent(pilot) + "&cp_code=" + encodeURIComponent(cp_code),
			"width", this.width,
			"height", this.height,
			"quality", "high",
			"wmode", "transparent",
			"name", this.id,
			"allowScriptAccess", "always",
			"type", "application/x-shockwave-flash",
			"pluginspage", "http://www.adobe.com/go/getflashplayer"
			);
		} else {
			var alternateContent = '<table id="'+ this.id +'" width="'+ this.width +'" height="' + this.height +'" border="0"><tr><td align="center" valign="middle">'
			+ '<a href="http://www.adobe.com/go/getflashplayer" target="_blank"><img src="http://image.gameyarou.jp/tekki/blogparts/get_adobe_flash_player.png" '
			+ 'width="158" height="39" alt="Get Flash Player" title="このサイトをご覧になるには「Flash Player」が必要です。" border="0"/></a>'
			+ '</td></tr></table>';
			return alternateContent;
		}

	},

	wheelInit		: function() {
		var obj = document.getElementById(this.id);
		if (obj) {
			if (window.addEventListener)
				document.addEventListener("DOMMouseScroll", this.onWheel.bind(this), false);

			this.documentOnWheel = document.onmousewheel; // Backup
			document.onmousewheel = this.onWheel.bind(this);

			obj.focus();
		}
	},

	onWheel		: function(e) {
		var obj = document.getElementById(this.id);
		if (obj) {
			if (window.event) {
				if (event.srcElement == obj) {
					obj.focus();
					obj.mousewheelHandler(event.wheelDelta);
					event.cancelBubble = true;
					event.returnValue = false;
					return false;
				}
			}else{
				if (e.target == obj) {
					obj.focus();
					if (e.detail && (e.detail != 0)) {
						obj.mousewheelHandler(0 - e.detail);
					}else{
						obj.mousewheelHandler(e.wheelDelta/40);
					}
					e.stopPropagation();
					e.preventDefault();
					return false;
				}
			}
		}
		return true;
	},

	onWheelDisable		: function(e) {
		return false;
	},
	
	close		 : function() {
		if (navigator.product) {
			document.removeEventListener("DOMMouseScroll", this.onWheel.bind(this), false);
		}else{
			document.onmousewheel = (this.documentOnWheel) ? this.documentOnWheel : null;
		}
		
		LPlib.close();

		this.wating = false;

		if (MainTekkiNewsControls && MainTekkiNewsControls.Restart) MainTekkiNewsControls.Restart();
	},
	
	goURL		: function(url, target) {
		if (target=="top") top.location.href = url;
		else if (target=="parent") parent.location.href = url;
		else if (target=="opener") opener.location.href = url;
		else if (target=="blank") window.open(url);
		else self.location.href = url;

		/* Add Custom Script Here ***************************************/
	}

};

// Replace 'this' prototype  for functions
Function.prototype.bind = function( thisObj ) {
	var method = this;
	return function() {
		method.apply(thisObj, arguments);
	}
};
