/*---------------------------------------------------------------
-----------------------------------------------------------------
IMG SRC base javascript
-----------------------------------------------------------------

.Set Class
.click Event
.formSubmit
.browserCheck
.addEvent
.scrollAdd
.initRollovers
.external links
.is_all_ws
.smooth_scroll

-----------------------------------------------------------------
---------------------------------------------------------------*/

/*@cc_on _d=document;eval('var document=_d')@*/

/*=================================================================
//
// .Set Class
//
=================================================================*/
function setClass(_target, _class) {
	var elm;
	if((typeof _target).toLowerCase() == 'string'){
		elm = $(_target);
	}else{
		elm = _target;
	}
	if(document.all){
		if(navigator.userAgent.indexOf("Opera") != -1){
			elm.setAttribute('class', _class);
		}else {
			elm.setAttribute('className', _class);
		}
	}else{
		elm.setAttribute('class', _class);
	}
}


/*=================================================================
//
// .click Event
//
=================================================================*/
function clicklink(linkLoc) {
	if(linkLoc != "")	{
		location.href = linkLoc;
	}
}

/*=================================================================
//
// .formSubmit
//
=================================================================*/
function formSubmit(_target) {
	var form = document.forms[_target];
	form.submit();
	return false;
}

/*=================================================================
//
// .browserCheck
//
=================================================================*/
function BrowserCheck(){
		var b = navigator.appName;
		if (b == "Netscape") this.b = "NN";
		else if (b == "Microsoft Internet Explorer") this.b = "IE";
		else this.b = b;
		this.version = navigator.appVersion;
		this.vSub = navigator.vendorSub;
		this.userAgent = navigator.userAgent;
		this.appVersion = navigator.appVersion;
		this.v = parseInt(this.version);
		this.vs = parseFloat(this.vSub);
		
		this.NN = (this.b == "NN");
		this.NN3 = (this.b == "NN" && this.v == 3);
		this.NN4 = (this.b == "NN" && this.v == 4);
		this.NN6x = (this.b == "NN" && this.v == 5 && this.vs >= 6.01);
		this.NN6 = (this.b == "NN" && this.v == 5);
		this.NN7 = (this.b == "NN" && this.v == 5 && this.vs >= 7);
		
		this.IE = (this.b == "IE");
		this.IE3 = (this.userAgent.indexOf('MSIE 3')>0);
		this.IE45 = (this.userAgent.indexOf('MSIE 4.5')>0);
		this.IE401 = (this.userAgent.indexOf('MSIE 4.01')>0);
		this.IE4 = (this.userAgent.indexOf('MSIE 4')>0);
		this.IE51 = (this.userAgent.indexOf('MSIE 5.1')>0);
		this.IE512 = (this.userAgent.indexOf('MSIE 5.12')>0);
		this.IE514 = (this.userAgent.indexOf('MSIE 5.14')>0);
		this.IE52 = (this.userAgent.indexOf('MSIE 5.2')>0);
		this.IE5 = (this.userAgent.indexOf('MSIE 5')>0);		
		this.IE6 = (this.userAgent.indexOf('MSIE 6')>0);
		this.IE7 = (this.userAgent.indexOf('MSIE 7')>0);
		
		this.GEK = (this.userAgent.indexOf("Gecko") != -1);
		this.SAF = (this.userAgent.indexOf("Safari",0) != -1);
		this.FF = (this.userAgent.indexOf("Firefox") != -1);
		this.CAB = (this.userAgent.indexOf("iCab",0) != -1);
		this.OPE = (this.userAgent.indexOf("Opera",0) != -1);
		
		this.Win = (this.userAgent.indexOf('Win',0) != -1);
		this.Mac = (this.userAgent.indexOf('Mac',0) != -1);
		this.MacOSX = (this.userAgent.indexOf('Mac OS X',0) != -1);
		if(this.IE512 || this.IE52){
			this.MacOSX=true;
		}
		else if(this.IE514){
			if (navigator.plugins) {
				for (i=0; i < navigator.plugins.length; i++ ) {
					if (navigator.plugins[i].name.indexOf('QuickTime') >= 0 && navigator.plugins[i].filename.indexOf('.plugin')!=-1){
						this.MacOSX=true;
					}
				}
			}
		}
		this.Unix = (this.appVersion.indexOf('X11',0) != -1);
}

var checkB = new BrowserCheck();


/*=================================================================
//
// .flashplayer_check
//
=================================================================*/
var flash_version = 9;
var FlashInstalled = false;
var pv = 6;

