//ほかのライブラリとのコンフリクトを避ける
$ = jQuery.noConflict();

//	====================================================
//	Useful Javascript Library
//	Haste Ver 1.20
//	
//	1.別ウィンドウで開かせる
//	2.クリックで消えるテキストフィールド初期値
//	3.ロールオーバー、カレント表示スクリプト
//	4.scrollsmoothly
//	5.アコーディオン
//	6.iframe代用スクリプト
//	7.タブ切り替え
//	
//	====================================================




//	====================================================
//	別ウィンドウで開かせる
//	classにpopupを指定
//	====================================================

window.onload=autoPOP;

function autoPOP()
{
	var x = document.getElementsByTagName('a');
	for (var i=0;i<x.length;i++)
	{
		if (x[i].getAttribute('className') == 'popup' || x[i].getAttribute('class') == 'popup')
		{
			x[i].onclick = function () {
			return winOpen(this.href)
			}
			x[i].title += '別ウィンドウで開きます';
		}
	}
};

function winOpen(url) {
	window.open(
		url,
		'popup'
	);

	return false;
};





//	====================================================
//	クリックで消えるテキストフィールド初期値
//	====================================================
$(document).ready(function() {
	$('input[title],textarea[title]').each(function() {
		$(this).css("color","#888"); 
		if($(this).val() === '') {
			$(this).val($(this).attr('title'));
		}
		
		$(this).focus(function() {
			if($(this).val() == $(this).attr('title')) {
				$(this).val('').addClass('focused');	
			}
		});
		$(this).blur(function() {
			if($(this).val() === '') {
				$(this).val($(this).attr('title')).removeClass('focused');	
			}
		});
	});
});





//	====================================================
//	ロールオーバー、カレント表示スクリプト
//
//	class="roll"が指定された要素はロールオーバー効果が適用される。
//	中身のimgは_on付きのものに変わる。
//	class="rollgroup"が指定されていた場合は連動してロールオーバー効果がかかる
//	
//	設定例：
//	別途dummy_over.jpgを同じフォルダに用意する
//	<img src="dummy.jpg" class="roll" /> 
//	
//	カレント表示方法
//	ページヘッダーにリンクと対応したIDを指定
//	<script type="text/javascript">
//		SITE.current='#u001';
//	</script>
//	
//	<li class="nav001" id="u001"><a href="/" title="HOME"><img src="/common/images/nav001.png" alt="HOME" class="roll" /></a></li>
//	
//	====================================================

//共通JS内で定義する変数、functionはこのオブジェクトにまとめる
SITE = {
	basepath : '/',
	preloader : {
		loadedImages: [],
		load: function (url){
			var img = this.loadedImages;
			var l = img.length;
			img[l] = new Image();
			img[l].src = url;
		}
	}
};


$(function(){
	if (SITE.current){
		$(SITE.current).addClass('current');
		$(SITE.current).find('.roll').each(function(){
			var img = $(this);
			var crsrc = img.attr('src').replace(/(\.gif|\.jpg|\.png)/, "_current$1");
			img.attr('src', crsrc);
		});
	}
});

$(function(){
	//class="roll"はロールオーバーを設定 (src属性を_on付きのものに差し替える) 
	$('.roll').each(function(){
		this.originalSrc = $(this).attr('src');
		this.rolloverSrc = this.originalSrc.replace(/(\.gif|\.jpg|\.png)/, "_over$1");
		SITE.preloader.load(this.rolloverSrc);
	});
	//通常ロールオーバー
	$('.roll').not($('.rollgroup .roll, .current .roll')).hover(function(){
		$(this).attr('src',this.rolloverSrc);
	},function(){
		$(this).attr('src',this.originalSrc);
	});
	//グループ化されたロールオーバー
	//$('.rollgroup').hover(function(){
	//	$(this).find('.roll').each(function(){
	//		$(this).attr('src',this.rolloverSrc);
	//	});
	//},function(){
	//	$(this).find('.roll').each(function(){
	//		$(this).attr('src',this.originalSrc);
	//	});
	//});
	
});




