﻿// JavaScript Document

//页面加载开始
$(function(){

	//所有页面
		//$("#sys_menu li").mousemove(function(){
		//	$("#sys_menu li").removeClass("selected");
		//	$(this).addClass("selected");
		//})

	//主页
	if($('body').attr('id')=='page_homeindex'){
		initPlaybox();
	};

	//商城首页
	if($('body').attr('id')=='page_shopindex'){
		initPlaybox();
		initScroll();
	};

	//商城列表页
	if($('body').attr('id')=='page_shoplist'){
		$("#sortList .box_func").show();
		vheight=$("#sortList .box_list").height();
		if(vheight>50){
			$("#sortList .box_list").css("overflow","hidden").height(50);
			$("#sortList .box_list").after("<span id='btnAll'><a>显示全部</a></span>");
			$("#btnAll").click().toggle(
				function(){
					$("#sortList .box_list").animate( { height: vheight}, 1000 );
					$("#btnAll a").html("显示精简").addClass("selected");
				},
				function(){
					$("#sortList .box_list").animate( { height: 50}, 1000 )
					$("#btnAll a").html("显示全部").removeClass("selected");
				}
			)
	  }
	};

	//商城内容页
	if($('body').attr('id')=='page_shopcontent'){
	  $('#photoList').jcarousel({
	  	auto: 5,
			wrap: 'last',
			initCallback: mycarousel_initCallback
		});
		$('#photoList a').click(function(){
			$("#photoView img").hide().attr("src",$(this).attr("para")).fadeIn();
		})
	}

	//视频首页
	if($('body').attr('id')=='page_videoindex'){
		initPlaybox();
	};

	//精品展藏类别显示效果
	if($('body').attr('id')=='page_enjoylist'){
		$("#sortList .box_func").show();
		vheight=$("#sortList .box_list").height();
		$("#sortList .box_list").css("overflow","hidden").height(50);
		$("#sortList .box_list").after("<span id='btnAll'><a>显示全部</a></span>");
		$("#btnAll").click().toggle(
			function(){
				$("#sortList .box_list").animate( { height: vheight}, 1000 );
				$("#btnAll a").html("显示精简").addClass("selected");
			},
			function(){
				$("#sortList .box_list").animate( { height: 50}, 1000 )
				$("#btnAll a").html("显示全部").removeClass("selected");
			}
		)
	};

	//赏析所有页
	if($('body').attr('id')=='page_enjoyindex'){
		$("#enjoy_header").pngFix();
//	  $('#indexShow .show_list').jcarousel({
//        vertical: true,
//        scroll: 2,
//        auto: true
//		});
		initPlaybox();
		initScroll();
	}

	//赏析列表页
	if($('body').attr('id')=='page_enjoylist'){
		$("#enjoy_header").pngFix();
		$("#listselA").selectbox();
		$("#listselB").selectbox();
		$("#listselC").selectbox();
		$("#listselD").selectbox();
		$("#sortList select").change(function(){
			alert($(this).val());
		}); 
	};

	//赏析内容页
	if($('body').attr('id')=='page_enjoycontent'){
		$("#enjoy_header").pngFix();
	  $('#photoList').jcarousel({
			wrap: 'last',
			initCallback: mycarousel_initCallback
		});
		$('#photoList a').click(function(){
			$("#photoView img").hide().attr("src",$(this).attr("para")).fadeIn();
		})
	}

	//商城首页
	if($('body').attr('id')=='page_help'){
		//initTextlist();
		$("#textList").treeview({
			animated: "fast",
			persist: "location",
			collapsed: true,
			unique: true
		});
	};

	//活动页
	if($('body').attr('id')=='page_activitiesindex'){
		initPlaybox();
	};

	//博物馆页
	if($('body').attr('id')=='page_museumindex'){
		initPlaybox();
	};

});


//页面加载结束


//通用脚本

//首页推荐区
var t=n=vcount=0;
var vplayboxTime=5000;
function initPlaybox(){
	vcount=$("#playbox_list a").size();
	$("#playbox_list a:not(:first-child)").hide();
	$("#playbox_info").html("<p>"+$("#playbox_list a:first-child").find("img").attr('alt')+"</p>");
	$("#playbox_text li:first-child").css({"background":"#97c3fb",'color':'#000'});
	$("#playbox_info").click(function(){window.open($("#playbox_list a:first-child").attr('href'), "_blank")});
	$("#playbox_text li").click(function(){
		var i = $(this).text()-1;
		n = i;
		if (i >= vcount) return;
		$("#playbox_info").html("<p>"+$("#playbox_list a").eq(i).find("img").attr("alt")+"</p>");
		$("#playbox_info").unbind().click(function(){window.open($("#playbox_list a").eq(i).attr('href'), "_blank")})
		$("#playbox_list a").filter(":visible").fadeOut(500).parent().children().eq(i).fadeIn(3000);
		$(this).css({"background":"#97c3fb",'color':'#000'}).siblings().css({"background":"#000",'color':'#fff'});
	});
	t = setInterval("showAuto()",vplayboxTime);
	$("#playbox").hover(function(){clearInterval(t)}, function(){t = setInterval("showAuto()",vplayboxTime);});
}
function showAuto(){
	n = n >= (vcount - 1) ? 0 : ++n;
	$("#playbox_text li").eq(n).trigger('click');
}

//首页活动区
vscrollHeight=219;
vscrollStop=false;
vscrollPretop=0;
vscrollCurrenttop=0;
vscrollStoptime=0;
function initScroll(){
	$("#scrollList1")
	//.css("width","0")
	//.css("height",vscrollHeight)
	.css("overflowX","visible")
	.css("overflowY","hidden")
	.css("scrollTop","0")
	.css("white-space","nowrap")
	.hover(
		function(){vscrollStop=true},
 		function(){vscrollStop=false}
	);
  $("#scrollList2").html($("#scrollList1").html());
  $("#scrollList1").html($("#scrollList2").html()+$("#scrollList2").html());
  setInterval("startScroll()",50);
}
function startScroll(){
  if(vscrollStop==true) return;
	vscrollCurrenttop+=1;
  if(vscrollCurrenttop==74){
		vscrollStoptime+=1;
		vscrollCurrenttop-=1;
		if(vscrollStoptime==50){
			vscrollCurrenttop=0;
			vscrollStoptime=0;
		}
	}else{   
		vscrollPretop=scrollList1.scrollTop;
		scrollList1.scrollTop+=1;
		if(vscrollPretop==scrollList1.scrollTop){
			scrollList1.scrollTop=scrollList2.offsetHeight-vscrollHeight;
			scrollList1.scrollTop+=1;
		}
	}
}

//图片滚动
function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

//初始化列表
function initTextlist(){
	$("#textList ul li a").each(function(i){
		if ($(this).parent().children("ul").size()>0){
			$(this).attr("href","");
			$(this).removeAttr("href");
			$(this).click(function(){
				$(this).parent().children("ul").slideToggle("normal");
				$(this).toggleClass("list1");
			});
		};
	})
}