$(document).ready(function() {
	//topline 头部下拉菜单					   
	$('#topLine_nav').hover(function(){
	  $(this).addClass('topLine_nav');
	  $('#topLine_nav div').show();
	}).mouseleave(function(){
	  $(this).removeClass('topLine_nav');
	  $('#topLine_nav div').hide();
	});



   //列表隔行换色
   $('.tableGray tbody tr:even').addClass('bgGray');
   $('.tableGray tbody tr:odd').addClass('bgWhite'); 


   //list 列表 赛事筛选
	$('.sx').click(function(){
	  $(this).addClass('sx2');
	  $('.sx_li').show();
	});
	$('.sx_li').mouseleave(function(){
	  $('.sx').removeClass('sx2');
	  $(this).hide();
	});
	
	
	//help tips 
	$('#iconHelp1').hover(function(){
	  $('#helpTips1').show();									 
    }).mouseleave(function(){
	  $('#helpTips1').hide();	
	});
	
	
	//首页左边 伸缩
	$('.leftPrize h5').click(function(){
	  $('.leftPrize dl').hide(500);
	  $(this).next('dl').show(500);
	});

   //首页左边 排行
   $(".prizeRanking ol").find("li em:lt(3)").addClass("bgRed");
   
});



//弹出隐藏层
function ShowDiv(show_div,bg_div){
document.getElementById(show_div).style.display='block';
document.getElementById(bg_div).style.display='block' ;
var bgdiv = document.getElementById(bg_div);
bgdiv.style.width = document.body.scrollWidth;
// bgdiv.style.height = $(document).height();
$("#"+bg_div).height($(document).height());
};
//关闭弹出层
function CloseDiv(show_div,bg_div)
{
document.getElementById(show_div).style.display='none';
document.getElementById(bg_div).style.display='none';
};




/**************** tab ****************/
function tabMember(num,url){
		for(var id = 0;id<=7;id++)
		{
			if(id==num)
			{
				document.getElementById("on"+id).style.display="block";
				document.getElementById("myon"+id).className="on";
				if(url!=''&& url!=null){
					window.location.href=url;//给跳转url
				}
			}
			else
			{  
				document.getElementById("on"+id).style.display="none";
				document.getElementById("myon"+id).className="";
		}
	}
	
}

$(document).ready(function(){
	$(".menu li").hover(function(){
			$(this).addClass("hover");
			$(this).children("ul").show();
			$(".menu li ul li").removeClass("hover");
		},function(){
			$(this).removeClass("hover");
			$(this).children("ul").hide();
			$(".menu li ul li").removeClass("hover");
		}
	); 
	
})

// JavaScript Document
$(function(){
	var sw = 1;
	$(".banner .num a").mouseover(function(){
		sw = $(".num a").index(this);
		myShow(sw);
	});
	function myShow(i){
		$(".banner .num a").eq(i).addClass("cur").siblings("a").removeClass("cur");
		$(".banner ul li").eq(i).stop(true,true).fadeIn(600).siblings("li").fadeOut(600);
		$(".banner ol li").eq(i).stop(true,true).fadeIn(600).siblings("li").fadeOut(600);
	}
	//����ֹͣ������������ʼ����
	$(".banner").hover(function(){
		if(myTime){
		   clearInterval(myTime);
		}
	},function(){
		myTime = setInterval(function(){
		  myShow(sw)
		  sw++;
		  if(sw==5){sw=0;}
		} , 5000);
	});
	//�Զ���ʼ
	var myTime = setInterval(function(){
	   myShow(sw)
	   sw++;
	   if(sw==5){sw=0;}
	} , 3500);
})
/* QQ客服 */
function myEvent(obj,ev,fn){
	if (obj.attachEvent){
		obj.attachEvent('on'+ev,fn);
	}else{
		obj.addEventListener(ev,fn,false);
	};
};
function getbyClass(id,sClass){
	var oParent = document.getElementById(id);
	var all = oParent.getElementsByTagName('*');
	var array = [];
	for (var i=0; i<all.length; i++){
		if (all[i].className == sClass){
			array.push(all[i]);
		};
	};
	return array;
};
function getStyle(obj,name){
	if(obj.currentStyle){
		return obj.currentStyle[name];
	}else{
		return getComputedStyle(obj,false)[name];
	};
};
function Running(obj,json,fnEnd){
	clearInterval(obj.timer);
	obj.timer=setInterval(function(){
		var now=0;
		var bStop=true;
		for (var attr in json){
			if(attr=='opacity'){
				now=Math.round(parseFloat(getStyle(obj,attr))*100);
			}else{
				now=parseInt(getStyle(obj,attr));
			};
			var speed=(json[attr]-now)/5;
			speed=speed>0?Math.ceil(speed):Math.floor(speed);
			if(now!=json[attr])bStop=false;
			if(attr=='opacity'){
				obj.style.filter='alpha(opacity:'+now+speed+')';
				obj.style.opacity=(now+speed)/100;
			}else{
				obj.style[attr]=speed+now+'px';
			};
		}
		if(bStop){
			clearInterval(obj.timer);
			if(fnEnd)fnEnd();
		}
	}, 30);
}
function Flexing(obj,json,fnEnd){
	clearInterval(obj.timer);
	obj.timer=setInterval(function(){
		var now=0;
		var bStop=true;
		for (var attr in json){
			if(!obj.speed)obj.speed={};
			if(!obj.speed[attr])obj.speed[attr]=0;
			now=parseInt(getStyle(obj,attr));
			if(Math.abs(json[attr]-now)>1 || Math.abs(obj.speed[attr])>1){
				bStop=false;
				obj.speed[attr]+=(json[attr]-now)/5;
				obj.speed[attr]*=0.85;
				var MaxSpeed=65;
				if(Math.abs(obj.speed[attr])>MaxSpeed){
					obj.speed[attr]=obj.speed[attr]>0?MaxSpeed:-MaxSpeed;
				};
				obj.style[attr]=now+obj.speed[attr]+'px';
			};
		};
		if(bStop){
			clearInterval(obj.timer);
			obj.style[attr]=json[attr]+'px';
			if(fnEnd)fnEnd();
		};
	}, 30);
}
function setqq(obj,num){

	if (obj.length!=num.length){
		alert('\nspan的个数与QQ号码的个数不符，请设置5个QQ号码!\n\n[设置未成功!]');
		return;
	}else{
		for (var i=0; i<num.length; i++){
		
			
			var online= new Array(); 
			src="http://webpresence.qq.com/getonline?Type=1&"+num[i]+":";
			console.info(src);
			console.log(online);
			if (online[0]==0)
				
				obj[i].innerHTML = "<a target='_blank' href='http://wpa.qq.com/msgrd?v=3&uin="+num[i]+"&site=qq&menu=yes'><img src='http://www.beikecai.com/images/ballpic/kf"+i+".png' border=0 align=center /></a>";
			else
				obj[i].innerHTML = "<a target='_blank' href='http://wpa.qq.com/msgrd?v=3&uin="+num[i]+"&site=qq&menu=yes'><img src='http://www.beikecai.com/images/ballpic/kf"+i+i+".png' border=0 align=center /></a>"; 
		};
	};
};
function settop(id,id2,top){
	var obj = document.getElementById(id);
	var box = document.getElementById(id2);
	obj.style.top = box.style.top = top+'px';
};
function dealy(id,time){
	var obj = document.getElementById(id);
	var timer = setTimeout(function(){
		Flexing(obj,{right:0});
	},time*1000);
};
function click_fn(id,id2){
	var obj = document.getElementById(id);
	var box = document.getElementById(id2);
	obj.onclick = function(){
		Running(obj,{right:-200},function(){
			box.style.display = 'block';
			Running(box,{right:10, opacity:100});					
		});
	};
	box.onclick = function(){
		timer = setTimeout(function(){
			Running(box,{right:-220,opacity:0},function(){
				box.style.display = 'none';
				Flexing(obj,{right:-73});
			});			
		},3000);
	};
};


