
// コンフリクトを回避
jQuery.noConflict();

(function($) {

	$.fn.alignheight = function(options){
		var settings = {
			target:">div",	//対象ブロック要素
			alignheightClass:"alignHeight"	//適用後に付与するクラス名
		}
		if(options){
			$.extend(settings, options);
		}
		this.each(function(){
			var height_array = new Array();
			target = $(settings.target,this);
			target.each(function(i){
				$(this).addClass(settings.alignheightClass);
				height_array.push(Number($(this).height()));
			});
			var Height = height_array.sort(function(a,b){return (a-b);}).pop();
			target.height(Height);
		});
		return this;
	}

	$.fn.blocklink = function(options){
		var settings = {
			hoverClass:"bl-hover",	//ロールオーバー時のクラス名
			nth:1,	//何番目のリンクを有効にするか
			wraplinks:1	//内包するa要素個別のリンクを有効にするか（0で無効）
		}
		if(options){
			$.extend(settings, options);
		}
		$(this).each(function(){
			var Link = $("a:eq("+(settings.nth-1)+")",this);
			var Href = Link.attr("href");
			if(Href!=undefined){
				var Target = Link.attr("target");
				$(this).mouseover(function(){
					$(this).addClass(settings.hoverClass);
				}).mouseout(function(){
					$(this).removeClass(settings.hoverClass);
				}).click(function(){
						if(Target==""){
							Target="_self";
						}
						if(!bAnchorHover){
						window.open(Href,Target);
						}
				}).css("cursor","pointer");
				var bAnchorHover=false;
				$("a",this).hover(
					function(){bAnchorHover=true},
					function(){bAnchorHover=false}
				);
				if(!settings.wraplinks){
					$("a",this).click(function(){
						window.open(Href,Target);
						return false;
					});
				}
			}
		});
		return this;
	}
	
	$(function(){

		$("#global-navi li").each(function(i){
			$(this).attr("id","menu"+i);
		});
		//アクティブハイライト処理
		switch($("body").attr("class")){
			case "exterior" :
				var menu = $("#menu0 a");
				break;
			case "landscape" :
				var menu = $("#menu1 a");
				break;
			case "webcatalog" :
				var menu = $("#menu2 a");
				break;
			case "case" :
				var menu = $("#menu3 a");
				break;
			case "download" :
				var menu = $("#menu4 a");
				break;
		}
		if(menu!=undefined){
			menu.addClass("over");
		}

		//ロールオーバー
		$("img.over").mouseover(function(){
			$(this).attr("src",$(this).attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_o$2").replace("_o_o","_o"));
		}).mouseout(function(){
			if(fontSize!=$(this).attr("id")){
				$(this).attr("src",$(this).attr("src").replace(/^(.+)_o(\.[a-z]+)$/, "$1$2"));
			}
		}).each(function(){
			$("<img>").attr("src",$(this).attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_o$2"));
		}).click(function(){
			$(this).attr("src",$(this).attr("src").replace(/^(.+)_o(\.[a-z]+)$/, "$1$2"));
		});

		//文字サイズの取得
		if($.cookie("font-size")){
			var fontSize = $.cookie("font-size");
			$("#inbox").addClass(fontSize);
		}else{
			//クッキーがない場合の初期値
			var fontSize = "size1";
		}
		//現在選択されている文字サイズのボタンをロールオーバー時グラフィックに変更
		$("#"+fontSize).attr("src",$("#"+fontSize).attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_o$2"));

		//文字サイズボタン
		if($("#size1")!=undefined){
			$("#size1").click(function(){
				$("#inbox").removeClass(fontSize);
				$("#"+fontSize).attr("src",$("#"+fontSize).attr("src").replace(/^(.+)_o(\.[a-z]+)$/, "$1$2"));
				fontSize = "size1";
				$("#inbox").addClass(fontSize);
				$.cookie("font-size",fontSize,{path:"/"});
				$("#"+fontSize).attr("src",$("#"+fontSize).attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_o$2"));
			});
			$("#size2").click(function(){
				$("#inbox").removeClass(fontSize);
				$("#"+fontSize).attr("src",$("#"+fontSize).attr("src").replace(/^(.+)_o(\.[a-z]+)$/, "$1$2"));
				fontSize = "size2";
				$("#inbox").addClass(fontSize);
				$.cookie("font-size",fontSize,{path:"/"});
				$("#"+fontSize).attr("src",$("#"+fontSize).attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_o$2"));
			});
			$("#size3").click(function(){
				$("#inbox").removeClass(fontSize);
				$("#"+fontSize).attr("src",$("#"+fontSize).attr("src").replace(/^(.+)_o(\.[a-z]+)$/, "$1$2"));
				fontSize = "size3";
				$("#inbox").addClass(fontSize);
				$.cookie("font-size",fontSize,{path:"/"});
				$("#"+fontSize).attr("src",$("#"+fontSize).attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_o$2"));
			});
		}
		$("#fontsize a").click(function(){
			return false;
		});

		//アンカーリンク
		if(location.href.indexOf("file")==0){
			var url = "file://" + location.hostname + location.pathname + location.search;
		}else if(location.href.indexOf("https")==0){
			var url = "https://" + location.hostname + location.pathname + location.search;
		}else{
			var url = "http://" + location.hostname + location.pathname + location.search;
		}
		$("a[href*=#],area[href*=#]").click(function() {
			var id = this.href.substring(this.href.indexOf('#'),this.href.length);
			var hrefUrl = this.href.split(id);
			if(String(hrefUrl[0]) == String(url)) {
				var hash = this.hash;
				if(!hash || hash == "#")
					return false;
				if(id == '#inbox') { 
					$($.browser.safari ? 'body' : 'html')  
						.animate({scrollTop: 0}, 500, "easeInOutCubic");
					return false;
				}else if(id != "#"){
					$($.browser.safari ? 'body' : 'html')  
						.animate({scrollTop: $(hash).offset().top}, 500, "easeInOutCubic");
					return false;
				}
			}
		});

		$(".lucent img").hover(function(){
			$(this).animate({
				opacity: .8
			},{
				duration: 200,
				queue: false
			})
		}, function(){
			$(this).animate({
				opacity: 1
			}, {
				duration: 200,
				queue: false
			})
		});

		// boxの高さを揃える
		function setEqualHeight(columns){
			var tallestcolumn = 0;
			columns.each( function(){
				currentHeight = $(this).height();
				if(currentHeight > tallestcolumn){
					tallestcolumn = currentHeight;
				}
			});
			// ブラウザ分岐処理
			// （IE7以下＝height適用、それ以外はmin-height適用）
			if ($.browser.msie && $.browser.version < 7){
				columns.css("height",tallestcolumn);
			} else{
				columns.css("min-height",tallestcolumn);
			}
		}
		$(document).ready(function() {
			$(".category-list").each(function(){ 
				setEqualHeight($(this).parent().find(".category-list .wrap")); 
			});
			// other
			setEqualHeight($(".heightLine"));
		});

		//★blocklinkの使用例
		/*$(".wrap div")
		.blocklink({
			//中にa要素があれば、クリックで1番目のa要素と同じリンク動作
			hoverClass:"bl-hover",	//ロールオーバー時に付与するクラス名
			nth:1,	//何番目のリンクを有効にするか
			wraplinks:1	//内包するa要素個別のリンクを有効にするか（0で無効）
		})*/

		//★alignheightの使用例（divだけでなく子要素のpも一括指定しています）
		/*$(".wrap")
		.alignheight({
			//wrapクラスの直下にあるdivのp要素の高さを揃える（子要素を先に）
			target:">div p",	//対象ブロック要素
			alignheightClass:"alignHeight"	//適用後に付与するクラス名
		})
		.alignheight({
			//wrapクラスの直下にあるdivの高さを揃える（最後に親要素）
			target:">div",	//対象ブロック要素
			alignheightClass:"alignHeight"	//適用後に付与するクラス名
		});*/

		$(".text-field").focus(function(){
			$(this).css("background", "#FEF4E9");
		});
		$(".text-field").blur(function(){
			$(this).css("background", "#ffffff");
		});
		$(".form th:odd, .form td:odd").css("background-color","#FDFCF4");

//		$(".list_products > li:odd").css("background-color","#E4E4E4");
		$("a.external").append('<span class="icon-nw"><img src="/images/icon/icon_nw.gif" alt="" width="10" height="9" /></span>');

	});

})(jQuery);