//	====================================================
//	scrollsmoothly.js
//	Copyright (c) 2008 KAZUMiX
//	http://d.hatena.ne.jp/KAZUMiX/20080418/scrollsmoothly
//	Licensed under the MIT License:
//	http://www.opensource.org/licenses/mit-license.php
//	
//	更新履歴
//	2009/02/12
//	スクロール先が画面左上にならない場合の挙動を修正
//	2008/04/18
//	公開
//	====================================================
//
//(function(){
//   var easing = 0.25;
//   var interval = 20;
//   var d = document;
//   var targetX = 0;
//   var targetY = 0;
//   var targetHash = '';
//   var scrolling = false;
//   var splitHref = location.href.split('#');
//   var currentHref_WOHash = splitHref[0];
//   var incomingHash = splitHref[1];
//   var prevX = null;
//   var prevY = null;
//
//   // ドキュメント読み込み完了時にinit()を実行する
//   addEvent(window, 'load', init);
//
//   // ドキュメント読み込み完了時の処理
//   function init(){
//     // ページ内リンクにイベントを設定する
//     setOnClickHandler();
//     // 外部からページ内リンク付きで呼び出された場合
//     if(incomingHash){
//       if(window.attachEvent && !window.opera){
//         // IEの場合はちょっと待ってからスクロール
//         setTimeout(function(){scrollTo(0,0);setScroll('#'+incomingHash);},50);
//       }else{
//         // IE以外はそのままGO
//         scrollTo(0, 0);
//         setScroll('#'+incomingHash);
//       }
//     }
//   }
//
//   // イベントを追加する関数
//   function addEvent(eventTarget, eventName, func){
//     if(eventTarget.addEventListener){
//       // モダンブラウザ
//       eventTarget.addEventListener(eventName, func, false);
//     }else if(window.attachEvent){
//       // IE
//       eventTarget.attachEvent('on'+eventName, function(){func.apply(eventTarget);});
//     }
//   }
//   
//   function setOnClickHandler(){
//     var links = d.links;
//     for(var i=0; i<links.length; i++){
//       // ページ内リンクならスクロールさせる
//       var link = links[i];
//       var splitLinkHref = link.href.split('#');
//       if(currentHref_WOHash == splitLinkHref[0] && d.getElementById(splitLinkHref[1])){
//         addEvent(link, 'click', startScroll);
//       }
//     }
//   }
//
//   function startScroll(event){
//     // リンクのデフォルト動作を殺す
//     if(event){ // モダンブラウザ
//       event.preventDefault();
//       //alert('modern');
//     }else if(window.event){ // IE
//       window.event.returnValue = false;
//       //alert('ie');
//     }
//     // thisは呼び出し元になってる
//     setScroll(this.hash);
//   }
//
//   function setScroll(hash){
//     // ハッシュからターゲット要素の座標をゲットする
//     var targetEle = d.getElementById(hash.substr(1));
//     if(!targetEle)return;
//     //alert(scrollSize.height);
//     // スクロール先座標をセットする
//     var ele = targetEle;
//     var x = 0;
//     var y = 0;
//     while(ele){
//       x += ele.offsetLeft;
//       y += ele.offsetTop;
//       ele = ele.offsetParent;
//     }
//     var maxScroll = getScrollMaxXY();
//     targetX = Math.min(x, maxScroll.x);
//     targetY = Math.min(y, maxScroll.y);
//     targetHash = hash;
//     // スクロール停止中ならスクロール開始
//     if(!scrolling){
//       scrolling = true;
//       scroll();
//     }
//   }
//
//   function scroll(){
//     var currentX = d.documentElement.scrollLeft||d.body.scrollLeft;
//     var currentY = d.documentElement.scrollTop||d.body.scrollTop;
//     var vx = (targetX - currentX) * easing;
//     var vy = (targetY - currentY) * easing;
//     var nextX = currentX + vx;
//     var nextY = currentY + vy;
//     if((Math.abs(vx) < 1 && Math.abs(vy) < 1)
//       || (prevX === currentX && prevY === currentY)){
//       // 目標座標付近に到達していたら終了
//       scrollTo(targetX, targetY);
//       scrolling = false;
//       location.hash = targetHash;
//       prevX = prevY = null;
//       return;
//     }else{
//       // 繰り返し
//       scrollTo(parseInt(nextX), parseInt(nextY));
//       prevX = currentX;
//       prevY = currentY;
//       setTimeout(function(){scroll()},interval);
//     }
//   }
//   
//   function getDocumentSize(){
//     return {width:Math.max(document.body.scrollWidth, document.documentElement.scrollWidth), height:Math.max(document.body.scrollHeight, document.documentElement.scrollHeight)};
//   }
//
//   function getWindowSize(){
//     var result = {};
//     if(window.innerWidth){
//       var box = d.createElement('div');
//       with(box.style){
//         position = 'absolute';
//         top = '0px';
//         left = '0px';
//         width = '100%';
//         height = '100%';
//         margin = '0px';
//         padding = '0px';
//         border = 'none';
//         visibility = 'hidden';
//       }
//       d.body.appendChild(box);
//       var width = box.offsetWidth;
//       var height = box.offsetHeight;
//       d.body.removeChild(box);
//       result = {width:width, height:height};
//     }else{
//       result = {width:d.documentElement.clientWidth || d.body.clientWidth, height:d.documentElement.clientHeight || d.body.clientHeight};
//     }
//     return result;
//   }
//   
//   function getScrollMaxXY() {
//     if(window.scrollMaxX && window.scrollMaxY){
//       return {x:window.scrollMaxX, y:window.scrollMaxY};
//     }
//     var documentSize = getDocumentSize();
//     var windowSize = getWindowSize();
//     return {x:documentSize.width - windowSize.width, y:documentSize.height - windowSize.height};
//   }
//   
// }());





