/**
* Diary js functions
**/

diaryControlDiary2Init = function() {
    // 更改回應狀態功能
    $('select[name="replyOn"]').change(function() {
        var id = $(this).attr('id');
        var res = $('option:selected', this).val();
        $('#modal').html('處理中...').jqmShow();
        $.ajax({
            url: 'ajax_diary_reply_on.php',
            type: 'post',
            cache: false,
            data: {id: id, res: res},
            success: function(data) {
                $('#modal').html(data);
                setTimeout(function() {
                    $('#modal').html('').jqmHide();
                }, 1500);                
            },
            error: function() {
                setTimeout(function() {
                    $('#modal').html('').jqmHide();
                }, 1500);
            }
        });
    });
    
    // modal
    $('#modal').jqm({modal: true});
}

// diary control photo2_4 page initial
drama.diaryControlPhotos2_4 = function() {
	var cate = $('#cate option:selected').val();
	
	$('#cate').change(function() {
		$('#file').fileUploadSettings('scriptData','&cate='+$('#cate option:selected').val()+'&id='+$('#id').val());
	});
	
	// button upload
	$('#btnUpload').click(function() {
		if ($('#select option:selected') == '') {
			alert('請先建立目錄');		
		} else {
			$('#file').fileUploadStart();
		}
	});
	
	// upload modify
	$('#file').fileUpload({
		uploader: 'uploader.swf',
		script: 'ajax_multi_upload.php',
		cancelImg: 'cancel.png',
		scriptData: {cate: cate, id: $('#id').val()},
		auto: false,
		multi: true,
		fileDesc: 'JPG',
		fileExt: '*.jpg',
		sizeLimit: 1500000,
		simUploadLimit: 5,
		buttonImg: 'images/diary_search/bn_control_browse.gif	',
		width: 61,
		height: 24,
		wmode: 'transparent',
		onError: function(a, b, c, d) {
			if(d.type == 'File Size') {
				$('#log').html($('#log').html() + c.name + ' 檔案大小超過規定' + '<br>');
			}
		},
		onComplete: function(a, b, c, d, e) {
			if(d == '0') {
				$('#log').html($('#log').html() + c.name + ' 上傳發生錯誤' + '<br>');
			}
		}
	});
	
}

// diary gallery detail page init
drama.diaryGalleryDetailInit = function() {
	// modal initial
	$('#transfer, #complain').jqm({modal: true});
	
	// complain submit button
	$('#btnComplainSubmit').click(function() {
		var username = $('#complain_username').val();
		var reason = $('#complain_reason').val();
		var contents = $('#complain_contents').val();
		$.ajax({
			url: 'ajax_diary_complain.php',
			cache: false,
			type: 'post',
			data: {username: username, reason: reason, contents: contents},
			success: function(data) {
				alert(data);
				if ($.trim(data) == '順利發送') {
					$('#complain').jqmHide();
				}
			}
		});
		return false;
	});
	
	// transfer submit button
	$('#btnTransferSubmit').click(function() {
		var name = $('#transer_name').val();
		var email = $('#transer_email').val();
		var contents = $('#transer_message').val();
		var rndNum = $('#rndNum').val();
		$.ajax({
			url: 'ajax_diary_transfer_to_friend.php',
			cache: false,
			type: 'post',
			data: {name: name, email: email, contents: contents, rndNum: rndNum },
			success: function(data) {
				alert(data);
				if ($.trim(data) == '轉寄成功') {
					$('#transfer').jqmHide();
				}
			}
		});
		return false;
	});
	
	// transfer button
	$('#btnTransfer').click(function() {
		$('#transfer').jqmShow();
		return false;
	});
	
	// complain button
	$('#btnComplain').click(function() {
		$('#complain').jqmShow();
		return false;
	});
}

