/* ready
----------------------------------------------- */
$(function() {

	// smartphone
	var nav = navigator.userAgent;
	var ref = document.referrer;
	if (ref.indexOf("webcolor.jp") == -1 && nav.indexOf("iPad") == -1 && (nav.indexOf("iPhone") > 0 || nav.indexOf("Android") > 0 || nav.indexOf("iPod") > 0)) {
		location.href = "http://www.webcolor.jp/smt/";
	}

	// flash
	var flashvars = {};
	var params = { scale:"noScale", salign:"lt", menu:"false", allowScriptAccess:"always" };
	var attributes = {};
	swfobject.embedSWF("/common/pageup.swf", "pageup_button", "265", "160", "9.0.0", "/js/expressInstall.swf", flashvars, params, attributes);

	// window open
	$(".blank").bind("click", wopen);

	// anchor
	$(".anchor").bind("click", anchor);
	
	// image hover
	$(".hover").hover(imageRollOver, imageRollOut);
	
	// pageup
	$("#pageup_button a").bind("click", pageup);

});

/* seasonEvents
----------------------------------------------- */
function seasonEvents() {

	var date = new Date();
	var month = date.getMonth() + 1;
	var day = date.getDate();

	if (month == 12 && (day >= 15 && day <= 26)) {
		christmasEvent();
	}
	if ((month == 12 && (day >= 29 && day <= 31)) || (month == 1 && (day >= 1 && day <= 7))) {
		newyearEvent();
	}
}
function christmasEvent() {

	var item1 = $(document.createElement("div"));
	var item2 = $(document.createElement("div"));
	item1.attr({ id:"event_wreath" });
	item2.attr({ id:"event_present" });
	$("#title").append(item1);
	$("#title").append(item2);

	item1.css({ opacity:0 });
	item2.css({ top:-300 });

	item1.delay(500).animate({ opacity:1, top:20 }, 1000, "easeInOutCirc");
	item2.delay(1500).animate({ top:55 }, 1000, "easeOutBounce");
}
function newyearEvent() {

	var item1 = $(document.createElement("div"));
	var item2 = $(document.createElement("div"));
	item1.attr({ id:"event_shishimai" });
	item2.attr({ id:"event_kagamimochi" });
	$("#title").append(item1);
	$("#title").append(item2);

	item1.css({ top:-300 });
	item2.css({ top:-300 });

	item1.delay(500).animate({ top:15 }, 500, "easeInCirc", function() {
		$(this).animate({ top:0 }, 400, "easeOutCirc", function() {
			$(this).animate({ top:15 }, 500, "easeOutBounce");
		});
	});
	item2.delay(1500).animate({ top:35 }, 500, "easeInOutCirc");
}

/* wopen
----------------------------------------------- */
function wopen() {
	var url = $(this).attr("href");
	var w = window.open(url);
	w.focus();
	return false;
}

/* anchor
----------------------------------------------- */
function anchor() {
	var url = $(this).attr("href");
	$("html, body").animate({ scrollTop: $(url).offset().top - 10 }, 1000, "easeInOutCubic");
	return false;
}

/* image hover
----------------------------------------------- */
function imageRollOver() {
	$(this).stop();
	$(this).css({ opacity:0.7 });
}
function imageRollOut() {
	$(this).stop();
	$(this).animate({ opacity:1 }, 500);
}

/* pageup
----------------------------------------------- */
function pageup() {
	var time = $(window).height() / 1000;
	$("html, body").animate({ scrollTop: 0 }, 1000 * time, "easeInOutCubic");
	return false;
}

