
if (!window.console) {
	 var names = ["assert", "count", "debug", "dir", "dirxml", "error", "group", "groupEnd", "info", "log", "markTimeline", "profile", "profileEnd", "time", "timeEnd", "trace", "warn"];
	 window.console = {};
	 for (var i = 0; i < names.length; ++i)
	 	window.console[names[i]] = function(){};
}

(function($){
	
	$.extend($.support, {
		orientation		: ("orientation" in window),
		touch			: ("ontouchend" in document && "ontouchstart" in document)
	});
	
	// タッチデバイス
	$(function(){
		if (!$.support.touch) { return; }
		setTimeout(function(){ if (window.pageYOffset === 0) { window.scrollTo(0,1); } }, 100);
		
		$(window).bind("orientationchange",function(event){
			//window.orientation 0 90 180 -90
			event.preventDefault();
			setTimeout(function(){ if (Math.round(window.pageYOffset / 10) <= 10) { window.scrollTo(0,1); } }, 100);
		});
	});
	
	var slideimage;
	$(function(){
		// トップ
		if ($(".slideimage").length) {
			$("html").addClass("top");
			
			var urls	= [];
			for (var i = 1; i <= 7; i++) {
				urls.push("" + ((i < 10) ? "0" + i: "" + i));
			}
			
			$.preload(urls, {
				base	: "/common/images/slideimages/slideimage",
				ext		: ".jpg",
			});
			slideimage	= $("div.slideimage").slideimage({ onfinish : function(interval){
				clearInterval(interval);
				document.location.href	= "#brandampersand";
			}});
		}
	});
	
	// address
	$.address.init(function(event) {
		if (!$("body").hasClass("top")) { return; }
	}).change(function(event) {
		if (!$("body").hasClass("top")) { return; }
		
		var current			= event.value.replace(/^\//,"");
		
		$("#header ul li.brand a").each(function() {
			var href	= $(this).attr("href");
			if ((/#/).test(href)) {
				href		= href.split("#")[1];
				$("body").toggleClass(href, (current == href));
			}
		});
		
		if (current && $("#" + current).length) {
			$(".background").hide();
			slideimage.stop();
			var target	= $("#" + current);
			target.css({zIndex:10}).fadeIn("slow");
			$("#header ul li.brand a").each(function(){
				var href	= $(this).attr("href");
				if ((/#/).test(href)) {
					href		= href.split("#")[1];
					if(!(current == href)) { $("#" + href).fadeOut("slow"); }
				}
			});
		} else {
			$(".background").show();
			$("#header ul li.brand a").each(function(){
				var href	= $(this).attr("href");
				if ((/#/).test(href)) {
					href		= href.split("#")[1];
					if($("#" + href).length) { $("#" + href).fadeOut("slow"); }
				}
			});
		}
		
	}).history(true);
	
	// Common
	$(function(){
		// サブメニュー仮
		$("#header ul ul").hide();
		$("#header ul ul").each(function(){
			var self	= $(this);
			self.parents("li").hover(function(){
				$("a:first",$(this)).addClass("active");
				self.fadeIn("fast");
			},function(){
				$("a:first",$(this)).removeClass("active");
				self.fadeOut("fast");
			});
		});
		
		// 仮
		$("a").click(function(){
			if ((/^#$/).test($(this).attr("href"))) { return false; }
		});
		
		// キャンペーン
		if ($(".campaign").length) {
			$(".campaign a[target='_blank']").click(function(){
				window.open(this.href);
				return false;
			});
			$(".campaign").biggerlink();
		}
		
		// 商品一覧 ツールチップ
		$(".product-list li a").hover(function(){
			var selfrect	= {
				width	: $(this).width(),
				height	: $(this).height(),
				top		: $(this).offset().top,
				left	: $(this).offset().left
			};
			
			var tooltip		= $("span", this).clone();
			tooltip.addClass("tooltip");
			tooltip.hide();
			$("body").append(tooltip);
			tooltip.css({
				top		: (selfrect.top - tooltip.height() - 45),
				left	: (selfrect.left + (selfrect.width / 2) - (tooltip.width() / 2) - 5),
				zIndex	: 100
			});
			tooltip.css({
				top		: "-=10px"
			});
			tooltip.animate({opacity:"show", top:"+=10px"}, "slow");
			
		}, function(){
			$("span.tooltip").animate({
				opacity	:"hide",
				top		:"-=10px"
			}, "fast", function(){
				$(this).remove();
			});
		});
	});
	
	
})(jQuery);
