
//全局输入框及按钮效果
$(function(){
	$('.inp1').focus(function(){
		$(this).removeClass('inp1_out').addClass('inp1_in');
	}).blur(function(){
		$(this).removeClass('inp1_in')
	}).hover(function(){
		if($(this).hasClass('inp1_in')){ return false }
		$(this).addClass('inp1_out')
	},function(){
		$(this).removeClass('inp1_out')
	})
})

//首页商品分类
function setLeftMenu(_pdtArys){
	var _fly = $('#flyMenu');
	var _flyAt = $('#flyMenu .fly_menu_at');
	var _flyTable = $('#flyMenu .fly_menu_table');
	var _item = $('#leftMenu li');
	var _pdtAry = _pdtArys;
	var _time;
	var _top;
	var _left;
	var _tops;
	
	$.each(_item,function(i,e){
		var _e = $(e);
		var _xy = _e.offset();
		
		_e.hover(function(){
			clearTimeout(_time);
			_item.removeClass('linkOn');
			_fly.hide();
			if(_e.hasClass('last')){return false};
			var _xy = $(_item[0]).offset();
			var _xys = _e.offset();
			_top = _xy.top;
			_left = _xy.left + 142;
			_flyAt.css('marginTop',_xys.top - _top - 2 );
			_flyTable.html(_pdtAry[_e.attr('pa')]);
			tableColor(_flyTable);
			_fly.css({'top':_top,'left':_left}).show();
			_e.addClass('linkOn');
		},function(){
			_time = setTimeout(function(){_flyTable.html();_item.removeClass('linkOn');_fly.hide()},200);
		});
	})
	
	_fly.hover(function(){
		clearTimeout(_time);
	},function(){
		_time = setTimeout(function(){_flyTable.html();_item.removeClass('linkOn');_fly.hide()},200);
	});
	
	function tableColor(_obj){
		var _tr = _obj.find('tr');
		_tr.hover(function(){
			_tr.removeClass('linkOn');
			$(this).addClass('linkOn');
		},function(){
			$(this).removeClass('linkOn');
		});
	}
}
	
//首页搜索类别
function setSeachType(){
	var _btn = $('#mainSeach .seach_typess a')
	_btn.click(function(){
		_btn.removeClass('linkOn');
		$(this).addClass('linkOn');
	});

}

/*20110701首页小广告轮换*/
//首页轮换广告

function setGds(_id,_time,_speed){
	
	/*---------------------
	_id:容器id
	_time:轮换间隔的时间
	_speed:轮换速度
	
	----------------------*/
	
	var _gds = $('#'+_id);
	var _obj = _gds.find('.pop_pic li');
	var _item = _gds.find('.pop_num li');
	
	var _time = _time;
	var _speed = _speed;
	var _t;
	var _num = 0;
	var _tf = true;
	var _tf2 = true;
	
	$.each(_obj,function(i,e){
		$(e).css('z-index',99-i);
	});
	_obj.show();
	
	_gds.hover(function(){
		_tf = false;
	},function(){
		_tf = true;
	});
	_item.click(function(){
		if(!_tf2){return false;}
		_tf2 = false;
		clearTimeout(_t);
		var _int = parseInt($(this).html());
		var _ints = _int - 1;
		var _into = _ints - 1 - _num;
		if(_ints == _num){_tf2 = true;return false;}else{
			if(_ints > _num){
				if(_into>0){
					for(var i=0; i<_into; i++){
						$(_obj[_num + i + 1]).hide();
					}
				};
				$(_obj[_num]).fadeOut(_speed,function(){_tf2 = true;});
				_num = _ints;
				_item.removeClass('linkOn');
				$(_item[_num]).addClass('linkOn');
			}else{
				_num = _ints;
				$(_obj[_num]).fadeIn(_speed,function(){_tf2 = true;if(_into != -2){
					_into = Math.abs(_into) - 2;
					for(var i=0; i<_into; i++){
						$(_obj[_ints + i + 1]).show();
					}
				};});
				_num = _ints;
				_item.removeClass('linkOn');
				$(_item[_num]).addClass('linkOn');
			}
		}
		_t = setTimeout(function(){gdsNext()},_time);
	});
	
	function gdsGo(){
		_t = setTimeout(function(){gdsNext()},_time);
	};
	
	function gdsNext(){
		if(!_tf){gdsGo();return false;}
		if(_num < _obj.length - 1){
			$(_obj[_num]).fadeOut(_speed);
			_item.removeClass('linkOn');
			$(_item[_num + 1]).addClass('linkOn');
			_num+=1;
		}else{
			_num = 0;
			$(_obj[_num]).fadeIn(_speed,function(){_obj.show();});
			_item.removeClass('linkOn');
			$(_item[_num]).addClass('linkOn');
		}
		gdsGo();
	};
	gdsGo();
}
/*20110701首页小广告轮换 - end*/
	
