﻿var timeOutId;
$(document).ready(function() {
    var word = $("#keyText").text();
    if (word != "") {
        $('.search_list').removeHighlight().highlight(word);
    }
    //links event
    new Marquee("linkList", 0, 1, 645, 28, 20, 4000, 1000);

    //加载flashbanner
    function swfLoad() {
        if ($("#banner").is("div")) {
            try {
                var url = $(".swfUrl");
                var so = new SWFObject(url.attr("value"), "fshow", "100%", "100%", 7);
                so.addParam("menu", "false");
                so.addParam("wmode", "transparent");
                so.addParam("scale", "noBorder");
                //so.addParam("scale","noscale");
                //so.addParam("scale","showAll");
                //so.addParam("scale","exactFit");
                so.write("banner");
            } catch (error) { }
        }

    }
    swfLoad();


    //导航菜单事件
    var timeoutId;
    $(".nav ul li").hover(function() {
        var a = $(this).children("a");
        var div = $(this).children("div");
        timeoutId = setTimeout(function() {
            a.addClass("hover");
            div.has("a").slideDown("fast");
        }, 200);

    }, function() {
        clearTimeout(timeoutId);
        $(this).children("a").removeClass("hover");
        $(this).children("div").slideUp("fast");
    });

    /*****left Nav event start*****/
    try {
        var speed = 150;
        var $currentLi = $("#leftNav ul .current");
        if ($currentLi.is("li")) {
            if ($currentLi.children(".menus").is("div")) {
                $currentLi.children(".menus").slideDown(speed);
            }
        }
        $("#leftNav ul li").hover(function() {
            $currentLi = $("#leftNav ul .current");
            var $hoverLi = $(this);
            if ($currentLi.is("li")) {

            } else {
                $hoverLi.addClass("current");
                if ($hoverLi.children(".menus").is("div")) {
                    $hoverLi.children(".menus").slideDown(speed);
                }
            }
            timeOutId = setTimeout(function() {
                if (!$hoverLi.hasClass("current")) {
                    if ($currentLi.children(".menus").is("div")) {
                        $currentLi.children(".menus").slideUp(speed, function() {
                            $currentLi.removeClass("current");
                            $hoverLi.addClass("current");
                            $hoverLi.children(".menus").slideDown(speed);
                        });
                    } else {
                        $currentLi.removeClass("current");
                        $hoverLi.addClass("current");
                        $hoverLi.children(".menus").slideDown(speed);
                    }
                }

            }, 301);

        }, function() {
            clearTimeout(timeOutId);
        });
    } catch (error) {
        //alert(error.name+":"+error.message);
    }
    /*****left Nav event start*****/

    /*****FAQ event start*****/
    var $faqs = $(".FAQ > a");
    if ($faqs.is("a")) {
        $faqs.click(function() {
            var click_a = $(this);
            if (!$(".FAQ .open").is("a")) {
                click_a.addClass("open");
            }
            if (!click_a.hasClass("open")) {
                $(".FAQ .open").next("div").slideUp(250, function() {
                    $(".FAQ .open").removeClass("open");
                    click_a.addClass("open");
                    click_a.next("div").show(250);
                });
            } else {
                if (click_a.next("div").css("display") == "block") {
                    click_a.next("div").slideUp(250);
                } else {
                    click_a.next("div").slideDown(250);
                }
            }
            return false;
        });
    }
    /*****FAQ event end*****/

    /*****Image Player Start*****/
    ImgShow();
    /*****Image Player end*******/

    /*******发展历程切换 start******/
    if ($("#fzlc > a").is("a")) {

        $("#fzlc > a").click(function() {
            var $this = $(this);
            if (!$this.hasClass("current")) {
                //$(".fzlc_" + $("#fzlc .current").attr("href")).css("display", "none");
                //$("#fzlc .current").removeClass("current");
                //$this.addClass("current");
                //$(".fzlc_" + $this.attr("href")).css("display", "block");
            }
            //return false;
        });
    }

    /*******发展历程切换 end******/

    /*******业务范围切换 start******/
    if ($("#ywfw > a").is("a")) {
        if ($("#ywfw .current").is("a")) {
            $(".ywfw_" + $("#ywfw .current").attr("href")).css("display", "block");
        } else {
            $("#ywfw a").first().addClass("current");
            $(".ywfw_" + $("#ywfw a").first().attr("href")).css("display", "block");
        }
        $("#ywfw > a").mouseover(function() {
            var $this = $(this);
            if (!$this.hasClass("current")) {
                $(".ywfw_" + $("#ywfw .current").attr("href")).css("display", "none");
                $("#ywfw .current").removeClass("current");
                $this.addClass("current");
                $(".ywfw_" + $this.attr("href")).css("display", "block");
            }

        }).click(function() { return false; });
    }

    /*******业务范围切换 end******/

    /**********图片播放器 start************/

    ImgPlayer("playBox1", "ulImgBox1", "prev1", "next1");
    ImgPlayer("playBox2", "ulImgBox2", "prev2", "next2");
    ImgPlayer("playBox3", "ulImgBox3", "prev3", "next3");
    /**********图片播放器 end************/

    /****首页模块切换 start*****/
    hover("tab_1", "content_1"); //新闻资讯
    hover("tab_2", "content_2"); //投资专区
    hover("tab_3", "content_3"); //节能服务
    hover("tab_4", "content_4"); //产品与技术
    hover("tab_5", "content_5"); //解决方案
    hover("tab_6", "content_6"); //案例
    /****首页模块切换 end*****/
	
	/*搜索事件*/
	$("#keyword").keydown(function(e){
		if(e.keyCode == 13){
			var keyword = $(this).val();
			if (keyword != "") {
				//$(".btn_search").trigger("click");
				window.location.href="/search.aspx?t=&key="+keyword;
				$("form").submit(function(){ return false;});
			}else{
				alert("请输入搜索关键字!");
            	return false;
			}
	    }
	});
	
	 //搜索事件
    $("#search").click(function() {
        var keyword = $("#keyword").val();
        if (keyword != "") {
            var url = "/search.aspx?t=&key=" + keyword;
            url = encodeURI(url);
            $(this).attr("href", url);
            return true;
        } else {
            alert("请输入搜索关键字!");
            return false;
        }
    });
});


