var mainPage=0;
var pageLoaded=1;
var scrollCount=0;
function small_init(){
	pageLoaded=1;
	balloonInit();

}

function init(){
	mainPage=1;
	pageLoaded=1;
	balloonInit();
	stInit();
}

function init2(){
	heightAdjustInit();
	adRightInit();
	//adLeftInit();
	//adBottomInit();
}

function init3(resize){
	if(mainPage){
		//alert();
		winY=contentsHeight();
		adRightFix(resize);
		//adLeftFix(resize);
		//adBottomFix(resize);
		if(!resize){
			heightAdjustInit2();
		}else{
			if(bw.ie){
				heightAdjustInit2();
			}
		}
	}
	



	/*スクリプトを読み込む*/
	//$.getScript("./common/script/require/test.js", function(){
		//alert("Script loaded and executed.");
	//});
}

	
function colorDisco(){
	var color='rgb(255,100,130)';
	//var timeID=setInterval(eval('colorChange(color)'),1000);
}
function colorChange(color){
	//color='rgb(255,100,130)';
	//color
	
	/*var rnd1= 255-Math.floor(Math.random()*100);
	var rnd2= 255-Math.floor(Math.random()*100);
	var rnd3= 255-Math.floor(Math.random()*100);


	var color='rgb('+rnd1+','+rnd2+','+rnd3+')';*/

	var hnClass=$('.head-navi-class');
	var hnClass2=$('.head-navi-class-2');
	if(hnClass.length){
		for(var i=0; i< hnClass.length; i++){
			//alert(hnClass[i]);
			hnClass[i].style.backgroundColor =color;
			//if(hnClass[i].childNode[0]){
			//	hnClass[i].childNode.style.backgroundColor = color;
			//}
		}
		for(var i=0; i< hnClass2.length; i++){
			//alert(hnClass[i]);
			hnClass2[i].style.backgroundColor =color;
			//if(hnClass[i].childNode[0]){
			//	hnClass[i].childNode.style.backgroundColor = color;
			//}
		}

	}
	/*var lnClass=$('.left-navi-class');
	if(lnClass.length){
		for(var i=0; i< lnClass.length; i++){
			lnClass[i].childNodes[1].style.backgroundColor =color;
		}
	}*/

	var mlClass=$('.ml-class');
	if(mlClass.length){
		for(var i=0; i< mlClass.length; i++){
			mlClass[i].style.backgroundColor =color;
		}
	}

	var mlClass=$('.ml-button');
	if(mlClass.length){
		for(var i=0; i< mlClass.length; i++){
			mlClass[i].style.backgroundColor =color;
		}
	}
	var mrClass=$('.mr-class');
	if(mrClass.length){
		for(var i=0; i< mrClass.length; i++){
			mrClass[i].style.backgroundColor =color;
		}
	}

	var mrClass =$('.mr-button');
	if(mrClass.length){
		for(var i=0; i< mrClass.length; i++){
			mrClass[i].style.backgroundColor =color;
		}
	}


	/*var rnClass=$('.right-navi-class');
	if(rnClass.length){
		for(var i=0; i< rnClass.length; i++){
			rnClass[i].childNodes[1].style.backgroundColor =color;
		}
	}*/

	var fnClass=$('.foot-navi-class');
	//alert(fnClass.length);
	if(fnClass.length){
		for(var i=0; i< fnClass.length; i++){
			//alert(hnClass[i]);
			fnClass[i].style.backgroundColor =color;
		}
	}

}



var right_key;
var left_key;
var haObj=new Object();
function heightAdjustInit(){
	right_key=new Array (
		'mr-fff-1px',
		'mr-none-10px',
		'mrc-666-1px',
		'right-head',
		'right-body\.gif',
		'right-foot',
		'mr-item-intro',
		'mr-image',
		'0px 5px;',//text
		'0px 5px ',//text
		'2px 10px',//text
		'23px',//monitor
		'0px 0px 0px 31px',//qr
		'0px 1px 0px 6px',//button
		'0px 2px 2px 10px', //search
		'right-navi'
	);

	left_key=new Array(
		'ml-fff-1px',
		'ml-none-10px',
		'mlc-666-1px',
		'left-head',
		'left-body\.gif',
		'left-foot',
		'ml-item-intro',
		'ml-image',
		'0px 4px;',//text
		'0px 10px ',//text
		'2px 7px',//text
		'17px',//monitor
		'0px 0px 0px 26px',//qr
		'0px 6px 0px 1px',//button
		'0px 2px 2px 5px',//search
		'left-navi'
	);
	haObj.siteH=0;
	haObj.headH=0;
	haObj.leftH=0;
	haObj.centerH=0;
	haObj.rightH=0;
	haObj.footH=0;
	haObj.contentsH=0;
	haObj.heightCheck='';
	haObj.leftHeight =0;
	haObj.centerHeight =0;
	haObj.rightHeight =0;
	haObj.sideHeight =0;
	haObj.contentsHeight =0;
	haObj.leftBig =0;
	haObj.leftLock =0;
	haObj.leftSetup =0;
	haObj.rightBig =0;
	haObj.rightLock=0;
	haObj.rightSetup=0;


	haObj.init=1;
	
	//contentsHeight();
	//heightAdjust();
}
var timer='';

