var is_doing = 0;
var $obj = 0;
var $dotime = 5000;
function autoplay() {
	$("#fthumb>ul>.thumbs").removeClass("show");
	$("#fthumb>ul>.thumbs:eq("+$obj+")").addClass("show");
	$src = $("#fthumb>ul>.thumbs:eq("+$obj+")>img").attr("src");
	$("#imgshow").fadeOut("slow",function(){
										  $("#imgshow>img").attr("src",$src);
										  $("#imgshow").fadeIn("slow");
										  });
	$obj++;
	if ($obj > 3) $obj = 0;
}
$(document).ready(function(){
						   autoplay();
						   $("#tabs>li:eq(0)").addClass("hover");
						   $(".conts:eq(0)").css("display","block");
						   var auto = setInterval(function(){autoplay();},$dotime);
						   $("#fthumb>ul>.thumbs").bind("mouseover",function(){
																		clearInterval(auto);
																		$("#fthumb>ul>.thumbs").removeClass("show");
																		$(this).addClass("show");
																		$src = $("#"+$(this).attr("id")+">img").attr("src");
																		$("#imgshow").fadeOut("slow",function(){
																											  $("#imgshow>img").attr("src",$src);
																											  $("#imgshow").fadeIn("slow");
																											  });
																		$obj = parseInt($(this).attr("id").replace("thumb",""),10)+1;
																		if ($obj > 3) $obj = 0;
																		});
						   $("#fthumb>ul>.thumbs").bind("mouseout",function(){
																	   auto = setInterval(function(){autoplay();},$dotime);
																	   });
						   $("#tabs>li").bind("mouseover",function(){
																   $("#tabs>li").removeClass("hover");
																   $(".conts").css("display","none");
																   $(this).addClass("hover");
																   $(".conts:eq("+$("#tabs>li").index(this)+")").css("display","block");
																   });
						   });


function showwin($url) {
	var $iw = 600;//图片展示窗口的宽度
	var $ih = 400;//图片展示窗口的高度
	$ww = $(window).width();
	$wh = $(window).height();
	$bh = $("body").height();
	$st = $(document).scrollTop();
	$("body").append("<div id='mask'></div>");
	$("#mask").css({"position":"absolute","top":"0","left":"0","width":$ww+"px","height":$bh+"px","z-index":"1000","background":"#ffffff","filter":"Alpha(Opacity=0)","-moz-opacity":"0","opacity":"0"});
	$("body").append("<div id='image'><img id='showimg' onload='resizeimg(this.id,"+$iw+","+$ih+");' src='/img/blank.gif' /><img id='hideimg' src='/img/blank.gif' style='display:none;' /><div id='allimg' style='display:none;'></div></div>");
	$("#image").css({"position":"absolute","top":parseInt(($wh-$ih)/2+$st,10)+"px","left":parseInt(($ww-$iw)/2,10)+"px","width":$iw+"px","height":$ih+"px","background":"#ffffff","border-color":"#cccccc","border-width":"5px","border-style":"solid","display":"none","z-index":"1001"});
	$("#image").append("<div id='ctrl_bar'><a href='javascript:void(0)' id='img_pre' style='cursor:pointer; display:none;'>上一张</a>&nbsp;<a id='img_next' style='cursor:pointer; display:none;' href='javascript:void(0)' >下一张</a>&nbsp;<a href='javascript:void(0)' style='cursor:pointer;' onclick='hidewin()'>关闭</a></div>");
	$("#ctrl_bar").css({"position":"absolute","right":"10px","bottom":"5px","text-align":"right","z-index":"2000","width":"160px","height":"30px","line-height":"30px","border-color":"#FF3300","border-width":"3px","border-style":"solid","text-align":"center","filter":"Alpha(Opacity=60)","-moz-opacity":"60","opacity":"60","background":"#ffffff"});
	$("#image").fadeIn("slow",function(){
									   $.get($url,function(data){
														   $curr = 0;
														   data_arr = data.split("|$|");
														   var imghtml = '';
														   for (i=0;i<data_arr.length;i++) {
															   imghtml += '<img src="'+data_arr[i]+'" />';
														   }
														   $("#allimg").html(imghtml);
														   if (data_arr.length>1) {
															   $("#img_pre").show();
															   $("#img_next").show();
															   $("#hideimg").attr("src",data_arr[$curr]);
															   setTimeout(function(){$("#showimg").attr("src",data_arr[$curr]);},10);
															   $("#img_pre").bind("click",function(){
																								   if ($curr>0) {
																									   $curr--;
																									   $("#hideimg").attr("src",data_arr[$curr]);
																									   setTimeout(function(){$("#showimg").attr("src",data_arr[$curr]);},10);
																								   }
																								   });
															   $("#img_next").bind("click",function(){
																								   if ($curr<data_arr.length-1) {
																									   $curr++;
																									   $("#hideimg").attr("src",data_arr[$curr]);
																									   setTimeout(function(){$("#showimg").attr("src",data_arr[$curr]);},10);
																								   }
																								   });
														   } else {
															   $("#hideimg").attr("src",data_arr[$curr]);
														       setTimeout(function(){$("#showimg").attr("src",data_arr[$curr]);},10);
														   }
														});
									   });
	$(window).bind("scroll",function(){
									 $("#image").css("top",parseInt(($wh-$ih)/2+$(document).scrollTop(),10)+"px");
									 });
}

