//==============================================================================
//  ■TOP画面：カスタム(中島オート)
//
//  ■説明：
//==============================================================================

//--------------------------------------------------
// 初期処理
//--------------------------------------------------
$(document).ready(function(){

	// HOME
	set_icon_mouse_event('#menu_button1');
	// 在庫車両
	set_icon_mouse_event('#menu_button2');
	// 車探し依頼
	set_icon_mouse_event('#menu_button3');
	// 車の査定
	set_icon_mouse_event('#menu_button4');
	// 点検・車検
	set_icon_mouse_event('#menu_button5');
	// ご利用者の声
	set_icon_mouse_event('#menu_button6');
	// お得チラシ
	set_icon_mouse_event('#menu_button7');
	// ブログ
	set_icon_mouse_event('#menu_button8');

	// メーカー選択イベントの設定
	set_maker_select('irai_maker', 'irai_syasyu');

	// おすすめ車両一覧
	$('#osusume_list_button').click(go_zaiko_list_page);

	// 希望の条件の車検索
	$('#joken_match_button').click(search_irai);

	// イベントダイアログ設定
	var buttons_event = {
		'閉じる' : close_event_dialog
	};
	$('#dialog_event').dialog({
		 autoOpen: false
		,title: "イベント情報"
		,width: 860
		,modal: true
		,resizable: false
		,buttons: buttons_event
	});

	// トピックスダイアログ設定
	var buttons_topics = {
		'閉じる' : close_topics_dialog
	};
	$('#dialog_topics').dialog({
		 autoOpen: false
		,title: "トピックス & What's News"
		,width: 400
		,modal: true
		,resizable: false
		,buttons: buttons_topics
	});

});

//--------------------------------------------------
// メーカー・車種を条件に在庫一覧ページへ遷移
//--------------------------------------------------
function search_maker_syasyu(maker, syasyu)
{
	if(maker != undefined){
		$('#joken_maker').val(maker);
	}
	if(syasyu != undefined){
		$('#joken_syasyu').val(syasyu);
	}
	go_zaiko_list_page();
}

//--------------------------------------------------
// 価格を条件に在庫一覧ページへ遷移
//--------------------------------------------------
function search_price(from, to)
{
	if(from != undefined){
		$('#joken_price_from').val(from);
	}
	if(to != undefined){
		$('#joken_price_to').val(to);
	}
	go_zaiko_list_page();
}

//--------------------------------------------------
// 在庫一覧ページへ遷移
//--------------------------------------------------
function go_zaiko_list_page()
{
	$('#form_joken').submit();
}

//--------------------------------------------------
// 在庫詳細ページへ遷移
//--------------------------------------------------
function go_zaiko_detail(zaiko_code)
{
	$('#zaiko_code').val(zaiko_code);
	$('#form_osusume').submit();
}

//--------------------------------------------------
// 車両捜索ページへ遷移
//--------------------------------------------------
function search_irai()
{
	var maker = $('#irai_maker').val();
	var syasyu = $('#irai_syasyu').val();

	location.href = $('#root_dir').val()+'site/contact/search.php?m='+maker+'&s='+syasyu;
}

//--------------------------------------------------
// イベントダイアログを開く
//--------------------------------------------------
function show_event_dialog(index)
{
	var content = $('#event_content_'+index).val();
	var title   = $('#event_title_'+index).val();
	var date    = $('#event_date_'+index).val();
	var image2  = $('#event_image2_'+index).val();
	var image3  = $('#event_image3_'+index).val();
	var exist_image = false;

	$('#ui-dialog-title-dialog_event')
		.html(title);
	$('#dialog_event_date')
		.html(date);
	$('#dialog_event_content')
		.html(content);
	var event_image = $('#dialog_event_image');

	event_image.children()
	           .remove();

	var img_count = 0;

	if(image2 != ''){
		event_image.append('<img src="'+image2+'" />');
		exist_image = true;
		img_count++;
	}
	if(image3 != ''){
		event_image.append('<img src="'+image3+'" />');
		exist_image = true;
		img_count++;
	}
	if(exist_image){
		//event_image.css('display', 'block');
		var img_area_height = 600 * img_count;
		event_image.css({
			 'display': 'block'
			,'width'  : '800px'
			,'height' : img_area_height+'px'
			});
	}

	$('#dialog_event').dialog('open');

	location.hash = '#main';
}

//--------------------------------------------------
// イベントダイアログを閉じる
//--------------------------------------------------
function close_event_dialog(index)
{
	$('#dialog_event').dialog('close');
}

//--------------------------------------------------
// トピックスダイアログを開く
//--------------------------------------------------
function show_topics_dialog(index)
{
	var content = $('#topics_content_'+index).val();

	$('#dialog_topics').html(content);

	$('#dialog_topics').dialog('open');
}

//--------------------------------------------------
// トピックスダイアログを閉じる
//--------------------------------------------------
function close_topics_dialog(index)
{
	$('#dialog_topics').dialog('close');
}