if (checkB.OPE) {
	var sp = navigator.plugins["Shockwave Flash"].description.indexOf("Flash");
	var ep = navigator.plugins["Shockwave Flash"].description.lastIndexOf(" ");
	var aver = parseFloat(navigator.plugins["Shockwave Flash"].description.substring(sp+pv,ep));
	if(aver >= flash_version){
		FlashInstalled = true;
	}
} else if(checkB.Win && checkB.IE){
	document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
	document.write('on error resume next \n');
	document.write('contentVersion = ' + flash_version + ' \n');
	document.write('FlashInstalled = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & contentVersion))) \n');
	document.write('</SCR' + 'IPT\> \n');
	if(checkB.IE4){
		FlashInstalled = false;
	}
}else if(checkB.Mac && checkB.IE){
	if(!checkB.IE4 && navigator.plugins["Shockwave Flash"]){
		var sp = navigator.plugins["Shockwave Flash"].description.indexOf("Flash");
		var ep = navigator.plugins["Shockwave Flash"].description.lastIndexOf(" ");
		var aver = parseFloat(navigator.plugins["Shockwave Flash"].description.substring(sp+pv,ep));
		if(aver >= flash_version){
			FlashInstalled = true;
		}
	}
}else if(checkB.NN && navigator.plugins["Shockwave Flash"]){
	if(checkB.NN7 || checkB.NN6 || checkB.NN6x || checkB.NN4){
		var sp = navigator.plugins["Shockwave Flash"].description.indexOf("Flash");
		var ep = navigator.plugins["Shockwave Flash"].description.lastIndexOf(" ");
		var aver = parseFloat(navigator.plugins["Shockwave Flash"].description.substring(sp+pv,ep));
		if(aver >= flash_version){
			FlashInstalled = true;
		}
	}
}

/*=================================================================
//
// .setSWF
//
=================================================================*/
function setSwf(swf, replaceid, flashid, bgcolor, w, h) {
	if(FlashInstalled){
		
		var randomNumber = Math.random();
		var htmlText = '<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + flash_version + ',0,0,0\" width=\"' + w + '\" height=\"' + h + '\" id=\"' + flashid + '\">';
		if(checkB.Win){
			htmlText += '<param name=\"movie\" value=\"' + swf + '?' + randomNumber + '\">';
		}else{
			htmlText += '<param name=\"movie\" value=\"' + swf + '\">';
		}
		
		htmlText += '<param name=\"quality\" value=\"high\">';
		htmlText += '<param name=\"bgcolor\" value=\"' + bgcolor + '\">';
		htmlText += '<param name=\"allowFullScreen\" value=\"true\">';
		
		if(checkB.IE){
			htmlText += '<embed src=\"' + swf + '?' + randomNumber + '\" quality=\"high\" bgcolor=\"' + bgcolor + '\" allowFullScreen=\"true\" width=\"' + w + '\" height=\"' + h + '\" name=\"' + flashid + '\" type=\"application/x-shockwave-flash\" pluginspage=\"https://www.macromedia.com/go/getflashplayer\">';
		}else{
			htmlText += '<embed src=\"' + swf + '\" quality=\"high\" bgcolor=\"' + bgcolor + '\" allowFullScreen=\"true\" width=\"' + w + '\" height=\"' + h + '\" name=\"' + flashid + '\" type=\"application/x-shockwave-flash\" pluginspage=\"https://www.macromedia.com/go/getflashplayer\">';
		}
		
		htmlText += '</object>';
		if($(replaceid)){
			$(replaceid).innerHTML = htmlText;
		}
	} else {
		var htmlText = '<div style="padding:10px 0 0 40px;color:#333333;"><p>';
		htmlText += '<a href="http://www.adobe.com/shockwave/download/index.cgi?Lang=Japanese&P1_Prod_Version=ShockwaveFlash">最新版のFlash Playerをダウンロードしてください。</a>';
		if($(replaceid)){
			$(replaceid).innerHTML = htmlText;
		}
	}
}

/*=================================================================
//
// .addEvent
//
=================================================================*/
function addEvent(elm, evType, func, useCapture) {
	if(elm.addEventListener){
		elm.addEventListener(evType, func, useCapture);
		return true;
	} else if(elm.attachEvent){
		var r = elm.attachEvent('on' + evType, func);
		return r;
	} else {
		elm['on' + evType] = func;
	}
}

/*=================================================================
//
// .initRollovers
//
=================================================================*/
function initRollovers() {
	if (!document.getElementById) return;
	
	var overPath = "_on";	
	
	var aPreLoad = new Array();
	var sTempSrc;
	var aImages = document.getElementsByTagName('img');

	for (var i = 0; i < aImages.length; i++) {		
		if (aImages[i].className == 'imgover') {
			var src = aImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			var hsrc = src.replace(ftype, overPath+ftype);
			//hsrc = 'over' + hsrc;

			aImages[i].setAttribute('hsrc', hsrc);
			
			aPreLoad[i] = new Image();
			aPreLoad[i].src = hsrc;
			
			aImages[i].onmouseover = function() {
				sTempSrc = this.getAttribute('src');
				this.setAttribute('src', this.getAttribute('hsrc'));
			}	
			
			aImages[i].onmouseout = function() {
				if (!sTempSrc) sTempSrc = this.getAttribute('src').replace(overPath+ftype, ftype);
				this.setAttribute('src', sTempSrc);
			}
		}
	}
}

