
/* env =================================== */

var medicom_home ="/";

/* ipad ipod =================================== */

if(navigator.userAgent.match(/iPad/i) != null || navigator.userAgent.match(/iPod/i) != null){
$("#mainframe").css("overflow","visible");
//alert();
}


/* rotate banner =================================== */

var bannerwidth = 140; // width
var bannerheight = 40 + 2; // height + margin
var showbanners = 3;

var xt = 0;
var nowbanner = 0;
var banners = 0;
var bhtmlarray;

function rotateBanner(){
	bhtmlarray = new Array();
$("#sidebanner").css("max-height",( bannerheight * showbanners ) );
$("#sidebanner").css("height",( bannerheight * showbanners ) );
$("#sidebanner_frame").css("height",( bannerheight * showbanners ) );
$(".sidebannerdiv a").css("width",( bannerwidth) );
$("#sidebanner").css("overflow","hidden");
	banners = $("#sidebanner_inner .sidebannerdiv").length;
	var randarray = new Array();
		for(i=0;i<banners;i++){
			randarray [i]= i;
		}
	$("#sidebanner_inner .sidebannerdiv").each(function(){
		bhtmlarray.push($(this).html());
	});

	var z = 0;
 $("#sidebanner_inner .sidebannerdiv").each(function(){
		if(	z < showbanners){ $(this).show() }else{ $(this).hide()  }
		z++;
	});

nowbanner = bhtmlarray.length; // showbanners;
setInterval(dorotateBanner, 5000);

}

function dorotateBanner(){
var nextbanner = nowbanner - 1;
if(nextbanner < 0){ nextbanner = banners -1;}
nowbanner =  nextbanner;
$("#sidebanner_inner").prepend('<div class="sidebannerdiv">'+bhtmlarray[nowbanner]+'<'+"/div>").animate({top:-bannerheight},0).animate({top:0},700,   "easeOutBounce");
$("#sidebanner_inner .sidebannerdiv").eq(4).remove();
//console.log(bhtmlarray[0]);
}

/* layout =================================== */

function sidemaxHeight() {
//var top_pad = ($(window).height() - $("#sidebottom").height()) /2  - ( ($("#sidebottom  a  img").height() +150) /2 ) ;
var top_pad = ($(window).height() - $("#sidebottom").height()) /2  - ( ($("#sidebottom  a  img").height() +35) /2 ) ;

if(navigator.userAgent.match(/iPad/i) == null && navigator.userAgent.match(/iPod/i) == null){
	$("#mainframe").css("height", $(window).height());
}else{
	if($("#mainframe").height() > $(document).height()){
	$("#sidenavi,#sidenavi2").css("height", $("#mainframe").height());
	}else{
	$("#sidenavi,#sidenavi2").css("height", $(document).height());
	}
}
	$("#sidelogo").css('height',$(window).height() - $("#sidebottom").height()-top_pad ); 

//if( $("#sidelogo").height() <= 220 ){
if( $("#sidelogo").height() <= 100 ){
top_pad = 35;
}
	$("#sidelogo").css('padding-top', top_pad  );
footerfixexe();
//alert($(document).height()+":"+$(window).height());

}

var fix_h = 0;

function footerfixexe(){
	if($("#bottomarea").size() > 0){
		if($("#p_contents").size() > 0){
	footerfix("#mainframe","#mainframe_inner","#p_contents","#bottomarea");
		}
		if($("#n_contents").size() > 0){
	footerfix("#mainframe","#mainframe_inner","#n_contents","#bottomarea");
		}
		if($("#contents").size() > 0){
	footerfix("#mainframe","#mainframe_inner","#contents","#bottomarea");
		}
	}

}

function footerfix(m,mi,c,f) {
	var d_h = $(m).height();
	var f_t = $(c).outerHeight(true);//offset().top;
	var f_h = $(f).outerHeight(true);
	var c_h = $(c).height();
//console.log(c+":"+f+": "+d_h+" "+f_t+" "+f_h+" "+c_h+" "+fix_h+" ");
//$(f).css("width",$(c).width() - 56);
//$(document).ready(function(){
if( $(window).width() - $(c).innerWidth(true) <= 20 ){
//console.log("a");
$(f).css("width",$(window).width() -201 - 56);
}else{
$(f).css("width",$(c).innerWidth(true) - 56);
}
//}
//console.log($(window).width() +" "+$(c).innerWidth(true) + " "+($(window).width() - $(c).innerWidth(true)) +" "+$(f).width());
/*
	if((f_h) < d_h -c_h){
 fix_h = (d_h - (f_t+f_h));
$(f).css("position","absolute").css("bottom",-51).css("width",$(c).width() - 56);
	//$(c).css("margin-bottom", fix_h);
	}else{
$(f).css("position","absolute").css("bottom",-51).css("width",$(c).width() - 56);
//$(f).css("position","static");
	}
*/
if($(m).height() > f_t ){
$(mi).css("min-height",$(m).height() -151);
}

}


