﻿//搜索查询
function SiteSearch(send_url, divTgs) {
	var str = $.trim($(divTgs).val());
	if (str.length > 0) {
	    //window.location.href = send_url + "/" + encodeURI($(divTgs).val()) + ".html";
	    window.location.href = send_url + "/" + $(divTgs).val() + ".html";
	}
}

//替换关健字
function ReplaceKeywords(divTgs, keyword){
	var divHtml = $(divTgs).html();
	var reg = new RegExp("\\" + keyword, "g");
	divHtml = divHtml.replace(reg, "<span style=\"color:#F00;font-weight:normal;\">" + keyword + "</span>");
	$(divTgs).html(divHtml);
}

//控制字体大小
function SetFontSize(divTgs, fontSize){
    $(divTgs).css("font-size", fontSize + "px");
    $(divTgs + " a").css("font-size", fontSize + "px");
    $(divTgs + " b").css("font-size", fontSize + "px");
    $(divTgs + " span").css("font-size", fontSize + "px");
    $(divTgs + " p").css("font-size", fontSize + "px");
}

//页面放大缩放
//var _pagesize = 1; //缩位变量
//function TogglePageSize(zoom){
//	switch(zoom)
//	{
//		case "big":
//			_pagesize=_pagesize+2;
//			document.body.style.zoom = 1+_pagesize/100;
//			break
//		case "small":
//			_pagesize=_pagesize-2;
//			if(_pagesize>0){
//				document.body.style.zoom = 1+_pagesize/100;
//			}
//			break
//	}
//}

//======================以下代码适用于一般页面========================
//字体缩放函数
//function ToggleFontSize(divTgs, zoom){
//	var step = 2; //字体放大步长px
//	var minSize = 5; //最小字体px
//	var maxSize = 36; //最大字体px
//	var isRun = true; //保正比例大小
//	//检查整体字体大小
//	$(divTgs).children().each(function(){
//		var _font = parseInt($(this).css("font-size"));
//		if(zoom == "big" && _font >= maxSize){
//			isRun = false;
//			return;
//		}
//		if(zoom == "small" && _font <= minSize){
//			isRun = false;
//			return;
//		}
//	});
//	//执行放大或缩小
//	if(isRun == true){
//		$(divTgs).children().each(function(){
//			var font;
//			switch(zoom)
//			{
//				case "big":
//					font = parseInt($(this).css("font-size")) + step;
//				break
//				case "small":
//					font = parseInt($(this).css("font-size")) - step;
//				break
//			}
//			if(font >= minSize && font <= maxSize){
//				$(this).css("font-size", font + "px");
//			}
//		});
//	}
//};
//==================================================================
/*------------------------------首页幻灯--------------------*/
$(document).ready(function() {

    //Set Default State of each portfolio piece
    $(".paging").show();
    $(".paging a:first").addClass("active");

    //Get size of images, how many there are, then determin the size of the image reel.
    var imageWidth = $(".window").width();
    var imageSum = $(".image_reel img").size();
    var imageReelWidth = imageWidth * imageSum;

    //Adjust the image reel to its new size
    $(".image_reel").css({ 'width': imageReelWidth });

    //Paging + Slider Function
    rotate = function() {
        var triggerID = $active.attr("rel") - 1; //Get number of times to slide
        var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide

        $(".paging a").removeClass('active'); //Remove all active class
        $active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)

        //Slider Animation
        $(".image_reel").animate({
            left: -image_reelPosition
        }, 500);

    };

    //Rotation + Timing Event
    rotateSwitch = function() {
        play = setInterval(function() { //Set timer - this will repeat itself every 3 seconds
            $active = $('.paging a.active').next();
            if ($active.length === 0) { //If paging reaches the end...
                $active = $('.paging a:first'); //go back to first
            }
            rotate(); //Trigger the paging and slider function
        }, 7000); //Timer speed in milliseconds (3 seconds)
    };

    rotateSwitch(); //Run function on launch

    //On Hover
    $(".image_reel a").hover(function() {
        clearInterval(play); //Stop the rotation
    }, function() {
        rotateSwitch(); //Resume rotation
    });

    //On Click
    $(".paging a").click(function() {
        $active = $(this); //Activate the clicked paging
        //Reset Timer
        clearInterval(play); //Stop the rotation
        rotate(); //Trigger rotation immediately
        rotateSwitch(); // Resume rotation
        return false; //Prevent browser jump to link anchor
    });

});