// diary control friend1 initial
drama.diaryControlFriend1Init = function() {
	$('#username').focus();
	
	// save all button
	$('#btnSaveAll').click(function() {
		var s = 'func=upd&'
		var arr = [];
		$('[name="box[]"]').each(function() {
			arr.push('id[]=' + $(this).attr('id') + '&nickName[]=' + $(this).parents('tr').find('[name="nickName"]').val());
		});
		s += arr.join('&');
		$('#block').html('儲存中....').jqmShow();
		$.ajax({
			url: 'ajax_diary_friend_func.php',
			type: 'post',
			cache: false,
			data: s,
			success: function(data) {
				$('#block').html(data);
				setTimeout(function() {
					$('#block').html('').jqmHide();
				}, 1500);
			},
			error: function() {
				$('#block').html('發生錯誤');
				setTimeout(function() {
					$('#block').html('').jqmHide();
				}, 1500);
			}
		});
		return false;
	});
	
    // 儲存圖片
    $('img[name="imgSave"]').each(function() {
        $(this).hover(function() {
            $(this).attr('src', 'images/diary_search/diary_control_photo_over_07.gif');
        }, function() {
            $(this).attr('src', 'images/diary_search/diary_control_photo_07.gif');
        });
    });
    
	// save button
	$('[name="btnSave"]').each(function() {
		$(this)
            .click(function() {
			    var id = $(this).parents('tr').find('[name="box[]"]').attr('id');
			    var nickName = $(this).parents('tr').find('[name="nickName"]').val();
			    $('#block').html('儲存中....').jqmShow();
			    $.ajax({
				    url: 'ajax_diary_friend_func.php',
				    type: 'post',
				    cache: false,
				    data: {func: 'upd', 'id[]': id, 'nickName[]': nickName},
				    success: function(data) {
					    $('#block').html(data);
					    setTimeout(function() {
						    $('#block').html('').jqmHide();
					    }, 1500);
				    },
				    error: function() {
					    $('#block').html('發生錯誤');
					    setTimeout(function() {
						    $('#block').html('').jqmHide();
					    }, 1500);
				    }
			    });
			    return false;
		    });
	});
	
	// delete all
	$('#btnDelAll').click(function() {
		if ($('[name="box[]"]:checked').size() == 0) {
			alert('請至少選一項');
		} else {
			if (confirm('確定要刪除嗎？')) {
				var s = 'func=del&';
				var arr = [];
				$('[name="box[]"]:checked').each(function() { 
					var id = $(this).attr('id');
					arr.push('id[]=' + id);
				});
				s += arr.join('&');
				
				$('#block').html('刪除中....').jqmShow();
				$.ajax({
					url: 'ajax_diary_friend_func.php',
					cache: false,
					type: 'post',
					data: s,
					success: function(data) {
						$('#block').html(data);
						window.location.reload();
					},
					error: function() {
						$('#block').html('發生錯誤');
						setTimeout(function() {
							$('#block').html('').jqmHide();
						}, 1500);
					}
				});
			}
		}
		return false;
	});
	
	// check all button
	$('#checkAll').click(function() {
		if ($(this).data('chk') != 1) {
			$('[name="box[]"]').attr('checked', 'checked');
			$(this).data('chk', 1);
		} else {
			$('[name="box[]"]').attr('checked', false);
			$(this).data('chk', 0);
		}
		
		return false;
	});
	
	// delete button
	$('[name="btnDel"]').each(function() {
		$(this).click(function() {
			var id = $(this).parents('tr').find('[name="box[]"]').attr('id');
			if (confirm('確定要刪除嗎？')) {
				$('#block').html('刪除中....').jqmShow();
				$.ajax({
					url: 'ajax_diary_friend_func.php',
					cache: false,
					type: 'post',
					data: {func: 'del', 'id[]': id},
					success: function(data) {
						$('#block').html(data);
						window.location.reload();
					},
					error: function() {
						$('#block').html('發生錯誤');
						setTimeout(function() {
							$('#block').html('').jqmHide();
						}, 1500);
					}
				});
			}
			return false;
		});
	});
	
	// add button
	$('#btnAdd').click(function() {
		if ($.trim($('#username').val()) == '') {
			alert('請填寫帳號');
			$('#username').focus();
		} else {
			switch ($('[name="tell"]:checked').val()) {
				case '1':
					// 要通知
					if ($.trim($('#contents').val()) == '') {
						alert('請輸入留言內容');
					} else {
						$('#block').html('查詢中....').jqmShow();
						$.ajax({
							url: 'ajax_diary_friend.php',
							cache: false,
							type: 'post',
							data: {name: $('#username').val(), nick: $('#nickName').val(), tell: $('[name="tell"]:checked').val(), contents: $('#contents').val()},
							success: function(data) {
								$('#block').html(data);
								window.location.reload();
							},
							error: function() {
								$('#block').html('發生錯誤');
								setTimeout(function() {
									$('#block').html('').jqmHide();
								}, 1500);
							}
						});
					}
					break;
				case '0':
					// 不通知
					$('#block').html('查詢中....').jqmShow();
					$.ajax({
						url: 'ajax_diary_friend.php',
						cache: false,
						type: 'post',
						data: {name: $('#username').val(), nick: $('#nickName').val(), tell: $('[name="tell"]:checked').val(), contents: $('#contents').val()},
						success: function(data) {
							$('#block').html(data);
							window.location.reload();
						},
						error: function() {
							$('#block').html('發生錯誤');
							setTimeout(function() {
								$('#block').html('').jqmHide();
							}, 1500);
						}
					});
					break;
			}
		}
		return false;
	});
	
	// modal initial
	$('#block').jqm({modal: true});
}