//addEvent(window, 'load', initRollovers, false);


/*=================================================================
//
// .external links
//
=================================================================*/
function externalLinks(){
	if(!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for(i=0;i<anchors.length;i++){
		var anchorlink = anchors[i];
		if(anchorlink.getAttribute("href") && anchorlink.getAttribute("rel") == "external"){
			anchorlink.target = "_blank";
		}
	}
}

addEvent(window, 'load', externalLinks, false);


/*=================================================================
//
// .subWin
//
=================================================================*/
function subWin(var_location, var_target, var_w, var_h, var_toolbar){
	var_width = parseInt(var_w);
	var_height = parseInt(var_h);
	
	if(checkB.Mac) {
		if(checkB.IE52 || checkB.IE51 ) {
			var_width -= 16;
			var_height -= 5;
		} else if(checkB.FF) {
			var_width += 0;
			var_height += 0;
		} else if(checkB.NN7) {
			var_width += 15;
			var_height += 15;
		} else if(checkB.OPE) {
			var_width += 10;
			var_height -= 5;
		} else {
		}
	} else if(checkB.Win) {
		if(checkB.IE) {
			var_width += 0;
			var_height += 0;
		} else if(checkB.FF){
			var_width += 0;
			var_height -= 0;
		} else if(checkB.NN7){
			var_width += 15;
			var_height -= 15;
		} else {
			var_width += 25;
			var_height += 15;
		}
	} else {
	}
	
	var_style = "width="+var_width+",height="+var_height+",toolbar="+var_toolbar+",scrollbars=no,resizable=no,directories=no,menubar=no,status=no,location=no";
	window.open(var_location, var_target, var_style);
}



/*=================================================================
//
// .is_all_ws
//
=================================================================*/
/**
 * スクリプト全体で、空白文字を以下のいずれかの文字として定義しています。
 *  "\t" TAB \u0009
 *  "\n" LF  \u000A
 *  "\r" CR  \u000D
 *  " "  SPC \u0020
 *
 * JavaScript の \s は非改行スペース(及び他の幾つかの文字)を含んでいる為
 * このスクリプトでは使用しません。
 */


/**
 * ノードのテキスト内容が完全に空白であるか判断
 *
 * @param nod  CharacterData インターフェイスを実装したノード
 *             (例: Text, Comment, CDATASection ノード)
 * @return     nod のテキスト内容が全て空白文字であれば true
 *             それ以外は false
 */
function is_all_ws( nod )
{
  // ECMA-262 第3版 の String 及び RegExp の機能を使用
  return !(/[^\t\n\r ]/.test(nod.data));
}


/**
 * 反復処理関数がノードを無視するべきかどうか判断
 *
 * @param nod  DOM1 の Node インターフェイスを実装したノード
 * @return     ノードが次のいずれかであれば true:
 *                1) 全て空白文字である Text ノード
 *                2) Comment ノード
 *             それ以外は false
 */
function is_ignorable( nod )
{
  return ( nod.nodeType == 8) || // コメントノード
         ( (nod.nodeType == 3) && is_all_ws(nod) ); // 全空白テキストノード
}

/**
 * 完全に空白或いはコメントのノードを無視するようにした nextSibling
 *
 * @param sib  参照ノード
 * @return     次のいずれか:
 *               1) is_ignorable 検査で無視できないと判断された sib に
 *                  最も近い後方の兄弟ノード、或いは
 *               2) 該当するノードがなければ null
 */
function node_after( sib )
{
	var cin = new Array();
	//alert(sib.childNodes.length);
	for(var i=0;i<sib.childNodes.length;i++){
		//alert("hoge");
		var checkNode = sib.childNodes[i];
		if(!is_ignorable(checkNode)){
			cin.push(checkNode);
		}
	}
	return cin;
}


/*=================================================================
//
// .smooth_scroll
//
=================================================================*/
function scrollAdd() {
  $$('a[href^=#]:not([href=#])').each(function(element) {
    element.observe('click', function(event) {
      new Effect.ScrollTo(this.hash.substr(1),{duration:1});
      Event.stop(event);
    }.bindAsEventListener(element))
  })
}
addEvent(window, 'load', scrollAdd, false);