﻿/*Tab切换
-id：节点唯一标识
-index：初始索引（从0开始）
-eventType：事件类型（0-鼠标滑动，1-鼠标点击）
-showDelay：渐显时间
-isAuto：是否自动切换
-autoDelay：自动切换时间间隔）*/
function HZ_Tab(id, index, eventType, showDelay, isAuto, autoDelay)
{
	if($("#"+ id + " .tMenu .t").size() == $("#"+ id + " .tBox").size())
	{
		var j;function slide(j){$("#"+ id + " .tMenu .t").removeClass("current");$("#"+ id + " .tMenu .t").eq(j).addClass("current");$("#"+ id + " .tBox").hide();$("#"+ id + " .tBox").eq(j).fadeIn(showDelay);}
		if(index < 0 || index > $("#"+ id + " .tMenu .t").size() - 1){index = 0;}
		$("#"+ id + " .tBox:not(:eq(" + index + "))").hide();
		$("#"+ id + " .tMenu .t:eq(" + index + ")").addClass("current");
		$("#"+ id + " .tMenu .t").each(function(i)
			{if(eventType == 0){$(this).mouseover(function(){slide(i);});}else{$(this).click(function(){slide(i);});}}
		);
		if(isAuto)
		{
			j = index-1; var timer = null;
			function autoPlay(){n = $("#"+ id + " .tMenu .t").size()-1; j++;if(j > n){j = 0;}slide(j);timer = window.setTimeout(autoPlay, autoDelay);}
			function hookThumb()
			{$("#"+ id + " .tMenu .t").hover(function(){if (timer){clearTimeout(timer);j = $(this).prevAll().filter(".t").length;}},function (){timer = window.setTimeout(autoPlay, autoDelay);this.blur();return false;});$("#"+ id + " .tBox").hover(function(){if (timer){clearTimeout(timer);j = $(this).prevAll().filter(".tBox").length;}},function (){timer = window.setTimeout(autoPlay, autoDelay);this.blur();return false;});}autoPlay();hookThumb();
		}
	}
	else
	{
		alert("ID为[ " + id + " ]的tab个数有误！请检查");
	}
}


/*自动播放
-id：节点唯一标识
-showDelay：渐显时间
-autoDelay：自动切换时间间隔）*/
function HZ_AutoPlay(id, showDelay, autoDelay)
{
	$("#"+ id + " .tBox:not(:first)").hide();var j = -1;var timer = null;
	function autoPlay(){n = $("#"+ id + " .tBox").size()-1; j++;if(j > n){j = 0;}slide(j);timer = window.setTimeout(autoPlay, autoDelay);}
	function slide(j){$("#"+ id + " .tBox").hide();$("#"+ id + " .tBox").eq(j).fadeIn(showDelay);}
	function hookThumb()
	{$("#"+ id + " .tBox").hover(function(){if (timer){clearTimeout(timer);j = $(this).prevAll().filter(".tBox").length;}},	function (){timer = window.setTimeout(autoPlay, autoDelay);this.blur();return false;});}autoPlay();hookThumb();
}


/*滚动信息
-id：节点唯一标
-lineHeight：行高
-speed：速度
-delay：时间间隔识*/
function HZ_Marquee(id, lineHeight, speed, delay)
{
	var t;
	var p=false; 
	var o=document.getElementById(id);
	o.innerHTML+=o.innerHTML; 
	o.onmouseover=function(){p=true}
	o.onmouseout=function(){p=false}
	o.scrollTop = 0;
	function start(){
		t=setInterval(scrolling,speed);
		if(!p){ o.scrollTop += 1;} 
	} 
	function scrolling(){ 
		if(o.scrollTop%lineHeight!=0){
			o.scrollTop += 1; 
			if(o.scrollTop>=o.scrollHeight/2) o.scrollTop = 0;
		}else{ 
			clearInterval(t);
			setTimeout(start,delay); 
		}
	}
	setTimeout(start,delay);
}

//设置字体大小
function HZ_SetFontSize(size) 
{ 
	var zoom=document.all?document.all['Zoom']:document.getElementById('Zoom'); 
	zoom.style.fontSize=size+'px'; 
}







