// JavaScript Document

jQuery(function(){
	
	// top_main_nav
	var $top_main_nav = jQuery('.top_main_nav');
	$top_main_nav.find( '.level_1_li' ).hover(
		function(){
			var $this = jQuery(this);
			$this.addClass('hover').find(' > ul').show();
		},
		function(){
			var $this = jQuery(this);
			$this.removeClass('hover').find(' > ul').hide();
		}
	);
	
	// homepage slide album
	new MMJS.SlideAlbum( {
		//selectors
		ds_selector: '.hp_pic_slide ul.ds',  //data source selector
		img_con_selector: '.hp_pic_slide .screen',  //image container selector
		//data default
		default_trans : 'fade',
		//init settings
		auto_start : true,			//the slide will be start after the page is loaded.
		btn_nav_perm_show : false,
		//interval time
		interval: 3, //global interval in seconds
		//transaction flash var
		flash_t_p1: 50,	// flash parse1 in microseconds
		flash_t_p2: 400,	// flash parse2 in microseconds
		//transaction fade var
		fade_t_p1: 'slow',
		fade_t_p2: 'slow',
		//nav
		nav_ul_selector:'.hp_pic_slide ul.ds',
		nav_active_item:null,
		nav_active_class_name:'active',
		// enable inArea ( like click left | right side to toggle the prev | next picture )
		enable_inArea_action:false
	} );
	
	//guesttype radio
	jQuery( 'input[name=guesttype]' ).change(function(){
		var item_num = parseInt(this.value);
		var target_sel = '.guesttype' + item_num + '_form';
		jQuery( '.guesttype_form > div' ).hide().filter(target_sel).show();
	}).first().click();
	
	//INIT js_promotion_nav_ul
	jQuery('.js_promotion_nav_ul > li').click( function(){
		var $this = jQuery( this ).siblings().removeClass('active').end().addClass('active');
		var target_sel = $this.find( 'a' ).attr( 'rel' );
		jQuery('.js_promotion_content_wrap > div').hide().filter(target_sel).show();
	}).hover(
		function(){
			jQuery( this ).addClass( 'hover' );
		},function(){
			jQuery( this ).removeClass( 'hover' );
		}
	).first().click();
	
	new MMJS.SlideWindow({
		//selector
		'list_sel':'.js_promotion_nav_ul',							//LIST
		'data_ul_sel':'.js_promotion_nav_ul',						//UL with the data
		'btn_page_prev_sel':'.js_promotion_prev a',			//PREV按钮
		'btn_page_next_sel':'.js_promotion_next a',			//NEXT按钮
		//var
		'page_mode':'page',					//分页移动的数量 one|page|smo   smo = inshow minus one
		'pos_attr':'top',					//position变动的属性
		'block_px_attr':-80,					//与pos_attr相关的属性的block的值
		'num_inshow':3,							//窗口中显示的数量
		'animate_speed':'fast',			//动画速度
		'default_index':1						//默认选中的项
	});
	

	// INIT gallery_s1
	new MMJS.SlideWindow({
		//selector
		'list_sel':'.js_gallery_s1_nav_ul',							//LIST
		'data_ul_sel':'.js_gallery_s1_nav_ul',						//UL with the data
		'btn_page_prev_sel':'.js_gallery_s1_prev a',			//PREV按钮
		'btn_page_next_sel':'.js_gallery_s1_next a',			//NEXT按钮
		//var
		'page_mode':'page',					//分页移动的数量 one|page|smo   smo = inshow minus one
		'pos_attr':'left',					//position变动的属性
		'block_px_attr':-208,					//与pos_attr相关的属性的block的值
		'num_inshow':3,							//窗口中显示的数量
		'animate_speed':'normal',			//动画速度
		'default_index':1						//默认选中的项
	});
	
	// INIT gallery_s2
	var gallery_s2_slide_window = new MMJS.SlideWindow({
		//selector
		'list_sel':'.js_gallery_s2_nav_ul',							//LIST
		'data_ul_sel':'.js_gallery_s2_nav_ul',						//UL with the data
		'btn_page_prev_sel':'.js_gallery_s2_prev a',			//PREV按钮
		'btn_page_next_sel':'.js_gallery_s2_next a',			//NEXT按钮
		//var
		'page_mode':'page',					//分页移动的数量 one|page|smo   smo = inshow minus one
		'pos_attr':'left',					//position变动的属性
		'block_px_attr':-110,					//与pos_attr相关的属性的block的值
		'num_inshow':7,							//窗口中显示的数量
		'animate_speed':'normal',			//动画速度
		'default_index':1						//默认选中的项
	});

	/* init spec album window */
	var gallery_s2_album = new MMJS.SlideAlbum({
		//selectors
		ds_selector: '.js_gallery_s2_nav_ul',  //data source selector
		img_con_selector: '.js_gallery_s2_image_con',  //image container selector
		//data getter
		get_src : function(){ return this.find('a').first().attr('href') },
		get_alt : function(){ return this.find('a').first().attr('alt') },
		get_title : function(){ return this.find('a').first().attr('title') },
		get_trans : function(){ return this.find('a').first().attr('rel') },
		//data default
		default_src : '',
		default_alt : '',
		default_title : '',
		default_trans : 'fade',
		//init settings
		auto_start : true,			//the slide will be start after the page is loaded.
		btn_nav_fade : false,		//if true ,the [PREV] and [NEXT] will show and hide with fadeIn/fadeOut animation.
		btn_nav_perm_show : true,	//permanently show the [PREV] and [NEXT] btns
		//interval time
		interval: 3, //global interval in seconds
		//transaction flash var
		flash_t_p1: 50,	// flash parse1 in microseconds
		flash_t_p2: 400,	// flash parse2 in microseconds
		//transaction fade var
		fade_t_p1: 'slow',
		fade_t_p2: 'slow',
		callback_goto:function(i){gallery_s2_slide_window.goto(i+1)}
	});

	
	//Init jQuery UI Object
	
	var datepicker_settings = {
		'dayNames': ['星期日','星期一','星期二','星期三','星期四','星期五','星期六'],
		'dayNamesMin': ['日','一','二','三','四','五','六'],
		'monthNames': ['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'],
		'minDate': '+0',
		//'maxDate': '+14d',
		'showMonthAfterYear': true,
		'dateFormat': 'yy-mm-dd'
	};
	

	(function(){
		
		$date_checkin = jQuery('#hp_rb_date_in');
		$date_checkout = jQuery('#hp_rb_date_out');
		
		if( $date_checkin.length && $date_checkout.length ){
		
			function parseDate( str ){
				var ra = /([\d]{4})-([\d]{2})-([\d]{2})/.exec(str);
				return Date.parse(ra[2] + '/' + ra[3] + '/' + ra[1]);
			}
			
			$date_checkin.datepicker(datepicker_settings);//.datepicker( 'setDate' , $date_checkin.val() );
			$date_checkout.datepicker(datepicker_settings);//.datepicker( 'setDate' , $date_checkout.val() ).datepicker( 'option', {'minDate':(new Date( parseDate($date_checkin.val())+24*3600*1000 ) )} );				
			
			$date_checkin.datepicker( 'option', { 
				'onSelect':function(dateText, inst) {
					//alert( ( parseDate(dateText) ) );
					$date_checkout.datepicker( 'option', {'minDate':(new Date( parseDate(dateText)+24*3600*1000 ) ),'maxDate':(new Date( parseDate(dateText)+14*24*3600*1000 ) )} );
				}
			});
			
		}
		
	})();	
	
	
	//INIT js_tab
	jQuery('.js_tab a').click( function(){
		var $this = jQuery(this);
		var target_sel = $this.attr( 'rel' );
		var $target = jQuery( target_sel );
		$this.parents('li').siblings().removeClass('active').end().addClass('active');
		$target.siblings().hide().end().show();
		return false;
	} ).focus(function(){this.blur()}).first().click();
	
	
	//INIT fancybox
	$(".js_fancybox").fancybox({
	});

	$(".js_fancybox_iframe").fancybox({
		'padding':0
	});
	
	//INIT .pic_desc_item .js_show_once , .pic_desc_item .js_hide_once
	jQuery(".pic_desc_item .js_show_once").click(function(){
		var $this = jQuery(this);
		$this.parents('.pic_desc_item').find('.detail').show().end().find('.js_hide_once').show();
		$this.hide();
	});
	jQuery(".pic_desc_item .js_hide_once").click(function(){
		var $this = jQuery(this);
		$this.parents('.pic_desc_item').find('.detail').hide().end().find('.js_show_once').show();
		$this.hide();
	});
	
	/* hp_toggle */
	jQuery('.hp_room_booking .toggle_btn a').click( function(){
		var $this = jQuery(this);
		var $target = jQuery( '.hp_room_booking .form' ).first();
		if ( $target.is(':visible') ){
			$this.removeClass('active');
			$target.hide();
		}else{
			$this.addClass('active');
			$target.show();
		}
		return false;
	}).focus(function(){this.blur();}).click();
	
});
	