// diary control messenger1 page initial
drama.diaryControlMessenger1Init = function() {
    // change status
    $('img[name="btnShow"], img[name="btnHide"]').each(function() {
        $(this).click(function() {
            var $id = $(this).attr('id'),
                $way = $(this).attr('way');
            $('#block').html('變更中...').jqmShow();
            $.post('ajax_board_status.php', {id: $id, way: $way}, function(data) {
                $('#block').html(data);
                if (data == '變更成功') {
                    setTimeout(function() {
                        window.location.reload();
                    }, 1500);
                } else {
                    setTimeout(function() {
                        $('#block').html('').jqmHide();
                    }, 1500);
                }
            });
        });
    });
    
    // delete message
    $('img[name="btnDel"]').each(function() {
        $(this).click(function() {
            if (confirm('確定要刪除嗎？')) {
                var $id = $(this).attr('id');
                $('#block').html('刪除中...').jqmShow();
                $.post('ajax_board_del.php', {id: $id}, function(data) {
                    $('#block').html(data);
                    if (data == '刪除成功') {
                        setTimeout(function() {
                            window.location.reload();
                        }, 1500);
                    } else {
                        setTimeout(function() {
                            $('#block').html('').jqmHide();
                        }, 1500);
                    }
                });
            }
        });
    });

	// submit button
	$('[name="btnSubmit"]').each(function() {
		$(this).click(function() {
			var id = $(this).attr('id'),
			    contents = $(this).parents('.replyContent').find('[name="replay"]').val(),
                secret;
			if ($(this).parents('.replyContent').find('[name="secret"]').is(':checked')) { secret = 1; } else { secret = 0 };
			$('#block').html('儲存中....').jqmShow();
			$.ajax({
				url: 'ajax_diary_board_reply.php',
				cache: false,
				type: 'post',
				data: {id: id, contents: contents, secret: secret},
				success: function(data) {
					$('#block').html(data);
					setTimeout(function() {
                        window.location.reload();
						$('#block').jqmHide();
					}, 1500);
				},
				error: function() {
					$('#block').jqmHide();
				}
			});
		});
		
	});
	
	// modal initial
	$('div#block').jqm({modal: true});
	
	// reply button
	$('[name="btnReply"]').each(function(i) {
		$(this).click(function() {
			$('div.replyContent').eq(i).toggle();
		});
	});
    
    $('[name="btnCancel"]').each(function(i) {
        $(this).click(function() {
            $('div.replyContent').eq(i).toggle();
        });
    });
	
	// mouseover effection
	$('[name="btnDel"], [name="btnHide"], [name="btnReply"], [name="btnCancel", [name="btnSubmit"]]').each(function() {
		$(this).data('hoverImg', {on: $(this).attr('src').replace('_messenger_', '_messenger_over_'), out: $(this).attr('src')});
		$(this).hover(function() {
			$(this).attr('src', $(this).data('hoverImg').on);
		}, function() {
			$(this).attr('src', $(this).data('hoverImg').out);
		});
	});
}

// diary messenger page initial
drama.diaryMessengerInit = function() {
	$('#subject').focus();
	
	// cancel button
	$('#btnCancel').click(function() {
		var frm = $('#messengerForm');
		$('input, textarea', frm).val('');
		$('#secret', frm).attr('checked', false);
		$('#subject', frm).focus();
		return false;
	});
}
		