/***********自定义函数***********/

/***********ImgPlayer start***********/
function ImgPlayer(playBoxId, ulImgBoxId,prevId,nextId) {
    try {
        //图片播放器  ---start
        var $prev = $("#" + prevId);
        var $next = $("#" + nextId);
        var $ul = $("#" + ulImgBoxId);
        var $li = $("#"+ulImgBoxId+ " li");
        var $playBox = $("#" + playBoxId);
        var imgWidth = 100;
        var showWidth = imgWidth * 4;
        var _width = 0;

        //展示图片
        showImg(ulImgBoxId, $playBox);
        
        $ul.find("li").each(function() {
            var $li = $(this);
            _width += ($li.outerWidth() + 10);
        });
        $ul.width(_width);

        $playBox.find("img").attr("src", $("#" + ulImgBoxId + " .current").find("img").attr("src"));
        $playBox.find("span").html($("#" + ulImgBoxId + " .current").find("img").attr("title"));

        $next.click(function() {
            var $current = $("#"+ulImgBoxId+" .current");
            if ($current.next("li").is("li")) {
                $current.removeClass("current");
                $current.next("li").addClass("current");
            } else { return false; }

            //展示图片
            showImg(ulImgBoxId, $playBox);
            var n = $current.index() - $li.first().index();
            if (n != 0) {
                var left = parseInt($ul.css("left"));
                if ((_width + left) > showWidth) {
                    $ul.animate({
                        left: '-=' + imgWidth
                    }, 300, "", function() {

                    });
                }
            }
            return false;

        });

        $prev.click(function() {
        var $current = $("#" + ulImgBoxId + " .current");
            if ($current.prev("li").is("li")) {
                $current.removeClass("current");
                $current.prev("li").addClass("current");
            } else { return false; }
            //展示图片
            showImg(ulImgBoxId, $playBox);

            var n = $current.index() - $li.last().index();
            if (n < -1) {
                var left = parseInt($ul.css("left"));
                if (left < 0) {
                    $ul.animate({
                        left: '+=' + imgWidth
                    }, 300, "", function() {

                    });
                }
            }
            return false;
        });

        $li.click(function() {
            var $current = $("#" + ulImgBoxId + " .current");
            var index = $current.index();
            var lastIndex = $li.last().index();

            if (index == $(this).index()) return false;

            if (index == 0) {
                index = 1;
            } else if (index == lastIndex) {
                index = lastIndex - 2;
            }
            var rangeWidth = ($(this).index() - index) * imgWidth;

            $li.siblings(".current").removeClass("current");
            $(this).addClass("current");

            //展示图片
            showImg(ulImgBoxId, $playBox);
            var left = -parseInt($ul.css("left"));
            if (rangeWidth > 0) {
                //向左滚动
                if ((_width - (showWidth + left)) < rangeWidth)
                    rangeWidth = _width - (showWidth + left);
                $ul.animate({
                    left: '-=' + rangeWidth
                }, 300, "", function() {

                });

            } else {
                //向右滚动
                var temp = -rangeWidth;
                if (left < temp) temp = left;
                $ul.animate({
                    left: '+=' + temp
                }, 300, "", function() {

                });
            }

            return false;
        });
        //图片播放器  ---end
    } catch (err) {
        var txt = "本页中存在错误。\n\n"
        txt += "错误描述：" + err.description + "\n\n"
        txt += "点击“确定”继续。\n\n"
        //alert(txt);

    }


}

