$(document).ready(function(){
	$('#item-01').tabs({
		fxShow: { height: 'show', opacity: 'show' }
	});
	$('#pages li a').click(function() {
		location.href = $(this).attr('href');
	});
});


$(function() {
	$('a.lightbox').lightBox({
		'overlayBgColor': '#FFF',
		imageLoading: '/img/lightbox-ico-loading.gif'
	});
	
	$('a.item-del').click(function() {
		return confirm('この記事を削除してもよろしいですか？');
	});
	$('select').change(function() {
		var v = this.options[this.selectedIndex].value;
		if (this.className && v) {
			switch (this.className) {
				// 礼金
				case 'ItemReikin':
					if ($('#ItemValue').val().match(/^\d+$/)) {
						$('#' + this.className).val(v * $('#ItemValue').val() - 0);
					}
					break;
				// 敷金
				case 'ItemDeposit':
					if ($('#ItemValue').val().match(/^\d+$/)) {
						$('#' + this.className).val(v * $('#ItemValue').val());
					}
					break;
				// 間取り
				case 'ItemLayout':
					if ($('#ItemLayout').val().match(/^\d+$/)) {
						$('#' + this.className).val($('#ItemLayout').val() + v);
					}
					break;
				default:
					$('#' + this.className).val(v);
					break;
			}
		}
	});

	$('#soku').click(function() {
		if ($('#soku').attr('checked') == true) {
			$('#ItemAvailable').val('即日');
		}
		else {
			$('#RentalAvailable').attr('disabled', false);
		}
	});
		$('.item-img img').each(function() {
			var asp = this.width / this.height;
			if (this.width < this.height) {
				this.style.height = 90 + 'px';
				this.style.width = 90 * asp + 'px';
			}
			else {
				this.style.width = 120 + 'px';
				this.style.height = 120 / asp + 'px';
			}
		});
		$('.item-image-main p img').each(function() {
			var asp = this.width / this.height;
			if (this.width < this.height) {
				this.style.height = 195 + 'px';
				this.style.width = 195 * asp + 'px';
			}
			else {
				this.style.width = 260 + 'px';
				this.style.height = 260 / asp + 'px';
			}
		});
		$('.item-detail-sub-img').each(function() {
			var asp = this.width / this.height;
			if (this.width < this.height) {
				this.style.height = 98 + 'px';
				this.style.width = 98 * asp + 'px';
			}
			else {
				this.style.width = 130 + 'px';
				this.style.height = 130 / asp + 'px';
			}
		});
});

function initRollOverImages() {
	var image_cache = new Object();
	$(".staff-img img").each(function(i) {
		var imgsrc = this.src;
		var slash = this.src.lastIndexOf('/');
		var imgname = this.src.substr(slash+1).split('.');
		var imgsrc_on = this.src.substr(0, slash) + '/' + imgname[0] + '.' + 2 + '.' + imgname[2];
		image_cache[this.src] = new Image();
		image_cache[this.src].src = imgsrc_on;
		$(this).hover(
			function() { this.src = imgsrc_on; },
			function() { this.src = imgsrc; }
		);
	});
}
$(document).ready(initRollOverImages);