// diary gallery large page initial
drama.diaryGalleryLarge = function() {
	// modal initial
	$('#transfer, #complain').jqm({modal: true});
	
	// complain submit button
	$('#btnComplainSubmit').click(function() {
		var username = $('#complain_username').val();
		var reason = $('#complain_reason').val();
		var contents = $('#complain_contents').val();
		var rndNum = $('#rndNum').val();
		$.ajax({
			url: 'ajax_diary_transfer_to_friend.php',
			cache: false,
			type: 'post',
			data: {name: name, email: email, contents: contents, rndNum: rndNum },
			success: function(data) {
				alert(data);
				if ($.trim(data) == '順利發送') {
					$('#complain').jqmHide();
				}
			}
		});
		return false;
	});
	
	// transfer submit button
	$('#btnTransferSubmit').click(function() {
		var name = $('#transer_name').val();
		var email = $('#transer_email').val();
		var contents = $('#transer_message').val();
		$.ajax({
			url: 'ajax_diary_transfer_to_friend.php',
			cache: false,
			type: 'post',
			data: {name: name, email: email, contents: contents },
			success: function(data) {
				alert(data);
				if ($.trim(data) == '轉寄成功') {
					$('#transfer').jqmHide();
				}
			}
		});
		return false;
	});
	
	// transfer button
	$('#btnTransfer').click(function() {
		$('#transfer').jqmShow();
		return false;
	});
	
	// complain button
	$('#btnComplain').click(function() {
		$('#complain').jqmShow();
		return false;
	});
	
	// copy navigator
	$('.gallery_large_page:eq(1)').html($('.gallery_large_page:eq(0)').html());
}

// diary gallery page initial
drama.diaryGalleryInit = function() {

}

// diary control photo1 page initial
drama.diaryControlPhoto1Init = function() {
	// save button define
	$('a[name="btnSave"]').each(function() {
		$(this).click(function() {
			var id = $(this).attr('id');
			var tr = $(this).parents('table').parents('tr');
			var name = tr.find('input#name').val();
			var cate = tr.find('select#category option:selected').val();
			var desc = tr.find('input#description').val();
			
			if ($.trim(name) == '') {
				alert('請填寫相簿名稱');
			} else {
				$('div#block').html('儲存中....').jqmShow();
				$.ajax({
					url: 'ajax_album_list_save.php',
					cache: false,
					type: 'post',
					data: {id: id, name: name, cate: cate, desc: desc},
					success: function(data) {
						$('div#block').html(data);
						setTimeout(function() {
							$('div#block').jqmHide();
						}, 1500);					
					},
					error: function() {
						$('div#block').html('發生錯誤');
						setTimeout(function() {
							$('div#block').jqmHide();
						}, 1500);	
					}
				})
			}
			
			return false;
		});
	});
	
	// modal init
	$('div#block').jqm({modal: true});
}

// diary content page initial
drama.diaryContentInit = function() {
	// 選擇網址
	$('input#userUrl').click(function() {
		$(this).select();
	});
}

// diary read detail page initial
drama.diaryReadDetailInit = function(username) {
	$('div#block').jqm({modal: true});
	$('div#diaryReply').jqm({model: true});
	
	// 版主回應
	$('a[name="ownerReply"]').click(function() {
		var aid = $(this).attr('id');
		$.ajax({
			url: 'ajax_owner_reply.php',
			cache: false,
			success: function(data) {
				$('div#diaryReply').html(data).jqmShow();
			},
			complete: function() {
				$('input#btnOwnerSubmit').click(function() {
					if ($.trim($('#ownerRe').val()) == '') {
						alert('請輸入內容');
						$('#ownerRe').focus();
					} else {
						if (confirm('確定要送出嗎？')) {
							$('input#btnOwnerSubmit').attr('disabled', true);
							$('img#ajaxLoading').show();
							$.ajax({
								url: 'ajax_diary_owner_reply.php',
								cache: false,
								dataType: 'json',
								type: 'POST',
								data: {id: aid, contents: $('#ownerRe').val()},
								success: function(data) {
									alert(data.msg);
									if (data.msg == '回覆完成') {
										window.location.reload();
									} else {
										alert(data.msg);
										$('input#btnOwnerSubmit').attr('disabled', false);
										$('img#ajaxLoading').hide();
									}
								}
							});
						}
					}
					return false;
				});
				$('div#diaryReply').jqmAddClose('input#btnOwnerClose');
			}
		});
		return false;
	});
	
	// 回應功能
	$('input#btnReply').click(function() {
		$('div#block').html('回應中....').jqmShow();
		$.ajax({
			url: 'ajax_article_reply.php',
			type: 'POST',
			dataType: 'json',
			cache: false,
			data: $('form#formReply').serialize(),
			success: function(data) {
				$('div#block').html(data.msg);
				if (data.msg == '回應成功') {
					setTimeout(function() {
						window.location.reload();
					}, 2000);
				} else {
					setTimeout(function() {
						$('div#block').jqmHide();
					}, 2000);					
				}
			}
		});
		return false;
	});

	// 推薦按鈕
	$('a#btnRecommend').click(function() {
		$('div#block').html('處理中....').jqmShow();
		var aid = $(this).attr('aid');
		$.ajax({
			url: 'ajax_diary_recommend.php',
			cache: false,
			type: 'GET',
			data: {aid: aid},
			dataType: 'json',
			success: function(data) {
				$('div#block').html(data.msg);
				setTimeout(function() {
					$('div#block').jqmHide();
				}, 1500);
			}
		});
		return false;
	});
	
	// 內文縮圖
	$(window).load(function() {
		var div = $('div#imgResize');
		$('img', div).each(function() {
			if ($(this).width() > 500) {
				$(this).width(500);
			}
		});
	});
	
	// load 肖像
	var container = $('div#diary_information_pic2');
	$.ajax({
		url: 'ajax_load_portrait.php',
		type: 'GET',
		cache: false,
		data: {name: username},
		success: function(data) {
			var res = $(data).filter('div#res').html();
			container.html(res);
		}
	});
}

