//jquery-lazyload
jQuery(function(){
	jQuery("#content img[original]").lazyload({
		placeholder:"http://www.zuipin.cn/skin/frontend/default/default/images/grey.gif"
	})
})
/**
 * slide (Version 1.3)
 *
 * Create a Slide
 * @example new Slide(container,options);
 * on Jquery
 *
 */
function Slide(container, options, callback){
	this.container=jQuery(container);
	this.list=jQuery(container+' .J_slide_list');
	this.handle=jQuery(container+' .J_slide_trigger li');
	this.item=jQuery(container+' .J_slide_item');
	this.itemWH=0;
	this.count=this.handle.length;
	this.timer=null;
	this.eTime=null;
	this.options=jQuery.extend({
		auto:true,
		delay:4,
		duration:500,
		effect:'fade',
		event:'mouseover',
		firstDelay:null,
		index:1,
		vertical:true
		},options);
	this.init();
	if(callback){
		callback();
		}
	}
Slide.prototype={
	init:function(){
		var slideClip, itemW, itemH, itemWH,
			that=this,
			list=this.list, item=this.item,
			op=this.options, auto=!!op.auto, vertical=!!op.vertical;
		if(op.effect==='fade'){
			list.css({position:'relative'});
			item.css({position:'absolute'});
			}
		if(op.effect==='slide'){
			list.css({position:'absolute'});
			if(!list.parent().hasClass('J_slide_clip')){
				list.wrap('<div class="J_slide_clip"></div>');
				}
			itemW=item.outerWidth(true);
			itemH=item.outerHeight(true);
			this.container.find('.J_slide_clip').css({position:'relative',overflow:'hidden',height:itemH,width:itemW});
			this.itemWH=vertical?itemH:itemW;
			}
		this.handle.bind(op.event, this._trigger(this));
		if(op.index>this.count||op.index<1){
			op.index=1;};
		this._showFirst(op.index);
		if(auto){
			this._auto(op.firstDelay);
			this.container.hover(function(){that._stop();},function(){that._auto();});
			}
		},
	_trigger:function(o){
		return function(e){
			var index, op=o.options, handle=o.handle;
			if(op.index===(handle.index(this)+1)){
				return;
				}
			index=op.index=handle.index(this)+1;
			o._show(index);
			};
		},
	_show:function(i){
		var that=this, op=this.options, vertical=!!op.vertical;
		this.handle.removeClass('current').eq(i-1).addClass('current');
		if(op.effect==='fade'){
			clearTimeout(this.eTime);
			this.eTime=setTimeout(function(){that.item.not(that).css({zIndex:1}).eq(i-1).css({zIndex:9}).animate({opacity:1},that.options.duration,function(){
				that.item.not(this).css({opacity:0})
				});},150);
			}
		if(op.effect==='slide'){
			itemWH=this.itemWH;
			this.list.stop().animate({top:-itemWH*(i-1)},this.options.duration);
			}
		},
	_showFirst:function(i){
		var op=this.options, vertical=!!op.vertical;
		this.handle.removeClass('current').eq(i-1).addClass('current');
		if(op.effect==='fade'){
			this.item.not(this).css({zIndex:1, opacity:0}).eq(i-1).css({zIndex:9, opacity:1});
			}
		if(op.effect==='slide'){
			itemWH=this.itemWH;
			this.list.css({top:-itemWH*(i-1)});
			}
		},
	_auto:function(delay){
		var that=this,
			op=that.options;
		this.timer=setTimeout(function(){
			op.index = op.index< that.count? ++op.index: 1;
			that._show(op.index);
			that._auto();
			}, delay ? delay*1000 : op.delay*1000);
		},
	_stop:function(){
		clearTimeout(this.timer);
		}
	};
/**
 * carousel (Version 1.5)
 * Create a carousel
 * @example new Carousel(container, showCount, options, callback);
 * on Jquery
 *
 */
function Carousel(container, showCount, options, callback){
	this.container=jQuery(container);
	this.clip=jQuery(container+' .J_carousel_clip');
	this.list=jQuery(container+' .J_carousel_list');
	this.item=jQuery(container+' .J_carousel_item');
	this.trigger=jQuery(container+' .J_carousel_trigger');
	this.showCount=showCount;
	this.timer=null;
	this.options=jQuery.extend({
		auto:true,
		delay:4,
		direction:'',
		duration:100,
		etype:'click',
		num:showCount,
		vertical:false
		},options);
	this.init();
	if(callback){
		callback();
		}
	}
