//////////////////////////////////////////////////////
//                    GAME
//////////////////////////////////////////////////////


var gPreViewFlg = 1;
var runGameID = "";
var yj_refresh = yj_refresh;

//ゲームの制御
function handleGame(id, src, title, width, height, ver){

 var so = new SWFObject(src, title, width , height, ver);
 so.write('gameflash_' + id);
 chgGameFlash(id);

}

// フラッシュへの切り替え
function chgGameFlash(id){
 _YCSP_LO.cleanup();

 if(runGameID){ chgGameImg(runGameID); }

 yg_getObj("gamediv_"+id).innerHTML = yg_getObj("gameflash_"+id).innerHTML;
 yg_getObj("gameflash_"+id).innerHTML = "";
 runGameID = id;
 window.clearTimeout(yj_refresh);
}


// 画像への切り替え
function chgGameImg(id, edit){
 yg_getObj("gamediv_"+id).innerHTML = yg_getObj("gameimage_"+id).innerHTML;
 // 編集ボタンが押されたときにはパチンコライト版のリンク切り替え
 if(edit == 1){ if(yg_getObj("gamechg_"+id)){chgLightVer(id);} }
}
// パチンコライト版画像への切り替え
function chgGameImgLight(id){
 yg_getObj("gamediv_"+id).innerHTML = yg_getObj("gameimagelight_"+id).innerHTML;
}


// ゲーム遊び方ウィンドウ
function wopen1(open_url) {
 window.open (open_url, "howToPlayGame","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=550, height=650");
}


// パチンコライト版へのリンクに切り替え
function chgLightVer(id){
 yg_getObj("gamechg_"+id).innerHTML = yg_getObj("gamelight_"+id).innerHTML;
}


// パチンコ通常版へのリンクに切り替え
function chgNormalVer(id){
 yg_getObj("gamechg_"+id).innerHTML = yg_getObj("gamenormal_"+id).innerHTML;
}


//////////////////////////////////////////////////////
//                    Media RSS
//////////////////////////////////////////////////////
var detectableWithVB = false;
var pluginFound = false;

function canDetectPlugins() {
    if( detectableWithVB || (navigator.plugins && navigator.plugins.length > 0) ) {
	return true;
    } else {
	return false;
    }
}

function detectFlash(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('Shockwave','Flash'); 
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
	pluginFound = detectActiveXControl('ShockwaveFlash.ShockwaveFlash.1');
    }
    // check for redirection
    return pluginFound;
}

function detectDirector(redirectURL, redirectIfFound) { 
    pluginFound = detectPlugin('Shockwave','Director'); 
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
	pluginFound = detectActiveXControl('SWCtl.SWCtl.1');
    }
    // check for redirection
    return pluginFound;
}

function detectQuickTime(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('QuickTime');
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
	pluginFound = detectQuickTimeActiveXControl();
    }
    return pluginFound;
}

function detectReal(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('RealPlayer');
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
	pluginFound = (detectActiveXControl('rmocx.RealPlayer G2 Control') ||
		       detectActiveXControl('RealPlayer.RealPlayer(tm) ActiveX Control (32-bit)') ||
		       detectActiveXControl('RealVideo.RealVideo(tm) ActiveX Control (32-bit)'));
    }	
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectWindowsMedia(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('Windows Media');
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
	pluginFound = detectActiveXControl('MediaPlayer.MediaPlayer.1');
    }
    return pluginFound;
}

function detectPlugin() {
    // allow for multiple checks in a single pass
    var daPlugins = detectPlugin.arguments;
    // consider pluginFound to be false until proven true
    var pluginFound = false;
    // if plugins array is there and not fake
    if (navigator.plugins && navigator.plugins.length > 0) {
	var pluginsArrayLength = navigator.plugins.length;
	// for each plugin...
	for (pluginsArrayCounter=0; pluginsArrayCounter < pluginsArrayLength; pluginsArrayCounter++ ) {
	    // loop through all desired names and check each against the current plugin name
	    var numFound = 0;
	    for(namesCounter=0; namesCounter < daPlugins.length; namesCounter++) {
		// if desired plugin name is found in either plugin name or description
		if( (navigator.plugins[pluginsArrayCounter].name.indexOf(daPlugins[namesCounter]) >= 0) || 
		    (navigator.plugins[pluginsArrayCounter].description.indexOf(daPlugins[namesCounter]) >= 0) ) {
		    // this name was found
		    numFound++;
		}   
	    }
	    // now that we have checked all the required names against this one plugin,
	    // if the number we found matches the total number provided then we were successful
	    if(numFound == daPlugins.length) {
		pluginFound = true;
		// if we've found the plugin, we can stop looking through at the rest of the plugins
		break;
	    }
	}
    }
    return pluginFound;
} // detectPlugin