// diary read page initial
drama.diaryReadInit = function(username) {
	// 內文縮圖
	$(window).load(function() {
		var div = $('div#imgResize');
		$('img', div).each(function() {
			if ($(this).width() > 500) {
				$(this).width(500);
			}
		});
	});
	
	// load 肖像
	var container = $('div#diary_information_pic2');
	$.ajax({
		url: 'ajax_load_portrait.php',
		type: 'GET',
		cache: false,
		data: {name: username},
		success: function(data) {
			var res = $(data).filter('div#res').html();
			container.html(res);
		}
	});
}

// diary control diary1 page initial
drama.diaryContorlDiary1Init = function() {
    // modal initial
	$('div#block')
		.addClass('jqmWindow')
		.jqm({modal: true});
		
	// 回應功能
	$('select[name="reply"]').change(function() {
		var opt = $('option:selected', this).val();
		var mdid = $(this).attr('id');
		$('div#block').html('處理中').jqmShow();
		$.ajax({
			url: 'ajax_diary_reply.php',
			cache: false,
			type: 'GET',
			dataType: 'json',
			data: {mdid: mdid, val: opt},
			success: function(data) {
				$('div#block').html(data.msg);
				setTimeout(function() {
					$('div#block').jqmHide();
				}, 1500);
			}
		});
	});
	
	// 刪除按鈕
	$('#btnDel').click(function() {
		var chk = $('input[name="chk"]:checked');
		if (chk.size() == 0) {
			alert('請至少選一項');
		} else {
			if (confirm('確定要刪除嗎？')) {
				var str = '';
				chk.each(function() {
					str += 'id[]=' + $(this).attr('id') + '&';
				});
				
				$('div#block').html('處理中....').jqmShow();
				$.ajax({
					url: 'ajax_diary_del.php',
					cache: false,
					data: str,
					type: 'POST',
					dataType: 'json',
					success: function(data) {
						if (data.err != '') {
							$('div#block').html(data.err);
							setTimeout(function() {
								$('div#block').jqmHide();
							}, 3000);
						} else {
							$('div#block').html(data.res);
							setTimeout(function() {
								window.location.reload();
							}, 3000);
						}
					}
				});
			}
		}
	});
	
	// 目錄切換
	$('select#diaryCategory').change(function() {
		var opt = $('option:selected', this).val();
		window.location = '?diary_category=' + opt;
	});
}

// diary control diary4 edit page initial
drama.diaryControlDiary4EditInit = function() {
	$('input#subject').focus();
	
	// 載入fckeditor
	var o = new FCKeditor('contents');
	o.BasePath = '/fckeditor/';
	o.Width = 700;
	o.Height = 400;
	o.ToolbarSet = 'drama';
	o.ReplaceTextarea();
}

