
(function($) {
	
	/*
	 图片单
	 img  图片地址
	 url  链接
	 text 文本介绍
	*/
	$.fn.photo = function(opts) {
        this.opts  = $.extend({},$.fn.photo.defaults, opts);
		this.init();
	}
	$.fn.photo.prototype = {
		/* 初始化 */
		init:function(){
			
			/* 标签类型 */
			var tabType = function(type){
				var html = "";
				if(type == "number"){
					  contentobj.each(function(i){
						html +="<"+_opts.tabItem+" class=\""+_opts.tabDefaultCss+"\">" + (i+1) + "</"+_opts.tabItem+">";
					  });
				}else if(type == "text"){
					  contentobj.each(function(i){
						var text = $(this).find("img").attr("alt");
						html +="<"+_opts.tabItem+" class=\""+_opts.tabDefaultCss+"\">" + text + "</"+_opts.tabItem+">";
					  });
	
				}else if(type == "image"){
					  contentobj.each(function(i){
						var text = $(this).find("img").attr("alt");
						html +="<"+_opts.tabItem+" class=\""+_opts.tabDefaultCss+"\">" + "<img src=\"" + _opts.imageTab[i] +"\" />" + "</"+_opts.tabItem+">";
					  });
				}
				return html;
			}
			/* 图片切换动画效果 */
			var fade = function(tab){
				index = tabobj.index(tab);
				
				contentobj.filter(':visible').fadeOut(100, function(){
                    contentobj.eq(index).fadeIn(200);
                });
				$(tab).addClass(_opts.tabOverCss).siblings().removeClass(_opts.tabOverCss);
			}
			
			/* 切换显示函数 */
			var changeTab = function(){
                index++;  //累积索引值
                if (index == count){index = 0};  
                tabobj.eq(index).trigger('mouseleave');
            };
			
			
			var _this = this;
			var index = 0;
            var contentobj = $("#" + _this.opts.contentId + " " + _this.opts.contentItem);
			var count = $(contentobj).size();
			var _opts = _this.opts;
            
			$("#"+_opts.tabId).html(tabType(_opts.tabType));
			var tabobj = $("#" + _opts.tabId + " " + _opts.tabItem);
			var auto = setInterval(changeTab,_opts.autoTimer);
			
			/* 标签项经过函数 */
			tabobj.hover(function(){
                clearInterval(auto)
                fade(this);
            }, function(){
                fade(this);
            }); 
			/* 图片项经过函数 */
			contentobj.hover(function(){
                clearInterval(auto)
            }, function(){
                auto = setInterval(changeTab,_opts.autoTimer);
            });
			
			
		}
		
	}

	/* 默认参数 */
	$.fn.photo.defaults = {
		/* 图片内容显示框 */
		contentId:"photo",
		/* 单项标签 */
		contentItem:"li",
		/* 自动切换时间间隔 */
		autoTimer:3000,
		/* tab 类型 number 类型,text 文本类型,image 图片类型 */
		tabType:"number",
		/* 图片标签数组 */
		imageTab:Array(),
		/* 标签id */
		tabId:"photo_tab",
		/* 标签项 */
		tabItem:"li",
		/*标签经过样式*/
		tabDefaultCss:"",
		/* 标签经过样式 */
		tabOverCss:"",
		outTime:100,
		inTime:200
    };
	
	
})(jQuery);