// Here we write out the VBScript block for MSIE Windows
if ((navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1)) {
    document.writeln('<script language="VBscript">');

    document.writeln('\'do a one-time test for a version of VBScript that can handle this code');
    document.writeln('detectableWithVB = False');
    document.writeln('If ScriptEngineMajorVersion >= 2 then');
    document.writeln('  detectableWithVB = True');
    document.writeln('End If');

    document.writeln('\'this next function will detect most plugins');
    document.writeln('Function detectActiveXControl(activeXControlName)');
    document.writeln('  on error resume next');
    document.writeln('  detectActiveXControl = False');
    document.writeln('  If detectableWithVB Then');
    document.writeln('     detectActiveXControl = IsObject(CreateObject(activeXControlName))');
    document.writeln('  End If');
    document.writeln('End Function');

    document.writeln('\'and the following function handles QuickTime');
    document.writeln('Function detectQuickTimeActiveXControl()');
    document.writeln('  on error resume next');
    document.writeln('  detectQuickTimeActiveXControl = False');
    document.writeln('  If detectableWithVB Then');
    document.writeln('    detectQuickTimeActiveXControl = False');
    document.writeln('    hasQuickTimeChecker = false');
    document.writeln('    Set hasQuickTimeChecker = CreateObject("QuickTimeCheckObject.QuickTimeCheck.1")');
    document.writeln('    If IsObject(hasQuickTimeChecker) Then');
    document.writeln('      If hasQuickTimeChecker.IsQuickTimeAvailable(0) Then ');
    document.writeln('        detectQuickTimeActiveXControl = True');
    document.writeln('      End If');
    document.writeln('    End If');
    document.writeln('  End If');
    document.writeln('End Function');

    document.writeln('</scr' + 'ipt>');
}

function checkFileType(mime, types){
    for(var i = 0; i < types.length; i++){
        if(mime.indexOf(types[i]) != -1){
           return true; 
        } 
    }
    return false;
}

function embedMedia(url){

    var isFlashFile = false; 
    var isWmv_QtFile = false; 
    var isQtFile = false; 
    var isIE = false; 
    var qIndex;
    var fileExtensionIndex;
    var fileExtension = "";
    var targetUrl;
    var mimeType;

    if((navigator.userAgent.indexOf('MSIE') != -1)){
        isIE = true;
    }

    targetUrl = url;
    qIndex = targetUrl.indexOf("?");
    if(qIndex != -1){
         targetUrl = targetUrl.substring(0, qIndex); 
    }

    fileExtensionIndex = targetUrl.lastIndexOf(".");
    if(fileExtensionIndex != -1){
         fileExtension = targetUrl.substring(fileExtensionIndex+1).toLowerCase();
    }

    if(fileExtension == "swf"){
        mimeType = "video/flash";
        isFlashFile = true;   
    }else if(fileExtension == "mp3"){
        mimeType = "audio/mpeg";
        isWmv_QtFile = true; 
    }else if(fileExtension == "mp4"){
        mimeType = "video/mp4";
        isQtFile = true;
    }else if(fileExtension == "mov"){
        mimeType = "video/quicktime";
        isQtFile = true;
    }else if(fileExtension == "m4v"){
        mimeType = "video/x-m4v";
        isQtFile = true;
    }

    if(isFlashFile || isWmv_QtFile || isQtFile){

        if((isFlashFile && detectFlash()) ||
           (isWmv_QtFile && ((isIE && detectWindowsMedia()) || detectQuickTime())) ||
           (isQtFile && detectQuickTime()) 
        ){
            var tag = "<embed id=\"media-player\" src=\"" + url + "\" controller=\"true\" autoplay=\"true\" type=\"" + mimeType + "\" frameborder=\"no\" ></embed>";
            document.write(tag);
        }else{
            document.write("<p>ファイルの再生にはプラグインのインストールが必要です。");
            document.write("<br>詳しくは<a href=\"http://help.yahoo.co.jp/help/jp/myyahoo/myyahoo-42.html\" onClick=\"window.open(\'http://help.yahoo.co.jp/help/jp/myyahoo/myyahoo-42.html\',\'mediaHelp\',\'menubar=yes, toolbar=yes, location=yes, status=yes, resizable=yes\');return false;\">こちら</a></p>");
        }

    }else{
        document.write("<p>サポート外のファイルです。</p>");
    }
}

function openMediaWindow(url){
    windowHandle = window.open(url,'MediaWindow','width=685, height=450, menubar=no, toolbar=no, location=no, status=no, resizable=no');
    if (!windowHandle) { windowHandle.opener = self; }
    windowHandle.focus();
}

