﻿// JScript 文件
var i=0;//最新消息的轮换序号
var timer_;//定时器变量
var novel_index=-1;//#novel_list>ul>li的最后那个li的索引值
$(document).ready(function(){

novel_index=$("#novel_list>ul>li").size()-1;
imgmove();
imgScroll();
imgChange();
getVedioList(1);
getBestNewVideo();
getTopPoster("4","2");//把产品类型是2,3得都读取出来
//getTopGuidcar("2","4");
newsEffect();
$("#news_list h2,#news_list p").mouseover(function(){//1
clearTimeout(timer_);
});//1
$("#news_list h2").mouseover(function(){//1
i=$(this).attr("id");
mouseoverNews();
});//1

$("#news_list h2,#news_list p").mouseout(function(){//1
i=1;
timer_=setInterval("timer()",3000);
});//1
});

function imgChange()//实现首页右上角“亚士里道”，“旺角”，“尖沙嘴”点击上去的换图效果，思路跟只换一副底图的不同！使用时，只需要img的id跟其中一副默认底图的前缀名称一致就可以！
{//1
 $("#AreaBtnList img").each(function(){//2
$(this).bind("click",function(){//3
$(this).attr("src","img/button"+$(this).attr("id")+"b.jpg");
$("#AreaBtnList img").not($(this)).each(function(){//4
$(this).attr("src","img/button"+$(this).attr("id")+".jpg");
});//4
getVedioList($(this).attr("id"));//获取地区编号与该元素Id匹配的地区的短片
});//3
});//2
}//1

function imgScroll()//图片上下滚动
{
	$("#prv").click(function()
	{
		$("#ScrollImgList>ul").animate({marginTop:-68},500,function(){$("#ScrollImgList>ul>li:first").appendTo("#ScrollImgList>ul");$(this).css("marginTop",0);});
	}	
	);

    $("#nex").click(function()
	{
       $("#ScrollImgList>ul>li:last").prependTo("#ScrollImgList>ul");
	   $("#ScrollImgList>ul").css("marginTop",-68).animate({marginTop:0},500);

	}	
	)
}


function getVedioList(areaId){
$("#ScrollImgList").html("<div style=' width:100px; height:16px;top:80px;left:83px; position:absolute;'><img alt='' src='img/loadding.gif'  /></div>");
$.ajax({
type:"get",
dataType:"json",
url:"handle.ashx",
data:"type=getVideo&area="+areaId,
success:function(result){
$("#ScrollImgList").html("<ul></ul>");
var data=result.vediolist;
$.each(data,function(i,n){
$("#ScrollImgList ul").append("<li><img id='"+n.t1_10+"' alt='' src='"+n.t1_11+"' /><div><h5>"+n.t1_3+"</h5><p>"+n.t1_7.substr(0,25)+"...</p></div></li>");
});
$("#ScrollImgList ul img").each(function(){
$(this).bind("click",function(){$("#ifr").attr("src","play.htm?video="+$(this).attr("id"));});
});

},

error:function(){$("#ScrollImgList").html("<div style=' width:200px; height:16px;top:128px;left:75px; position:absolute;color:White;'>Coming Soon...</div>");}
});

}


function getBestNewVideo(){//1
$("#crop_video_list").html("<div style=' width:100px; height:16px;top:20px;left:130px; position:absolute;'><img style=' width:60px; height:60px;'  alt='' src='img/loadding.gif'  /></div>");
$.ajax({//2
type:"get",
dataType:"json",
url:"handle.ashx",
data:"type=bestNew",
success:function(result){//3
$("#crop_video_list").html("<ul></ul>");
$.each(result.bestnew,function(i,n){//4
$("#crop_video_list ul").append("<li><a href='video.html'><img alt='' src='"+n.t1_11+"' /></a><h5>"+n.t1_3.substr(0,15)+"</h5>")
});//4
},//3
error:function(){$("#crop_video_list").html("<div style=' width:200px; height:16px;top:44px;left:70px; position:absolute;color:White;'>Coming Soon...</div>");}

});//2
}//1

function getTopPoster(pagesize,typeId){//1最新四个海报或者卡片作品
//$("#design_list").html("<div style=' width:100px; height:16px;top:20px;left:130px; position:absolute;'><img style=' width:60px; height:60px;'  alt='' src='img/loadding.gif'  /></div>");
$.ajax({//2
type:"get",
dataType:"json",
url:"handle.ashx",
data:"type=production&pagesize="+pagesize+"&typeId="+typeId,
success:function(result){//3
$("#design").html("<ul></ul>");
$.each(result.production,function(i,n){//4
$("#design ul").append("<li><h5>"+n.t2_2+"</h5><a href='showroom.html'><img alt='' src='production/upload/"+n.t2_3+".jpg'/></a><p>"+n.t2_5.substr(0,36)+"</p></li>");
});//4
},//3
error:function(){alert("抱歉，伺服器繁忙，未讀取到您要的資料！");}
});//2
}//1

