//淡入淡出時間長短
var fade_duration	=	1200;
var change_pic_duration	= 5000;
var winheight = $(window).height();
var box_20_slider_pos	=	0;
var box_20_slider_count	=	0;

function load_fb(){
//	var fb='<iframe src="http://www.facebook.com/plugins/like.php?href=donnahsu.com&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe>';
//	$('.social_box>.fb_content').append(fb);
}

function initial_ele(){
	
var els	=	new Array('box_0','box_1','box_4','box_12','box_13','box_16');

	var i = 0;
	for (i = 0; i < els.length; i++) {
		var el = els[i];
		$('#' + el).find('.gallery_class').cycle({
			fx: 'fade',
			speed: 1500,
			timeout: 6500,
			startingSlide: 0,
			next: '#'+el+' img',
			pager: '#'+el+' .page'
		});
	}
}

function initial_popup(){
	//box_5 box_17 box_20 box_28
		 $('body').click(
		 	function (event){
				close_all_popup();
			}
		 );			
		 $('#box_container').click(
		 	function (event){
				close_all_popup();
			}
		 );			
	
	$('#box_5').click(function(event){
		close_all_popup();
		var pop_width	=	$('#box_5 .popup_box .popup_bg1').width();
		pop_width	+= $('#box_5').width();	
		//計算popup box 要出來的位置	
		cal_pop_position('box_5' , pop_width);
		$('#box_5 .popup_box').css('width','0px');
		//設定圖片輪撥
		var el 	='box_5';
		$('#'+el).find('.popup_box ul').cycle({
			fx: 'popup_fade',
			speed: 1500,
			timeout: 6500,
			startingSlide: 0,
			next:   '#box_5 .btn_right',
			prev:   '#box_5 .btn_left'
		});		
		event.stopPropagation();
			$('#box_5').mouseleave(
			function(){
				close_all_popup();
			}
		);			
	});
	
	
	$('#box_20').click(function(event){
		close_all_popup();
		
		$('#box_20').addClass('_open');
		var pop_width	=	$('#box_20 .popup_box .cloud_box').width();
	 	pop_width	+=	$('#box_20 .popup_box .paperwal_box').width();
		pop_width	+= 170;
		//計算popup box 要出來的位置
		cal_pop_position('box_20', pop_width);
		
		//設定圖片輪撥
		var el 	='box_20';
		$('#box_20').find('.paperwal_box ul').cycle({
			fx: 'fade',
			timeout: 0,
			startingSlide: 0,
			next:   '#box_20 .paperwal_box li img',
			after: function(curr,next,opts){
				box_20_slider_pos = opts.currSlide;
				
				$('#box_20 .load_info a').each(
					function(i){
						$(this).click(function(event){
							event.stopPropagation();
						});
						
						if(i==0){
							this.href	= 'image/wallpaper/0'+(box_20_slider_pos +1)+'_a.jpg';
						}
						else{
							this.href	=	 'image/wallpaper/0'+(box_20_slider_pos +1)+'_b.jpg';
						}	
					}
				);
			}
		});
		
		event.stopPropagation();
		$('#box_20').mouseleave(
			function(){
				close_all_popup();
			}
		);
		
		
	});
	
	
	$('#box_17').click(function(event){
		close_all_popup();
		
		$('#box_17').addClass('_open');
		var pop_width	=	$('#box_17 .popup_box .popup_bg1').width();
		pop_width	+= 170;
		//計算popup box 要出來的位置
		cal_pop_position('box_17', pop_width);
		
		//設定圖片輪撥
		$('#box_17').find('.popup_box ul').cycle({
			fx: 'popup_fade',
			speed: 1500,
			timeout: 6500,
			startingSlide: 0,
			next:   '#box_17 .btn_right',
			prev:   '#box_17 .btn_left'
		});
		
		event.stopPropagation();
		$('#box_17').mouseleave(
			function(){
				close_all_popup();
			}
		);		
	});	
	
	
	$('#box_28').click(function(event){
		close_all_popup();
		
		$('#box_17').addClass('_open');
		var pop_width	=	$('#box_28 .popup_box .popup_bg1').width();
		pop_width	+= 170;
		//計算popup box 要出來的位置
		cal_pop_position('box_28', pop_width);
		
		//設定圖片輪撥
		$('#box_28').find('.popup_box ul').cycle({
			fx: 'popup_fade',
			speed: 1500,
			timeout: 6500,
			startingSlide: 0,
			next:   '#box_28 .btn_right',
			prev:   '#box_28 .btn_left'
		});
		
		event.stopPropagation();
		
	});		
	
}