//	====================================================
//	アコーディオン＆トグルメニュー
//	アコーディオン動作にする場合は、<dl>に class="accMenu" を付与
//	トグルメニュー動作にする場合は、<dl>に class="tglMenu" を付与
//  最初に開いておくものには、<dd>に class="default" を付与
//
//	====================================================
//(function($){	
//	$.fn.fademenu = function(options){
//		var 
//			defaults = {
//				slideup : 240,
//				slidedown : 120
//			},
//			settings = $.extend({}, defaults, options);
//			
//	    var acc = $('dd','.accMenu');
//	    var tgl = $('dd','.tglMenu');
//	    	// デフォルトオープン以外を閉じる
//			$(acc.not('.default')).hide();
//		    $(tgl.not('default')).hide();
//			// アコーディオンタイプの動作
//		    $('dt','.accMenu').click(function(){
//		        var next = $(this).next();
//		       	acc.not(next).slideUp(settings.slideup);
//		        if(next.is(':visible')){
//		            next.slideUp(settings.slideup);
//		        }else{
//		            next.slideDown(settings.slidedown);
//		        }
//		    });
//			// トグルタイプの動作
//		    $('dt','.tglMenu').click(function(){
//		        var next = $(this).next();
//		        if(next.is(':visible')){
//		            next.slideUp(settings.slideup);
//		        }else{
//		            next.slideDown(settings.slidedown);
//		        }
//		    });
//			return this;
//	}
//
//})(jQuery);
//
//$(document).ready(function(){
//	$('.accMenu').fademenu();
//});






