﻿/**
 *
 * 首页JS操作文件
 *
 * @FileName: index.js
 * @Auther: Pandao
 * @QQ: 272383090
 * @CreateTime: 2011-09-07 15:21:59
 * @UpdateTime: 2011-09-16 09:35:58
 * Copyright 2011 泉州市科伟信息咨询有限公司版权所有，禁止非法用于商业用途，否则后果自负!
 */

//全局变量
var textScrollTimer;
var homeBannerTimer;
var homeBannerIndex = 0;   //起始位置
var homeBannerTotal;       //图片总数
var bannerOutTime = 8000;  //间隔时间，默认为8秒
var prevTime = false;      //是否点击了上一张

//=====================  页面加载完成后开始执行的操作 Start =====================

$(function() {
    //==================== 首页Banner切换动画 Start ======================
    homeBannerTotal = $('.scrollimg').length;  //取得图片总数

    //$('#test').val('');

    //切换动画函数
    function bannerScroll()
    {
        $('#home_banner_wrap').stop(); //停止动画

        //上一张
        if(prevTime == true) {
            homeBannerIndex --;
            if(homeBannerIndex <= 0) homeBannerIndex = homeBannerTotal;
        } else {
            homeBannerIndex ++;
        }

        //输出调试信息
        //$('#test').val(homeBannerIndex +'/' +homeBannerTotal + ', marginTop:'+$('#home_banner_wrap').css('margin-top'));

        //$('#home_banner_wrap').animate({marginTop:'-'+( (homeBannerIndex-1) * 310)+'px'}, 700);
        $('#home_banner_wrap a').eq(homeBannerIndex-1).siblings().hide();
        $('#home_banner_wrap a').eq(homeBannerIndex-1).fadeIn(1500);
        $('.home_banner_nav a').removeClass('this').eq(homeBannerIndex-1).addClass('this');

        if(prevTime == false && homeBannerIndex == homeBannerTotal) homeBannerIndex = 0;
    }

    //利用递归实现自动切换，即每到退出时间时执行一次当前函数
    function bannerAutoScroll()
    {
        bannerScroll();
        homeBannerTimer = setTimeout(bannerAutoScroll, bannerOutTime);
    }

/*
    //初始自动滚动
    bannerAutoScroll();
    //鼠标放在Banner层时停止自动滚动，移出时继续自动滚动
    $('#home_banner').hover(function() {
        clearTimeout(homeBannerTimer);
    }, function() {
        if(prevTime == true && homeBannerIndex == homeBannerTotal) homeBannerIndex = 0;
        prevTime = false;
        bannerAutoScroll();
    });

    //点击切换到第几张
    $('.home_banner_nav li').hover(function() {
        if($(this).children('a').attr('class') == 'this') return ;
        $(this).children('a').addClass('hover');
    }, function() {
        if($(this).children('a').attr('class') == 'this') return ;
        $(this).children('a').removeClass('hover');
    }).click(function() {
        prevTime = false;
        if($(this).children('a').attr('class') == 'this') return ;

        homeBannerIndex = $(this).children('a').html() - 1;
        $('.home_banner_nav a').removeClass('hover');
        $(this).children('a').removeClass('hover');
        $(this).children('a').addClass('this');

        bannerScroll();
    });

    //下一张
    $('#next_btn').click(function() {
        prevTime = false;
        homeBannerIndex = $('.home_banner_nav a.this').html();
        if(homeBannerIndex == homeBannerTotal) homeBannerIndex = 0;

        bannerScroll();
    });

    //上一张
    $('#prev_btn').click(function() {
        prevTime = true;
        homeBannerIndex = $('.home_banner_nav a.this').html();

        bannerScroll();
    });
*/
    //==================== 首页Banner切换动画 End ======================

    //服务项目切换鼠标经过和移开状态
    $('.project').hover(function() {
        $(this).css({borderTop : '10px solid #E11925', paddingTop: '5px'});
    }, function() {
        $(this).css({borderTop : '10px', paddingTop: '15px'});
    });

    //公司动态滚动
    function newsAutoScroll() {
        textScroll("#company_news_right");
        textScrollTimer = setTimeout(newsAutoScroll, 3000);
    }

    //开始滚动新闻列表
    newsAutoScroll();

    //鼠标在新闻滚动区域时停止自动滚动，离开后继续自动滚动
    $('.news_list').hover(function() {
        clearTimeout(textScrollTimer);
    }, function() {
        newsAutoScroll();
    });

    //鼠标经过案例图片时，滑出案例名称介绍透明层，移出时则隐藏透明层
    $('.cases_list li').hover(function() {
       // $(this).css({backgroundColor:'#f6f6f6', borderColor:'#ddd'});
        $(this).children('.cases_title').show().animate({bottom:0}, 300);
    }, function() {
        $(this).children('.cases_title').animate({bottom: '-40px'}, 300, function() {
            $(this).hide();
        });

        $(this).css({backgroundColor:'#fff', borderColor:'#f6f6f6'});
    });
});

//=====================  页面加载完成后开始执行的操作 End =====================