//自动播放
function HZ_AutoPlay(id, showDelay, autoDelay)
{
	$("#"+ id + " .tBox:not(:first)").hide();
	var j = -1;var timer = null;
	function autoPlay(){n = $("#"+ id + " .tBox").size()-1; j++;if(j > n){j = 0;}slide(j);timer = window.setTimeout(autoPlay, autoDelay);}
	function slide(j){$("#"+ id + " .tBox").hide();$("#"+ id + " .tBox").eq(j).fadeIn(showDelay);}
	function hookThumb()
	{$("#"+ id + " .tBox").hover(function(){if (timer){clearTimeout(timer);j = $(this).prevAll().filter(".tBox").length;}},	function (){timer = window.setTimeout(autoPlay, autoDelay);this.blur();return false;});}autoPlay();hookThumb();
}


//新闻图片切换
function HZ_ShowPicNews()
{
	$(".widget .jCarouselLite").jCarouselLite({
		btnNext: ".widget .next_pic",
		btnPrev: ".widget .prev_pic",
		auto: 4000,
		speed: 1200,
		visible: 4,
		scroll: 1,
		step:2,
		onMouse:true,
		id:"focus",
			beforeStart: function(b) {
			$(".widget .mid img").fadeOut(200, function(){
			   $(".widget .mid img").fadeIn(200); 										   
			   $(".widget .mid img").attr("src", b[0].children[0].children[0].src );
			   
			}); 
		},
		easing: "backout"
	});
	$(".widget .jCarouselLite img").mouseover(function() {
		$(".widget .mid img").attr("src", $(this).attr("src"));
		$(".widget .mid img").parent().attr("href", $(this).parent().attr("href"));
		
	})
}


//杂志切换
function HZ_ShowMagazine()
{
	$.fn.infiniteCarousel = function () {
	
		function repeat(str, num) {
			return new Array( num + 1 ).join( str );
		}
	  
		return this.each(function () {
			var $wrapper = $('> div', this).css('overflow', 'hidden'),
				$slider = $wrapper.find('> ul'),
				$items = $slider.find('> li'),
				$single = $items.filter(':first'),
				
				singleWidth = $single.outerWidth(), 
				visible = Math.ceil($wrapper.innerWidth() / singleWidth),
				currentPage = 1,
				pages = Math.ceil($items.length / visible);            
	
	
			// 1. Pad so that 'visible' number will always be seen, otherwise create empty items
			if (($items.length % visible) != 0) {
				$slider.append(repeat('<li class="empty" />', visible - ($items.length % visible)));
				$items = $slider.find('> li');
			}
	
			// 2. Top and tail the list with 'visible' number of items, top has the last section, and tail has the first
			$items.filter(':first').before($items.slice(- visible).clone().addClass('cloned'));
			$items.filter(':last').after($items.slice(0, visible).clone().addClass('cloned'));
			$items = $slider.find('> li'); // reselect
			
			// 3. Set the left position to the first 'real' item
			$wrapper.scrollLeft(singleWidth * visible);
			
			// 4. paging function
			function gotoPage(page) {
				var dir = page < currentPage ? -1 : 1,
					n = Math.abs(currentPage - page),
					left = singleWidth * dir * visible * n;
				
				$wrapper.filter(':not(:animated)').animate({
					scrollLeft : '+=' + left
				}, 500, function () {
					if (page == 0) {
						$wrapper.scrollLeft(singleWidth * visible * pages);
						page = pages;
					} else if (page > pages) {
						$wrapper.scrollLeft(singleWidth * visible);
						// reset back to start position
						page = 1;
					} 
	
					currentPage = page;
				});                
				
				return false;
			}
			
			$wrapper.after('<a class="arrow back">&lt;</a><a class="arrow forward">&gt;</a>');
			
			// 5. Bind to the forward and back buttons
			$('a.back', this).click(function () {
				return gotoPage(currentPage - 1);                
			});
			
			$('a.forward', this).click(function () {
				return gotoPage(currentPage + 1);
			});
			
			// create a public interface to move to a specific page
			$(this).bind('goto', function (event, page) {
				gotoPage(page);
			});
		});  
	};
	
	$(document).ready(function () {
	  $('.magazine-in').infiniteCarousel();
	});
}

//向左滚动图片
function HZ_MarqueeLeftImg(id)
{
	var speed=40;
	var tab=document.getElementById(id);
	var tab1=document.getElementById(id + "1");
	var tab2=document.getElementById(id + "2");
	tab2.innerHTML=tab1.innerHTML;
	function H_PicMarquee(){
	if(tab2.offsetWidth-tab.scrollLeft<=0)
	tab.scrollLeft-=tab1.offsetWidth
	else{
	tab.scrollLeft++;

	}
	}
	var MyMar=setInterval(H_PicMarquee,speed);
	tab.onmouseover=function() {clearInterval(MyMar)};
	tab.onmouseout=function() {MyMar=setInterval(H_PicMarquee,speed)};
}