//	====================================================
//	iframe代用スクリプト
//	<head>
//	<script type="text/javascript">
//	$(function(){
//		$('a.iframe').iframe();
//	});
//	</script>
//	</head>
//
//	<a href="myIframe.html" class="iframe w:300 h:300">
//
//  Options:
//  -------
//  width:      	width of iframe (default: 640)			w:640
//  height:      	height of iframe (default: 480)			h:480
//  scrolling:   	auto									sc:auto
//  frameborder:	height of iframe (default: 0)			fb:0
//  marginwidth:	margin of iframe (default: 0)			wm:0
//  marginheight:	margin of iframe (default: 0)			hm:0
//	====================================================

 
 jQuery.fn.iframe = function(options) {
    return this.each(function() {
        var $this = jQuery(this);
        var cls = this.className;
        
        var opts = jQuery.extend({
            frameborder:  ((cls.match(/fb:(\d+)/)||[])[1]) || 0,
            marginwidth:  ((cls.match(/wm:(\d+)/)||[])[1]) || 0,
            marginheight: ((cls.match(/hm:(\d+)/)||[])[1]) || 0,
            width:        ((cls.match(/w:(\d+)/)||[])[1]) || 640,
            height:       ((cls.match(/h:(\d+)/)||[])[1]) || 480,
            scrolling:    ((cls.match(/sc:(\w+)/)||[])[1]) || "auto",
            version:     '1,0,0,0',
            cls:          cls,
            src:          $this.attr('href') || $this.attr('src'),
			id:			  $this.attr('id'),
            caption:      $this.text(),
            attrs:        {},
            elementType:  'div',
            xhtml:        true
        }, options || {});
        
        var endTag = opts.xhtml ? ' />' : '>';

        var a = ['<iframe src="' + opts.src + '"'];
		if(opts.id){
			a.push(' id="' + opts.id + '"');
		}else{
			a.push(' id="content_iframe"');
		}
		a.push(' frameborder="' + opts.frameborder + '"');
		a.push(' marginwidth="' + opts.marginwidth + '"');
		a.push(' marginheight="' + opts.marginheight + '"');
		a.push(' width="' + opts.width + '"');
		a.push(' height="' + opts.height + '"');
		a.push(' scrolling="' + opts.scrolling + '"');
		a.push(endTag);
        
        // convert anchor to span/div/whatever...
        var $el = jQuery('<' + opts.elementType + ' class="' + opts.cls + '"></' + opts.elementType + '>');
        $el.html(a.join(''));
        $this.after($el).remove();
    });
};




/*!
 * jQuery corner plugin: simple corner rounding
 * Examples and documentation at: http://jquery.malsup.com/corner/
 * version 2.01 (08-SEP-2009)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 */

/**
 *  corner() takes a single string argument:  $('#myDiv').corner("effect corners width")
 *
 *  effect:  name of the effect to apply, such as round, bevel, notch, bite, etc (default is round). 
 *  corners: one or more of: top, bottom, tr, tl, br, or bl. 
 *           by default, all four corners are adorned. 
 *  width:   width of the effect; in the case of rounded corners this is the radius. 
 *           specify this value using the px suffix such as 10px (and yes, it must be pixels).
 *
 * @author Dave Methvin (http://methvin.com/jquery/jq-corner.html)
 * @author Mike Alsup   (http://jquery.malsup.com/corner/)
 */
