// JQuery Action for gllover.com
// Author: kandytang[at]msn.com
// Home: www.jgpy.cn
// Pubdate: 2010-6-20
// Last Modified: 2010-6-30 14:45:48

function slide(){
	$("#slidenav .cur").removeClass("cur").next().addClass("cur");
	if ($("#slidenav .cur").is(".last")) {
		$("#slidenav li:last").removeClass("cur")
		$("#slidenav li:first").addClass("cur");
	}
	$("#slidenav li.cur").trigger("mouseover");
}

function imgresize(){
	$("#text img").each(function(){
		if ($(this).width()>710) {
			$(this).width("100%")
		}
								 });
}

$(function(){

	// slide
	$("#slide").wrapInner('<div id="slideshow"/>').append('<ul id="slidenav"/>');
	$("#slideshow img:gt(0)").hide();
	var i = 0;
	while(i<$("#slide img").length) {
		$("#slidenav").append("<li>"+(i+1)+"</li>")
	++i
	}
	$("#slidenav").append("<li/>");
	$("#slidenav li:last").addClass("last").hide();
	$("#slidenav li").mouseover(function(){
		var n = $(this).text()-1;
		//alert(n)
		$(this).addClass("cur").siblings().removeClass("cur");
		setTimeout(function(){
			$("#slideshow img:visible").stop(false,true).fadeOut()
			$("#slideshow img").eq(n).stop(false,true).fadeIn()
			},200)
									 });
	$("#slidenav li:first").addClass("cur");
	var s = setInterval(function(){slide()},4000);
	$("#slideshow img").hover(function(){
		clearTimeout(s)					   
							   },function(){
		s = setInterval(function(){slide()},4000);						   
							   });

	// wrap
	$("#wrap .inner").append("<div class='clear'/>");
	// bbslist
	//$("#bbslist ul").find("a[title],br").remove().find("a:gt(8)").remove();
	var bbslist = $("#bbslist ul a:not([title])");
	$("#bbslist ul").empty().html(bbslist).find("a:gt(8)").remove();
	$("#bbslist ul a").wrap("<li/>");
	// gallery
	var pos = $("#gallery .imglist a").height()+20;
	var innerh = $("#gallery .innerlist").height();
	
	$("#gallery .imglist a").click(function(){
		var imgsrc = $("img",this).attr("src");
		$("#text center img").attr("src",imgsrc).width("auto");
		$("#gallery .imglist a").removeClass("cur");
		$(this).addClass("cur");
		imgresize();
		return false;
									 });
	$("#nextpic").click(function(){
		$(".innerlist").animate({top:"-="+pos},function(){
			//alert($(this).position().top)
			$("a.cur",this).parent().next().find("a").trigger("click")
			if (-$(this).position().top>=innerh) {
				//alert("ok");
				$(this).animate({top:0})
				$("#gallery .imglist a:first").trigger("click")
			}
														});
								 });
	$("#prevpic").click(function(){
		$(".innerlist").animate({top:"+="+pos},function(){
			//alert($(this).position().top)
			$("a.cur",this).parent().prev().find("a").trigger("click")
			if ($(this).position().top>0) {
				//alert("ok");
				$(this).animate({top:0});
				$("#gallery .imglist a:first").trigger("click")
			}
														});
								 });
	$("#gallery .imglist a:first").trigger("click")
	$("#gallery .imglist img").each(function(){
		var h = $(this).height();
		var ph = $(this).parent().height();
		var pad = ph-h;
		//alert(h+" "+ph+" "+pad)
		if (h>ph) {
			$(this).css("top",pad)
		}
											 });
	
})