function close_all_popup(){
	
	
	var pop_box	=		$('#box_20 .popup_box');
	if( !pop_box.hasClass('nosee')){
		pop_box.addClass('nosee');
		$('#box_20').removeClass('_open');
	}
	
	pop_box	=		$('#box_28 .popup_box');
	if( !pop_box.hasClass('nosee')){
		pop_box.addClass('nosee');
	}	
	pop_box	=		$('#box_5 .popup_box');
	if( !pop_box.hasClass('nosee')){
		pop_box.addClass('nosee');
	}		
	pop_box	=		$('#box_17 .popup_box');
	if( !pop_box.hasClass('nosee')){
		pop_box.addClass('nosee');
	}		
}

function cal_pop_position(pop_id , pop_width ){
	
	var header_width = $('#box_container').width();
	$('#'+pop_id+' .popup_box').removeClass('nosee');
	
	var pop_pos		=	$('#'+pop_id).position();
		//判斷右邊是否會超過
		if( (pop_pos.left + pop_width ) > header_width ){
			if($('#'+pop_id+' .popup_box').hasClass('_cowben'))
				$('#'+pop_id+' .popup_box').removeClass('_cowben');
		}
		else{
			if( !$('#'+pop_id+' .popup_box').hasClass('_cowben'))
				$('#'+pop_id+' .popup_box').addClass('_cowben');
		}	
}

function close_popup(pop_id){
	alert($('#box_20').hasClass('_open'));
	$('#box_20').removeClass('_open');
	$(pop_id +' .popup_box').addClass('nosee');
}



function initial_show_box(){
	var $win = $(window);
	$win.bind('scroll resize', function(){
		move_showbox(0);
	}).scroll();	// 觸發一次 scroll()
	//
	$('#donna_hsu_linkbtn').click(
		function(){
			open_show_box('donna_hsu'+lang ,
				function(){
					hide_quick_nav();
				}
			);
		}
	);
	//快速導覽裡的六藝故事
	$('#donnahsulinkbtn').click(
		function(){
			open_show_box('donna_hsu'+lang ,
				function(){
					hide_quick_nav();
				}
			);
		}
	);
		
	
	$('#store_index_linkbtn').click(
		function(){
			open_show_box('store_index'+lang , 
				function (){
					
					hide_quick_nav();				
					
					$('#second_layer').click(
					function(event){
						event.stopPropagation();
					});
				//增加第二層觸發事件
					$('#showbox_div').find('.alpha_bg ._td ._point').each(
						function (i,v){
							$(this).click(
								function(){
									var index = i+1;
									if($('#second_layer').html() != '')
										$('#second_layer').fadeOut('fast');	
									$('#second_layer').load('showbox/store'+lang+'/store_'+index+'.html',
										function(){
											var border_width	=	0;
											var layer_width = $('#second_layer').width() - border_width*2 ;
											
											var winwidth	=	$(window).width();
											var left_pos	=  (winwidth - layer_width )/2 - border_width;	
																						
									        $.blockUI({ 
									            message: $('#second_layer') ,
												css: { left:left_pos+'px' , top:'30%' , width:layer_width , border: 'none'}
									           }); 
											$('#second_layer').fadeIn('fast');
											$('.blockOverlay').click(
												function(){
													$.unblockUI();
													$('#second_layer').html('');
												}
											);
											//增加close_btn關閉事件
											$('#second_layer .second_close_btn').click(
													function(event){
														$('#second_layer').fadeOut(
															function (){
																 $.unblockUI();
																 $('#second_layer').html('');
															}
														);
														event.stopPropagation();
													}
											);
										}
									);
								}
							);
						}
					);				
					
				}
			
			);

		}
	);	
	var image_box	=	new Array('box_3' 	, 'box_19' , 'guidelinkbtn');	
	var i = 0;
	for (i = 0; i < image_box.length; i++) {
		var box	=	image_box[i];
		$('#'+box).click(function(){
			open_show_box('guidebook' , function(){
					$('#nav_control_div').attr('title','open navigetion');
					$('#nav_control_div').html('快速導覽 <img class="icons_01" src="css/css_img/hold.gif" />');
					$("#nav_show_div").fadeOut("slow");					
				set_showbox_play();
				
			});
		});
	}		
	
 	image_box	=	new Array(	'box_8' 	, 'box_9'  	, 'box_7'	, 'box_10'  , 'imagebookbtn'
								, 'box_15' 	, 'box_18' 	,'box_21'	, 'box_23'	, 'box_26'
								,'box_27'	, 'box_29'	,'box_30'	, 'box_31'	, 'box_32'
								,'box_33'	 );
	for (i = 0; i < image_box.length; i++) {
		var box	=	image_box[i];
		$('#'+box).click(function(){
			open_show_box('image_book' , function(){
					$('#nav_control_div').attr('title','open navigetion');
					$('#nav_control_div').html('快速導覽 <img class="icons_01" src="css/css_img/hold.gif" />');
					$("#nav_show_div").fadeOut("slow");					
				set_showbox_play();
			});
		});
	}	
		
}