//底部信息
function setMainFoot(){
	$('#mainFoot li.nt').hover(function(){
		$(this).addClass('linkOn');
	},function(){
		$(this).removeClass('linkOn');
	});
}

//首页商品滚动
function setPdt(){
	var _tf = false;
	$.each($('.pdt_show,.hot_pdt'),function(i,e){
		var _e = $(e);
		var _l = _e.find('ul.usB');
		var _b = _l.find('li').size();
		var _p = _e.find('.box_dian');
		var _num = 186;
		
		_l.width(_b * _num);
		_l.attr('_now',1);
		_l.attr('_max',_b/5);
		
		var _str = '<li class="linkOn"></li>';
		for(var i=1; i<_b/5; i++){
			_str += '<li></li>';
		};
		_str = '<ul>' + _str + '</ul>';
		_p.html(_str).css('marginLeft','-' + (_p.width()/2));
		
		var _mbox = _e.find('.box_soll');
		var _lbtn = _e.find('.box_prve');
		var _rbtn = _e.find('.box_next');
		
		var _d = _p.find('li');
		
		$.each(_d,function(i,e){
			$(e).click(function(){
				_l.attr('_now',i);
				goPdt(_l,'go',_d);
			});
		})
		
		_lbtn.click(function(){
			goPdt(_l,'prve',_d)
		}).hover(function(){$(this).addClass('bpLinkOn')},function(){$(this).removeClass('bpLinkOn')});
		_rbtn.click(function(){
			goPdt(_l,'next',_d)
		}).hover(function(){$(this).addClass('bnLinkOn')},function(){$(this).removeClass('bnLinkOn')});
	})
	function goPdt(_obj,_next,_dian){
		if(_tf){ return false; }
		if(_next == 'next'){
			var _now = parseInt(_obj.attr('_now'));
			if(_now == parseInt(_obj.attr('_max'))){ _now = 0 }
			_tf = true;
			var _n = 930 * _now;
			_obj.animate({'left':'-' + _n},{duration:350,complete:function(){_tf = false}});
			_obj.attr('_now',_now + 1);
			_dian.removeClass('linkOn');
			$(_dian[_now]).addClass('linkOn');
		}
		if(_next == 'prve'){
			var _now = parseInt(_obj.attr('_now'));
			if(_now == 1){ _now = parseInt(_obj.attr('_max')) + 1 }
			_tf = true;
			_now = _now - 1;
			var _n = 930 * _now - 930;
			_obj.animate({'left':'-' + _n},{duration:350,complete:function(){_tf = false}});
			_obj.attr('_now',_now);
			_dian.removeClass('linkOn');
			$(_dian[_now - 1]).addClass('linkOn');
		}
		if(_next == 'go'){
			var _now = parseInt(_obj.attr('_now'));
			if(_now == parseInt(_obj.attr('_max'))){ _now = 0 }
			_tf = true;
			var _n = 930 * _now;
			_obj.animate({'left':'-' + _n},{duration:350,complete:function(){_tf = false}});
			_obj.attr('_now',_now + 1);
			_dian.removeClass('linkOn');
			$(_dian[_now]).addClass('linkOn');
		}
	}
}

//商家后台左导航
function setMemberLeftMenu(){
	var _btn = $('#leftMenu a.lv1');
	_btn.click(function(){
		var _this = $(this);
		if(_this.hasClass('lv1LinkOn')){
			_this.removeClass('lv1LinkOn');
			_this.next('ul').hide();
		}else{
			_this.addClass('lv1LinkOn');
			_this.next('ul').show();
		}
	});
}

//Table鼠标移动变色
function setTableBg(_id){
	$('#'+ _id + ' tbody tr').hover(function(){
		$(this).addClass('linkOn');
	},function(){
		$(this).removeClass('linkOn');
	})
}
function setTableTr(_class){
	$('div.' + _class).hover(function(){
		if($(this).hasClass('nc')) return false;
		$(this).addClass('table_style2_linkOn');
	},function(){
		$(this).removeClass('table_style2_linkOn');
	})
}

