var _bubble;
var _bubbleHolder;
var _agt = navigator.userAgent.toLowerCase();
var _ver = navigator.appVersion.toLowerCase();
var _isWin = (_ver.indexOf("win") != -1) ? true : false;
var _isMac = (_agt.indexOf("mac") != -1) ? true : false;
var _isIE  = (_ver.indexOf("msie") != -1) ? true : false;
var _isFF = (_agt.indexOf("firefox") != -1) ? true : false;
var _isOpera = (_agt.indexOf("opera") != -1) ? true : false;

var _cookieName = "MarineCommitEnquete";

var date = new Date();

function getVoteCookie(){
	var valName = _cookieName + "=";
	var myCookie = document.cookie + ";";
	var start = myCookie.indexOf(valName);
	if(start != -1){
		var end = myCookie.indexOf(";", start);
		var params_str = unescape(myCookie.substring(start + valName.length, end));
		//alert("Cookie = " + unescape(params_str)); // クッキーにどんなことが書いてあるのかチェック用↓
		return params_str;
	}else{
		//alert(_cookieName + "なんてcookie存在しない");
		return false;
	}
}

function initBubble(){
	// _displayNavigatorInfo();
	//if(_hasFlashPlugin(8, 0, 0) && _hasRequiredBrowser()){
	//	_createBubble();
	//}
}

function initBubbleWithOutNavi(){
	// _displayNavigatorInfo();
	if(_hasFlashPlugin(8, 0, 0) && _hasRequiredBrowser()){
		_createBubbleWithOutNavi();
	}
}


function initLogin(){

	if(!document.getElementById("bubbleHolder")){
		var e0 = new FlashElement(gCmRootPath + "world/navi/navi.swf?=" + date.getTime(), "540", "900", gCmRootPath + "world/navi/FlashLogin.swf?=" + date.getTime());
		var browserId = "others";
		if(_isIE){
			browserId = "ie";
			e0.wmode = "transparent";
		}
		e0.id = "bubble";
		e0.flashVars = "BROWSER_ID=" + browserId + "&DOC_ROOT=" + gCmRootPath;
		var str = "";
		str += '<div id="bubbleHolder">';
		str +=  e0.toString2();
        str += '</object>';
		str += '</div>';

		document.write(str);

		//
		_bubbleHolder = document.getElementById("bubbleHolder");
		var style = _bubbleHolder.style;
		style.position ="absolute";
		style.zindex = "100";
		if(_isFF){
			style.top = "-1";
		}else{
			style.top = "0";
		}
		if(_isIE){
			style.left = "514px";
		}else{
			style.left = "767px";
		}

		_bubble = _getMovie("FlashLogin");

	}
}


function _createBubble(){
	if(!document.getElementById("bubbleHolder")){
		var e0 = new FlashElement(gCmRootPath + "world/navi/navi.swf?=" + date.getTime(), "540", "900");
		var browserId = "others";
		if(_isIE){
			browserId = "ie";
			e0.wmode = "transparent";
		}
		e0.id = "bubble";
		e0.flashVars = "BROWSER_ID=" + browserId + "&DOC_ROOT=" + gCmRootPath;
		//
		var str = "";
		str += '<div id="bubbleHolder">';
		str +=  e0.toString();
		str += '</div>';
		document.write(str);
		//
		_bubbleHolder = document.getElementById("bubbleHolder");
		var style = _bubbleHolder.style;
		style.position ="absolute";
		style.zindex = "100";
		if(_isFF){
			style.top = "-1";
		}else{
			style.top = "0";
		}
		if(_isIE){
			style.left = "514px";
		}else{
			style.left = "767px";
		}
		_bubble = _getMovie("bubble");
	}
}

function _createBubbleWithOutNavi(){
	if(!document.getElementById("bubbleHolder")){
		var e0 = new FlashElement(gCmRootPath + "world/navi/FlashLogin.swf?=" + date.getTime(), "540", "900");
		var browserId = "others";
		if(_isIE){
			browserId = "ie";
			e0.wmode = "transparent";
		}
		e0.id = "bubble";
		e0.flashVars = "BROWSER_ID=" + browserId + "&DOC_ROOT=" + gCmRootPath;
		//
		var str = "";
		str += '<div id="bubbleHolder">';
		str +=  e0.toString();
		str += '</div>';
		document.write(str);
		//
		_bubbleHolder = document.getElementById("bubbleHolder");
		var style = _bubbleHolder.style;
		style.position ="absolute";
		style.zindex = "100";
		if(_isFF){
			style.top = "-1";
		}else{
			style.top = "0";
		}
		if(_isIE){
			style.left = "770px";
		}else{
			style.left = "767px";
		}
		_bubble = _getMovie("bubble");
	}
}

function _getMovie(aId){
	var ref = 0;
	if(_isIE) ref = window[aId];
	else ref = document[aId];
	return ref;
}


// plug -in detection script by Macromedia
function JSGetSwfVer(i){
	if (navigator.plugins != null && navigator.plugins.length > 0){
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
      		var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			descArray = flashDescription.split(" ");
			tempArrayMajor = descArray[2].split(".");
			versionMajor = tempArrayMajor[0];
			versionMinor = tempArrayMajor[1];
			if ( descArray[3] != "" ) {
				tempArrayMinor = descArray[3].split("r");
			} else {
				tempArrayMinor = descArray[4].split("r");
			}
      		versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
            flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
      	} else {
			flashVer = -1;
		}
	}
	else {
		flashVer = -1;
	}
	return flashVer;
}

function _hasFlashPlugin(reqMajorVer, reqMinorVer, reqRevision){
 	reqVer = parseFloat(reqMajorVer + "." + reqRevision);
	for (i=25;i>0;i--) {	
		if (_isIE && _isWin && !_isOpera){
			versionStr = VBGetSwfVer(i);
		} else {
			versionStr = JSGetSwfVer(i);		
		}
		if (versionStr == -1 ){ 
			return false;
		} else if (versionStr != 0) {
			if(_isIE && _isWin && !_isOpera){
				tempArray = versionStr.split(" ");
				tempString = tempArray[1];
				versionArray = tempString .split(",");				
			} else {
				versionArray = versionStr.split(".");
			}
			versionMajor = versionArray[0];
			versionMinor = versionArray[1];
			versionRevision = versionArray[2];
			
			versionString = versionMajor + "." + versionRevision;   // 7.0r24 == 7.24
			versionNum = parseFloat(versionString);
			if ( (versionMajor > reqMajorVer) && (versionNum >= reqVer) ){
				return true;
			} else {
				return ((versionNum >= reqVer && versionMinor >= reqMinorVer) ? true : false );	
			}
		}
	}
}

function _hasRequiredBrowser(){
	var b = false;
	// firefox
	if(_agt.indexOf("firefox") != -1){
		var verIndex = _agt.indexOf("firefox") + 8;
		if (parseInt(_agt.charAt(verIndex)) >= 1) b = true;
	}
	// ie5+
	else if(_isIE && !_isMac){
		var tmp = _ver.split("msie");
		var ieVer = parseFloat(tmp[1]);
		if(ieVer >= 5.0) b = true;
	}
	// safari
	else if(_isMac){ 
		if( (parseInt(navigator.appVersion)) >= 5 && (navigator.product="gecko")){
			b = true;
		}
	}
	return b;
}