function set_showbox_play(){
						//加入輪播
		$('#showbox_div').find('.img_box ul').cycle({
						fx: 'fade',
						speed: 1500,
						timeout: 6500,
						startingSlide: 0,
						next:   '#showbox_div .btn_right',
						prev:   '#showbox_div .btn_left'
		});		
	
}

function move_showbox(default_padding){
	
	if($('#showbox_div').css('display') != 'none'){
		win_obj	=	$(window);
		winheight	=	win_obj.height();
		var content_height	=	$('#showbox_div .show_box').height();
		var padd_top	=	default_padding + win_obj.scrollTop() + ( (winheight - content_height) / 2 );
		if(content_height > winheight)
			padd_top	=	0;
		$('#showbox_div .alpha_bg').css('padding-top',padd_top+'px');
		$('#showbox_div .loading').css('padding-top',padd_top+'px');
	}
}

function resize_showbox(){
	var header_width = $('#header_container').css('width');
	$('#showbox_div').css('width' , $(document).width());	
	$('#showbox_div').css('height' , $(document).height());		
}

function open_show_box(link_page , loaded_func){
	resize_showbox();
	
	$('#showbox_div').css('display','block');
	$('#showbox_div').html('<div class="loading show_box">Loading</div>');
	
		win_obj	=	$(window);
		//winheight	=	win_obj.height();
		var content_height	=	100;
		var padd_top	=	win_obj.scrollTop() + ( (winheight - content_height) / 2 );
		if(content_height > winheight)
			padd_top	=	0;
		$('#showbox_div .loading').css('padding-top',padd_top+'px');	
	
	
	$('#showbox_div').load('showbox/'+link_page+'.html',
		function(){
			move_showbox(0);
			
			$('#showbox_div .show_box').click(function(event){
				event.stopPropagation();				
			});
			$('#showbox_div .close_btn').click(
				function(){
					$('#showbox_div').html('');
					winheight	=	$(window).height();
					$('#showbox_div').hide();
				}
			);
			$('#showbox_div .alpha_bg').click(
				function(){
					$('#showbox_div').html('');
					winheight	=	$(window).height();
					$('#showbox_div').hide();
				}
			);			
			
			loaded_func.call();
		}
	);
	
}