function heightAdjustInit2(){

	if(!haObj.init){
		return false;
	}

	//alert(ch);
	if(
		siteNaviObj.load &&
		headNaviObj.load &&
		leftNaviObj.load &&
		//rightNaviObj.load &&
		footNaviObj.load
		
	){

		if(haObj.leftHeight && haObj.centerHeight && haObj.rightHeight){

			if(haObj.centerHeight>haObj.leftHeight && !haObj.leftLock){
				haObj.leftBig=1;
			}
			if(haObj.centerHeight<haObj.leftHeight && !haObj.leftLock){
				haObj.leftBig=0;
			}
			if(haObj.centerHeight>haObj.rightHeight && !haObj.rightLock){
				haObj.rightBig=1;
			}
			if(haObj.centerHeight<haObj.rightHeight && !haObj.rightLock){
				haObj.rightBig=0;
			}
			//alert(haObj.centerH);
			//alert(timer);
			//timer= setTimeout("htest()",1000);

			heightAdjust();

		}else{
			//alert(timer);
			//timer= setTimeout("reInit()",1000);
		}

	}else{
		//alert(timer);
		timer= setTimeout("reInit()",2000);
	}
}

function reInit(){
	init3();
}

function heightAdjust(){
	if(haObj.leftBig && !haObj.leftLock && !haObj.leftSetup){
		haObj.leftLock=1;
		var diff=haObj.centerHeight-haObj.leftHeight;
		sidePlus('right','left', diff+200);
	}
	
	
	if(haObj.rightBig && !haObj.rightLock && !haObj.rightSetup){
		haObj.rightLock=1;
		var diff =haObj.centerHeight-haObj.rightHeight;
		sidePlus('left','right', diff+200);

	}
	
	if(!haObj.leftBig && !haObj.leftLock && !haObj.leftSetup){
		haObj.leftLock=1;
		var diff=haObj.leftHeight-haObj.centerHeight;
		sideMinus('left', diff);
	}
	if(!haObj.rightBig && !haObj.rightLock && !haObj.rightSetup){
		haObj.rightLock=1;
		var diff =haObj.rightHeight-haObj.centerHeight;
		sideMinus('right', diff);
	}
	
}	




function sidePlus(from_name,to_name,diff){
	if($('#'+from_name+'-navi').length && $('#'+to_name+'-navi').length && $('#'+to_name+'-navi')[0].innerHTML){
		var tmpClass=$("."+from_name+"-navi-class");
		var tmpH=0;
		
		while(true){
			var count=0;
			for(var i=0; i< tmpClass.length; i++){

				tmpH +=$('#'+ tmpClass[i].id)[0].offsetHeight;
				if(diff < tmpH){
					break;
				}else{
					count++;
				}
			}

		
			var res='';
			for(var i=0; i<count; i++){
				//if($('#'+tmpClass[i].id).length){
					var tmp_src= $('#'+tmpClass[i].id)[0].innerHTML;
					for(var j=0; j<right_key.length; j++){
						tmp_src=tmp_src.replaceAll(eval(from_name+'_key[j]'), eval(to_name+'_key[j]'));
					}
					res += tmp_src;
				//}
			}
			if($('#'+from_name+'-navi').length && $('#'+to_name+'-navi').length && $('#'+to_name+'-navi')[0].innerHTML){
				$('#'+to_name+'-navi')[0].innerHTML+= res;
		
			}
			if(diff < tmpH){
				break;
			}
		}
		eval('haObj.'+to_name+'Setup=1;');

	}else{
		

	}
	if(eval('haObj.'+to_name+'Lock')){
		eval('haObj.'+to_name+'Lock=0;');
	}
}