$(function(){
	var ol = $(".prizeRanking ol");
	var lists = ol.children("li");
	
	lists.first().clone().appendTo(ol);
	var STEP = 2;
	
	var start = function(div){
		var height = div.height();
		(function rollUp(){
			height -= STEP;
			if(0 >= height){
				div.css("margin-top", "");
				div.appendTo(ol);
				return ;
			}
			
			var top = div.css("margin-top").replace("px", "");
			top = parseInt(top);
			top -= STEP;
			div.css("margin-top", top + "px");
			window.setTimeout(function(){ rollUp(); }, 30);
		})();
	};
	
	window.setInterval(function(){
		var cur = ol.children("li").first();
		cur.css("margin-top", "");
		start(cur);
	}, 5000);
});

/** 右侧导航栏动画处理 */
$(function(){
    "use strict";

    $(".navibody li .item").hover(function(){
        $(this).css("background-color", "red");
        var div = $(this).siblings(".navbar-tip");
        var width = div.width();
        var tip = div.find("p");
        div.show();
        if(div.hasClass("qr") || div.hasClass("list")){
            div.fadeIn();
        }
        else{
            tip.stop().animate({
                right: 0
            }, 100);
        }
    }, function(){
        $(this).css("background-color", "transparent");
        var div = $(this).siblings(".navbar-tip");
        if(div.hasClass("qr")){
            div.fadeOut();
        }
    });

    $(".navibody li .navbar-tip").hover(function(){
    	$(this).siblings(".item").css("background-color", "red");
    }, function(){
        var div = $(this);
        var tip = div.find("p");
        $(this).siblings(".item").css("background-color", "transparent");
        if(div.hasClass("qr") || div.hasClass("list")){
            div.fadeOut();
        }
        else{
            tip.stop().animate({
                right: "-200px"
            }, 500, function(){ div.hide(); });
        }
    });
});

/** 设置QQ客服 */
$(function(){
    "use strict";

    var QQ = ['2946506216','2947309407','1311387743','2877853910','2192679183'];

    function setQQList(list){
        var length = list.length;
        var ol = $("#kf");
        var li = "<ol>";
        for(var i = 0; i < length; ++i){
            var qq = list[i];
            var href = "http://wpa.qq.com/msgrd?v=3&uin=" + qq + "&site=qq&menu=yes";
            var imgSrc = "http://wpa.qq.com/pa?p=2:" + qq + ":51";

            li += "<li>";
            li += "" +
                "<span class='span_t'>" + (i + 1) + ":</span>" +
                "<span class='qq_num'>" +
                    "<a target='_blank' href='" + href + "'>" +
                        "<img border='0' src='" + imgSrc + "' alt='贝壳彩' title='点击咨询'>" +
                    "</a>" +
                "</span>";
            li += "</li>";
        }
        li += "</ol>";
        ol.html(li);
    }
    setQQList(QQ);
});

