/* UTF-8 編碼
 * --------------------------------------------------------------------
 * init.sitepage.js
 *
 * by Guan-Ting Chen, fi@livemail.tw
 *
 * Copyright (c) 2009 Guan-Ting Chen
 * Licensed under MIT (http://www.opensource.org/licenses/MIT-license.php)
*/
$(document).ready(function () {
	// auxiliary design
	if (0 < $('.table-keyin').length) {
		var input_auxiliary = $('input[class*=auxiliary],textarea[class*=auxiliary]');

		if (0 < input_auxiliary.length) {
			input_auxiliary.each(function () {
				var self = $(this);

				if (undefined != self.attr('title')) {
					self.addClass('input-help');

					if ('' == self.val()) {
						self.addClass('input-help').val(self.attr('title'));
					}

					self.bind('focus', function () {
						$(this).addClass('input-focus');

						if (self.attr('title') == self.val()) {
							self.removeClass('input-help').val('');
						}
					});
		
					self.bind('blur', function () {
						$(this).removeClass('input-focus');

						if ('' == self.val()) {
							self.addClass('input-help').val(self.attr('title'));
						}
					});
				}
			});
		}
	}

	$('a[href*=#page:goback]').bind('click', function (event) {
		history.back();		
	});
	
	$('a[href*=#page:favorite]').bind('click', function (event) {
		event.preventDefault();
		var data = $(this).attr('rel').split('#'); // title, url
		addFavorite(data[1], data[0]);
	});
	
	$('a[href*=#form:submit]').bind('click', function (event) {
		event.preventDefault();
		var self = $(this);
		if ('' == self.attr('rel')) {
			$(this).parents('form:eq(0)').submit();
		} else {
			if (true == confirm(self.attr('rel'))) {
				$(this).parents('form:eq(0)').submit();
			}
		}
	});
});