function sideMinus(id_name,diff,border){
	//alert(diff);
	if(diff <200){
		return false;
	}
	if(!border){
		border=0;
	}
	//alert(haObj.leftHeight);
	//alert(haObj.rightHeight);
	if($('#'+id_name+'-navi').length){
		var tmpClass=$("."+id_name+"-navi-class");
		var tmpH=0;
		var count=1;
		//alert(tmpClass.length);
		for(var i=0; i< tmpClass.length; i++){

			diff=diff-$('#'+ tmpClass[i].id)[0].offsetHeight;
			if(diff < border){
				break;
			}else{
				count++;
			}
		}
		var max = tmpClass.length-count;
		var res='';
		for(var i=0; i<max; i++){
			res+= $('#'+tmpClass[i].id)[0].innerHTML;
		}
		if($('#'+id_name+'-navi').length && $('#'+id_name+'-navi')[0].innerHTML){
			$('#'+id_name+'-navi')[0].innerHTML= res;
		}
		//eval('haObj.'+id_name+'Setup=1;');

	}
		
}





function contentsHeight(){
	//alert(ch);

		haObj.siteH =$("#siteNaviIn").attr('offsetHeight');
		haObj.headH =$("#headNaviIn").attr('offsetHeight');
		haObj.leftH =$("#leftNaviIn").attr('offsetHeight');
		haObj.centerH =$("#centerContents").attr('offsetHeight');
		haObj.rightH =$("#rightNaviIn").attr('offsetHeight');
		haObj.footH =$("#footNaviIn").attr('offsetHeight');

		if(haObj.leftH){
			haObj.leftHeight= haObj.siteH+haObj.headH+haObj.leftH+haObj.footH;
		}
		if(haObj.centerH){
			haObj.centerHeight= haObj.siteH+haObj.headH+haObj.centerH+haObj.footH;
		}
		if(haObj.rightH){
			haObj.rightHeight= haObj.siteH+haObj.headH+haObj.rightH+haObj.footH;
		}
		if(haObj.leftH && haObj.rightH){
			haObj.sideHeight =haObj.leftH>haObj.rightH?haObj.leftH:haObj.rightH;
		}
		
		
		if(haObj.centerH){
			haObj.contentsHeight=haObj.centerHeight>haObj.sideHeight?haObj.centerHeight:haObj.sideHeight;
		}
//alert(haObj.centerHeight);


		var res='';
		/*
		if(haObj.contentsHeight){
			res+='全部:'+haObj.contentsHeight+'<br>';
		}
		if(haObj.leftH){
			res+='左:'+haObj.leftH+'<br>';
		}
		if(haObj.centerH){
			res+='中:'+haObj.centerH +'<br>';
		}
		if(haObj.contentsHeight){
			res+='右:'+haObj.rightH+'<br>';
		}

		
		if($("#pageInfo")[0]){
			$("#pageInfo")[0].innerHTML=res;
		}
		*/

		return (haObj.contentsHeight);
	
}







function adjustNavi(type,frame_name){
	heightAdjustInit();
	contentsHeight();
	if(!haObj.leftH){
		//alert();
		timer= setTimeout('adjustNavi(\''+type+'\',\''+frame_name+'\')',500);
		return false;
	}
	var frameObj= window.parent.document.getElementsByTagName("iframe");

	var hit;
	for(i=0; i< frameObj.length; i++){
		if(frameObj[i].name == frame_name){
			hit=i;
			//frameObj[i].width=width;
			//frameObj[i].height=height;
		}
	}
	var parentH=frameObj[hit].height;

	if(parentH > haObj.leftH){
		//alert('plus');

		sidePlus('right','left', parentH -haObj.leftH+200);
		//alert($("#leftNaviIn").attr('offsetHeight'));

	}else{
		//alert('minus');
		sideMinus('left', haObj.leftH-parentH,-300);
		//alert($("#leftNaviIn").attr('offsetHeight'));
	}


}
function adjustFrame(id_name,frame_name){
	//heightAdjustInit();
	//contentsHeight();
	//alert(id_name+':'+$('#'+id_name)[0].offsetHeight);

	if(!$('#'+id_name)[0].offsetHeight){
		timer= setTimeout('adjustFrame(\''+id_name+'\')',500);
		return false;
	}

	//alert($('#'+id_name)[0].childNodes[0].id);
	//var child_id=$('#'+id_name)[0].childNodes[0].id
	//if(child_id){
	//	for(i=0; i<$('#'+child_id)[0].childNodes.length; i++){
			//alert($('#'+child_id)[0].childNodes[i].id);
	//	}
		//alert($('#'+child_id)[0].childNodes[4].id);
	//}

	//alert(id_name+':'+$('#'+id_name)[0].offsetHeight);
	
}

