﻿$(function() {
    //广告图轮换
    var curIndex = 0;
    var picCount = $(".banner img").size();
    var fadeShow;
    $(".banner img:first").show();
    if (picCount > 1) {
        autoShow();
    }
    function autoShow() {
        $(".banner img").eq(curIndex - 1).fadeOut();
        $(".banner img").eq(curIndex).fadeIn();
        curIndex++;
        curIndex = curIndex >= picCount ? 0 : curIndex;
        fadeShow = setTimeout(autoShow, 4000);
    }

//    //两边等高
//    var sh = $(".side").height();
//    var mh = $(".main").eq(0).height();
//    if (sh < mh) {
//        if (mh < 400) {
//            $(".side,.main").height(400);
//        }
//        else {
//            $(".side").height(mh - 145);
//        }
//    }

    //图片新闻切换
    var ImgCurIndex = 0;
    var picNum = $(".img_news a").size();
    var ImgFadeShow;
    var onID = 0;
    $(".img_news a:first").show();
    if (picNum > 1) {
        ImgAutoShow();
    }
    function ImgAutoShow() {
        $(".img_news a").eq(ImgCurIndex - 1).hide();
        $(".img_news a").eq(ImgCurIndex).fadeIn();
        ImgCurIndex++;
        ImgCurIndex = ImgCurIndex >= picNum ? 0 : ImgCurIndex;
        ImgFadeShow = setTimeout(ImgAutoShow, 4000);
    }

    function ImgStopShow() {
        clearTimeout(ImgFadeShow);
    }

    //首页tab新闻切换
    $(".tab_cont:first").show();
    $("#tab_1").hover(function() {
        if ($(this).attr("class").indexOf("active") == -1) {
            $(this).removeClass().addClass("tab_1_active");
        }
        $("#tab_2").removeClass().addClass("tab_2");
        $(".more").attr("href", "News.aspx?id=1&pid=0");
        $(".tab_cont").eq(0).show().siblings(".tab_cont").hide();
    },
  function() {
  });
    $("#tab_2").hover(function() {
        if ($(this).attr("class").indexOf("active") == -1) {
            $(this).removeClass().addClass("tab_2_active");
        }
        $("#tab_1").removeClass().addClass("tab_1");
        $(".more").attr("href", "News.aspx?id=3&pid=0");
        $(".tab_cont").eq(1).show().siblings(".tab_cont").hide();
    },
  function() {
  });
  
  $(".mainNav>li").hover(function(){
    $(this).find("a:first").addClass("on");
    $(this).find("ul:first").show();
  },
  function(){
    $(this).find("a:first").removeClass("on");
    $(this).find("ul:first").hide();
  })
  
  
  //左侧菜单一级展开收缩
  $(".sideNav > li > a").click(function(){
      $(".sideNav>li>a").removeClass("on");
      $(this).addClass("on");
      if( $(this).next("ul:first").is(":hidden") )
      {
        $(this).next("ul:first").slideDown();
      }
      else
      {
        $(this).next("ul:first").slideUp("fast");
      }
  });
  //左侧菜单二级展开收缩
  $(".sideNav > li > ul > li > a").click(function(){
      $(".sideNav a").removeClass("on");
      $(this).addClass("on");
      $(this).parent("li").parent("ul").parent("li").find("a:first").addClass("on");
      
      if( $(this).next("ul:first").is(":hidden") )
      {
        $(this).next("ul:first").show();
      }
      else
      {
        $(this).next("ul:first").hide();
      }
  });
  
     //当前链接页面的菜单高亮显示
    var rel = window.location.href;
    var $links = $(".sideNav a");
 
    //菜单高亮
    $.each($links, function(i, a) {
        //后面的判断弥补如新闻详情页的菜单选中状态
        if (rel == a ) {
            $(this).addClass("on");
            $(this).parents("ul").show();
        }
    });
  
})
  

function setHomePage() {
    var host = location.href;
    host = host.replace("//", "#");
    host = host.substr(0, host.indexOf("/")).replace("#", "//");
    if (document.all) {
        document.body.style.behavior = 'url(#default#homepage)';
        document.body.setHomePage(host);
    }
    else if (window.sidebar) {
        if (window.netscape) {
            try {
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
            }
            catch (e) {
                alert("该操作被浏览器拒绝，如果想启用该功能，请在地址栏内输入 about:config,然后将项 signed.applets.codebase_principal_support 值该为true");
            }
        }
        var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
        prefs.setCharPref('browser.startup.homepage', host);
    }
}


function addFavorite() {
    var title = document.title;
    var url = location.href;
    if (window.sidebar) {
        window.sidebar.addPanel(title, url, "");
    }
    else if (document.all) {
        window.external.AddFavorite(url, title);
    }
    else {
        return true;
    }
}

