/*--------------------------------------------------
* 選択状態の画像とクラスの切り替え
--------------------------------------------------*/
(function($){
	$.fn.selected = function( i_value ) {
		if ( typeof(i_value) == "undefined" ) {
			return $(this).data("selected") ? true : false;
		}
		
		if ( i_value == "toggle" ) {
			return $(this).selected( $(this).data("selected") ? false : true );
		}
		
		if ( i_value == "preload" ) {
			return $(this).each(function(){
				var $i = $(this).find("img");
				if ( !$i.length ) return;
				if ( !$(this).data("selected") == !i_value ) return;
				var src = $i.attr("src");
				var selected = src.replace(/(\-(selected|over)(\-over)?)?(\.[^\.]+)$/,"$4").replace(/(\.[^\.]+)$/,"-selected$1");
				$("<img />").attr("src",selected);
			});
		}
		
		return $(this).each(function(){
			var $i = $(this).find("img");
			if ( !$i.length ) return;
			if ( !$(this).data("selected") == !i_value ) return;
			var src = $i.attr("src");
			if ( i_value ) {
				var selected = src.replace(/(\-(selected|over)(\-over)?)?(\.[^\.]+)$/,"$4").replace(/(\.[^\.]+)$/,"-selected$1");
				$(this).unbind("mouseenter");
				$(this).unbind("mouseleave");
				$i.attr("src",selected);
				$(this).simpleRollOver();
				$(this).addClass("selected");
			} else {
				var src = src.replace(/(\-(selected|over)(\-over)?)?(\.[^\.]+)$/,"$4");
				$(this).unbind("mouseenter");
				$(this).unbind("mouseleave");
				$i.attr("src",src);
				$(this).simpleRollOver();
				$(this).removeClass("selected");
			}
			$(this).data("selected",i_value);
		});
	}
})(jQuery);

/*--------------------------------------------------
* ショップ検索
--------------------------------------------------*/

(function($){
	$.fn.shopSearchSelect = function( i_value ) {
		return this.each(function(){
			if ( typeof(i_value) == "undefined" ) i_value = !$(this).selected();
			var c = $(this).attr("href").replace(/#(.+)$/,"$1");
			$("div#ShopSearch a").selected(false);
			if ( i_value ) {
				$(this).selected(true);
				$("div.shopBox").not("."+c).stop().slideUp(300);
				$("div.shopBox."+c).stop().slideDown(300);
			} else {
				$("div.shopBox").stop().slideDown(300);
			}
			$(this).selected(i_value);
			
			var st;
			if ( $("div#FloorMap").length ) st = $("div#FloorMap").offset().top + $("div#FloorMap").height();
			else st = $("div#Visual").offset().top + $("div#Visual").height();
			$("html,body").stop().animate( { scrollTop:st, time:600 } );
			return i_value;
		});
	};
	
	
	$(window).load(function(){
		$("div#ShopSearch a").click(function(){
			$(this).shopSearchSelect();
			return false;
		});
	});
})(jQuery);

