//弹出图片
function popPic(){
	var $picList = $("#rightColumn .tdpic span");
	var $searchList = $("#rightColumn .tdpic a");
	var $option = $("select[name='sel']");
	var time,len = $picList.length,prev = 0;
	
	$option.change( function(){
		var curIndex = $(this).val();
		clearTimeout(time);
		$($picList[prev]).fadeOut(600);
		$($searchList[prev]).hide();
		$($searchList[curIndex]).show();
		
		$("#errorMsg").removeClass("littleiconno");
		$("#errorMsg").html("");
		$("#searchKeyWord").val("");
		$("#yzmMsg").removeClass("littleiconno");
		$("#yzmMsg").html("");
		$("#authcode").val("");
		
		$($searchList[curIndex]).click(function(e){
			clearTimeout(time);
			$($picList[curIndex]).show();
			e.preventDefault();
			time = setTimeout(function(){
				$($picList[curIndex]).fadeOut(1000);				
			},4000);
		});
		
		prev = curIndex;
	} );
	
	$($searchList[prev]).click(function(e){
		$($picList[prev]).show();
		e.preventDefault();
		time = setTimeout(function(){
			$($picList[prev]).fadeOut(1000);				
		},4000);
	});
	
}

function popPicDeliver(){
	var $picList = $("#rightColumn .tdpic span");
	var $searchList = $("#rightColumn .tdpic a");
	
	if($searchList.length==1){
		$($searchList[0]).click(function(e){	
			$($picList[0]).show();
			e.preventDefault();
			time = setTimeout(function(){
				$($picList[0]).fadeOut(1000);				
			},4000);
		});
	}else if($searchList.length==2){
		$($searchList[0]).click(function(e){	
			$($picList[1]).fadeOut(0);
			$($picList[0]).show();
			e.preventDefault();
			time = setTimeout(function(){
				$($picList[0]).fadeOut(1000);				
			},4000);
		});
		
		$($searchList[1]).click(function(e){	
			$($picList[0]).fadeOut(0);
			$($picList[1]).show();
			e.preventDefault();
			time = setTimeout(function(){
				$($picList[1]).fadeOut(1000);				
			},4000);
		});
	}

}
//查看详情
function see(){
	var $list = $("#deliver-install-result .list");
	var $content = $("#deliver-install-result .content");
	var len = $list.length;
	var curIndex = -1,curline=-1;;
	$list.each( function(index){
		$(this).hover(function(){
			$($list[index]).addClass('zebra');
		},function(){
			if( !$($list[index]).hasClass('on') ){
				$($list[index]).removeClass('zebra');
			}
		});
		$(this).find('a').click( function( e ){
			var cur = $($list[curIndex]).find('a');
			var common = $($list[index]).find('a');
			var height = $($content[index]).height();
			
			/*if( curIndex != index && curIndex >= 0 ){
				$($list[curIndex]).removeClass('on');
				cur.addClass('moveLeft').removeClass('on');
				cur.html("查看详情");
				$($content[curIndex]).hide().removeClass('on');
			}*/
			
			if( $($list[index]).hasClass('on') ){
				$($content[index]).find(".status").each(function(i){
					$(this).stop(true,true);
					var height=$(this).height();
					var _this=this;
					$(this).animate({height:0+"px"},300,function(){
						$($list[index]).removeClass('on');
						common.addClass('moveLeft').removeClass('on');
						common.html("查看详情");
						$($content[index]).hide().removeClass('on');
						if( index == len -1 ){
							$($list[index]).addClass('listLast');
						}
						_this.innerHTML=_this.innerHTML;
						$(_this).height("auto");
					});
				});	
			}else{
				$($list[index]).addClass('on');
				common.addClass('on').removeClass('moveLeft');
				common.html("关闭详情");
				$($content[index]).addClass('on');
				
				//局部刷新 服务单条记录的对应详细信息
				var serviceType = $("#serviceType").val();
			    if(serviceType == 'distributionService'){	
					var productId = $(this).attr('name');//商品ID
					var memberCardNo = $(this).attr('title');//会员卡号
					var temp = $(this).attr('id');//销售单号
					var tempId = "#saleNum"+temp;
					var saleNum = $(tempId).val();
					if(saleNum != temp){
						toPageNoBlock('SNDistributionServiceDetailInfoView?saleNum='+temp+'&productId='+productId+'&memberCardNo='+memberCardNo,'distributionView'+temp);
					}
				}
				
				$($content[index]).addClass('on').show();
				$($content[index]).find(".status").each(function(i){
					$(this).stop(true,true);
					var _this=this;
					var height=$(this).height();
					
					$(this).height(0).animate({height:height+"px"},300,function(){
						_this.innerHTML=_this.innerHTML;
						$(_this).height("auto");
						if( index == len -1 ){
							$($list[index]).removeClass('listLast');
						}
					});
				});
			}
			curIndex = index;
			e.preventDefault();
		} );					 
	} );
}
//pop win
function openWin(){
	var $win = $("#popWin");
	var $closeWin = $("#close");
	var $btn = $("#btn");
	
	$btn.click(function(){
		if( $win.css("display") == "none" ){
			$win.show();
		}						
	});
	$closeWin.click(function( e ){
		if( $win.css("display") != "none" ){
			$win.hide();
		}
		e.preventDefault();						 
	});
}

//input border
function inputBorder(){
	var $input = $(".orderText01");
	var $inputCode = $("input[name='code']");
	var $bigInput = $(".orderText03");
	var $text = $(".orderText02");
	$input.each(function(index){
		$(this).hover( function(){
			$($input[index]).addClass( 'border01' );			   
		},function(){
			$($input[index]).removeClass( 'border01' );	
		} );	
	});
	$bigInput.hover( function(){
		$(this).addClass( 'border01' );			   
	},function(){
		$(this).removeClass( 'border01' );	
	} );
	$text.hover( function(){
		$(this).addClass( 'border01' );			   
	},function(){
		$(this).removeClass( 'border01' );	
	} );
	$inputCode.hover( function(){
		$inputCode.addClass( 'border02' );
	},function(){
		$inputCode.removeClass( 'border02' );	
	} );
}


function clearText(o){
	if(o.innerHTML == "预约服务的商品名称、品牌，服务时间xxxx" ){
		o.innerHTML = "";
	}
}
function showText(o){
	if(o.innerHTML == "" ){
		o.innerHTML = "预约服务的商品名称、品牌，服务时间xxxx";
	}
}

$( function(){
	popPic();
	popPicDeliver();
	see();
	openWin();
	inputBorder();	
	
});
