/*column切换*/
var exchangeId = '';

function tag_silder(option){
	var o = option,
		$initial = o.initial || 0,
		$handler = $(o.handler) || {},
		changing_Item = o.changing_Item || {};

	var _index = $initial;
	
	//initialize
	$handler.each(function(){var $this = $(this);$this.parents('ul').find('a').eq(_index).addClass('active')});
	$(changing_Item).each(function(){var $this = $(this);$this.parents().find(changing_Item).eq(_index).css({'display':'block'})});
	
	//events hover
	$handler.hover(function(){
		var $this = $(this);
		$this.parents('ul').find('a').removeClass('active');
		$this.addClass('active');
		$this.parents('ul').find('a').each(function(i){
			var $this = $(this);
			if ($this.hasClass('active')) _index = i;
		});
		$this.parents('.hd').next('.bd').children(changing_Item).css({'display':'none'}).eq(_index).css({'display':'block'});
	},function(){});
	$handler.click(function(){return false;})
}

/*去掉最后一个list样式*/
function lastone(obj,style){
	var $o = $(obj),style=style;
	$o.each(function(){
		$(this).children().last().addClass(style);
	})
}

/* zebra */
function zebra(option){
	var o = option,
		$obj = $(o.obj) || {}, 
		col = o.col || '', 
		col2 = o.col2 || '';
	$obj.each(function(i){
		$(this).addClass([col,col2][i%2]);
	})
}


/* 弹出层 */
function layerPopup(optional){	
	var o = optional,
		target = $(o.target) || {},
		handler = $(o.handler) || {},
		masker = $(o.masker) || {};
	
	//exchange var	
	var productId = $('#productId'),
		productName = $('#productName'),
		AUBi = $('#AUBi'),
		productImg = $('#productImg');

	var _offLeft = 0, _offTop = 0,_tarW= target.outerWidth(),_tarH = target.outerHeight();

	var exchangeHiddenId = $('#exchangeHiddenId');

	handler.click(function(){
		exchangeId = this.id;
		exchangeHiddenId.val(this.id);
		_offLeft = (($(window).width()-_tarW)/2) + $(document).scrollLeft();		
		_offTop = (($(window).height()-_tarH)/2) + $(document).scrollTop();
	
		$.ajax({
			url: 'integral_mask.jsp?id='+exchangeId,
			cache: false,
			success: function(json){
				var json = eval('('+json+')');
				productId.val(json.id);
				productName.text(json.name);
				AUBi.text(json.price);
				productImg.attr('src',json.image_url);
				masker.show().css({'height':$(window).height() + $(document).scrollTop()+'px','z-index':'9998'});
				target.fadeIn().css({'left':_offLeft+'px','top':_offTop+'px','z-index':'9999'});	
			}
		})
		return false;
	});

	$(window).bind('resize scroll',function(){
		var _w = $(document).scrollLeft()>0? $(window).width()+$(document).scrollLeft(): $(window).width();
		var _l = $(document).scrollTop()>0? $(window).height()+$(document).scrollTop():$(window).height();
		masker.css({'width':_w+'px','height':_l+'px'});
		_offLeft = (($(window).width()-_tarW)/2)+$(document).scrollLeft();		
		_offTop =  (($(window).height()-_tarH)/2)+ $(document).scrollTop();
		target.css({'left':_offLeft+'px','top':_offTop+'px'});
	})	

	//close
	target.find('.close, .cancel').click(function(){
		target.fadeOut();
		masker.hide();
		return false;
	});
}


/* 弹出层submit */
function layerShow(optional){	
	var o = optional,
		lShow = $(o.lShow) || {},
		lHide = $(o.lHide) || {},
		masker = $(o.masker) || {};

	var _offLeft = 0, _offTop = 0,_tarW= lShow.outerWidth(),_tarH = lShow.outerHeight();

	_offLeft = (($(window).width()-_tarW)/2) + $(document).scrollLeft();		
	_offTop = (($(window).height()-_tarH)/2) + $(document).scrollTop();

	lHide.hide();
	lShow.fadeIn().css({'left':_offLeft+'px','top':_offTop+'px','z-index':'9999'});	
	
	var _w = $(document).scrollLeft()>0? $(window).width()+$(document).scrollLeft(): $(window).width();
	var _l = $(document).scrollTop()>0? $(window).height()+$(document).scrollTop():$(window).height();
	masker.css({'width':_w+'px','height':_l+'px'}).show();
	
	$(window).bind('resize scroll',function(){
		var _w = $(document).scrollLeft()>0? $(window).width()+$(document).scrollLeft(): $(window).width();
		var _l = $(document).scrollTop()>0? $(window).height()+$(document).scrollTop():$(window).height();
		masker.css({'width':_w+'px','height':_l+'px'});
		_offLeft = (($(window).width()-_tarW)/2)+$(document).scrollLeft();		
		_offTop =  (($(window).height()-_tarH)/2)+ $(document).scrollTop();
		lShow.css({'left':_offLeft+'px','top':_offTop+'px'});
	})	
	
	//close
	lShow.find('.close, .cancel').click(function(){
		lShow.fadeOut();
		masker.hide();
		return false;
	});
}


/*Reply*/
function replyShow(optional){
	var o = optional,
		user_reply = o.user_reply,
		$handle = $(o.handle) || {},
		reply = o.reply || {},
		$close = $(o.close) || {};

	$handle.click(function(){
		if (user_reply==1){
			$(this).hide();
			$(this).parent().find(reply).show();
			return false;
	
		}else{
			alert("登陆后才能回复评论");
		}
	});
	$close.click(function(){
		$(this).parent().parent().find(o.handle).show();
		$(this).parent().hide();
		return false;
	});
}


function img_silder(option){
	var o = option,
		initial = o.initial || 0,
		handler = $(o.handler) || {},
		changing_Item =  $(o.changing_Item) || {};
		
	var _index = initial;
	
	
	//initialize
	handler.eq(_index).addClass('current');
	changing_Item.eq(_index).css({'display':'block'});
	
	
	//events click
	handler.click(function(){
		var $this = $(this);
		handler.removeClass('current');
		$this.addClass('current');
		handler.each(function(i){
			var $this = $(this);
			if ($this.hasClass('current')) _index = i;
		});
		changing_Item.css({'display':'none'}).eq(_index).css({'display':'block'});
	});
	

	//autorun
	var auto = function(){
		repeater = setInterval(function(){
			if(_index >= handler.size()) _index = 0;
			move(_index++);
		},3000);
	};

	//stop
	var stop = function(){
		clearInterval(repeater);
	}

	//move
	function move(_index){
		handler.removeClass('current').eq(_index).addClass('current');
		changing_Item.css({'display':'none'}).eq(_index).css({'display':'block'});			
	};

	//auto
	auto();
}