function showImg(ulImgBoxId,playBoxObj) {
    var obj = $("#" + ulImgBoxId + " .current");
    if (obj instanceof Object) {
        if (obj.is("li")) {
            playBoxObj.find("img").animate({
                opacity: 0.2
            }, 500, "", function() {
                playBoxObj.find("img").attr("src", obj.find("img").attr("src"));
                if(playBoxObj.find("span").is("span"))
                    playBoxObj.find("span").html(obj.find("img").attr("title"));
                    
                if (playBoxObj.find("#newsTitle").is("a"))
                    playBoxObj.find("#newsTitle").html(obj.find("img").attr("title"));    
                    
                if (playBoxObj.find("a").is("a"))
                    playBoxObj.find("a").attr("href", obj.find("img").attr("href"));

                if (playBoxObj.find("#subContent").is("p"))
                    playBoxObj.find("#subContent").html(obj.find("img").attr("subContent"));   
                
                $(this).animate({
                    opacity: 1
                }, 500);
            });
        }
    }
}
/***********ImgPlayer end***********/


/***********图片新闻自动轮播 start***********/
/**
  * param1:The Class Name Of ImgList
  **/
var timeId;
var autoTimeId;
function ImgShow() {
    ImgAutoShow();
   var $newsInfo = $("#newsInfo");
   var $imgList = $("#hotNewsList a");
   if ($imgList.is("a")) {

       var showImg = $(".showImg");
       showImg.children("a").attr("href", $("#hotNewsList .now").attr("link"));
       showImg.find("img").attr("src", $("#hotNewsList .now").attr("src"));
       showImg.find("img").attr("title", $("#hotNewsList .now").attr("title"));
	   showImg.find("p").html($("#hotNewsList .now").attr("title"));
       $newsInfo.find("a").attr("href", $("#hotNewsList .now").attr("link"));
       $newsInfo.find("#tit").html($("#hotNewsList .now").attr("title"));
       $newsInfo.find("#subC").html($("#hotNewsList .now").attr("subContent"));
       
       $imgList.mouseover(function() {
           var $now = $("#hotNewsList .now");
           var $this = $(this);
           timeId = setTimeout(function() {
               if (!$this.hasClass("now")) {
                   $now.removeClass("now");
                   $this.addClass("now");
                   showImg.find("img").animate({
                       opacity: 0.2
                   }, 500, "", function() {
                       showImg.children("a").attr("href", $this.attr("link"));
                       showImg.find("img").attr("src", $this.attr("src"));
                       showImg.find("img").attr("title", $this.attr("title"));
					   showImg.find("p").html($this.attr("title"));
                       $newsInfo.find("a").attr("href", $this.attr("link"));
                       $newsInfo.find("#tit").html($this.attr("title"));
                       $newsInfo.find("#subC").html($this.attr("subContent"));
                       showImg.find("img").animate({
                           opacity: 1
                       }, 500, "", function() {

                       });
                   });
               }
           }, 501);


       }).mouseout(function() {
           clearTimeout(timeId);
           clearTimeout(autoTimeId);
           autoTimeId = setTimeout(ImgAutoShow, 5000);
       }).click(function() {
           return false;
       });		
   }
}
function ImgAutoShow(){

    if ($("#hotNewsList .now").is("a")) {
        if ($("#hotNewsList .now").next("a").is("a")) {
            $("#hotNewsList .now").next("a").trigger("mouseover");
		}else{
		    $("#hotNewsList a:first").trigger("mouseover");
		}
	}else{
	    $("#hotNewsList a:first").addClass("now");
	}
 	autoTimeId = setTimeout(ImgAutoShow,5000);
}
/***********图片新闻自动轮播 end***********/

/***********一般切换效果 start***********/
function hover(tabClassName,contentClassName){
	var $tab = $("."+tabClassName);
	var $content = $("."+contentClassName);
	if($tab.find("a.hover").is("a")){
		if(!$tab.find("a.now").is("a")){
			var temp_a = $tab.find("a.hover").first();
			temp_a.addClass("now");
			$content.find("."+temp_a.attr("name")).css("display","block");
		}else{
			$content.find("."+$tab.find("a.now").attr("name")).css("display","block");
		}
		$tab.find("a.hover").mouseover(function() {
		    var $now = $tab.find(".now");
		    var $this = $(this);
		    if (!$this.hasClass("now")) {
		        $content.find("." + $now.attr("name")).css("display", "none");
		        $now.removeClass("now");
		        $this.addClass("now");
		        $content.find("." + $this.attr("name")).css("display", "block");
		    } else {

		    }
		}).click(function() {  });
    }
}


/***********一般切换效果 end***********/

/******打开一个新窗口******/
function openWin(url) {
    var iWidth = 690;                           //弹出窗口的宽度;
    var iHeight = 1090;                          //弹出窗口的高度;
    var iTop = (window.screen.availHeight - 30 - iHeight) / 2;       //获得窗口的垂直位置;
    var iLeft = (window.screen.availWidth - 10 - iWidth) / 2;        //获得窗口的水平位置;
    window.open(url, "_blank", 'height=' + iHeight + ',width=' + iWidth + ',top=' + iTop + ',left=' + iLeft + ',toolbar=no,menubar=no,scrollbars=yes,resizeable=yes,location=no,status=no');
}

function showMsg(msg) {
    alert(msg);
}
