/**
 * jQuery Cookie plugin
 *
 * Copyright (c) 2010 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */
jQuery.cookie = function (key, value, options) {

    // key and at least value given, set cookie...
    if (arguments.length > 1 && String(value) !== "[object Object]") {
        options = jQuery.extend({}, options);

        if (value === null || value === undefined) {
            options.expires = -1;
        }

        if (typeof options.expires === 'number') {
            var days = options.expires, t = options.expires = new Date();
            t.setDate(t.getDate() + days);
        }

        value = String(value);

        return (document.cookie = [
            encodeURIComponent(key), '=',
            options.raw ? value : encodeURIComponent(value),
            options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
            options.path ? '; path=' + options.path : '',
            options.domain ? '; domain=' + options.domain : '',
            options.secure ? '; secure' : ''
        ].join(''));
    }

    // key and possibly options given, get cookie...
    options = value || {};
    var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
    return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};

/**
 * tooltip.js
 */
var tooltip=function(){
	var id = 'tt';
	var top = -12;
	var left = -15;
	var maxw = 300;
	var speed = 10;
	var timer = 20;
	var endalpha = 90;
	var alpha = 0;
	var tt,t,c,b,h;
	var ie = document.all ? true : false;
	return{
		show:function(v,w){
			if(tt == null){
				tt = document.createElement('div');
				tt.setAttribute('id',id);
				t = document.createElement('div');
				t.setAttribute('id',id + 'top');
				c = document.createElement('div');
				c.setAttribute('id',id + 'cont');
				b = document.createElement('div');
				b.setAttribute('id',id + 'bot');
				tt.appendChild(t);
				tt.appendChild(c);
				tt.appendChild(b);
				document.body.appendChild(tt);
				tt.style.opacity = 0;
				tt.style.filter = 'alpha(opacity=0)';
				document.onmousemove = this.pos;
			}
			tt.style.display = 'block';
			c.innerHTML = v;
			tt.style.width = w ? w + 'px' : 'auto';
			if(!w && ie){
				t.style.display = 'none';
				b.style.display = 'none';
				tt.style.width = tt.offsetWidth;
				t.style.display = 'block';
				b.style.display = 'block';
			}
			if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
			//h = parseInt(tt.offsetHeight) + top;
			wid = parseInt(tt.offsetWidth) - left;
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(1)},timer);
		},
		pos:function(e){
			var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY;
			var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX;
			//tt.style.top = (u - h) + 'px';
			//tt.style.left = (l + left) + 'px';
			tt.style.top = (u - top) + 'px';
			tt.style.left = (l - wid) + 'px';
		},
		fade:function(d){
			var a = alpha;
			if((a != endalpha && d == 1) || (a != 0 && d == -1)){
				var i = speed;
				if(endalpha - a < speed && d == 1){
					i = endalpha - a;
				}else if(alpha < speed && d == -1){
					i = a;
				}
				alpha = a + (i * d);
				tt.style.opacity = alpha * .01;
				tt.style.filter = 'alpha(opacity=' + alpha + ')';
			}else{
				clearInterval(tt.timer);
				if(d == -1){tt.style.display = 'none'}
			}
		},
		hide:function(){
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(-1)},timer);
		}
	};
}();

/**
 * rollover.js
 */
function initRollOvers() {
	if (!document.getElementById){
		return;
	}
	
	var preLoads = new Array();
	var allImages = document.getElementsByTagName('img');

	for (var i = 0; i < allImages.length; i++) {		
		if (allImages[i].className == 'rollover') {
			var src = allImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			var oSrc = src.replace(ftype, '_on'+ftype);

			//-- スワップ元、スワップ先画像の登録
			allImages[i].setAttribute('pSrc', src);
			allImages[i].setAttribute('oSrc', oSrc);

			//-- イメージのプリロード
			preLoads[i] = new Image();
			preLoads[i].src = oSrc;

			//-- イベントの設定
			allImages[i].onmouseover = function() {
				this.setAttribute('src', this.getAttribute('oSrc'));
			}
			allImages[i].onmouseout = function() {
				this.setAttribute('src', this.getAttribute('pSrc'));
			}
		}
	}
}

function addOnload(func){
	if ( typeof window.addEventListener != "undefined" ){
		window.addEventListener( "load", func, false );
	}else if ( typeof window.attachEvent != "undefined" ) {
		window.attachEvent( "onload", func );
	}else{
		if ( window.onload != null ){
			var oldOnload = window.onload;
			window.onload = function ( e ) {
			oldOnload( e );
			window[func]();
		};
	}else
		window.onload = func;
	}
}
addOnload(initRollOvers);

/**
 * mail_address.js
 */
function converter(M){
	var str="", str_as="";
	for(var i=0;i<M.length;i++){
		str_as = M.charCodeAt(i);
		str += String.fromCharCode(str_as + 1);
	}
	return str;
}

function mail_inquiry()
{eval(String.fromCharCode(108,111,99,97,116,105,111,110,46,104,114,101,102,32,
61,32,39,109,97,105,108,116,111,58) 
+ 
converter(String.fromCharCode(110,115,110,104,96,118,96,114,100,63,115,106,120,45,104,100,100,105,45,110,113,45,105,111,
62,114,116,97,105,100,98,115,60)) 
+ "'");} 

function mail_admin()
{eval(String.fromCharCode(108,111,99,97,116,105,111,110,46,104,114,101,102,32,
61,32,39,109,97,105,108,116,111,58) 
+ 
converter(String.fromCharCode(118,118,118,96,99,108,104,109,63,104,100,100,105,45,110,113,45,105,111,
62,114,116,97,105,100,98,115,60)) 
+ "'");} 


/**
 * yahoo search
 */
$(function(){
if (document.location.protocol==="http:") {
	
	$("div#srchBox").html('<form action="/search_result.html" method="get" id="srch"><p id="srchForm"><input type="search" results="5" name="p" id="srchInput"><!--input type="submit" value="検索" id="srchBtn" onclick="document.getElementById(' + "'srchInput'" + ').focus();"--><input type="hidden" id="fr" name="fr" value="cse"><input type="hidden" id="ei" name="ei" value="UTF-8"><input type="hidden" id="csid" name="csid" value="WpAtchROE7KBZwCGZQlLsITEla9vpsuAnuzRnsoMFQ--"></p><input type="hidden" name="vs" value="eneken.ieej.or.jp" id="yjInsite"></form><img src="http://custom.search.yahoo.co.jp/images/window/WpAtchROE7KBZwCGZQlLsITEla9vpsuAnuzRnsoMFQ--.gif">');
	
	var sb = document.getElementById('srchBox');
	if (sb && sb.className == 'watermark') {
	  var si = document.getElementById('srchInput');
	  var f = function() { si.className = 'nomark'; };
	  var b = function() {
	    if (si.value == '') {
	      si.className = '';
	    }
	  };
	  si.onfocus = f;
	  si.onblur = b;
	  if (!/[&?]p=[^&]/.test(location.search)) {
	    b();
	  } else {
	    f();
	  }
	}
} else {
	$("img.top_search_img").attr("src", '/images/spacer.gif');
}
})
