﻿$().ajaxStop($.unblockUI);
function initNewsBriefList() {
	$.ajax({
		type: 'POST',
		url: 'news.php',
		dataType: 'html',
		data: 'op=brief',
		beforeSend: function(xhr) {
			xhr.setRequestHeader('Accept', 'text/html');
		},
		success: function(data) {
			$('#newsbrief').html(data);
		}
	});
}
function initNewsList() {
	$.ajax({
		url: 'news.php',
		dataType: 'html',
		beforeSend: function(xhr) {
			xhr.setRequestHeader('Accept', 'text/html');
		},
		success: function(data) {
			$('#news').html(data);
		}
	});
}
var SALELISTDIV = new Array();
SALELISTDIV[1] = 'salelist1';
SALELISTDIV[2] = 'salelist2';
SALELISTDIV[3] = 'salelist3';
SALELISTDIV[4] = 'salelist4';
SALELISTDIV[5] = 'salelist5';
SALELISTDIV[6] = 'salelist6';

var REQUESTBUTTON = new Array();
REQUESTBUTTON[1] = 'require1';
REQUESTBUTTON[2] = 'require2';
REQUESTBUTTON[3] = 'require3';
REQUESTBUTTON[4] = 'require4';
REQUESTBUTTON[5] = 'require5';
REQUESTBUTTON[6] = 'require6';

function initSaleAllList() {
	$.ajax({
		type: 'POST',
		url: 'sale_soon.php',
		dataType: 'html',
		beforeSend: function(xhr) {
			xhr.setRequestHeader('Accept', 'text/html');
		},
		success: function(data) {
			$('#salecontent').html(data);
			for(var i = 1; i < 7; i++) {
				initSaleList(i);
				$('#require'+i).click(function() { 
        			requestSale($(this)[0].id); 
				});
			}
		}
	});
}
function initSaleList() {
	var type = arguments[0];
	if(typeof arguments[1] == 'undefined') {
		pageId = 1;
	}
	else {
		pageId = arguments[1];
	}
	if(typeof arguments[2] == 'undefined') {
		order = '';
	}
	else {
		order = '&order=' + arguments[2];
	}
	if(jQuery.browser.msie) height = '37px';
	else height = '30px';
	$('#salelist'+type).block({
       	message: '<h3 style="height:' + height + '"><img src="js/busy.gif" />Loading...</h3>',  
        css: { border: 'none'},
        overlayCSS: { backgroundColor: '#fff' }  
    }); 
	$.ajax({
		type: 'POST',
		url: 'sale_soon.php',
		data: 'type=' + type + '&page=' + pageId + order,
		dataType: 'html',
		beforeSend: function(xhr) {
			xhr.setRequestHeader('Accept', 'text/html');
		},
		success: function(data) {
			displayId = SALELISTDIV[type];
			$('#' + displayId).css('display', 'none');
			$('#' + displayId).html(data);
			$('#' + displayId).fadeIn(1500);
		}
	});
}
function showSaleList(type) {
	for(var i = 1; i < 7; i++) {
		if(type == i) {
			showMe('listtype' + i);
		}
		else {
			hideMe('listtype' + i);
		}
	}
}
function showSaleDetail() {
	var reid = arguments[0];
	$.blockUI({ message: '<h2><img src="js/busy.gif" /> しばらくお待ちください...</h2>',css: { padding: '15px'} }); 
	$.ajax({
		type: 'POST',
		url: 'sale_soon.php',
		data: 'reid=' + reid,
		dataType: 'html',
		beforeSend: function(xhr) {
			xhr.setRequestHeader('Accept', 'text/html');
		},
		success: function(data) {
			$('#salecontent').html(data);
			zoomSnapshot();
		}
	});
}
function requestSaleDetail(type, reid) {
	$.ajax({
		type: 'POST',
		url: 'sale_soon.php',
		data: 'type=' + type + '&op=request&reid='+reid,
		dataType: 'html',
		beforeSend: function(xhr) {
			xhr.setRequestHeader('Accept', 'text/html');
		},
		success: function(data) {
			$('#salecontent').html(data);
			zoomSnapshot();
			return true;
		}
	});
	return true;
}
function requestSale() {
	for(i in REQUESTBUTTON) {
		if(arguments[0] == REQUESTBUTTON[i]) var type = i;
	}
	var selectFlag = false;
	var result = '';
	$("input:checkbox[@name='cbx"+type+"[]']:checked").each( function () {
		selectFlag = true;
		result = result + $(this).val() + ",";
	});
	if(selectFlag == true) {
		$.blockUI({ message: '<h2><img src="js/busy.gif" /> しばらくお待ちください...</h2>',css: { padding: '15px'} }); 
		$.ajax({
			type: 'POST',
			url: 'sale_soon.php',
			data: 'type=' + type + '&op=request&ck='+result,
			dataType: 'html',
			beforeSend: function(xhr) {
				xhr.setRequestHeader('Accept', 'text/html');
			},
			success: function(data) {
				$('#salecontent').html(data);
				return true;
			}
		});
	}
	else {
		alert('物件を選択してください。');
		//$.blockUI({ message: '<h2 id="no">物件を選択してください。</h2>' }); 
		//$('#no').click(function() { 
        //    $.unblockUI(); 
        //    return false; 
        //});
		//return false;
	}
}

function sortByPrice(type, pageId, order) {
	initSaleList(type, pageId, order);
}

function zoomSnapshot() {
	$('.thumb').click(function() { 
		$('#mainthumb').block({ message: '<h3>Loading...</h3>', css: { border: 'none',padding: '15px', backgroundColor: '#000', color: '#fff', opacity: '.5' }}); 
    	$('#re_picture').attr('src', $(this).attr('src'));
		$('#mainthumblink').attr('href', $(this).attr('src'));
		setTimeout($('#mainthumb').unblock(), 500); 
	});
}