function getTopGuidcar(pagesize,typeId){//1最新guid卡的作品
//$("#design_publi").html("<div style=' width:100px; height:16px;top:20px;left:130px; position:absolute;'><img style=' width:60px; height:60px;'  alt='' src='img/loadding.gif'  /></div>");
$.ajax({//2
type:"get",
dataType:"json",
url:"handle.ashx",
data:"type=production&pagesize="+pagesize+"&typeId="+typeId,
success:function(result){//3
$("#design_list").html("<ul></ul>");
$.each(result.production,function(i,n){//4
$("#design_list ul").append("<li><a href='showroom.html'><img alt='' src='production/upload/"+n.t2_3+".jpg' /></a><div><h5>"+n.t2_2+"</h5></div></li>");
});//4
},//3
error:function(){alert("暫時無書刊數據");}
});//2
}//1


function getVideoList(pageIndex,videoTypeId){//1
$.ajax({//2
type:"get",
dataType:"json",
url:"handle.ashx",
data:"type=getVideoList&videoTypeId="+videoTypeId+"&pageIndex="+pageIndex,
success:function(result){//3
$("#v_list").html("<ul></ul>");
$.each(result.vediolist,function(i,n){//4
$("#v_list ul").append("<li><img alt='' src='"+n.t1_11+"' /><div><h5>"+n.t1_3+"</h5><p>"+n.t1_7.substr(0,70)+"...</p><img alt='' src='img/play.jpg' /></div></li>");
});//4
},//3
error:function(){alert("error");}
});//2
}//1


function newsEffect(){//1最新消息的效果
$("#news_list h2:eq(0)").css("margin-top",0);
$("#news_list p").addClass("pHide");
$("#news_list p:eq(0)").addClass("pShow");
$("#news_list h2 a").css("color","#E1E1E1");
$("#news_list h2:eq(0) a").css("color","#A2E703");
timer_=setInterval("timer()",3000);
}//1


function timer(){//1最新消息定时器里面的函数
if(i==3){i=-1;}
$("#news_list p,#news_list h2 a").removeClass();
i+=1;
$("#news_list p").addClass("pHide");
$("#news_list p:eq("+i+")").addClass("pShow");
$("#news_list h2 a").css("color","#E1E1E1");
$("#news_list h2:eq("+i+") a").css("color","#A2E703");
$("#imgMove").attr("src",$("#imgB").attr("src")).css("z-index",30);$("#imgB").attr("src","img/"+$("#news_list h2:eq("+i+")").attr("title"));$("#imgMove").animate({left:-240,top:15},300,function bck(){$("#imgMove").css("z-index",10).animate({left:0,top:0},1000);})
if(i==0) $("#big a").attr("href","talkSHOW.html");
if(i==1) $("#big a").attr("href","http://www.ivision.com.hk/ebook/VOL01/index.aspx");
if(i==2) $("#big a").attr("href","DN.html");
}//1


function mouseoverNews(){//1鼠标停在最新消息上面时候
$("#news_list p,#news_list h2 a").removeClass();
$("#news_list p").addClass("pHide");
$("#news_list p:eq("+i+")").addClass("pShow");
$("#news_list h2 a").css("color","#E1E1E1");
$("#news_list h2:eq("+i+") a").css("color","#A2E703");
$("#imgMove").attr("src",$("#imgB").attr("src")).css("z-index",30);$("#imgB").attr("src","img/"+$("#news_list h2:eq("+i+")").attr("title"));$("#imgMove").animate({left:-240,top:15},300,function bck(){$("#imgMove").css("z-index",10).animate({left:0,top:0},1000);})
if(i==0) $("#big a").attr("href","talkSHOW.html");
if(i==1) $("#big a").attr("href","http://www.ivision.com.hk/ebook/VOL01/index.aspx");
if(i==2) $("#big a").attr("href","DN.html");
if(i==3) $("#big a").attr("href","Green GZ.html");
}//1

function imgmove(){
	var _left=function(){
		$("#novel_list>ul").animate({marginLeft:-332},1500,'',function(){
			$(this).find("li:lt(4)").appendTo( $("#novel_list>ul"));//lt()里面的数字是前四个li的索引
			$(this).css("marginLeft",0);
			});
	};
	var _right=function(){
		var i=novel_index-4;
		//$("#novel_list>ul").find("li:gt(3)").prependTo($("#novel_list>ul"));//gt（）里面的数字四最后四个的索引
		$("#novel_list>ul").find("li:gt("+i+")").prependTo($("#novel_list>ul"));//gt（）里面的数字四最后四个的索引,函数会自动适应，不用更改！
		$("#novel_list>ul").css("marginLeft",-332);
		$("#novel_list>ul").animate({marginLeft:0},1500,'',function(){
			
			});
	}
	$("#prv_h").bind("click",_left);		
	$("#nex_h").bind("click",_right);

}