function hidewin() {
	$("#image").fadeOut("slow",function(){
										$("#image").remove();
										$("#mask").remove();
										});
}

function resizeimg($obj,$fw,$fh) {//$obj为对象的ID
setTimeout(function(){
	$imgw = $("#hideimg").width();
	$imgh = $("#hideimg").height();
	if ($imgw/$imgh >= $fw/$fh) {
		if ($imgw>=$fw) {
			$tw = $fw;
			$th = parseInt($imgh/($imgw/$fw),10);
			$ipt = parseInt(($fh-$th)/2,10);
			$("#"+$obj).css({width:$tw+"px",paddingLeft:"0px",paddingTop:$ipt+"px",height:$th+"px"});
		} else {
			$ipl = parseInt(($fw-$imgw)/2,10);
			$ipt = parseInt(($fh-$imgh)/2,10);
			$("#"+$obj).css({width:$imgw+"px",height:$imgh+"px",paddingLeft:$ipl+"px",paddingTop:$ipt+"px"});
		}
	} else {
		if ($imgh>=$fh) {
			$th = $fh;
			$tw = parseInt($imgw/($imgh/$fh),10);
			$ipl = parseInt(($fw-$tw)/2,10);
			$("#"+$obj).css({width:$tw+"px",paddingLeft:$ipl+"px",paddingTop:"0px",height:$th+"px"});
		} else {
			$ipl = parseInt(($fw-$imgw)/2,10);
			$ipt = parseInt(($fh-$imgh)/2,10);
			$("#"+$obj).css({width:$imgw+"px",height:$imgh+"px",paddingLeft:$ipl+"px",paddingTop:$ipt+"px"});
		}
	}
},10);
}

function GetCookie(c_name)
{
	if (document.cookie.length > 0)
	{
		c_start = document.cookie.indexOf(c_name + "=")
		if (c_start != -1)
		{
			c_start = c_start + c_name.length + 1;
			c_end   = document.cookie.indexOf(";",c_start);
			if (c_end == -1)
			{
				c_end = document.cookie.length;
			}
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return null
}

function SetCookie(c_name,value,expiredays)
{
	var exdate = new Date();
	exdate.setDate(exdate.getDate() + expiredays);
	document.cookie = c_name + "=" +escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString()); //使设置的有效时间正确。增加toGMTString()
}

function showcal(){
	$("body").append('<div id="cal" style="width:500px; line-height:600px; text-align:center; height:600px; border:#cccccc 3px solid; position:absolute; overflow:hidden;">加载中。。。</div>');
	setTimeout(function(){$("#cal").html('<iframe width="500" height="600" scrolling="no" src="/cal/cal.html" border="0" frameborder="0"></iframe>')},100);
	$_w = $(window).width();
	$_h = $(window).height();
	$_l = parseInt(($_w-500)/2,10);
	$_t = parseInt(($_h-600)/2,10)+$(window).scrollTop();
	$("#cal").css({left:$_l+"px",top:$_t+"px",zIndex:9999});
}

function closecal(){
	$("#cal").remove();
}