/*親フレームを調節*/
/*rakuten.co.jpでは動かないように*/
/*rakuten.ne.jpならOK*/
function adjustParentFrame(id_name,frame_name){
	var url = document.URL;
	var info_check=1;
	if(url.match(/http\:\/\/(.+)\.rakuten\.co\.jp\/(.+)/)){
		return false;
	}
	//if(url.match(/http\:\/\/(.+)\.shiftwash\.mysite\/(.+)/)){
	//	info_check =1;
	//}
	if(! $('#'+id_name).length ){
		return false;
	}

	if($('#'+id_name)[0].offsetHeight){
		var child_height=$('#'+id_name)[0].offsetHeight+100;

		var frameObj= window.parent.document.getElementsByTagName("iframe");
		var hit;
		for(i=0; i< frameObj.length; i++){
			if(frameObj[i].name == frame_name){
				hit=i;
				//frameObj[i].width=width;
				//frameObj[i].height= child_height;
			}
		}
	
		frameObj[hit].height=child_height;
		var res='';
		if(info_check){

			res='<span style="color:#000;">';
			res+='高さ：'+child_height+'<br>';
			res+='</span>';

			if($('#pageInfo').length){
				//$('#pageInfo')[0].innerHTML=res;
			}
		}
	}

}


function changeIframeHeight(obj,class_name,frame_name,h){
	var frameObj= window.parent.document.getElementsByTagName("iframe");

	var hit;
	for(i=0; i< frameObj.length; i++){
		if(frameObj[i].name == frame_name){
			hit=i;
		}
	}
	frameObj[hit].height=h;
	
	var button_class=$('.'+class_name);
	for(var i=0; i<button_class.length; i++){
		button_class[i].style.position='relative';
		button_class[i].style.visibility='visible';
	}
	obj.style.position='absolute';
	obj.style.visibility ='hidden';
	if(h==600){
		var scrollX=document.body.scrollLeft;
		var scrollY=document.body.scrollTop-1600;
		if(bw.ie7 || bw.ie6){
			scrollY = document.documentElement.scrollTop-1600;
			//alert(scrollY);
		}
		
		window.scrollTo(scrollX,scrollY);
	}
}



function existImage(sImageUrl){
    var img = new Image();
    img.src = sImageUrl;
    return img.height > 0; // 読み込みに失敗すれば 0 になる。
}
  
















var adRight =new Object();
var winX =0;
var winY =0;
var preY =0;
var inY=0;

function adRightInit(){
	//pageHeight();

	adRIght=getDiv('adRight');
	
	myBody = document.getElementsByTagName('body')[0];
	adRight = document.createElement('div');
	adRight.id = 'adRight';
	myBody.appendChild(adRight);


	adRight = getDiv('adRight');

	adRight.style.zIndex=99999;
	adRight.className='adRight';
	adRight.setup='ok';
	adRight.style.left=0;
	adRight.style.top=0;
	adRight.style.position='absolute';
	
	winY=contentsHeight();
	
	adRightFix(0);
}


function adRightFix(resize){
	winX= document.body.offsetWidth;

	if(!resize){
		if(winY){
			if(preY == winY){
				return false;
			}
		}else{
			return false;
		}
	}



	var posX=winX-122;
	
	var img01_height=532;
	var img02_height=839;
	
	var img_all_height= img01_height+img02_height;



	var loop_count=winY/img_all_height;
	/*
	if(winX>1180){

		
		var html;
		html='<div style="position:absolute; top:100px;">';
		
		html+='<div id=\'ad-right-head\' style="position:relative;  left:'+posX+'px; width:122px; height:150px;"></div>';

		for(i=0; i<= loop_count; i++){
			var tmp_pos = 100+img_all_height*i;
			if(tmp_pos < winY){
				html+='<div id=\'ad-right-delivery\' style="position:relative; left:'+posX+'px; width:122px; height:532px;"></div>';
			}
			
			var tmp_pos = 100+592+405+img_all_height*i;
			if(tmp_pos < winY){
				html+='<div id=\'ad-right-present\' style="position:relative; left:'+posX+'px; width:122px; height:839px;"></div>';
			}
		}
		html+='<div id=\'ad-right-foot\' style="position:relative; left:'+posX+'px; width:122px; height:150px;"></div>';
		html+='</div>';

		if($("#adRight").length){
			document.getElementById(adRight.id).innerHTML = html;
		}
	}else{
		if($("#adRight").length){
			document.getElementById(adRight.id).innerHTML = '';
		}
	}
	*/
}

