
var lastid = 0;
var allrecom=1000000;
var allrecom_c=1000000;
var allcollect=1000000;
var allcollect_c=1000000;
var cur_cityid=0;
	$(function(){
		
		$('.nav_tag li').hover(
			function(){			
				var parent=$(this).parent();			
				var idx=parent.find('li').index(this);
				parent.find('li').removeClass('current');
				$(this).addClass('current');
				
				var offset = $(this).offset();		
				var pp=parent.parent().parent();
				var tagjt=pp.find('.tagjt');	
				tagjt.css({'left':offset.left+$(this).width()/2+tagjt.width()/2,'top':offset.top+$(this).height()+tagjt.height()/2});
	
				tagcon=pp.find('.con');
				tagcon.addClass('dpnone');
				tagcon.eq(idx).removeClass('dpnone');
				
			},
			function(){			
			}
		);
		$('.tagjt').each(function(){
			var li=$(this).prev('ul').find('.current');
			var offset =li.offset();
			$(this).css({'left':offset.left+li.width()/2+$(this).width()/2,'top':offset.top+li.height()+$(this).height()/2});
		});
		
		$("#box_imglist li").mousemove(function(){
			$(this).parent().children().removeClass('cur');
			$(this).addClass('cur');
			var idx=$("#box_imglist li").index($(this));
			var imgs=$("#box_imgshow").find('.img');
			imgs.hide();
			imgs.eq(idx).show();
			
		});
		
		/* 图片滚动*/
		var _auto;
		var rolltime=500;		
		var scrollUl=$("*[gmatype='piclistshow'] ul");
		var scrolllis=scrollUl.find('li');
		var liw =scrolllis.eq(0).width()+parseFloat(scrolllis.eq(0).css('margin-right'));
		var lic = scrolllis.length;
		scrollUl.css('width',liw*lic+'px');		
		
		$("*[gmatype='piclistshow'] .left").click(function(){
			scrollL();
		});
		
		$("*[gmatype='piclistshow'] .right").click(function(){	
			scrollR();
		});
		
		/*
		scrolllis.hover(function(){
			setCityInfo($(this));
			autoStop();
		},function(){
			autoPlay();
		});
		*/
		
		function scrollL(){
			autoStop();
			scrollUl.animate({'marginLeft': -liw}, rolltime, function(){
				scrollUl.find("li:first").appendTo( scrollUl );
				scrollUl.css("marginLeft",0);
				autoPlay();setCityInfo(scrollUl.find("li:first"));
			});			
		}
		
		function scrollR(){
			autoStop();
			scrollUl.find("li:last").clone().show().prependTo( scrollUl );
			scrollUl.find("li:last").remove();
			scrollUl.css("marginLeft",-liw);			
			scrollUl.animate({'marginLeft': 0}, rolltime,function(){
				autoPlay();setCityInfo(scrollUl.find("li:first"));
			});	
		}
		
		function autoPlay(){
		   // _auto = window.setTimeout(scrollL, 2000);
		};
		function autoStop(){
			//window.clearInterval(_auto);
		};
		
		setCityInfo(scrollUl.find("li:first"));
		autoPlay();
		/* 图片滚动*/
		
		
		
	
		
		$("#spic0").imageScroller({
			next:"#spic0 .right",
			prev:"#spic0 .left",
			frame:"#spic0 .viewin",
			width:120,
			child: "img",
			auto: false
		});	
		
		
		
		$("#spic1").imageScroller({
			next:"#spic1 .right",
			prev:"#spic1 .left",
			frame:"#spic1 .viewin",
			width:120,
			child: "img",
			auto: false
		});	
		
		$("#spic2").imageScroller({
			next:"#spic2 .right",
			prev:"#spic2 .left",
			frame:"#spic2 .viewin",
			width:120,
			child: "img",
			auto: false
		});	
		
		$("#spic3").imageScroller({
			next:"#spic3 .right",
			prev:"#spic3 .left",
			frame:"#spic3 .viewin",
			width:120,
			child: "img",
			auto: false
		});	
		
		$("#spic4").imageScroller({
			next:"#spic4 .right",
			prev:"#spic4 .left",
			frame:"#spic4 .viewin",
			width:120,
			child: "img",
			auto: false
		});	
		
		$(".view8 li").hover(
			function(){
				$(this).addClass('color1');
				var imgsrc=$(this).attr('gmaurl');
				var img=$(this).parent().parent().parent().find('.img');
				if(imgsrc!='0'){
					img.hide();
					img.attr('src',imgsrc);
					img.show(300);
				}
			}, 			
			function(){
				$(this).removeClass('color1');
			}
		);
		
		
		
		/*
			$(".spic .viewin imga").mouseover(function(){
			
				var proid=$(this).attr("proid");
				if(lastid == proid) return false;
				lastid = proid;
				var sid=$(this).attr('gmaid');
				var url='js_shoes_2.php';
				$.get(url,{'imgid':proid},function(data){
					if(data==''||data==null) return false;
					var arr=data.split('[_]');
					var rt=$("#spic"+sid).parent();
					var v8_li=rt.find(".view8 li");
					v8_li.eq(0).attr('gmaurl',arr[1]);
					v8_li.eq(1).attr('gmaurl',arr[2]);
					v8_li.eq(2).attr('gmaurl',arr[3]);
					v8_li.eq(3).attr('gmaurl',arr[4]);
					v8_li.eq(4).attr('gmaurl',arr[5]);
					v8_li.eq(5).attr('gmaurl',arr[6]);
					v8_li.eq(6).attr('gmaurl',arr[7]);
					v8_li.eq(7).attr('gmaurl',arr[8]);
					var img=rt.find(".view8 .img");
					img.fadeOut(100);
					img.attr('src',arr[1]);
					img.fadeIn(300);				
					
					var info=rt.find(".view8 .info");
					info.find('.title').next().html(arr[9]);
					info.find('p').eq(0).html(arr[10]).attr('href',arr[11]);
					
					rt.find(".xunpan a").attr('href','inquiry.php?action=sub&&proid='+proid);
				});
			});
		
		*/
		
		
		
		//推荐 产品
		$("*[gmatype='recom']").click(function(){
			var proid=$(this).attr('proid');
			var num=0;
			var obj=$(this);
			$.get('vote-ajax.php',{'type':'v','pid':proid},function(data){
				var pos=data.indexOf('_');
				
				if(pos>1){
					alert('推荐成功');
					var arr=data.split('_');
					num = arr[1];
					if(num>0 && allrecom>0){
						var pr=obj.parent().parent().parent();
						pr.find("*[gmatype='recom_bar']").animate({'width':'0px'},0).animate({'width':num*100/allrecom+'%'},1000);						
						pr.find("*[gmatype='recom_res']").hide().html(num).fadeIn();
						
					}
				}else{
					if(data=='voted'){
						alert('您已经推荐过了');
					}else{
						alert('推荐失败');
					}
				}				
			});
			
			
		});
		
		//收藏 产品
		$("*[gmatype='collect']").click(function(){
			var proid=$(this).attr('proid');
			var num=0;
			var obj=$(this);
			$.get('vote-ajax.php',{'type':'f','pid':proid},function(data){
				var pos=data.indexOf('_');
				
				if(pos>1){
					alert('收藏成功');
					var arr=data.split('_');
					num = arr[1];
					if(num>0 && allcollect>0){
						var pr=obj.parent().parent().parent();
						pr.find("*[gmatype='collect_bar']").animate({'width':'0px'},0).animate({'width':num*100/allcollect+'%'},1000);						
						pr.find("*[gmatype='collect_res']").hide().html(num).fadeIn();
						
					}
				}else{
					if(data=='favored'){
						alert('您已经收藏过了');
					}else if(data=='logout'){
						alert('您还没登陆');
					}else{
						alert('收藏失败');
					}
				}				
			});
			
			
		});
		
		//推荐 鞋企
		$("*[gmatype='recom_c']").click(function(){
			var cid=$(this).attr('cid'); 
			var num=0;
			var obj=$(this);
			$.get('vote-ajax.php',{'type':'vc','pid':cid},function(data){
				var pos=data.indexOf('_');

				if(pos>1){
					alert('推荐成功');
					var arr=data.split('_');
					num = arr[1];
					if(num>0 && allrecom_c>0){
						var pr=obj.parent().parent();
						pr.find("*[gmatype='recom_c_bar']").animate({'width':'0px'},0).animate({'width':num*100/allrecom_c+'%'},1000);						
						pr.find("*[gmatype='recom_c_res']").hide().html(num).fadeIn();
						
					}
				}else{
					if(data=='voted'){
						alert('您已经推荐过了');
					}else{
						alert('推荐失败');
					}
				}				
			});
			
			
		});
		
		//percentbar
		
		$.get('vote-ajax.php',{'type':'vm'},function(data){
			if(data){//alert(data)
				var arr=data.split('_');
				if(arr[0]>0){
					allrecom=arr[0];
				}
		
				if(arr[1]>0){
					allcollect=arr[1];
				}
				
				if(arr[2]>0){
					allrecom_c=arr[2];
				}
				
				if(arr[3]>0){
					allcollect_c=arr[3];
				}
				
				$('body').find('*[gmatype="recom_bar"]').each(function(){
					var num=$(this).parent().next('span').html();
					//$(this).css('width',num*100/data+'%');
					$(this).animate({'width':num*100/allrecom+'%'},1000);
				});
				
				$('body').find('*[gmatype="collect_bar"]').each(function(){
					var num=$(this).parent().next('span').html();
					//$(this).css('width',num*100/data+'%');
					$(this).animate({'width':num*100/allcollect+'%'},1000);
				});
				
				$('body').find('*[gmatype="recom_c_bar"]').each(function(){
					var num=$(this).parent().next('span').html();
					//$(this).css('width',num*100/data+'%');
					$(this).animate({'width':num*100/allrecom_c+'%'},1000);
				});

			}
		});
		
		$("#footer_bottom").css('top', $("#frlink_footer").height()+5);
		$("#frlink_footer").css('top', ($("#footer_bottom").height()+25)*-1);
		
	});
	
	function setCityInfo(li){	
	
			var id=li.attr("gmaid");
			if(cur_cityid==id) return false;
			cur_cityid=id;
			var tid="#txt_"+id; 
			var info=$(tid).html();
			if(info==''||info==null) return false;
			var infoarr=info.split('[_]');
			$('#con_xcfc .info .img').attr('src' , li.find('img').attr('src'));
			$('#con_xcfc .info ul').find('li').each(function(i){
				if(i==0){
					$(this).find('span').html(li.find('.title').html());
				}else{
					$(this).find('span').html(infoarr[i-1]);
				}
				i++;
			});
			num=infoarr[0];
			$('#con_xcfc .info ul').find("*[gmatype='recom_c_bar']").animate({'width':'0px'},0).animate({'width':num*100/allrecom_c+'%'},1000);						
			$('#con_xcfc .info ul').find("*[gmatype='recom_c_res']").hide().html(num).fadeIn();
			
			$('#con_xcfc .info ul').find("*[gmatype='recom_c']").attr('cid',id);

			$('#youshi_con').html(infoarr[infoarr.length-1]);
	}
	
	function setCityInfo2(obj){
		setCityInfo($(obj));
	}
	
	
	
		
	function view8chg(obj){
			
				var proid=$(obj).attr("proid");
				if(lastid == proid) return false;
				lastid = proid;
				var sid=$(obj).attr('gmaid');
				var url='js_shoes_2.php';
				$.get(url,{'imgid':proid},function(data){
					if(data==''||data==null) return false;
					var arr=data.split('[_]');
					var rt=$("#spic"+sid).parent();
					var v8_li=rt.find(".view8 li");
					v8_li.eq(0).attr('gmaurl',arr[1]);
					v8_li.eq(1).attr('gmaurl',arr[2]);
					v8_li.eq(2).attr('gmaurl',arr[3]);
					v8_li.eq(3).attr('gmaurl',arr[4]);
					v8_li.eq(4).attr('gmaurl',arr[5]);
					v8_li.eq(5).attr('gmaurl',arr[6]);
					v8_li.eq(6).attr('gmaurl',arr[7]);
					v8_li.eq(7).attr('gmaurl',arr[8]);
					var img=rt.find(".view8 .img");
					img.hide(100).attr('src',arr[1]).fadeIn(300);
					
					img.parent().attr('href','http://shoes.wooshoes.com/apshoes/'+proid+'.html');
					
					
					
				
					var info=rt.find(".evalu .info");
					info.find('.title').next().html(arr[9]);
					info.find('p').eq(0).children('a').html(arr[10]).attr('href',arr[11]);
					
					info.find("*[gmatype='recom_bar']").animate({'width':'0px'},0).animate({'width':arr[12]*100/allrecom+'%'},1000);						
					info.find("*[gmatype='recom_res']").hide().html(arr[12]).fadeIn();
					
					info.find("*[gmatype='collect_bar']").animate({'width':'0px'},0).animate({'width':arr[13]*100/allcollect+'%'},1000);						
					info.find("*[gmatype='collect_res']").hide().html(arr[13]).fadeIn();
					
					info.find("*[gmatype='recom']").attr('proid',arr[0]);
					info.find("*[gmatype='collect']").attr('proid',arr[0]);
					
					rt.find(".xunpan a").attr('href','inquiry.php?action=sub&&proid='+proid);
				});
		}
