/* ============================================================
*
* jquery.tools.min.js (navigator plugin) 商品横スクロール
*	
* ==============================================================*/
/*$(document).ready(function() {
	// initialize scrollable together with the navigator plugin
	$("#browsable1, #browsable2").scrollable();	
});*/



jQuery(function($){


/*
//初めの5つをitemwrapで囲む
$(".thumbnail:lt(5)").wrapAll("<div class='itemwap'></div>");

//thumbnail（画像）の要素数を数える
sum = $(".thumbnail").size();
//thumbnailを5つごとにitemwrapで区切って囲む
var n=1
for (i = 0; i < sum; i=i+5) {
var m=5*n-1
var n=n+1
$(".thumbnail:gt("+ m +"):lt(5)").wrapAll("<div class='itemwap'></div>");
};

//初めの5つをitemwrapで囲む
$(".thumbnail2:lt(4)").wrapAll("<div class='itemwap'></div>");

//thumbnail（画像）の要素数を数える
sum = $(".thumbnail2").size();
//thumbnailを5つごとにitemwrapで区切って囲む
var n=1
for (i = 0; i < sum; i=i+4) {
var m=4*n-1
var n=n+1
$(".thumbnail2:gt("+ m +"):lt(4)").wrapAll("<div class='itemwap'></div>");
};

//scrollableを適用
$("#browsable1, #browsable2").scrollable();	

//itemwapがひとつだけの場合はナビを非表示
wrapsum = $(".itemwap").size();
if(wrapsum==1){
$(".browse").addClass("disabled");
};
*/


});

/* ============================================================
*
* pageScroller スルスルスクロール
*	
* ==============================================================*/
(function($) {
	$.fn.pageScroller = function(options){
		// elementに格納
		var element = this;

		// 初期オプション
		var conf = $.extend({
			ScrollSpeed:		200
		}, options);
		
		// Easingの追加
		jQuery.easing.quart = function (x, t, b, c, d) {
			return -c * ((t=t/d-1)*t*t*t - 1) + b;
		};

		$("a[href^=#]",element).click(function(){
			var hash = this.hash;
			var offsetTop = $(hash).offset().top;
			var windowHeight = $("body").height();
			var flameHeight = $(window).height();
			
			if(windowHeight < flameHeight){
				var windowHeight = flameHeight;
			}
			if(offsetTop > windowHeight){
				var offsetTop = offsetTop - flameHeight;
			}
			
			if(!hash || hash == "#")
			return false;
			
			$($.browser.safari ? 'body' : 'html').animate({scrollTop: offsetTop}, conf.ScrollSpeed, "quart");
			return false;
			
		});
		
	return this;
	};
})(jQuery);


$(function(){
	// スクロールさせるクラスを追加する場合は以下のように
	// $(".追加クラス").pageScroller();
	$(".pageTop").pageScroller();
});