String.prototype.replaceAll = function(str1,str2){
	var temp = this;
	while(temp.indexOf(str1) != -1){
		temp=temp.replace(str1,str2);
	};
	return temp;
};



















var adLeft =new Object();

function adLeftInit(){

	adLeft=getDiv('adLeft');
	
	myBody = document.getElementsByTagName('body')[0];
	adLeft = document.createElement('div');
	adLeft.id = 'adLeft';
	myBody.appendChild(adLeft);


	adLeft = getDiv('adLeft');

	adLeft.style.zIndex=99999;
	adLeft.className='adLeft';
	adLeft.setup='ok';
	adLeft.style.left=0;
	adLeft.style.top=0;
	adLeft.style.position='absolute';
	
	winY=contentsHeight();
	
	adLeftFix(0);

}

function adLeftFix(resize){
	winX= document.body.offsetWidth;

	if(!resize){
		if(winY){
			if(preY == winY){
				return false;
			}
		}else{
			return false;
		}
	}


	var posX=0;
	
	var img01_height=532;
	var img02_height=839;
	
	var img_all_height= img01_height+img02_height;



	var loop_count=winY/img_all_height;
/*
	if(winX>1180){

		
		var html;
		html='<div style="position:absolute; top:100px;">';
		
		html+='<div id=\'ad-left-head\' style="position:relative;  left:'+posX+'px; width:122px; height:150px;"></div>';

		for(i=0; i<= loop_count; i++){
			var tmp_pos = 100+img_all_height*i;
			if(tmp_pos < winY){
				html+='<div id=\'ad-left-timesale\' style="position:relative; left:'+posX+'px; width:122px; height:522px;"></div>';
			}
			
			var tmp_pos = 100+592+405+img_all_height*i;
			if(tmp_pos < winY){
				html+='<div id=\'ad-left-etc\' style="position:relative; left:'+posX+'px; width:122px; height:839px;"></div>';
			}
		}
		html+='<div id=\'ad-left-foot\' style="position:relative; left:'+posX+'px; width:122px; height:150px;"></div>';
		html+='</div>';

		document.getElementById(adLeft.id).innerHTML = html;
	}else{
		document.getElementById(adLeft.id).innerHTML = '';
	}
*/
}













var adBottom =new Object();

function adBottomInit(){

	adBottom =getDiv('adBottom');
	
	myBody = document.getElementsByTagName('body')[0];
	adBottom = document.createElement('div');
	adBottom.id = 'adBottom';
	myBody.appendChild(adBottom);


	adBottom = getDiv('adBottom');

	adBottom.style.zIndex=99999;
	adBottom.className='adBottom';
	adBottom.setup='ok';
	adBottom.style.left=0;
	adBottom.style.top=0;
	adBottom.style.position='absolute';
	
	//winY=contentsHeight();
	
	adBottomFix(0);

}

function adBottomFix(resize){
	//winX= document.body.offsetWidth;

	if(!resize){
		if(winY){
			if(preY == winY){
				return false;
			}
		}else{
			return false;
		}
	}


	var posX=0;
	
	var y=winY;
	
	//var img_all_height= img01_height+img02_height;

	//var res='<div style="position:absolute; top:'+y+'px;">あああああ</div>';

	//var loop_count=winY/img_all_height;

	/*if(winX>1180){

		
		var html;
		html='<div style="position:absolute; top:100px;">';
		
		html+='<div id=\'ad-left-head\' style="position:relative;  left:'+posX+'px; width:122px; height:150px;"></div>';

		for(i=0; i<= loop_count; i++){
			var tmp_pos = 100+img_all_height*i;
			if(tmp_pos < winY){
				html+='<div id=\'ad-left-timesale\' style="position:relative; left:'+posX+'px; width:122px; height:522px;"></div>';
			}
			
			var tmp_pos = 100+592+405+img_all_height*i;
			if(tmp_pos < winY){
				html+='<div id=\'ad-left-etc\' style="position:relative; left:'+posX+'px; width:122px; height:839px;"></div>';
			}
		}
		html+='<div id=\'ad-left-foot\' style="position:relative; left:'+posX+'px; width:122px; height:150px;"></div>';
		html+='</div>';

		//alert(document.getElementById(adBottom));
		document.getElementById(adBottom.id).innerHTML = html;
	}else{
		document.getElementById(adBottom.id).innerHTML = '';
	}*/

//document.getElementById(adBottom.id).innerHTML = res;
}




function stInit() {
	
	
	var stBox = $(".stOn");
	for(i=0; i < stBox.length; i++) {
		stBox[i].style.position = 'absolute';
		stBox[i].style.visibility = 'hidden';
	}
}


