/**
 * 起票時処理サンプル
 */
$(document).ready(function(){
	// ロールオーバー
	ROfunction();
	// クーポンプリントアウトクリック
	clickPrintoutCoupon();
});



/**
 * ロールオーバー画像の切り替え
 */
function ROfunction(){

	var imgNum = document.getElementsByTagName("img");
	var inputNum = document.getElementsByTagName("input");
	
	overNum = new Array;
	
	for (i = 0; i < imgNum.length; i++) {
		overNum[i] = imgNum[i];
	}
	
	for (i = 0; i < inputNum.length; i++) {
		overNum[i + imgNum.length] = inputNum[i];
	}
	
	for (i = 0; i < overNum.length; i++) {
		if (overNum[i].className.indexOf("Rover") != -1 && overNum[i].src.indexOf("_o.") == -1) {
			overNum[i].overimg = new Image();
			if (overNum[i].className.indexOf(":") != -1) {
				Replace = overNum[i].className.split(":");
				Replace = Replace[1].split(" ");
				overNum[i].overimg.src = Replace[0];
			}
			else {
				Replace = overNum[i].src.length;
				overNum[i].overimg.src = overNum[i].src.substring(0, Replace - 4) + "_o" + overNum[i].src.substring(Replace - 4, Replace);
			}
			overNum[i].setAttribute("out", overNum[i].src);
			overNum[i].onmouseover = new Function('this.src=this.overimg.src;');
			overNum[i].onmouseout = new Function('this.src=this.getAttribute("out");');
		}
	}
}



/**
 * クーポンプリントアウトクリック時のアクション
 */
function clickPrintoutCoupon(){
	
	if($('#PrintoutCoupon') && $('#id')){
		
		$('#PrintoutCoupon').click(function(){
			
			$.ajax({
				type: "GET",
				url: "/shop_info/couponcount.php",
				data: "id="+$('#id').val(),
				success: function(msg){
					window.print();
				}
			});
			
		});
	}
}



/**
 * サムネイル画像のリサイズ
 * 
 * 該当するクラス名を設定した画像オブジェクトに対して
 * 指定したサイズ内にフィットする形で
 * 画像をリサイズする
 * 
 * @extends prototype.js
 * @param r_height 高さ
 * @param r_width 幅
 * @param classname クラス名
 */
function resizeImages(r_height, r_width, classname){
	
	$('.'+classname).each(function(){
		// オリジナルサイズを取得
		var o_img = new Image();
		o_img.src = $(this).attr('src');
		var o_height = o_img.height;
		var o_width = o_img.width;
		// 伸縮率を取得
		var per = 0;
		if((r_height/o_height) > (r_width/o_width)){
			per = r_width/o_width;
		}else{
			per = r_height/o_height;
		}
		// 表示をリサイズ
		$(this).attr('height', o_height * per);
		$(this).attr('width', o_width * per);
	});
	
}


