$(function(){
//CLASS SET
	$("#contents").find("li:first-child,dl dt:first-child,dl dt:first-child+dd,").addClass("fc");
	$(".gin_p1_nedan").find("tr:first-child,th:first-child,td:first-child").addClass("fc");
	$("#rightblock li").addClass("fc");
	
	if($(".indexmenu").length){
		$(".indexmenu li:odd").addClass("odd");
	}
	
	var pathname = location.pathname.split("/");
	filename = new RegExp(pathname[pathname.length-1].slice(0,-5));
	$("#rightblock li img").each(function(){
		if($(this).attr("id").match(filename)){
			$(this).attr("src",$(this).attr("src").replace("_off.","_on."));
		}
	});
	
	$("a").click(function(){
		if($(this).attr("href").match(/javascript|^http/) || !location.href.match(/^http/)){
		}else if($(this).attr("href").match(/index\.cgi/) ){
			var https = "https://lolipop-dp27281407.ssl-lolipop.jp/contact/index.cgi";
			$(this).attr("href",$(this).attr("href").replace($(this).attr("href"),https));
		}else if($(this).attr("href").match(/entry\.cgi/)){
			var https = "https://lolipop-dp27281407.ssl-lolipop.jp/recruit/entry.cgi";
			$(this).attr("href",$(this).attr("href").replace($(this).attr("href"),https));
		}else{
			if(!$(this).attr("href").match(/\.\.\//g)){
				u = location.pathname.slice(0,location.pathname.lastIndexOf("\/")+1);
			}else{
				u = "/";
			}
			l = $(this).attr("href").replace(/\.\.\/(.*?\/.*?\.(html|cgi)$)/,"$1");
			if(l.match(/\.\.\//g)){ l = l.replace("\.\.\/",""); }
			add = "http://www.shinseifoods.jp"+u+l;
			$(this).attr("href",$(this).attr("href").replace($(this).attr("href"),add));
		}
	});



/*  ================================================================================
	SSL Check
================================================================================  */
//var url = location.href;
//keys = new Array();
//keys[0] = 'entry';
//keys[1] = 'contact';
//keys[2] = 'hoge';

//key = '/' + keys.join('|')+'/';
//alert(key);
//if ( url.match(/^http:\/\/.*/) ) {
//	if ( url.match(key) ) {
//		url = url.replace("http://www.shinseifoods.jp/", "https://lolipop-dp27281407.ssl-lolipop.jp/");
//		location.replace(url);
//	} else {
//	}
//} else if ( url.match(/^https:\/\/.*/) ) {
//	if ( url.match(key) ) {
//	} else {
//		url = url.replace("https://lolipop-dp27281407.ssl-lolipop.jp/", "http://www.shinseifoods.jp/");
//		location.replace(url);
//	}
//}


	if($(".secret").length){
		$positionArry = new Array( "","0px","-950px","-1900px","-2850px","-3800px","-4750px","-5700px","-6650px" );
		var $scene;
		if(window.location.search){
			$scene = window.location.search.slice(-1);
			$("#stage #viewarea #image").animate({left: $positionArry[$scene]}, 1000);
		}
		$("#stage #scrollbtn a").click(function(){
			if(!$scene){ $scene = 1; }
			if($(this).parent().attr("class") == "lbtn"){ $scene--; }
			else{ $scene++; }

			if($scene < 1) $scene = 8;
			if($scene > 8) $scene = 1;
			$("#stage #viewarea #image").animate({left: $positionArry[$scene]}, 1000);
		});
		$("#stage #btn a").each(function(i){
			$(this).click(function(){
				$scene = i+1;
				$("#stage #viewarea #image").animate({left: $positionArry[$scene]}, 1000);
			});
		});
	}
});


function submitcheck(name){
	if($(".pp:checked").length){
		e= document[name];
		e.submit();
	}else{
		alert("個人情報保護方針に同意してください");
	}
}
function formreset(){
	$("form dl input,form dl select,form dl textarea").not('input[type="radio"],input[type="checkbox"],:hidden, :button, :submit,:reset').val('').removeAttr('checked').removeAttr('selected');
}


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

		for(var i=0; i < images.length; i++) {
			if(images[i].getAttribute("src").match("_off.")){
				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};
	}

}());