//设置上传文件按钮透明
function setFileOpacity(_id){
	$('#' + _id + ' div.btn3 input').css('opacity',0).show();
}

/*tabs - 切换效果*/
$(function(){
	var _btn = $('#tabsBox .tabs_menu a');
	var _box = $('#tabsBox .tabs_item .tabs_items');
	$.each(_btn, function(i,e){
		$(e).click(function(){
			_box.hide();
			_btn.removeClass('linkOn');
			$(_box[i]).show();
			$(e).addClass('linkOn');
			
			//让隐藏的iframe显示
			var _iframe = $(_box[i]).find('iframe');
			if(_iframe.size()>0){  //判断div下是否有iframe
				var iframe_id = _iframe.attr('id');
				window.frames[iframe_id].window.fixIframe();
			} 
			
		});
	})	
})
/*tabs - 切换效果 - end*/

	/*搜索类型选择窗口*/
function selectSeachType(){
	 var flyObj = $('#seachType');
	 var _type = $('#selectSeachType a');
	 var _buy = $('#seachType .noBuyIcon');	
	 var _member = $('#seachType .member');
		$('#selectSeachType').mouseenter(function(){ 
			flyObj.show();
		});
		flyObj.mouseleave(function(){ flyObj.hide(); });
		_buy.click(function(){
			_type.html(function(){
				return _buy.text();
			});
			flyObj.hide();
		});	
		_member.click(function(){
			_type.html(function(){
				return _member.text();
				
			});
			flyObj.hide();	
		});
	/*搜索类型选择窗口 - end*/
}


function setTxtScroll(_id,_class,_width){
	var _page = 1;
	var _page_width = _width;
	var _page_box = $('#' + _id);
	var _page_boxs = _page_box.find('.inner');
	var _pre = _page_box.find('.more_p');
	var _next =  _page_box.find('.more_n');
	var _page_size = _page_box.find('.'+_class+ ' ul').size();
	_page_boxs.css('width', _page_width * _page_size);
	_pre.hover(function(){
		$(this).addClass('plinkOn');
	},function(){
		$(this).removeClass('plinkOn');
	}).click(function(){
		if(_page > 1){
			_page -= 1;
			_page_boxs.animate({'marginLeft':_page_width*(-(_page - 1))});
		}else{
		
		}
	});
	
	_next.hover(function(){
		$(this).addClass('nlinkOn');
	},function(){
		$(this).removeClass('nlinkOn');
	}).click(function(){
		if(_page < _page_size){
			_page_boxs.animate({'marginLeft':_page_width*(-_page)});
			_page += 1;
		}else{
		
		}
	});
	
}

/*20110212修改 导航菜单弹出框*/
function setMore(){ 
	var _btn = $('#pdtMore');
	var _icon = _btn.find('.pdtMore');	
	var _box = $('#pdtmoreBox');
	var _boxTable = $('#flyMenu .fly_menu_table');
	var _fly = $('#flyMenu');
	
	var _btn_time;
	 _btn.hover(function(){
		 _icon.addClass('pdtLinkOn');
		_box.show();
	},function(){
		_btn_time = setTimeout(function(){
			_icon.removeClass('pdtLinkOn');
			_box.hide();
		}, 200)
	});
	
	var _box_time;
	_box.hover(function(){
		clearTimeout(_btn_time);
		clearTimeout(_fly_time);
	},function(){
		_box_time = setTimeout(function(){
			_icon.removeClass('pdtLinkOn');
			_box.hide();
		}, 200)
	});
	
	var _fly_time;
	_fly.hover(function(){
		clearTimeout(_box_time);
	},function(){
		_fly_time = setTimeout(function(){
			_icon.removeClass('pdtLinkOn');
			_box.hide();
		}, 200)
	});

}
/*20110212修改 导航菜单弹出框 - end*/

/*分享给好友弹出框效果*/
function setShare(){
	var _box = $('#shareBox');
	$('#Share').click(function(){
		$('#urlInp').val(window.location.toString());
		_box.show();
		/*复制到剪切板*/
		//var _txt = $('#urlInp').val();
		 $('input#copy-dynamic').zclip({
			path:'v4/js/ZeroClipboard.swf',
			copy:function(){ return $('input#urlInp').val();}
		 });
	});	
	_box.find('.close_btn').click(function(){
		_box.hide();	
	});
}

/*分享给好友弹出框效果 - end*/