/* ============================================================
*
* heightline 要素の高さを揃える
*	
* ==============================================================*/
new function(){
	
	function heightLine(){
	
		this.className="heightLine";
		this.parentClassName="heightLineParent"
		reg = new RegExp(this.className+"-([a-zA-Z0-9-_]+)", "i");
		objCN =new Array();
		var objAll = document.getElementsByTagName ? document.getElementsByTagName("*") : document.all;
		for(var i = 0; i < objAll.length; i++) {
			var eltClass = objAll[i].className.split(/\s+/);
			for(var j = 0; j < eltClass.length; j++) {
				if(eltClass[j] == this.className) {
					if(!objCN["main CN"]) objCN["main CN"] = new Array();
					objCN["main CN"].push(objAll[i]);
					break;
				}else if(eltClass[j] == this.parentClassName){
					if(!objCN["parent CN"]) objCN["parent CN"] = new Array();
					objCN["parent CN"].push(objAll[i]);
					break;
				}else if(eltClass[j].match(reg)){
					var OCN = eltClass[j].match(reg)
					if(!objCN[OCN]) objCN[OCN]=new Array();
					objCN[OCN].push(objAll[i]);
					break;
				}
			}
		}
		
		//check font size
		var e = document.createElement("div");
		var s = document.createTextNode("S");
		e.appendChild(s);
		e.style.visibility="hidden"
		e.style.position="absolute"
		e.style.top="0"
		document.body.appendChild(e);
		var defHeight = e.offsetHeight;
		
		changeBoxSize = function(){
			for(var key in objCN){
				if (objCN.hasOwnProperty(key)) {
					//parent type
					if(key == "parent CN"){
						for(var i=0 ; i<objCN[key].length ; i++){
							var max_height=0;
							var CCN = objCN[key][i].childNodes;
							for(var j=0 ; j<CCN.length ; j++){
								if(CCN[j] && CCN[j].nodeType == 1){
									CCN[j].style.height="auto";
									max_height = max_height>CCN[j].offsetHeight?max_height:CCN[j].offsetHeight;
								}
							}
							for(var j=0 ; j<CCN.length ; j++){
								if(CCN[j].style){
									var stylea = CCN[j].currentStyle || document.defaultView.getComputedStyle(CCN[j], '');
									var newheight = max_height;
									if(stylea.paddingTop)newheight -= stylea.paddingTop.replace("px","");
									if(stylea.paddingBottom)newheight -= stylea.paddingBottom.replace("px","");
									if(stylea.borderTopWidth && stylea.borderTopWidth != "medium")newheight-= stylea.borderTopWidth.replace("px","");
									if(stylea.borderBottomWidth && stylea.borderBottomWidth != "medium")newheight-= stylea.borderBottomWidth.replace("px","");
									CCN[j].style.height =newheight+"px";
								}
							}
						}
					}else{
						var max_height=0;
						for(var i=0 ; i<objCN[key].length ; i++){
							objCN[key][i].style.height="auto";
							max_height = max_height>objCN[key][i].offsetHeight?max_height:objCN[key][i].offsetHeight;
						}
						for(var i=0 ; i<objCN[key].length ; i++){
							if(objCN[key][i].style){
								var stylea = objCN[key][i].currentStyle || document.defaultView.getComputedStyle(objCN[key][i], '');
									var newheight = max_height;
									if(stylea.paddingTop)newheight-= stylea.paddingTop.replace("px","");
									if(stylea.paddingBottom)newheight-= stylea.paddingBottom.replace("px","");
									if(stylea.borderTopWidth && stylea.borderTopWidth != "medium")newheight-= stylea.borderTopWidth.replace("px","")
									if(stylea.borderBottomWidth && stylea.borderBottomWidth != "medium")newheight-= stylea.borderBottomWidth.replace("px","");
									objCN[key][i].style.height =newheight+"px";
							}
						}
					}
				}
			}
		}
		
		checkBoxSize = function(){
			if(defHeight != e.offsetHeight){
				changeBoxSize();
				defHeight= e.offsetHeight;
			}
		}
		changeBoxSize();
		setInterval(checkBoxSize,1000)
		window.onresize=changeBoxSize;
	}
	
	function addEvent(elm,listener,fn){
		try{
			elm.addEventListener(listener,fn,false);
		}catch(e){
			elm.attachEvent("on"+listener,fn);
		}
	}
	addEvent(window,"load",heightLine);
}



/*------------------------------------------
	lineHeightAddClass プラグインここから　※さわらない
-------------------------------------------*/
$(function(){
jQuery.fn.lineHeightAddClass = function(option){
	
    c = jQuery.extend({
        el: 'li',//高さを揃えたい子要素
        column: 0//何個づつ揃えるか / 指定なしor0ならば折り返し地点で自動高さ揃え
    },option);
	
	var x = 1;
		column = c.column;
		n = 0;
	
	$(this).each(function(){
		var offset = $(this).offset();
		var cl = Math.floor(offset.top + offset.left);//親要素独自のなにかをクラスに付与
		
		if(column==0){
			var firstT = $(c.el,this).offset().top;
			$(c.el,this).each(function(){
				if(firstT == $(this).offset().top) column = column+1;
			});
		}
			
		$(c.el,this).each(function(i){
			if((i%column)==0) n=n+1;
			$(this).addClass("heightLine-"+cl+x+'-'+n);
		});
		
	});
}
});

/*===== ▼ここから変更OK =====*/
$(function(){
	
	//高さを揃えたい要素に任意のクラスを付与
	$(".main02>div").addClass("lhc"); 
	
	//対象のクラスorID
	$(".main02").lineHeightAddClass({
									   
		//高さを揃えたい子要素
		el:"div.lhc" , 
		
		//何個づつ揃えるか / 指定なしor0ならば折り返し地点で自動高さ揃え
		column: 0
	});
	
});



/* ============================================================
*
* hoverImageChange オンマウス、マウスアウトで画像切り替え
*	
* ==============================================================*/
(function($) {
	$.fn.imageOverChange = function(options) {
		// elementに格納
		var element = $(this);
		
		// 初期オプション
		var conf = $.extend({
			// アニメーション設定 false or true
			animate: false,
			animateOpacity: 0.4,
			animateSpeed: 800,
			// 追加するホバーイメージ名
			hoverImage: "_on",
			// キャンセルクラス
			changeCance: "activeImg"
		}, options);
		
		element.each(function(){
			var thisSrc = this.src;
			
			// ON画像プリロード
			if(thisSrc.indexOf("_off.") > 1){
				var hoverSrc = thisSrc.replace("_off.",conf.hoverImage+'.');
				var preloadImages = $("<img>").attr("src", hoverSrc);
			}else {
				var hoverSrc = thisSrc.replace(/^(.+)(\.[a-z]+)$/, "$1"+ conf.hoverImage + "$2");
			}			

			// ホバー処理
			$(this).hover(function(){
				if(!$(this).hasClass(conf.changeCance)){
					$(this).attr("src",hoverSrc);
				}
				if(conf.animate) {
					$(this).stop().animate({opacity: conf.animateOpacity}, 0).animate({opacity: 1}, conf.animateSpeed);
				}
			},function (){
				if(!$(this).hasClass(conf.changeCance)){
					$(this).attr("src",thisSrc);
				}
			});
		});
		return this;
	}
})(jQuery);

