$(function(){
//CLASS SET
	if($("#itemlist li").length){
		linum = $("#itemlist li").length;
		if( linum%2 == 1 ){
			$('#itemlist ul').append('<li class="clearfix" style="background:#fff;padding-bottom:72px;"><div class="rightarea">&nbsp;</div></li>');
		}
		$("#itemlist li").addClass("clearfix");
		$("#itemlist li:odd").addClass("odd");
		$("#itemlist li:even").addClass("even");
	}
	
	$("ul li:first-child").addClass("fc");
	$("table th:first-child").addClass("fc");
	$("table td:first-child").addClass("fc");
	$("ul li:last-child").addClass("lc");
	
	$("#promotion dl dd").addClass("clearfix");
	$("#promotion ul.step li:odd").addClass("odd clearfix");
	$("#promotion ul.step li:even").addClass("even clearfix");
	$("ul#movielist li:odd").addClass("odd clearfix");
	$("ul#movielist li:even").addClass("even clearfix");
	/*******************/
	$("#mainblock table tr:odd").addClass("odd");
	$(".toggle_container").hide();
	$(".trigger").click(function(){
		$(this).next().slideToggle(200);
	});
	$(".iframe").fancybox({
		'padding'			: '0',
		'width'				: 656,
		'height'			: 376,
		'autoScale'			: false,
		'transitionIn'		: 'fade',
		'transitionOut'		: 'fade',
		'type'				: 'iframe'
	});
	/*******************/
	if($("#viewArea div").length){
		if (location.search.match(/5/)) {
			stage = 5
		} else {
			stage = 1;
		}
		zenbu();
		$("#btnArea a").click(function(){
			if($(this).find("img").attr("src").match(/\_l\_/)){ stage--; }else{ stage++; }
			zenbu();
		});
		$("#movebtn li img").each(function(i){
			$(this).click(function(){ stage = i+1; zenbu(); });
		});
	}
		
	function zenbu(){
		posi = new Array( "", "0px", "-890px", "-1780px", "-2670px", "-3560px", "-4450px" );
		$("#moveArea").animate({left: posi[stage]}, 500);
		if(stage <= 1){
			$("#btnArea li:eq(0)").css("display","none"); $("#btnArea li:eq(1)").css("display","block");
		}else if(stage >= 6){
			$("#btnArea li:eq(1)").css("display","none"); $("#btnArea li:eq(0)").css("display","block");
		}else{
			$("#btnArea li:eq(0)").css("display","block"); $("#btnArea li:eq(1)").css("display","block");
		}
		$("#movebtn li img").each(function(){
		  $(this).attr("src",$(this).attr("src").replace("_on.", "_off."));
		});
		$("#movebtn li:eq("+(stage-1)+") img").attr("src",$("#movebtn li:eq("+(stage-1)+") img").attr("src").replace("_off.", "_on."));
	}

	$("a").click(function(){
		if($(this).attr("href").match(/javascript|^http/) || !location.href.match(/^http/)){
		}else if(this.href.match(/mypage\/|entry\/|contact\/|login\/|regist\/|order\/|questionnaire\//)){
			var https = this.href.replace("http:","https:");
			$(this).attr("href",$(this).attr("href").replace($(this).attr("href"),https));
		}else{
			add = this.href.replace("https:","http:");
			$(this).attr("href",$(this).attr("href").replace($(this).attr("href"),add));
		}
	});

});

//smartRollover

function smartRollover() {
	if(document.getElementsByTagName) {
		var images = document.getElementsByTagName("img");

		for(var i=0; i < images.length; i++) {
			test = images[i];
			if(images[i].getAttribute("src").match("_off.") && !images[i].id.match(/movebtn/)){
				images[i].onmouseover = function() {
					this.setAttribute("src", this.getAttribute("src").replace("_off.", "_on."));
				}
				images[i].onmouseout = function() {
					this.setAttribute("src", this.getAttribute("src").replace("_on.", "_off."));
				}
			}
		}
	}
}

if(window.addEventListener) {
	window.addEventListener("load", smartRollover, false);
}
else if(window.attachEvent) {
	window.attachEvent("onload", smartRollover);
}


//scrollsmoothly

(function(){
	var easing = 0.25;
	var interval = 20;
	var d = document;
	var targetX = 0;
	var targetY = 0;
	var targetHash = '';
	var scrolling = false;
	var splitHref = location.href.split('#');
	var currentHref_WOHash = splitHref[0];
	var incomingHash = splitHref[1];
	var prevX = null;
	var prevY = null;
	
	addEvent(window, 'load', init);
	
	function init(){
		setOnClickHandler();
		if(incomingHash){
			if(window.attachEvent && !window.opera){
				setTimeout(function(){scrollTo(0,0);setScroll('#'+incomingHash);},50);
			}else{
				scrollTo(0, 0);
				setScroll('#'+incomingHash);
			}
		}
	}
	
	function addEvent(eventTarget, eventName, func){
		if(eventTarget.addEventListener){
			eventTarget.addEventListener(eventName, func, false);
		}else if(window.attachEvent){
			eventTarget.attachEvent('on'+eventName, function(){func.apply(eventTarget);});
		}
	}
	
	function setOnClickHandler(){
		var links = d.links;
		for(var i=0; i<links.length; i++){
			var link = links[i];
			var splitLinkHref = link.href.split('#');
			if(currentHref_WOHash == splitLinkHref[0] && d.getElementById(splitLinkHref[1])){
				addEvent(link, 'click', startScroll);
			}
		}
	}
	
	function startScroll(event){
		if(event){
			event.preventDefault();
		}else if(window.event){ // IE
			window.event.returnValue = false;
		}
		setScroll(this.hash);
	}
	
	function setScroll(hash){
		var targetEle = d.getElementById(hash.substr(1));
		if(!targetEle)return;
		var ele = targetEle;
		var x = 0;
		var y = 0;
		while(ele){
			x += ele.offsetLeft;
			y += ele.offsetTop;
			ele = ele.offsetParent;
		}
		var maxScroll = getScrollMaxXY();
		targetX = Math.min(x, maxScroll.x);
		targetY = Math.min(y, maxScroll.y);
		targetHash = hash;
			if(!scrolling){
			scrolling = true;
			scroll();
		}
	}
	
	function scroll(){
		var currentX = d.documentElement.scrollLeft||d.body.scrollLeft;
		var currentY = d.documentElement.scrollTop||d.body.scrollTop;
		var vx = (targetX - currentX) * easing;
		var vy = (targetY - currentY) * easing;
		var nextX = currentX + vx;
		var nextY = currentY + vy;
		if((Math.abs(vx) < 1 && Math.abs(vy) < 1) || (prevX === currentX && prevY === currentY)){
			scrollTo(targetX, targetY);
			scrolling = false;
			location.hash = targetHash;
			prevX = prevY = null;
			return;
		}else{
			scrollTo(parseInt(nextX), parseInt(nextY));
			prevX = currentX;
			prevY = currentY;
			setTimeout(function(){scroll()},interval);
		}
	}
	
	function getDocumentSize(){
		return {width:Math.max(document.body.scrollWidth, document.documentElement.scrollWidth), height:Math.max(document.body.scrollHeight, document.documentElement.scrollHeight)};
	}
	
	function getWindowSize(){
		var result = {};
		if(window.innerWidth){
			var box = d.createElement('div');
			with(box.style){
				position = 'absolute';
				top = '0px';
				left = '0px';
				width = '100%';
				height = '100%';
				margin = '0px';
				padding = '0px';
				border = 'none';
				visibility = 'hidden';
			}
			d.body.appendChild(box);
			var width = box.offsetWidth;
			var height = box.offsetHeight;
			d.body.removeChild(box);
			result = {width:width, height:height};
		}else{
			result = {width:d.documentElement.clientWidth || d.body.clientWidth, height:d.documentElement.clientHeight || d.body.clientHeight};
		}
		return result;
	}
	
	function getScrollMaxXY() {
		if(window.scrollMaxX && window.scrollMaxY){
			return {x:window.scrollMaxX, y:window.scrollMaxY};
		}
		var documentSize = getDocumentSize();
		var windowSize = getWindowSize();
		return {x:documentSize.width - windowSize.width, y:documentSize.height - windowSize.height};
	}

}());

/*  ================================================================================
	Google Analytics
================================================================================  */
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-17035200-1']);
_gaq.push(['_trackPageview']);

(function() {
  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