// diary control diary4 page initial
drama.diaryControlDiary4Init = function() {
	$('input#subject').focus();
		
	// 載入地圖
	if (GBrowserIsCompatible()) {
		var dPoint = new GLatLng(25.0342808, 121.5170595),  // 起始座標點
        $symIcon = new GIcon(),
        $markers_array = new Array();
		map = new GMap2(document.getElementById('googlemap'));
		map.addControl(new GSmallMapControl()); // 方向移動功能
		map.addControl(new GMapTypeControl()); // 地圖類型
        
        $symIcon.image = 'http://www.motorlove.com.tw/images/sym.png';
        $symIcon.iconSize = new GSize(41, 32);
        $symIcon.shadow = 'http://www.motorlove.com.tw/images/symShadow.png';
        $symIcon.shadowSize = new GSize(50, 39);
        $symIcon.iconAnchor = new GPoint(13, 25);
        $symIcon.infoWindowAnchor = new GPoint(0, 0);

        function createMarker($p, $html, $icon) {
            var $marker = new GMarker($p, {icon: $icon});
            GEvent.addListener($marker, 'click', function() {
                $marker.openInfoWindowHtml($html);
            });
            return $marker;
        }

        GDownloadUrl('store_xml.php', function($doc) {
            var $xmlDoc = GXml.parse($doc),
                $markers = $xmlDoc.documentElement.getElementsByTagName('m'),
                $len = $markers.length;
                
            for (i = 0; i < $len; i++) {
                var $lat = $markers[i].getAttribute('lat'),
                    $lng = $markers[i].getAttribute('lng'),
                    $html = $markers[i].getAttribute('c'),
                    $p = new GLatLng($lat, $lng);
                $markers_array.push(createMarker($p, $html, $symIcon));
            }
            
            var $mm = new GMarkerManager(map, {borderPadding: 1});
            $mm.addMarkers($markers_array, 0);
            $mm.refresh();
        });
		
		map.setCenter(dPoint, 15);
	}
	
	// 地址搜尋功能
	$('input#mapSearch').click(function() {
		var gencoder = new GClientGeocoder();
		var address = $('input#address').val();
		gencoder.getLatLng(address, function(point) {
			if (!point) {
				alert('找不到該地址！')
			} else {
				map.setCenter(point, 15);
				var marker = new GMarker(point, {draggable: true});
				$('input#lat').val(point.lat());
				$('input#lng').val(point.lng());
				map.addOverlay(marker);
				
				GEvent.addListener(marker, 'dragend', function() {
					$('input#lat').val(marker.getPoint().lat().toFixed(7));
					$('input#lng').val(marker.getPoint().lng().toFixed(7));
				});
			}
		});
	});
	
	// 載入fckeditor
	var o = new FCKeditor('contents');
	o.BasePath = '/fckeditor/';
	o.Width = 700;
	o.Height = 400;
	o.ToolbarSet = 'drama';
	o.ReplaceTextarea();
}

// map 找尋地點
function showAddress(a) {
	var ret = new GClientGeocoder();
	ret.getLatLng(a, function(point) {
		if (!point) {
			return '找不到';
		} else {
			map.setCenter(point, 15);
		}
	});
}

// diary control page initial
drama.diaryControlContentPageInit = function() {
	// modal initial
	$('div#block').jqm({modal: true});
	
	var frm = $('form#memberForm');
	
	// reset button
	$('input#btnReset').click(function() {
		window.history.back();
		return false;
	});
	
	// upload button
	$('input#btnUpload').click(function() {
		$('div#block').html('圖片上傳中').jqmShow();
		$.ajaxFileUpload({
			url:'ajaxUpload.php', 
			secureuri:false,
			fileElementId:'myImg',
			dataType: 'json',
			success: function (data, status) {
				$('input#myImg').val('');
				if(typeof(data.err) != 'undefined') {
					if(data.err != '') {
						$('div#block').html(data.err);
						setTimeout(function() {
							$('div#block').jqmHide();
						}, 1500);
					} else {
						$('div#block').html(data.msg);
						setTimeout(function() {
							$('div#block').jqmHide();
							drama.diaryLoadPortrait2() // 觸動Ajax即時load圖片
						}, 1500);
					}
				}
			},
			error: function (data, status, e) {
				$('div#block').html(e);
				setTimeout(function() {
							$('div#block').jqmHide();
						}, 1500);
			}
		});
	});
}

// ajax即時load圖片
drama.diaryLoadPortrait2 = function() {
	var imgContainer = $('dd.control_photo');
	$.ajax({
		url: 'ajax_load_portrait2.php',
		cache: false,
		type: 'GET',
		success: function(data) {
			imgContainer.html($(data).filter('div#res').html());
		}
	});
}

// load portrait
drama.loadPortrait = function(username) {
	// load 肖像
	var container = $('div#diary_information_pic2');
	$.ajax({
		url: 'ajax_load_portrait.php',
		type: 'GET',
		cache: false,
		data: {name: username},
		success: function(data) {
			var res = $(data).filter('div#res').html();
			container.html(res);
		}
	});
}