﻿$(document).ready(function(){
	//客服下拉
	var switch_num = $('.switch_ico li').size();
	var switch_time=window.setTimeout(function(){
		go_switch(1);
	},5000);
	function go_switch(n) {
		$('.switch_ico li').attr('class', '');
		$('.switch_ico li')[3-n].className = 'current';
		$(".switch_pic").animate({top:-195*n}, {duration:250});
		if (n+1>=switch_num) n = 0; else n++;
		switch_time=window.setTimeout(function(){
			go_switch(n);
		},5000);
	}
	$(".switch_ico li").click(function(){
		clearInterval(switch_time);
		var n = $(this).text();
		go_switch(n-1);			
	});
	var href = window.location.href.split("#");		//推广
	if (href.length==2) {
		if (href[1].substring(0,1)!='_') {
			href[1] = decodeURI(href[1]);
			$.cookie('recomUser', href[1], {expires: 0, path: '/', domain: '.tdd8.com'});
		}
	}
	
	var shai_num = $('.shai_pic li').size();
	var shai_time=window.setTimeout(function(){
		go_shai(1);
	},2500);
	function go_shai(n) {
		$(".shai_pic").animate({left:-165*n}, {duration:250});
		if (n+1>=shai_num) n = 0; else n++;
		shai_time=window.setTimeout(function(){
			go_shai(n);
		},5000);
	}
	$(".prv_left").click(function(){
		clearInterval(shai_time);
		var str = $(".shai_pic").css('left').replace('px', '');
		if (str=='auto') left1 = 0; else left1 = parseInt(str);
		if (left1==0)
			$(".shai_pic").animate({left:(-165*3)}, {duration:250});
		else 
			$(".shai_pic").animate({left:parseInt(left1+165)}, {duration:250});
	});
	$(".prv_right").click(function(){
		clearInterval(shai_time);
		var str = $(".shai_pic").css('left').replace('px', '');
		if (str=='auto') left1 = 0; else left1 = parseInt(str);
		if (left1==(-165*3))
			$(".shai_pic").animate({left:0}, {duration:250});
		else 
			$(".shai_pic").animate({left:parseInt(left1-165)}, {duration:250});
	});
	
	$(".shop_l").click(function(){
		var str = $(".shop_pic").css('left').replace('px', '');
		if (str=='auto') left1 = 0; else left1 = parseInt(str);
		if (left1==0)
			$(".shop_pic").animate({left:(-496*1)}, {duration:250});
		else 
			$(".shop_pic").animate({left:parseInt(left1+496)}, {duration:250});
	});
	$(".shop_r").click(function(){
		var str = $(".shop_pic").css('left').replace('px', '');
		if (str=='auto') left1 = 0; else left1 = parseInt(str);
		if (left1==(-496*1))
			$(".shop_pic").animate({left:0}, {duration:250});
		else 
			$(".shop_pic").animate({left:parseInt(left1-496)}, {duration:250});
	});
});
function showNewTip(n) {
	if ($.cookie('tao[newUser]')<=2 || $.cookie('tao[newUser]')==null) {
		var bodyX = document.documentElement.clientWidth;
		var bodyY = document.documentElement.clientHeight;
		var moveX = parseInt(bodyX/2);
		var moveY = parseInt(bodyY/2);
		var newtips = "<div class=\"tips_xiu\"><div class=\"tips_top\"><span><a href=\"javascript:;\" title=\"不再显示\" onclick=\"closeNewTip("+n+")\"> </a></span><h4 id=\"tips_title\">亲，您知道淘东东返利网吗？</h4></div><div class=\"tips_bg\" id=\"tips_text\"></div><div class=\"tips_end\"></div></div>";
		if (($.cookie('tao[newUser]')==0 || $.cookie('tao[newUser]')==null) && n==1) {
			var startX = parseInt(bodyX/2);
			var startY = 100;
			$('body').append(newtips);
			$(".tips_xiu").css({left:startX, top:startY});
			$('#tips_text').html('<h4 style=\"margin-top:-10px;\"><span>淘宝购物</span>用<span>淘东东</span>可省更多钱，真的吗？<br><img src=\"http://www.tdd8.com/template/default/jscode/jumpfanli.gif\" style=\"margin-left:-15px;\" /></h4><div class="tips_choose"><div class="smt1"><a href="http://www.tdd8.com/read-23.html" target="_blank">图解３步拿淘宝返利</a></div><div class="smt2"><a href="http://www.tdd8.com/user/register.php">立即注册</a></div></div>');
		} else if (($.cookie('tao[newUser]')==1 || $.cookie('tao[newUser]')==null) && n==2) {
			var startX = parseInt(bodyX/2)+625;
			var startY = 300;
			$('body').append(newtips);
			$(".tips_xiu").css({left:startX, top:startY});
			$('#tips_title').html('亲，您第一次使用！')
			$('#tips_text').html('<h4 style="line-height:25px;">您如何使用<span>淘东东tdd8</span>到<span>淘宝购物</span>，才能拿到额外的<span>返利</span>呢？<br>淘东东支持下面两种方式，1分钟即可学会！</h4><div class="tips_choose"><div class="smt1"><a href="http://www.tdd8.com/read-23.html" target="_blank"><strong>简单３步</strong> 拿返利</a></div><div class="smt2"><a href="http://www.tdd8.com/fanxianbao/index.php" target="_blank"><strong>一键</strong> 拿返利</a></div></div>');
		}
		$(".tips_xiu").animate({left:moveX, top:moveY, width:369, opacity:'show'}, {duration:400});
		$(window).scroll(function (){
			if ($(".tips_xiu").css('display')=='block') $(".tips_xiu").css('top', $(document).scrollTop()+moveY);		   
		});
	}
}

function closeNewTip(n) {
	$.cookie('tao[newUser]', n, {expires: 365, path: '/', domain: '.tdd8.com'});
	var bodyX = document.documentElement.clientWidth;
	var bodyY = document.documentElement.clientHeight;
	var startX = parseInt(bodyX/2);
	var startY = 100;
	if (n>1) {
		startX = parseInt(bodyX/2)+625;
		startY = 300;
	}
	$(".tips_xiu").animate({left:startX, top:startY, width:0, height:0, opacity:'hidden'}, {duration:400});
}

jQuery(document).ready(function($){
	var switch_time=window.setTimeout(function(){
	showNewTip(1);
	}, 2000);
});
