var tempImgId;
var timeoutID;
var isIE6=false;   
document.write("<!--[if lte IE 6]><script>isIE6=true;</scr"+"ipt><![endif]-->");   
$(document).ready(function(){
if(isIE6){
	var answer = confirm("您的浏览器版本过低,请更新您的浏览器");
		if(answer){
			window.location.href='http://www.microsoft.com/china/windows/internet-explorer/';
		}
	}
	$("a#img_"+0).show();
	$("ul#img_a_list").find("li:first").attr("class","selected");
	tempImgId = 0;
	timeoutID = setTimeout('refreshImg()',5000);

	$("ul#img_a_list").find("li").each(function(i){
		$(this).find("a").bind("click",function(e){
			refreshTimeOut();
			return showImg(i);
		});
	});
	$("div.poster_image").find("a.previous").bind("click",function(e){
		refreshTimeOut();
		if(tempImgId>0){
			var id = tempImgId;
			id--;
			return showImg(id);
		}else if(tempImgId==0){
			var id = tempImgId;
			id = 4;
			return showImg(id);
		}
	});
	$("div.poster_image").find("a.next").bind("click",function(e){
		refreshTimeOut();
		if(tempImgId<4){
			var id = tempImgId;
			id++;
			return showImg(id);
		}else if(tempImgId == 4){
			var id = tempImgId;
			id = 0;
			return showImg(id);
		}
	});
	var m = 0;
	var divHtml = Array();
	var j = 0;
	var ulHtml = Array();
	var k = 0;
	var footerHtml = Array();
	$.getJSON("./?mod=news&ac=do&t="+Math.random(), function(json){
		$.each(json,function(pkey,pvalue){
		var n = 0;
		var html = Array();
 		$.each(pvalue,function(key,value){
			if(key==0){
				divHtml[m] = '<a href="index.php?mod=news&ac=show&op=show&class=1&type='+value.type+'&newsid='+value.newsid+'" class="bigimg"><img src="./Global/attachment/'+value.pic+'.homebig.thumb.jpg" width="316" height="162" alt="#" /></a><a href="index.php?mod=news&ac=show&op=show&class=1&type='+value.type+'&newsid='+value.newsid+'" class="bigimg_title">'+value.title+'</a>';
				m++;
				footerHtml[k] = '<a href="index.php?mod=news&ac=show&op=show&class=1&type='+value.type+'">Read More</a>';
				k++;
			}else{
				html[n] = '<li>';
				n++;
				html[n] = '<a href="index.php?mod=news&ac=show&op=show&class=1&type='+value.type+'&newsid='+value.newsid+'" class="smallimg"><img src="./Global/attachment/'+value.pic+'.homesmall.thumb.jpg" width="86" height="55" alt="#" /></a><a href="index.php?mod=news&ac=show&op=show&class=1&type='+value.type+'&newsid='+value.newsid+'" class="smallimg_title">'+value.title+'</a>';
				n++;
				html[n] = '</li>';
				n++;
			}
		});
		html = html.join('');
		ulHtml[j] = html;
		j++;
		});
		$("ul#ul_tabs").find("li").find("a").each(function(i){
			$(this).bind("click",function(){
				$("ul#ul_tabs").find("li").removeClass("selected");
				$(this).parent().addClass("selected");
				$("div#tab div.news_bigimg").html(divHtml[i]);
				$("div#tab ul").html(ulHtml[i]);
				$("div#tab div.box_footer_button").html(footerHtml[i]);
				return false;
			});
		});
	});
	$("div#blockup1").before('<div class="markA" id="markA"></div>');
	$("div#blockup1").slideDown("");
	$("a#next_chain").bind("click",function(){
		$("div#blockup1").slideUp("");
		$("div#markA").remove();
	});
});
function refreshImg(){
	var id = tempImgId;
	if(id == 4){
		id = -1;
	}
	id++;
	showImg(id);
	timeoutID = setTimeout('refreshImg()',5000);
}
function refreshTimeOut(){
  clearTimeout(timeoutID);
  timeoutID = setTimeout('refreshImg()',10000);
}
function showImg(id){
	$("ul#img_a_list").find("li#imgli_"+tempImgId).removeAttr("class");
	$("ul#img_a_list").find("li#imgli_"+id).attr("class","selected");
	var id = id;
	$("a.img").stop().fadeOut();
	if(!$("a#img_"+tempImgId).is(':hidden')){
		$("a#img_"+tempImgId).fadeOut("fast",function(){
			if($("a#img_"+id).is(':hidden')){
				$("a#img_"+id).fadeIn("fast");
			}
		});
	}
	tempImgId = id;
}

