
var _naviHiddenHeight = 0;

(function($) {

	$.fn.bannerButton = function(options){

		this.each(function(){

			$(this).append($('<div class="rect-over"></div>'));

			var rectOver
			$(".rect-over",this).each(function(){
				rectOver = $(this);
			});
			
			
			// img のサイズを取って 設定するように修正
						
			$("img",this).each(function(){
				rectOver.css({
					width:$(this).width(),
					height:$(this).height()
				});
			});
			
			$(this).css("cursor","pointer").
			mouseenter(function(){
				$(".rect-over",this).css("visibility","visible")
			}).
			mouseleave(function(){
				$(".rect-over",this).css("visibility","hidden")
			}).
			click(function(){
				var _href = $("a",this).attr("href");
				var _target = $("a",this).attr("target");
				_target = _target == "" ? "_self" : _target;
				window.open(_href, _target);
			});
		});
	  
	};

























	/**
	*
	*  画像のフェードアウト切り替え （shoplist store）
	* 	
	*/
	$.fn.picgallery = function(options){
	
		this.each(function() {  
			
			var _self = $(this);
			var _viewer = $($(".viewer",this)[0]);
			
			var imgs = [];
			imgs.push(_viewer.html());			
			$("li",this).each(function(){
				//imgs.push($($("img",this)[0]));
				imgs.push($(this).html());
			});

			
			var cnt = 1;
			var cntmax = imgs.length;
			if(cntmax > 1)_timer();
			
			function _timer(){
				setInterval(_change,5000)
			}
			
			function _change(){
				_viewer.animate(
				{ opacity: 0 }, 
				{ duration:300, easing:"easeOutExpo", complete:_changeExe});

			}
			//
			function _changeExe(){
				_viewer.html(imgs[cnt]);
				_viewer.animate(
				{ opacity: 1 }, 
				{ duration:2000, easing:"easeOutExpo"});
				cnt++;
				if(cnt >= cntmax) cnt = 0;
			}
								
		});
	
	};










	/**
	*
	*  タイトル付きリスト （SeasonImages navi）
	* 	
	*  表示非表示のコントロール
	*
	*/
	$.fn.titlelist = function(options){
	
		this.each(function() {  
			
			var _self = $(this);
			
			var c = 0;
			$('dt a',this).each(function(){
			
				//タイトルが選択状態かどうか
				if($(this).hasClass("selected")){

					$($('dd',_self)[c]).css("display","block");
				}
				
				c++;
			})
					
		});
	
	};






	/**
	*
	*  使用方法と規約アコーディオンUI （Downloadページ用）
	* 	
	*  開閉のコントロール
	*
	*/
	$.fn.accordionForDownload = function(options){
	
		this.each(function() {  
			
			//タイトル
			
			
			//開く用タイトルを新たに作成
			

			//閉じるアクション設定			
			
			
			function _show(){
				_dl.css("visibility","visible");
				_title.css("visibility","hidden");
				
				if(jQuery.browser.msie){

					_dd.animate(
					{ height: _dd_height }, 
					{ duration:0 });
					
				}else{
				
					_dd.animate(
					{ height: _dd_height }, 
					{ duration:500, easing:"easeInOutExpo" });
					
				}

			}
			
			var animating = false;
			function _hide(){
				if(animating) return;

				if(jQuery.browser.msie){

					_dd.css('height','0px');
					__hideDone();
					
				}else{
				
				animating = true;
				_dd.stop();				
				_dd.animate(
				{ height: 0 }, 
				{	duration:500,
					easing:"easeInOutExpo",
					complete:__hideDone
				});
				
				}
				
			}
			//
			function __hideDone(){
				_dd.css('display','none');
				_dl.css("visibility","hidden");
				_title.css("visibility","visible");
				animating = false;
			}
			
					
		});
	
	};
















	/**
	*
	*  左部分navi expand List
	* 	
	*  開閉リストのコントロール
	*
	*/
	$.fn.expandlist = function(options){
	
		var self = this;
	
		//defaultを定義
		if(options == undefined){
			options = {
				multiopen:false,
				needopen:false
			};
		}
		
		//複数Openが許可されるかどうか
		if(options.multiopen == undefined) options.multiopen = false;
		
		//常に１つは開いていなくてはならないかどうか
		if(options.needopen == undefined) options.needopen = false;
		
		this.each(function() {  
				
			var title;
					
			if($(this).attr('name') == undefined || $(this).attr('name') == ""){
				gLog("jQuery.expandlist 対象に title attibute を設定しユニークな文字列を指定してください")
				return;
			}else{
				title = $(this).attr('name');
			}
				
			//複数開閉対応	
			var multiopen = options.multiopen;
			
			//必ず１つは開いていなくてはならないか
			var needopen = options.needopen;
					
			//リストリスト
			var lists = [];
			
			//個々のリストのタイトル部分（開閉のトリガリンク）
			var indexs = [];
			
			//個々のリスト
			var uls = [];
			
			//個々のリストの高さ
			var ul_heights = [];
			
			//開閉状況
			var openflgs = [];
					
			if($.cookie == undefined){
				gLog("jquery.cookie.js を includeしてください。","WARN")
			}

			//削除
			//$.cookie('expandlist_' + title, '', {path: '/',expires:-1});
			
			//クッキーチェック
			var _cookie = _getCookie();
			
			//開閉チェック
			if(needopen){
			var cl = _cookie.length;
			var hasOpenUl = false;
			for(var i = 0;i<cl;i++){
				if(_cookie[i] == "1"){
					hasOpenUl = true;
					break;
				}
			}
			if(!hasOpenUl){
				_cookie[0] = "1";
			}
			}
				
			openflgs = _cookie;
			_setCookie(openflgs);
					

			var counter = 0;
			//対象の一番高い高さ
			var maxh = 0;
			//対象を走査
			$('.list',this).each(function(){
					
				lists.push($(this));
					
				//スイッチ
				$('.switch',this).each(function(){				
					indexs.push($(this));
					$(this).attr("name",counter)
					$(this).click(function(e){
						_select($(this).attr("name"));
						return false;
					});
				});
					
				//ul			
				$('ul',this).each(function(){				
					uls.push($(this));
					ul_heights.push($(this).height())
					maxh = maxh > $(this).height() ? maxh : $(this).height();
					$(this).css({display:'block', overflow:'hidden',height:"0px"});
					
					if(openflgs[counter] == undefined){
						openflgs[counter] = "0";
					}else if(openflgs[counter] == "1"){
						_open(counter,true);
						maxh = 0;
					}
				});
						
				_naviHiddenHeight += maxh;
						
				_setCookie(openflgs);
						
				counter++;
					
			});



			
			/**
			 * 選択
			 */
			function _select(_index,quick){
				var index = Number(_index);
				if(Number(openflgs[index])){
					_close(index,quick);
				}else{
					_open(index,quick);
					if(!multiopen){
						//他を閉じる
						var l = uls.length;
						for(var i=0;i<l;i++){
							if(i != index){
								if(Number(openflgs[i])){
									_close(i,quick);
								}
							}
						}
					}
				}

			}
			
			/**
			 * 開く
			 */
			function _open(index,quick){
				var target = uls[index]
				var height = ul_heights[index];
				if(quick){
					target.css("height",height + "px");
				}else{
					target.animate(
					{ height: height }, 
					{ duration:500, easing:"easeInOutExpo" });
				}
				openflgs[index] = '1';
				indexs[index].addClass("switch-selected");
				_setCookie(openflgs);
			}		
			
			/**
			 * 閉じる
			 */
			function _close(index,quick){
				var target = uls[index]
				if(quick){
					target.css("height","0px");
				}else{
					target.animate(
					{ height: 0 }, 
					{ duration:500, easing:"easeInOutExpo" });
				}
				openflgs[index] = '0';
				indexs[index].removeClass("switch-selected");
				_setCookie(openflgs);
			}	
			
			
			/**
			 * クッキーの取得
			 */
			function _getCookie(){
				var liststr = $.cookie('expandlist_' + title);
				if(liststr == undefined || liststr == "" || liststr == null) return [];
				//alert(liststr.split(","))
				return liststr.split(",");
			}

			/**
			 * クッキーの書き込み
			 */
			function _setCookie(list){
				if(list == undefined || list == "" || list == null) return;
				var liststr = list.join(",");
				$.cookie('expandlist_' + title, liststr, { path: '/', expires:3});
			}

					
		});
		
	};












	/**
	*
	*  HOME Features 
	*
	*  画像スライド機能
	*
	*/
	$.fn.featureslider = function(options){

		this.each(function() {  

			//item位置
			var position = 0;
			var positionmax = 0;	
			
			//基本X位置
			var basepositionx = !jQuery.browser.mozilla && !jQuery.browser.msie ? 10 : 2;
				
			//itemのサイズ
			var itemwidth = 940;
				
			//itemのマージン値
			var marginRight = 0;	
			
			//Loopしているように見せるかどうか
			var loop = options.loop;
			
			//自動切り替え間隔
			var autointerval = 10000;
			
			//ロック状態
			var lock = true;
			
			//自動スクロール停止状態かどうか
			var stopautoscrollflg = true;

			//ウィンドウサイズ
			var winWidth = $(window).width();
			$(window).resize(onResizeHander);
					
			var obj = $(this); 				
				
			var s = $("li", obj).length;
			var w = $("li", obj).width(); 
			var h = $("li", obj).height(); 

			$("li", obj).each(function(){
				$(this).css("cursor","pointer").
				mouseenter(function(){
					$(".rect-over",this).css("visibility","visible")
				}).
				mouseleave(function(){
					$(".rect-over",this).css("visibility","hidden")
				}).
				append($('<div class="rect-over c"></div>')).
				click(function(){
					var _href = $("a",this).attr("href");
					var _target = $("a",this).attr("target");
					_target = _target == "" ? "_self" : _target;
					window.open(_href, _target);
					//location.href = $("a",this).attr("href");
				});
			});
			
			//前後に足す
			if(loop){
			
				//グレーの空エリア
				/*var html0 = "<li>" + $($("li", obj)[0]).html() + "</li>";
				var html1 = "<li>" + $($("li", obj)[s-1]).html() + "</li>";
				$($("li", obj)[0]).before(html0);
				$($("li", obj)[s]).after(html1);*/
				basepositionx += w + marginRight;
						
			}
			
			$("li", obj).each(function(){
				$(this).css('visibility','visible');
			});
			
			s = $("li", obj).length;

			$("ul", obj).css('width',s*w + marginRight * s + 160);
			$("ul", obj).css('marginLeft', winWidth);
			
			

			//インデックスの作成
			positionmax = s - (loop ? 2 : 0) - 1;
			for(var i=0;i<=positionmax;i++){
				$(document.createElement("p"))
						.html('<span class="numbox" rel="'+ i +'" href="javascript:void(0);"><div class="num"><img src="images/'+ "thumnail0"+(i+1) +'_off.jpg" /></div></span>')
						.appendTo($("#"+ options.numericId))
						.mousedown(function(){						
							goto(Number($("span",$(this)).attr('rel')),false,true);
						});
				
			}
			
			
			

			
			var ptrgs = $("p",$("#"+ options.numericId));
			var ptrg = $(ptrgs[1]);
			var pmarginRight = Number(ptrg.css("marginLeft").split("px")[0]);
			//var iwidth = ptrgs.width() + pmarginRight;
			var iwidth = ptrgs.width() + pmarginRight;
			var icnt = ptrgs.length;
			//var holderwidth = iwidth * icnt + pmarginRight + 22;
			//if($.browser.msie && $.browser.version=="6.0") holderwidth += pmarginRight * 2;
			//$("#"+ options.numericId).css('width',holderwidth);
					
			//スクロール位置で自動スクロールON/OFFコントロール
			$(window).scroll(function(){
				checkScroll();
			});	
					
			var qq = 0;
			setTimeout(function(){
				lock = false;
				goto(0);
			},1000);
				
				
			/**
			 * 移動
			 */
			function goto(n,quick,stopautoscroll){
				if(lock) return;

				position = n;
				var newx = (-1 * ( n * (itemwidth + marginRight))) + Math.round((winWidth / 2)) - (itemwidth / 2) - basepositionx;
				var difx = Math.abs(Number($("ul",obj).css('marginLeft').split("px")[0]) - newx);
				var easeing = quick ? "easeOutExpo" : "easeInOutExpo";
				$("ul",obj).stop();
				$("ul",obj).animate(
							{ marginLeft: newx }, 
							{ duration:/*difx * 1.2*/900, easing:easeing });
				initIndexButton();
							
				if(stopautoscrollflg) return;
					
				if(!stopautoscroll){
					startTimer();
					checkScroll();
				}else{
					stopautoscrollflg = true;
					stopTimer()
				}

			}
			
			/**
			 * 次へ移動
			 */
			function next(){
				var newposition = position + 1;
				newposition = newposition > positionmax ? 0 : newposition;
				goto(newposition);
			}
				
			/*
			 * リサイズハンドラ
			 */
			function onResizeHander(){
				var tmpwinWidth = $(window).width();
				if(winWidth != tmpwinWidth){
					winWidth = tmpwinWidth;
					goto(position,true);
				}
			}	
					
			/*
			 * ボタンアクション切り替え
			 */
			function initIndexButton(){
				var c = 0;
				$("span","#"+ options.numericId).each(function(){
					if(c == position){
						$(this).addClass("numbox-over");
					}else{
						$(this).removeClass("numbox-over");
					}
					$(this).mouseover(function(){							
						$(this).addClass("numbox-over");
					}).mouseout(function(){		
						if($(this).attr('rel') != position){				
							$(this).removeClass("numbox-over");
						}
					});
					c ++;
				});
			}
			
			/**
			 * タイマー切り替え
			 */
			var siid;
			function startTimer(){
				stopTimer()
				siid = setInterval(next,autointerval);
			}
			function stopTimer(){
				clearInterval(siid)
			}
			
			/**
			 * スクロール位置調査
			 */
			var lockbyscroll = false;
			function checkScroll(){
				if($(document).scrollTop() > 400){
					lockbyscroll = true;
					stopTimer();
					return false;
				}else{
					if(stopautoscrollflg) return false;
					if(lockbyscroll){
						lockbyscroll = false;
						stoptTimer();
					}
					return true;
				}
			}
						
		});
	  
	};

})(jQuery);