/* top page =================================== */


function shownews(){
	$("#topnewsarea").slideDown('fast');
}
function hidenews(){
//	$("#topnewsarea").hide();
	$("#topnewsarea").slideUp('fast');
}
function showcontents(e,nm){
$("#contents .productdata").clearQueue();
$("#contents .productdata").stop(true,true);
$("#contents .productdata").hide();
$("#contents").html("");
var scurl =e.attr("href")+" #contents div";  // medicom_home+"./WI/0029.php";
var n = 0
for(n = 1 ; n <= 4; n++){
	$("#topbt"+n+" a").css("background-image","url("+medicom_home+"./images/top_navi_0"+n+".gif)");
}
e.css("background-image","url("+medicom_home+"./images/top_navi_0"+(nm+1)+"a.gif)");

if (!(typeof history.pushState === 'undefined')) {
history.pushState(null, null,e.attr("href"));
	$("#contents").load(scurl,null,function(){
		$("#contents").vgrid({
				easeing: "easeOutQuint",
				time: 400,
				delay: 20
			});
		xt = 0;
		$("#contents .productdata").each(function(){
					xt += 50;
					$(this).delay(xt+50).fadeIn('fast');
		});
		$('#contents div a,#p_tlist div a').easyToolTip();
		footerfixexe();
	});
}else{
location.href = e.attr("href");
}

return false;

}

function showcontentshtml5(url5){
if(url5 == undefined){url5 =document.URL;}

$("#contents .productdata").clearQueue();
$("#contents .productdata").stop(true,true);
$("#contents .productdata").hide();
$("#contents").html("");
var scurl =url5+" #contents div";  // medicom_home+"./WI/0029.php";
var n = 0
for(n = 1 ; n <= 4; n++){
	$("#topbt"+n+" a").css("background-image","url("+medicom_home+"./images/top_navi_0"+n+".gif)");
	if(url5.indexOf("/list/0001/") != -1){
$("#topbt"+2+" a").css("background-image","url("+medicom_home+"./images/top_navi_0"+(2)+"a.gif)");
	}else if(url5.indexOf("/list/0002/") != -1){
$("#topbt"+3+" a").css("background-image","url("+medicom_home+"./images/top_navi_0"+(3)+"a.gif)");
	}else if(url5.indexOf("/list/0003/") != -1){
$("#topbt"+4+" a").css("background-image","url("+medicom_home+"./images/top_navi_0"+(4)+"a.gif)");
	}else 	if(url5.indexOf("/list/NEWITEM/") != -1){
$("#topbt"+2+" a").css("background-image","url("+medicom_home+"./images/top_navi_0"+(2)+"a.gif)");
	}else if(url5.indexOf("/list/LIMITEDITEM/") != -1){
$("#topbt"+3+" a").css("background-image","url("+medicom_home+"./images/top_navi_0"+(3)+"a.gif)");
	}else if(url5.indexOf("/list/MAILORDERITEM/") != -1){
$("#topbt"+4+" a").css("background-image","url("+medicom_home+"./images/top_navi_0"+(4)+"a.gif)");
	}else{
$("#topbt"+1+" a").css("background-image","url("+medicom_home+"./images/top_navi_0"+(1)+"a.gif)");
	}

}

$("#contents").load(scurl,null,function(){

$("#contents").vgrid({
		easeing: "easeOutQuint",
		time: 400,
		delay: 20
	});
xt = 0;
$("#contents .productdata").each(function(){
			xt += 50;
			$(this).delay(xt+50).fadeIn('fast');
});
$('#contents div a,#p_tlist div a').easyToolTip();
footerfixexe();
});
return false;

}

var orgin_url = location.href;
var evflag = 0;
function set_popstate(){
	if (!(typeof history.pushState === 'undefined')) {
		$(window).bind('popstate', function (event) {
		//	console.log("url:"+event.target.document.URL);
		//	console.log("url:"+location.href);
			console.log("called"+orgin_url+":"+event.target.document.URL);
			if(evflag !=0 && orgin_url != location.href){
			 showcontentshtml5(event.target.document.URL);
			}
		});
		if(evflag == 0 && orgin_url == location.href ){
		xt = 0;
			$("#contents .productdata").delay(100).each(function(){
			xt += 50;
			$(this).delay(xt+50).fadeIn('fast');
			evflag = 1;
			});
		
		}
	}else{
		xt = 0;
			$("#contents .productdata").delay(100).each(function(){
			xt += 50;
			$(this).delay(xt+50).fadeIn('fast');
			});
		evflag = 1;
	}

}

