// 初始化 - Jquery_auto.js
$.auto = {
	init: function() {
		for (module in $.auto) {
			if ($.auto[module].init)
				$.auto[module].init();
		}
	}
};

// 自动隐藏元素
$.auto.hide = {
	init: function() {
		$('.Hide').hide();
	}
};


// 鼠标移动显示
$.auto.hover = {
	init: function() {
		$('IMG.Hover')
			.bind('mouseover', this.enter)
			.bind('mouseout', this.exit)
			.each(this.preload);
	},
	preload: function() {
		this.preloaded = new Image;
		this.preloaded.src = this.src.replace(/^(.+)(\.[a-z]+)$/, "$1_over$2");
	},
	enter: function() {
		this.src = this.src.replace(/^(.+)(\.[a-z]+)$/, "$1_over$2");
	},
	exit: function() {
		this.src = this.src.replace(/^(.+)_over(\.[a-z]+)$/, "$1$2");
	}
};


// 鼠标显示大图
$.auto.show_large_photo = {
	init: function() {
		$('IMG.show_large_photo')
			.bind('mouseover', this.enter)
			.bind('mouseout', this.exit)
			.each(this.preload);
	},
	preload: function() {
		this.preloaded = new Image;
		this.preloaded.src = $(this).attr("original").replace(/^(.+)_sum\.jpg$/, "$1");
	},
	enter: function() {
		$(this).after("<div class='l_photo'><img src='"+this.preloaded.src+"_b.jpg' /></div>");
	},
	exit: function() {
		$(this).next().hide("slow");
		$(this).next().remove();
	}
};


// 自动提交所选下拉框内容
$.auto.submit = {
	init: function() {
		$('SELECT.Submit').bind('change', this.on_change);
	},

	on_change: function() {
		if (this.value) this.form.submit();
	}
};


// 在label激活时自动全选输入内容
$.auto.select = {
	init: function() {
		$('LABEL.Select').each(this.label_action);
		$('INPUT.Select').bind('click', function(){ this.select(); });
	},

	label_action: function() {
		var field = $('#'+this.htmlFor).get(0);
		if (field && field.focus && field.select) {
			$(this).bind('click', function(){ field.focus(); field.select(); });
		}
	}
};



// 切换标签
$.auto.tabs = {
	init: function() {

		$('.Tabs').each(function(){
			var f = $.auto.tabs.click;
			var group = this;
			$('.Tab', group).each(function(){
				this.group = group;
				$(this).click(f);
				$('#'+this.id+'_body').hide();
			}).filter(':first').trigger('click');
		});

	},

	click: function() {
		var tab = $('#'+this.id+'_body').get(0);
		$('.Tab', this.group).each(function(){
			$(this).removeClass('Active');
			$('#'+this.id+'_body').hide();
		});

		$(this).addClass('Active');
		$(tab).show();

		var self = $("img", tab);
		$(self).each(function(){
			/* Save original only if it is not defined in HTML. */

			if (  !$(this).attr("loaded") )
			{
				 $(this).hide().attr("src", $(this).attr("original")).fadeIn("fast");
				 $(this).attr("loaded", 1);
			}

		});
            

		this.blur();

		return false;
	}
};

$(document).ready($.auto.init);


