$(document).ready(function(){

	if(navigator.userAgent.indexOf('iPhone') !=-1){

		$('div.CommentBox').css({'height':'100%'});
		$('#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').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").html("<center><div id='dataloading'>データ読込み中･･･</div></center>").load(targetUrl,function(){$(this).fadeOut(0).fadeIn(800);} );
	$(this).css({color:'gray'});
	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)})
		})
}