/* menu  =================================== */

function animateMenu(){

$("#gn_box a.gn_btn01").mouseover(function(){
		$(this).stop().animate(
			{backgroundPosition:"(0 3px)"}, 
			{duration:250})
		}).mouseout(function(){
		$(this).stop().animate(
			{backgroundPosition:"(-104px 3px)"}, 
			{duration:250})
		});
$("#gn_box a.gn_btn02").mouseover(function(){
		$(this).stop().animate(
			{backgroundPosition:"(0 3px)"}, 
			{duration:250})
		}).mouseout(function(){
		$(this).stop().animate(
			{backgroundPosition:"(-105px 3px)"}, 
			{duration:250})
		});
$("#gn_box a.gn_btn03").mouseover(function(){
		$(this).stop().animate(
			{backgroundPosition:"(0 3px)"}, 
			{duration:250})
		}).mouseout(function(){
		$(this).stop().animate(
			{backgroundPosition:"(-110px 3px)"}, 
			{duration:250})
		});
$("#gn_box a.gn_btn04").mouseover(function(){
		$(this).stop().animate(
			{backgroundPosition:"(0 3px)"}, 
			{duration:250})
		}).mouseout(function(){
		$(this).stop().animate(
			{backgroundPosition:"(-101px 3px)"}, 
			{duration:250})
		});
$("#gn_box a.gn_btn05").mouseover(function(){
		$(this).stop().animate(
			{backgroundPosition:"(0 3px)"}, 
			{duration:250})
		}).mouseout(function(){
		$(this).stop().animate(
			{backgroundPosition:"(-80px 3px)"}, 
			{duration:250})
		});
$("#gn_box a.gn_btn06").mouseover(function(){
		$(this).stop().animate(
			{backgroundPosition:"(0 3px)"}, 
			{duration:250})
		}).mouseout(function(){
		$(this).stop().animate(
			{backgroundPosition:"(-51px 3px)"}, 
			{duration:250})
		});
$("#gn_box a.gn_btn07").mouseover(function(){
		$(this).stop().animate(
			{backgroundPosition:"(0 3px)"}, 
			{duration:250})
		}).mouseout(function(){
		$(this).stop().animate(
			{backgroundPosition:"(-115px 3px)"}, 
			{duration:250})
		});
$("#gn_box a.gn_btn08").mouseover(function(){
		$(this).stop().animate(
			{backgroundPosition:"(0 3px)"}, 
			{duration:250})
		}).mouseout(function(){
		$(this).stop().animate(
			{backgroundPosition:"(-111px 3px)"}, 
			{duration:250})
		});
$("#gn_box a.gn_btn09").mouseover(function(){
		$(this).stop().animate(
			{backgroundPosition:"(0 3px)"}, 
			{duration:250})
		}).mouseout(function(){
		$(this).stop().animate(
			{backgroundPosition:"(-76px 3px)"}, 
			{duration:250})
		});
$("#gn_box a.gn_btn10").mouseover(function(){
		$(this).stop().animate(
			{backgroundPosition:"(0 3px)"}, 
			{duration:250})
		}).mouseout(function(){
		$(this).stop().animate(
			{backgroundPosition:"(-115px 3px)"}, 
			{duration:250})
		});

$("#gn_box a").each(function(){
var nurl = $(this).attr("href");
nurl = nurl.substring(medicom_home.length + 1,nurl.length);
//console.log(nurl+" : "+document.URL );
	if(document.URL.indexOf(nurl) != -1){
//	console.log("hit");
		$(this).parent("li").addClass("menu_current");
		$(this).unbind("mouseover");
		$(this).unbind("mouseout");
		$(this).css({"background-position":"0 3px"});
	}
if(document.URL.indexOf("/prod/") != -1 && nurl.indexOf("/prod/") != -1){
		$(this).parent("li").addClass("menu_current");
		$(this).unbind("mouseover");
		$(this).unbind("mouseout");
		$(this).css({"background-position":"0 3px"});
}
if(document.URL.indexOf("/list/") != -1 && nurl.indexOf("/list/") != -1){
		$(this).parent("li").addClass("menu_current");
		$(this).unbind("mouseover");
		$(this).unbind("mouseout");
		$(this).css({"background-position":"0 3px"});
}

});


}


