//create by Siva
//last modified 2011-07-18

var topShow = {
	hover : function(o,t,css){
		$(o).hover(function(){$(t).show()},function(){$(t).hide();});
		$(t).hover(function(){
			$(o).addClass(css);
			$(this).show();
		},function(){
			$(o).removeClass(css);
			$(this).hide();
		});
	}
};

var PhotoNews = function(o){
	o.num = 1;
	this.obj = o;
	o.length = $(o.bigPic).children().length;
	o.eachHeight = $(o.bigPic).children().eq(0).height();
	$(o.bigNum).children().click(function(){
	  var oIndex=$(o.bigNum).children().index(this);
	  $(this).addClass(o.css).siblings().removeClass(o.css);
	  $(o.bigPic).stop(true).animate({"marginTop":"-"+oIndex*o.eachHeight},o.animate);
	  o.num=oIndex+1;
	})
};

PhotoNews.prototype = {
	show : function(o){
		if(o.num<o.length){
			$(o.bigPic).animate({"marginTop":"-"+o.num*o.eachHeight},o.animate);
			$(o.bigNum).children().eq(o.num).addClass(o.css).siblings().removeClass(o.css);
			o.num++;
		}else{
			$(o.bigPic).animate({"marginTop":"0"},o.animate);
			o.num=1;
			$(o.bigNum).children().eq(0).addClass(o.css).siblings().removeClass(o.css);
		}
	},
	interval : function(){
		var that = this;
		var o = this.obj;
		var player = setInterval(function(){that.show(o);},o.scrollSpeed);
		$(o.bigPic).hover(function(){clearTimeout(player);},function(){player=setInterval(function(){that.show(o);},o.scrollSpeed);});
	}
};

$(function(){

	$t.setRegfrom();

	var indexNews = {
	bigPic : "#photo_player_con",
	bigNum : "#numlist",
	animate : 800,
	scrollSpeed : 4000,
	css : "sel"
	}

	$("#banner_close").bind("click",function(){$("#topbanner").hide();});

	new PhotoNews(indexNews).interval();

	topShow.hover("#show_all_lott","#all_lott_list","sel");

	function showFn(){
		$("#notice_list ul").animate({"marginTop":"-=36px"},600,function(){$("#notice_list ul").css("marginTop","0");$("#notice_list ul").append($("#notice_list ul li:lt(2)"));});
	}
	/** 首页公告滚动 **/
    var each_height=$("#notice_list li").height();
    var showNoticeList=setInterval(showFn,2000);
	var $oBox=$(".out_box");
	var $oBox_len=$(".out_box").length;
	if(window.ActiveXObject&&!window.XMLHttpRequest){
	window.onscroll=function(){
		for(i=0;i<$oBox_len;i++){	
			$oBox[i].style.top=150+document.documentElement.scrollTop+"px";
		}
	  }
	};
	
	//开奖号码tab
	showTab.mouseover({
		current : "#open_num_ul>li",
		target : "#open_num_box>div",
		css : "sel"
	});
	
	//公告、帮助tab
	showTab.mouseover({
		current : "#tit_notice_help>li",
		target : "#con_otice_help>div",
		css : "sel"
	});
	//走势图tab
	showTab.click({
		current : "#tit_trend>li",
		target : "#con_trend>div",
		css : "sel"
	});

	new IndexLottJson().bindValOrEvent({
		redCss : "num_style num_red_style",   // 红球样式
		blueCss : "num_style num_blue_style",  // 篮球样式
		jjcRedCss : "num_style_squre",  // 竞技彩红球
		jjcBlueCss : "" // 竞技彩篮球
	});

	var def = {
		size : 12,  // 显示长度
		target : "#tab_togather",// 需要操作的DIV
		title : "<tr>" +
				"<th width='75' scope='col'>彩种</th>" +
				"<th scope='col'>发起人</th>" +
				"<th scope='col' width='125'>战绩 </th>" +
				"<th scope='col' width='100'>方案进度</th>" +
				"<th scope='col' width='80'>方案金额</th>" +
				"<th scope='col' width='56'>每份</th>" +
				"<th scope='col' width='75'>剩余份数</th>" +
				"<th width='65' scope='col'>参与</th>" +
				"</tr>",
		value : "<tr>"+
				"<td align='left'>{lottName}</td>" +
				"<td align='left'><a href='http://trade.cpdyj.com/trade/user/buyhistory.html?username={userName}&lottype={lottId}&playtype={playId}'>{userName}</a></td>" +
				"<td><a style='cursor:pointer' onclick=\"$t.openStarHistory('{userName}','{lottId}','{playId}')\">{star}</a></td>" +
				"<td align='left'>{salePercent}</td>" +
				"<td align='right'>{money} 元</td>" +
				"<td align='center'>{perMoney} 元</td>" +
				"<td align='right'>{restCount} 份</td>" +
				"<td align='center'><a href='http://trade.cpdyj.com/trade/viewpath.go?lottype={lottId}&playtype={playId}&projectid={optId}' class='btn_twoword'>参与</a></td>" +
				"</tr>",
		loading : "#loading",
		allUri : "#all_project_uri",
		lock : "<span class='color_red'>(保)</span>",
		afterDo : function(){
			$("#tab_togather tr:even:not(:first)").css("backgroundColor","#F5FAFE");
			var defaultBg;
			$("#tab_togather tr:not(:first)").hover(function(){
				defaultBg=$(this).css("background-color");
				$(this).css("background-color","#FFFFE8");
			},function(){
				$(this).css("background-color",defaultBg);
			});
		}
	};

	$("#nav_project>li").bind("click",function(){
		$(this).addClass("sel").siblings().removeClass("sel");
		var i = this.id.split("_")[1];
		var j = this.id.split("_")[2];
		cpdyj.project.get({i:i,j:j},def);
	});

	cpdyj.project.get({i:0,j:0},def);//参见cpdyj.project.js

	$t.getAllMoney(function(val){//获得总中奖金额
		$("#allMoney").html(Math.round(val/1000)/100000);
	});

	$t.getWinner(function(i,username,lottname,expect,paymoney){
		$("#notice_list>ul").append("<li>&nbsp;" + username + "&nbsp;&nbsp;" + lottname + "&nbsp;&nbsp;喜中" + "&nbsp;<span class='color_red'>"+paymoney*1+" 元</span></li>");
	});

	$("#more_icon").hover(function(){
		$("#con_more").show();
	},function(){
		$("#con_more").hide();
	});

	cpdyj.login.isLogin(new LoginDiv(defaultLog));//如果不是使用defaultLog，可以重新定义
	
	//setTimeout(function(){if($("#topbanner")) {$("#topbannerimg").attr("src","http://img.starlott.com/resouce/upload/20111107222824-10487.jpg");setTimeout(function(){$("#banner_close").show();},1000);}},6*1000);
	setTimeout(function(){if($("#topbanner")) $("#banner_close").show();},1000);
});
