$(document).ready(function(){

	$("#menu h3[class!='hover2']").next().slideUp();
    var handler = $('#menu h3');
    menus = $('#menu ul');
    handler.click(function(){
        var _thisMenu = $(this).next();
        if(_thisMenu.is(':visible')){
        _thisMenu.show();
		$(this).css("background", "#ffffcc")
        }
        else {
        menus.slideUp();
		$("#menu h3").css({background:"#E7EBFE url(/imageFile04/arrow_down.gif) right center no-repeat"});
		
        _thisMenu.slideDown();
		$(this).css("background", "#ffffcc")
        }
		
    });

	if(navigator.userAgent.indexOf('iPhone') !=-1){

//		$('div.CommentBox').css({'height':'auto'});
		$('#footer').hide();
		$("a.zoom[rel*='imagebox']").click(function(){
					var LargeIMG = $(this).attr("href");
					var IMGSize = "/"+LargeIMG.split("/")[3]+"/"+LargeIMG.split("/")[4];
					LargeImage(IMGSize);
					return false;
					});

	}else{
		$.ImageBox.init({loaderSRC: '/order/DataFile/images/ajax-loader.gif',closeHTML: '<img src="/order/DataFile/images/window_close.jpg" border="0"/>'});
		$("#ImageBoxOuterContainer").bind('click',jQuery.ImageBox.hideImage);
		imgsize_setting();
}

	$(window).resize(function(){
//	pageSize=jQuery.iUtil.getScroll();
			$.ImageBox.init({loaderSRC: '/order/DataFile/images/ajax-loader.gif',closeHTML: '<img src="/order/DataFile/images/window_close.jpg" border="0"/>'});

	$("#ImageBoxOverlay").height($(window).height()).width($(window).width());//maskの全面表示
//	 $("#ImageBoxOverlay").css({width:$(window).width(),height:$(window).height()});
		imgsize_setting();
	

	var changeH =Math.floor(($(window).height()-150)*0.1)*10;
	var changeW =changeH*0.75;
// $("#ImageBoxContainer").css({width:changeH+20+'px',height:changeH+20+'px',left:0});
 $("#ImageBoxCurrentImage").animate({height:changeH,width:changeW});
 //.css({height:changeH,width:changeW})
 $("#ImageBoxCaption,#ImageBoxContainer").animate({width:changeW+20
 			//	,marginLeft:($(window).width()-$("#ImageBoxCurrentImage").width())/2-10
});
 $("#ImageBoxContainer")
 		.animate(
		    {
			height:changeH+20
//			width:changeW+20,
//			top:"0",
//			left:"0"
//			,marginLeft:($(window).width()-$("#ImageBoxCurrentImage").width())/2-10
		//	marginRight:($(window).width()-$("#ImageBoxCurrentImage").width())/2
			})
	});
	
var pages = $("#OpenClose");
var loading = $("#loading");
var content = $("#reviewdata");

content.hide();

pages.css({'cursor' : 'pointer','background-color' : 'yellow'}).text('[ グラフデータOPEN ]');

pages.click(function(){
		showLoading();
		$('#reviewdata').css("height","100%").toggle('slow',function(){if ($("#OpenClose").is(":contains('Close')")){$("#OpenClose").text('[ Open ]');}else{$("#OpenClose").text('[ Close ]');}})
		hideLoading();
	});


$("#page a").click(function () {
	var targetUrl = this.href + " #Comment";
 	$("#Comment").append("<div id='appenddiv' style='width:100%;height:100%;background-color:#ccc;position:absolute;top:0;left:0'></div>");//.fadeOut(0).fadeIn(800);

var reviewH = document.getElementById("review").getBoundingClientRect().top*-1;
var maincontentsH =$("#maincontents").scrollTop();
var top = maincontentsH-reviewH-150;
//	$("#Comment").height("150");
	$("#Comment").html("<center><div id='dataloading'>データ読込み中･･･</div></center>").load(targetUrl,function(){$(this).fadeOut(0).fadeIn(800)} );
// var o = document.getElementById("maincontents");
//for(i in o){y+=(i +"="+ o[i] +"<br>");}
//	$("#review").html(reviewH+":"+maincontentsH+":"+top);
	$("#maincontents").animate({scrollTop:top}, 800, 'swing'); 
	return false;
    });
function imgsize_setting(){
		if(750 >= $(window).height()-150){
				$("a.zoom[rel*='imagebox']").each(function () {
					var LargeIMG = $(this).attr("href");
					var IMGSize = LargeIMG.split("/")[2];
					var LargeIMGSize =Math.floor(($(window).height()-150)*0.075)*10;
					$(this).attr("href", function(){return LargeIMG.replace(IMGSize,LargeIMGSize)})
	//			.after(IMGSize+"-->"+LargeIMGSize+"<br />");
						});
				}}
function showLoading(){loading.css({visibility:"visible",opacity:"1",display:"block"});}
function hideLoading(){loading.fadeTo(1000, 0);	}

});
if(location.hostname=="localhost"){var linkurl=""}else{var linkurl="http://www.peaks-jp.com";}

function setITEM(i,x,c) {
if(x){		seturl=linkurl+"/order/\?mode=item_pickup&item_no=" + i +"&commentlog=" + i }
else if(c){	seturl=linkurl+"/order/\?mode=item_pickup&item_no=" + i +"&commentlog=" + i }
else {		seturl=linkurl+"/order/\?mode=item_pickup&item_no=" + i }
ITEMOpen=window.open(seturl,i,"width=680,height=500,scrollbars=yes,status=yes");ITEMOpen;ITEMOpen.focus();}
function cart() 	{cartOpen=window.open(linkurl+"/order/mart.cgi","cart","width=620,height=520,scrollbars=yes,status=yes");cartOpen;cartOpen.focus();}
//function sendhelp(send,out)	{sendOpen=window.open(linkurl+"/order?sendhelp=" + send + "&ver="+out ,"sendhelp","scrollbars=yes,resizable=yes,width=400,height=270");sendOpen;sendOpen.focus();}
function reduction(ac){reductOpen=window.open(linkurl+"/order/reduction.cgi\?" + ac ,"reduction","scrollbars=yes,resizable=yes,width=700,height=420");reductOpen;reductOpen.focus();}
function LargeImage(code){galleryPOP=window.open(linkurl+"/order/DataFile/largeimage.php?"+code,"gallery","scrollbars=no,resizable=yes,width=468,height=618");galleryPOP;galleryPOP.focus();}

function sendhelp(code,out){	
	var targetUrl = "/order/review/?sendhelp=" + code + "&ver="+out+" #help";
	$("#sendloading").hide().css({'border' : '1px solid #666','width' : '10%','padding' : '10px'});
	$("div.loading").show().html("<div class='dataloading'>データ読込み中･･･</div>");;
	$("#sendloading").load(targetUrl,function(){
		$("div.loading").hide();
		$("#sendloading").css({opacity:'0'}).animate({width:'90%',opacity:'1'});
		$("#sendhelpclose").css({cursor:'pointer',float:'right'}).bind("click",function(){$("#sendloading").fadeOut(500)})
		})
}