/*===== ▼ここから変更OK =====*/
$(function (){
			
	//対象のクラスorID
	$("img.imgover,input.imgover").imageOverChange({ 
												   
		// 透過アニメーション設定（false/true）
		animate: false,	
		
		// 透過度(0～0.1)
		animateOpacity: 0.4,
		
		// 透過スピード（ミリ秒）
		animateSpeed: 800,
		
		// 追加するホバーイメージ名
		hoverImage: "_on"
		
	});
	
});


/* ============================================================
*
* bnrGarelly タイマーでのバナー切り替え
*	
* ==============================================================*/
(function($) {
	$.fn.bnrGallery = function(options) {
		var element = this;
		var conf = $.extend({
			//初期表示タブ
			interval:		4000,
			galleryImage:	".galleryImage",
			galleryList:	".galleryList",
			activeMark:		"galleryImageActive" ,
			// アニメーション設定 false or true
			animate: false,
			animateOpacity: 0.8,
			animateSpeed: 100
		}, options);

		// moveSet
		var galleryListSize = $(conf.galleryList).children().size();
		$(conf.galleryImage).css({overflow: "hidden"}).children("div").css({position: "relative"});

		// load Function
		var loadFunction = function() {
			var activeHandle = $("li:first",conf.galleryList).addClass(conf.activeMark);
			edditClass(activeHandle);
			timer();
		}

		// Click Event
		$("li",element).click(function(){
			var activeHandle = this;
			edditClass(activeHandle);
			return false;
		});
	
		// Image hover Event
		$(conf.galleryImage).hover(function(){
			clearInterval(Imagechange);
		},function(){
			timer();
		});
	
		// List hover Event
		$("li",element).hover(function(){
			if(conf.animate) {
				$(this).stop().animate({opacity: conf.animateOpacity}, conf.animateSpeed);
			}
			clearInterval(Imagechange);
		},function(){
			$(this).stop().animate({opacity: 1}, conf.animateSpeed);
			timer();
		});
		
		// Add Class Event
		var edditClass = function(activeHandle){
			$(activeHandle).addClass(conf.activeMark).siblings().removeClass(conf.activeMark);
			imageChange(activeHandle);
		}
		
		// imageChange
		var imageChange = function(activeHandle){
			var showImage = $(activeHandle).find("a").attr("href");
			$(showImage).stop(true, true).fadeIn();
			$("div",conf.galleryImage).not(showImage).fadeOut().end();
		}
		
		// timer Start
		var timer = function() {
			Imagechange = setInterval(function(){
				var index = 1;
				var elems = $("li", conf.galleryList);
				for (var i=0; i<elems.size(); ++i) {
					if ($(elems[i]).attr("class").indexOf(conf.activeMark, 0) != -1) {
						index = i + 1;
						break;
					}
				}
				if(galleryListSize == index){
					$("." + conf.activeMark).removeClass(conf.activeMark);
					$("li:first",conf.galleryList).addClass(conf.activeMark);
				}else{
					$("." + conf.activeMark).removeClass(conf.activeMark).next().addClass(conf.activeMark);
				}
				var element = $("." + conf.activeMark);
				imageChange(element);
			},conf.interval);
		}
		
		loadFunction();
		
		return this;
	};
})(jQuery);


/*===== ▼ここから変更OK =====*/
$(function (){
			
	//対象のクラスorID
	$(".gallery").bnrGallery({
							 
		// バナーが切り替わるスピード（ミリ秒）
		interval: 5000,
		
		// 大きなバナーを表示するエリア
		galleryImage: ".galleryImage",
		
		// サムネイルバナーを表示するエリア
		galleryList: ".galleryList",
		
		// 選択されているサムネイルに付与するクラス
		activeMark: "galleryImageActive" , 
		
		// サムネイルホバー時にアニメーション（透過）するかどうか（true/false）
		animate: false,
		
		// animate:trueの時に何％透過させるか（0～1.0）
		animateOpacity: 0.5,
		
		// animate:trueの時の透過させるスピード（ミリ秒）
		animateSpeed: 1500
	});

});


/* ============================================================
*
* 外部リンクを_blankで
*	
* ==============================================================*/
$(document).ready( function () {
	$('a[href^="http"]').not('[href*="www.mkhomme.net"]').click(function(){
		window.open(this.href, '');
		return false;
	});
});