;(function($) { 

var moz = $.browser.mozilla && /gecko/i.test(navigator.userAgent);
var webkit = $.browser.safari && $.browser.version >= 3;

var expr = $.browser.msie && (function() {
    var div = document.createElement('div');
    try { div.style.setExpression('width','0+0'); }
    catch(e) { return false; }
    return true;
})();
    
function sz(el, p) { 
    return parseInt($.css(el,p))||0; 
};
function hex2(s) {
    var s = parseInt(s).toString(16);
    return ( s.length < 2 ) ? '0'+s : s;
};
function gpc(node) {
    for ( ; node && node.nodeName.toLowerCase() != 'html'; node = node.parentNode ) {
        var v = $.css(node,'backgroundColor');
        if (v == 'rgba(0, 0, 0, 0)')
            continue; // webkit
        if (v.indexOf('rgb') >= 0) { 
            var rgb = v.match(/\d+/g); 
            return '#'+ hex2(rgb[0]) + hex2(rgb[1]) + hex2(rgb[2]);
        }
        if ( v && v != 'transparent' )
            return v;
    }
    return '#ffffff';
};

function getWidth(fx, i, width) {
    switch(fx) {
    case 'round':  return Math.round(width*(1-Math.cos(Math.asin(i/width))));
    case 'cool':   return Math.round(width*(1+Math.cos(Math.asin(i/width))));
    case 'sharp':  return Math.round(width*(1-Math.cos(Math.acos(i/width))));
    case 'bite':   return Math.round(width*(Math.cos(Math.asin((width-i-1)/width))));
    case 'slide':  return Math.round(width*(Math.atan2(i,width/i)));
    case 'jut':    return Math.round(width*(Math.atan2(width,(width-i-1))));
    case 'curl':   return Math.round(width*(Math.atan(i)));
    case 'tear':   return Math.round(width*(Math.cos(i)));
    case 'wicked': return Math.round(width*(Math.tan(i)));
    case 'long':   return Math.round(width*(Math.sqrt(i)));
    case 'sculpt': return Math.round(width*(Math.log((width-i-1),width)));
    case 'dog':    return (i&1) ? (i+1) : width;
    case 'dog2':   return (i&2) ? (i+1) : width;
    case 'dog3':   return (i&3) ? (i+1) : width;
    case 'fray':   return (i%2)*width;
    case 'notch':  return width; 
    case 'bevel':  return i+1;
    }
};

$.fn.corner = function(options) {
    // in 1.3+ we can fix mistakes with the ready state
	if (this.length == 0) {
        if (!$.isReady && this.selector) {
            var s = this.selector, c = this.context;
            $(function() {
                $(s,c).corner(options);
            });
        }
        return this;
	}

    return this.each(function(index){
		var $this = $(this);
		var o = (options || $this.attr($.fn.corner.defaults.metaAttr) || '').toLowerCase();
		var keep = /keep/.test(o);                       // keep borders?
		var cc = ((o.match(/cc:(#[0-9a-f]+)/)||[])[1]);  // corner color
		var sc = ((o.match(/sc:(#[0-9a-f]+)/)||[])[1]);  // strip color
		var width = parseInt((o.match(/(\d+)px/)||[])[1]) || 10; // corner width
		var re = /round|bevel|notch|bite|cool|sharp|slide|jut|curl|tear|fray|wicked|sculpt|long|dog3|dog2|dog/;
		var fx = ((o.match(re)||['round'])[0]);
		var edges = { T:0, B:1 };
		var opts = {
			TL:  /top|tl|left/.test(o),       TR:  /top|tr|right/.test(o),
			BL:  /bottom|bl|left/.test(o),    BR:  /bottom|br|right/.test(o)
		};
		if ( !opts.TL && !opts.TR && !opts.BL && !opts.BR )
			opts = { TL:1, TR:1, BL:1, BR:1 };
			
		// support native rounding
		if ($.fn.corner.defaults.useNative && fx == 'round' && (moz || webkit) && !cc && !sc) {
			if (opts.TL)
				$this.css(moz ? '-moz-border-radius-topleft' : '-webkit-border-top-left-radius', width + 'px');
			if (opts.TR)
				$this.css(moz ? '-moz-border-radius-topright' : '-webkit-border-top-right-radius', width + 'px');
			if (opts.BL)
				$this.css(moz ? '-moz-border-radius-bottomleft' : '-webkit-border-bottom-left-radius', width + 'px');
			if (opts.BR)
				$this.css(moz ? '-moz-border-radius-bottomright' : '-webkit-border-bottom-right-radius', width + 'px');
			return;
		}
			
		var strip = document.createElement('div');
		strip.style.overflow = 'hidden';
		strip.style.height = '1px';
		strip.style.backgroundColor = sc || 'transparent';
		strip.style.borderStyle = 'solid';
	
        var pad = {
            T: parseInt($.css(this,'paddingTop'))||0,     R: parseInt($.css(this,'paddingRight'))||0,
            B: parseInt($.css(this,'paddingBottom'))||0,  L: parseInt($.css(this,'paddingLeft'))||0
        };

        if (typeof this.style.zoom != undefined) this.style.zoom = 1; // force 'hasLayout' in IE
        if (!keep) this.style.border = 'none';
        strip.style.borderColor = cc || gpc(this.parentNode);
        var cssHeight = $.curCSS(this, 'height');

        for (var j in edges) {
            var bot = edges[j];
            // only add stips if needed
            if ((bot && (opts.BL || opts.BR)) || (!bot && (opts.TL || opts.TR))) {
                strip.style.borderStyle = 'none '+(opts[j+'R']?'solid':'none')+' none '+(opts[j+'L']?'solid':'none');
                var d = document.createElement('div');
                $(d).addClass('jquery-corner');
                var ds = d.style;

                bot ? this.appendChild(d) : this.insertBefore(d, this.firstChild);

                if (bot && cssHeight != 'auto') {
                    if ($.css(this,'position') == 'static')
                        this.style.position = 'relative';
                    ds.position = 'absolute';
                    ds.bottom = ds.left = ds.padding = ds.margin = '0';
                    if (expr)
                        ds.setExpression('width', 'this.parentNode.offsetWidth');
                    else
                        ds.width = '100%';
                }
                else if (!bot && $.browser.msie) {
                    if ($.css(this,'position') == 'static')
                        this.style.position = 'relative';
                    ds.position = 'absolute';
                    ds.top = ds.left = ds.right = ds.padding = ds.margin = '0';
                    
                    // fix ie6 problem when blocked element has a border width
                    if (expr) {
                        var bw = sz(this,'borderLeftWidth') + sz(this,'borderRightWidth');
                        ds.setExpression('width', 'this.parentNode.offsetWidth - '+bw+'+ "px"');
                    }
                    else
                        ds.width = '100%';
                }
                else {
                	ds.position = 'relative';
                    ds.margin = !bot ? '-'+pad.T+'px -'+pad.R+'px '+(pad.T-width)+'px -'+pad.L+'px' : 
                                        (pad.B-width)+'px -'+pad.R+'px -'+pad.B+'px -'+pad.L+'px';                
                }

                for (var i=0; i < width; i++) {
                    var w = Math.max(0,getWidth(fx,i, width));
                    var e = strip.cloneNode(false);
                    e.style.borderWidth = '0 '+(opts[j+'R']?w:0)+'px 0 '+(opts[j+'L']?w:0)+'px';
                    bot ? d.appendChild(e) : d.insertBefore(e, d.firstChild);
                }
            }
        }
    });
};

$.fn.uncorner = function() { 
	if (moz || webkit)
		this.css(moz ? '-moz-border-radius' : '-webkit-border-radius', 0);
	$('div.jquery-corner', this).remove();
	return this;
};

// expose options
$.fn.corner.defaults = {
	useNative: true, // true if plugin should attempt to use native browser support for border radius rounding
	metaAttr:  'data-corner' // name of meta attribute to use for options
};
    
})(jQuery);


// 角丸サイズ
$('.rounded').corner("3px");



$(function(){
	//class="roll"はロールオーバーを設定 (src属性を_on付きのものに差し替える) 
	$('.cellOver').each(function(){
		this.originalCSS = $(this).css('background-color');
		this.rolloverCSS = "#FDF5F5"
		SITE.preloader.load(this.rolloverSrc);
	});
	//通常ロールオーバー
	$('.cellOver').hover(function(){
		$(this).css('background-color',this.rolloverCSS);
	},function(){
		$(this).css('background-color',this.originalCSS);
	});
});