$(document).ready(function(){
													 
	/*レンタル商品詳細 ポップアップ*/
	$("a[rel^='prettyPopin']").prettyPopin();
													 
	/*レンタル商品詳細 イメージ変更*/
	$("#imgarea li a").click(function () {
		var target_obj = $("#mainimg");
		target_obj.html('');
		
		var imgpath = $(this).attr("href");
		var img_size = $(this).children('img').attr('alt');
		var img_size_arr = img_size.split('x');
		var img_w = img_size_arr[0];
		var img_h = img_size_arr[1];
		var parent_h = target_obj.height();
		var mh = (parent_h > img_h) ? (parent_h - img_h)/2 : 0;
		
		target_obj.html('<img src="' + imgpath + '" width="' + img_w +'" height="' + img_h +'" style="margin-top:' + mh +'px;" alt="" />');
		
		return false;
	});

	/*イメージ上下センター*/
	$(".photolist li span img,#mainimg img,#imgarea li img").each(function(){
		var imgh = $(this).height();
		var parh = $(this).parents().height();
		if(parh > imgh){
			var mh = (parh - imgh)/2;
			$(this).css("marginTop",mh);
		}
	});

	/*サイドパネル*/
	$(".panel").hide();
	if($("body").hasClass("event")){
		$("#tab li:last-child a").addClass("selected");
		var tgt = $("#tab li:last-child a").attr("href");
	}else{
		$("#tab li:first-child a").addClass("selected");
		var tgt = $("#tab li:first-child a").attr("href");
	}
	$(tgt).show();
	
	$("#tab li a").click(function () {
		$("#tab li a").removeClass("selected");
		$(this).addClass("selected");
		$(".panel").hide();
		var tgt = $(this).attr("href");
		$(tgt).show();
		return false;
	});

	/*IEの:last-child*/
	if(!jQuery.support.opacity){ //IE6,7,8
		$("#pathlist li:last-child,form td label:last-child").addClass("lc");
		if(!jQuery.support.hrefNormalized){ //IE6,7
				$(".photolist span").click(function(e){
						var shiftKey = e.shiftKey;
						var url = $(this).parent("a").attr("href");
						if(shiftKey){
							window.open(url);
						}else{
							window.location=url;
						}
						return false;
					});		
		}
	}
	
	/* TEL＆FAX */
	$('form #tel, form #fax').change(function(){
		var v = replaceDoubleNum($(this).attr('value'));
		$(this).attr('value', v);
	});
	
	/*$('form input[type="text"]').change(function(){
		if(!$(this).attr('value')){
			$(this).attr('value', '');
		}
	});*/
});

function replaceDoubleNum(val){
	var result = val;
	for(var i = 0; i < val.length; i++){
		var char = val.charCodeAt(i);
		
		if(char >= 0xff10 && char <= 0xff19 ){
			result = result.replace(val.charAt(i),String.fromCharCode(char-0xfee0));	//全角数値なら
		}
		
		if(char == 0xff0d || char == 0x30fc || char == 0x2015 || char == 0x2212){
			result = result.replace(val.charAt(i),String.fromCharCode(0x2d));			//全角ハイフンなら
		}
	}
	return result;
}