Carousel.prototype={
	init:function(){
		var _this=this,
			item=this.item, list=this.list, options=this.options,
			auto=!!options.auto, vertical=!!options.vertical,
			itemLen=item.length, itemW=item.outerWidth(true), itemH=item.outerHeight(true), itemWH=vertical?item.outerHeight(true):item.outerWidth(true);
		list[vertical?'height':'width'](itemWH*itemLen).css({position:'absolute'});
		var listW=list.outerWidth(true), listH=list.outerHeight(true);
		this.clip.css({position:'relative',overflow:'hidden',width:(vertical?Math.max(listW,itemW):itemWH*this.showCount),height:(vertical?itemWH*this.showCount:Math.max(listH,itemH))});
		if(itemLen <= this.showCount){
			this.trigger.hide();
			return;
			}
		this.trigger.bind(options.etype,this._trigger(this,itemWH));
		if(auto){
			this._auto();
			this.container.hover(function(){_this._stop();},function(){_this._auto();});
			}
		},
	_trigger:function(_this,itemWH){
		return function(e){
			var listLast, listFirst,
				trigger=_this.trigger, list=_this.list, showCount=_this.showCount, options=_this.options, etype=options.etype, duration=options.duration, oNum=options.num,
				vertical=!!options.vertical,
				itemLen=_this.item.length, num=itemLen/showCount<2||itemLen/oNum<2 ? (itemLen/showCount<2 ? (oNum<itemLen%showCount ? oNum : itemLen%showCount) : showCount) : oNum,
				targetClass=e.target.className, animatePara=vertical?[{top:0,opacity:1},{top:-itemWH*num,opacity:1}]:[{left:0,opacity:1},{left:-itemWH*num,opacity:1}];
				//opacity修正IE下大图滚动视觉断开bug
			if(/prev/i.test(targetClass)){
				trigger.unbind(etype);
				for(var i=0,len=num; i<len; i++){
					listLast=list.find('.J_carousel_item:last');
					listLast.prependTo(list);
					}
				list.css(animatePara[1]);
				list.animate(animatePara[0],duration*num,function(){
					trigger.bind(etype,_this._trigger(_this,itemWH));
					});
				}
			if(/next/i.test(targetClass)){
				trigger.unbind(etype);
				list.animate(animatePara[1],duration*num,function(){
					list.css(animatePara[0]);
					for(var i=0,len=num; i<len; i++){
						listFirst=list.find('.J_carousel_item:first');
						listFirst.appendTo(list);
						}
					trigger.bind(etype,_this._trigger(_this,itemWH));
					});
				}
			return false;		
			};
		},
	_auto:function(){
		var _this=this,
			options=_this.options,
			trigger;
		this.timer=setTimeout(function(){
			trigger = options.direction ? '.J_carousel_prev' :'.J_carousel_next';
			_this.trigger.find(trigger).trigger(options.etype);
			_this._auto();
			},options.delay*1000);
		},
	_stop:function(){
		clearTimeout(this.timer);
		}
	};
//jquery.tabs
jQuery(function() {
  jQuery(".tabs > li > a").mouseover(function(e) {
    if (e.target == this) {
      var tabs = jQuery(this).parent().parent().children("li");
      var panels = jQuery(this).parent().parent().parent().children(".tabs-panel");
      var index = jQuery.inArray(this, jQuery(this).parent().parent().find("a"));
      if (panels.eq(index)[0]) {
        tabs.removeClass("current").eq(index).addClass("current");
        panels.addClass("hidden").eq(index).removeClass("hidden");
      }
    }
  });
});
//jquery.scrolltop
jQuery(function() {
  var viewH = document.documentElement.clientHeight == 0 ? document.body.clientHeight: document.documentElement.clientHeight;
  var Vwidth = 985;
  var goup;
  if (window.XMLHttpRequest) {
    goup = jQuery("<div style=\"right:-50px; POSITION: absolute;z-index:6666;\"><a href=\"#\"><img src=\"/images/totop.gif\" alt=\"返回顶部\" /></a></div>").hide();
    goup.css({
      position: "fixed",
      top: viewH - 66,
      left: (jQuery("body").width() - Vwidth) / 2 + Vwidth + 5
    });
  } else {
    goup = jQuery("<div style=\"POSITION: absolute;z-index:1000;\"><a href=\"#\"><img src=\"/images/totop.gif\" alt=\"返回顶部\" /></a></div>").hide();
    if (document.documentElement.clientWidth > Vwidth + 30) {
      if (jQuery(window).scrollTop() > 0) {
        goup.css({
          top: jQuery(window).scrollTop() + viewH - 66,
          left: (jQuery("body").width() - Vwidth) / 2 + Vwidth + 5
        }).show();
      }
    }
  }
  jQuery(window).scroll(function() {
    viewH = document.documentElement.clientHeight == 0 ? document.body.clientHeight: document.documentElement.clientHeight;
    if (jQuery(window).scrollTop() == 0) {
      goup.fadeOut();
    } else {
      goup.fadeIn();
      if (!window.XMLHttpRequest) {
        if (document.documentElement.clientWidth <= Vwidth + 30) {
          goup.hide();
        } else {
          goup.css({
            top: jQuery(window).scrollTop() + viewH - 66,
            left: (jQuery("body").width() - Vwidth) / 2 + Vwidth + 5
          });
        }
      } else {
        goup.css({
          position: "fixed",
          top: viewH - 66,
          left: (jQuery("body").width() - Vwidth) / 2 + Vwidth + 5
        });
      }
    }
  });
  jQuery("body").prepend(goup);
});

