﻿$.fn.iFadeSlide = function(iSet){
    iSet = $.extend({curCls:'on',interval:3000,leaveTime:150,fadeOutTime:400,fadeInTime:400},iSet);
    var imgField = $(iSet.field || '.focus_con > li');
    var icoField = $(iSet.ico || '.focus_btn');
	var curIndex = 0;
    var slideInterval = iSet.interval || 3000;
    var hoverTime = iSet.leaveTime || 150;
    var fadeOutTime = iSet.fadeOutTime || 400;
    var fadeInTime = iSet.fadeInTime || 400;
    var icos=null, fastHoverFun = null, autoSlideFun = null, hasIcoHighCls = null, changeFun = null,max=null;;
    var icoHtml = '';
	max=imgField.size();
    imgField.each(function(i){
        icoHtml += '<li>' + (i + 1) + '</li>';
    });
    icoField.append(icoHtml);
    changeFun = function(n){
        imgField.eq(n).fadeIn(fadeInTime).siblings("li").fadeOut(fadeOutTime);
        icos.eq(n).addClass(iSet.curCls).siblings().removeClass(iSet.curCls);
    }
    icos = icoField.find('li');
	imgField.first().css('z-index','1')
    icos.first().addClass(iSet.curCls);
    icos.hover(function(){
        clearInterval(autoSlideFun);
        curIndex = icos.index(this);
        hasIcoHighName = $(this).hasClass(iSet.curCls);

        fastHoverFun = setTimeout(function(){

            if (!hasIcoHighName) {
                changeFun(curIndex);
            }
        }, hoverTime);
    }, function(){
        clearTimeout(fastHoverFun);
        autoSlideFun = setInterval(function(){
            curIndex++;
            changeFun(curIndex);
            if (curIndex ==max ) {
				changeFun(0);
                curIndex = 0;
            }
        }, slideInterval)
    }).eq(0).trigger('mouseleave');
	imgField.hover(function(){
        curIndex = imgField.index(this);
        clearInterval(autoSlideFun);
    }, function(){
        icos.eq(curIndex).trigger('mouseleave');
    });
};
$(function(){
	$('div.focus').iFadeSlide({}); 
});

/*
 农有宝编写;
 2011年4月1日 09:49:19
*/
;(function($){
	$.fn.extend({
		iScrollLoop: function(options){
			var LoopSet = {
				parentName:'.theme-box',//集装箱
				moveName:'.pic-box',//滚动集合
				textName:'.theme-text',
				childName:'a',
				prevBtn:'#prev',
				nextBtn:'#next',
				times:3000,
				staIndex:-1,
				steps:1
			};
			options=options || {};
            $.extend(LoopSet,options); 
			
			var i = LoopSet.staIndex;
			var childWidth = $(LoopSet.parentName + ' ' + LoopSet.childName).outerWidth();
			var moveWidth = childWidth * LoopSet.steps;
			var moveLength = $(LoopSet.parentName + ' ' + LoopSet.moveName + ' ' + LoopSet.childName).length + 1;
			var moveNum = $(LoopSet.parentName + ' ' + LoopSet.moveName + ' ' + LoopSet.childName).length / LoopSet.steps - 1;
			var autoPage = null;
			pageAdd();
			$(LoopSet.parentName + ' ' + LoopSet.moveName).width(childWidth * moveLength);
			
			function pageScroll(i){
				$(LoopSet.parentName + ' ' + LoopSet.moveName).animate({left:- i * moveWidth},{queue: false, duration: 500}); // 滚动函数
				$(LoopSet.parentName + ' ' + LoopSet.textName).children().eq(i).show().siblings('a').hide();
				clearTimeout(autoPage);
			};
			
			function pageAdd(){// 向左滚动
				i++;
				if(i > moveNum){
					i = 0;
				}
				pageScroll(i);// 显示第一组 图片
				autoPage = setTimeout(pageAdd,LoopSet.times); // 5秒后 向左显示 第二组图片.
			};
			
			function pageRem(){//向右滚动
				i--;
				if(i < 0){
					i = moveNum;
				}
				pageScroll(i);
				autoPage = setTimeout(pageRem,LoopSet.times);
			};
			
			$(LoopSet.parentName).hover(function(){
					clearTimeout(autoPage);
				;},function(){
					autoPage = setTimeout(pageAdd,LoopSet.times)
				}); // 鼠标悬停 清除  滚动
											
			$(LoopSet.parentName + ' ' + LoopSet.prevBtn).click(function(){// 点击下一页
				clearTimeout(autoPage);
				pageRem();
			});
			$(LoopSet.parentName + ' ' + LoopSet.nextBtn).click(function(){//点击上一页
				clearTimeout(autoPage);
				pageAdd();
			});			
		}
	});
})(jQuery);



;(function($){
	$.fn.extend({
		Tab:function(options){
			var tabSet = {
				hover:'on',
				curIndex:'0'
			};
			
			options=options || {};
            $.extend(tabSet,options);
			
			var btn = $(tabSet.tabsName + ' ' + tabSet.btnName);
			var con = $(tabSet.tabsName + ' ' + tabSet.conName);
			var index = tabSet.curIndex;
			
			btn.eq(index).addClass(tabSet.hover);
			con.eq(index).show().siblings(tabSet.conName).hide();
				
			btn.hover(function(){
				index = btn.index(this); // 获取当前鼠标经过索引值
				$(this).addClass(tabSet.hover).siblings(tabSet.btnName).removeClass(tabSet.hover);
				con.eq(index).show().siblings(tabSet.conName).hide();
			})
		}
	})
})(jQuery);

/*
$(function(){
	$('#tab111').Tab({
		tabName:'#tab111',
		btnName:'h3',
		conName:'.tabCon',
		hover:'on',
		curIndex:'0'
	});
});
*/
