﻿/*
 * @Description: Main Function file
 * @Author:      mike+hu<mikeshin@126.com>
 * @Update:      mike+hu(2011-09-20 12:22)
 */
$(document).ready(function() {
	
	//////导航下拉菜单	
	$("ul.nav-list>li>div.nav-sublist").last().attr("id","nav-sublist-last");
	$("div.links>span").last().hide();
    $("ul.nav-list > li").hover(
        function () {
            $(this).find("> a").addClass("hover");
            $(this).find("div.nav-sublist").slideDown(100);
        },
        function () {
            $(this).find("> a").removeClass("hover");
            $(this).find("div.nav-sublist").slideUp(100);
        }
    );
	
	
	//////案例
	$("#sub-cases li").hover(function(){
			$(this).addClass("lihover");
			}, function() {
			$(this).removeClass("lihover");
	});

/**
 * 首页slide轮换
 * currentIndex: 当前slide的index
 * slideCount: slide的数量
 */
    var currentIndex = 1;
    var slideCount = 3;

/**
 * 显示选定slide
 */
    function getSlideShow() {
        $("#slide .slide-box").hide();
        $("#slide #slide-box-" + currentIndex).fadeIn();
        $("#slide-show a.slide-show-content").removeClass("current");
        $("#slide-show a.slide-show-content:eq(" + (currentIndex - 1) + ")").addClass("current");
        if(currentIndex === 4){
            document.getElementById("slide-show-1").style.display = "none";
            document.getElementById("slide-show-4").style.display = "";
        }
        if(currentIndex === 1){
            document.getElementById("slide-show-4").style.display = "none";
            document.getElementById("slide-show-1").style.display = "";
        }
    }

/**
 * 控制上一张还是下一张，到达极值后，循环显示
 * @param {string} direction 轮换方向 默认为next
 */
    function getNextSlideShow(direction) {
        if (!direction || direction == "next") {
            currentIndex++;
            if (currentIndex >= (slideCount + 1)) {
                currentIndex = 1;
            }
            
        }
        else if (direction == "previous") {
            currentIndex--;
            if (currentIndex <= 0) {
                currentIndex = slideCount;
            }
        }
        getSlideShow();
    }

    $("#slide-show a.slide-show-content").click(
        function () {
            currentIndex = parseInt($(this).attr("id").replace("slide-show-",""));
            getSlideShow();
            return false;
        }
    );

    $("#slide-show a#slide-show-previous").click(
        function () {
            getNextSlideShow("previous");
            return false;
        }
    );

    $("#slide-show a#slide-show-next").click(
        function () {
            getNextSlideShow();
            return false;
        }
    );

    //setInterval(getNextSlideShow, 6000);


/**
 * 首页update-new轮换
 */
    var currentNewsIndex = 1;
    var newsCount = $(".update-news>p").size();
    var startUpdateNews;

    function hideUpdateNews() {
        $("p#update-news-" + currentNewsIndex).show().css("top", "2").css("opacity", "1").animate({
                top: '15',
                opacity: 0
            }, 400);
    }

    function showUpdateNews() {
        $("p#update-news-" + currentNewsIndex).show().css("top", "-8px").css("opacity", "0").animate({
                top: '2',
                opacity: 1
            }, 400);
    }

    function getNextUpdateNews(direction) {
        hideUpdateNews();

        if (!direction || direction == "next") {
            currentNewsIndex++;
            if (currentNewsIndex >= (newsCount + 1)) {
                currentNewsIndex = 1;
            }
        }
        else if (direction == "previous") {
            currentNewsIndex--;
            if (currentNewsIndex <= 0) {
                currentNewsIndex = newsCount;
            }
        }

        showUpdateNews();
    }
    
    startUpdateNews = setInterval(getNextUpdateNews, 6000);

    $("a#update-news-control-up").click(
        function () {
            getNextUpdateNews("previous");
            return false;
        }
    );

    $("a#update-news-control-down").click(
        function () {
            getNextUpdateNews();
            return false;
        }
    );
    
    $("#update-news-control").mouseenter(
        function () {
            clearInterval(startUpdateNews);
        }
    ).mouseleave(
        function () {    
            startUpdateNews = setInterval(getNextUpdateNews, 6000);
        }
    )
	
	

	
	//////禁止右键和选择文本
//	$('body').bind('contextmenu', function() {
//      return false;
//    }); 
//	$('body').bind('selectstart', function() {
//      return false;
//    }); 

	//////全局导航高亮
    var url = document.URL;//取得当前页的URL
    
    if(/solu/.test(url.toLowerCase()))  //正则查找在url地址中是否有当前页
    {
        $("#nav_02 > a").addClass("on");
		$(".inside_banner").addClass("sub_img02");
    }else if(/product/.test(url.toLowerCase()))
    {
        $("#nav_03 > a").addClass("on");
		$(".inside_banner").addClass("sub_img03");
    }else if(/service/.test(url.toLowerCase()))
    {
        $("#nav_04 > a").addClass("on");
		$(".inside_banner").addClass("sub_img04");
    }else if(/human/.test(url.toLowerCase()))
    {
        $("#nav_04_01 > a").addClass("on");
		$(".inside_banner").addClass("sub_img04");
    }else if(/about/.test(url.toLowerCase()))
    {
        $("#nav_05 > a").addClass("on");
		$(".inside_banner").addClass("sub_img05");
    }else 
    {
        $("#nav_01 > a").addClass("on");
    }
	
});

